gh-91924: Fix __lltrace__ for non-UTF-8 stdout encoding#93199
gh-91924: Fix __lltrace__ for non-UTF-8 stdout encoding#93199vstinner merged 2 commits intopython:mainfrom vstinner:fix_lltrace
Conversation
|
Python 3.10 is also affected: lltrace must be set to 0 in prtrace(). In Python 3.10, the feature is enabled by setting |
|
Making |
|
The |
Fix __lltrace__ debug feature if the stdout encoding is not UTF-8. If the stdout encoding is not UTF-8, the first call to lltrace_resume_frame() indirectly sets lltrace to 0 when calling unicode_check_encoding_errors() which calls encodings.search_function().
|
My first implementation set lltrace to 1 at the end of lltrace_instruction() and lltrace_resume_frame() to workaround side effects of recusive calls to _PyEval_EvalFrame(). diff --git a/Python/ceval.c b/Python/ceval.c
index 230198b41f6a5..4d4681099e0df 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -148,6 +148,9 @@ lltrace_instruction(_PyInterpreterFrame *frame,
printf("%d: %s\n", offset * 2, opname);
}
fflush(stdout);
+
+ // gh-91924: PyObject_Print() can indirectly set lltrace to 0
+ lltrace = 1;
}
static void
lltrace_resume_frame(_PyInterpreterFrame *frame)
@@ -179,6 +182,9 @@ lltrace_resume_frame(_PyInterpreterFrame *frame)
printf("\n");
fflush(stdout);
PyErr_Restore(type, value, traceback);
+
+ // gh-91924: PyObject_Print() can indirectly set lltrace to 0
+ lltrace = 1;
}
#endif
static int call_trace(Py_tracefunc, PyObject *,But @sweeneyde is right, making the variable local is enough. I updated my PR. |
|
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
|
GH-93212 is a backport of this pull request to the 3.11 branch. |
…GH-93199) Fix __lltrace__ debug feature if the stdout encoding is not UTF-8. If the stdout encoding is not UTF-8, the first call to lltrace_resume_frame() indirectly sets lltrace to 0 when calling unicode_check_encoding_errors() which calls encodings.search_function(). (cherry picked from commit 5695c0e) Co-authored-by: Victor Stinner <vstinner@python.org>
Fix __lltrace__ debug feature if the stdout encoding is not UTF-8. If the stdout encoding is not UTF-8, the first call to lltrace_resume_frame() indirectly sets lltrace to 0 when calling unicode_check_encoding_errors() which calls encodings.search_function(). (cherry picked from commit 5695c0e) Co-authored-by: Victor Stinner <vstinner@python.org>
|
In the 3.10 branch, making lltrace variable local would require to change call_function(). I prefer to minimize changes and so I wrote a simpler change: PR #93214. |
Fix lltrace debug feature if the stdout encoding is not UTF-8.
If the stdout encoding is not UTF-8, the first call to
lltrace_resume_frame() indirectly sets lltrace to 0 when calling
unicode_check_encoding_errors() which calls
encodings.search_function().