-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-91924: Fix __lltrace__ for non-UTF-8 stdout encoding #93199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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 <[email protected]>
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 <[email protected]>
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().