-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-137576: Fix for Basic REPL Showing Incorrect Code in Tracebacks with PYTHONSTARTUP #137625
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
2f30324
e93e161
3d46e8f
29cff26
c2fce15
752aea7
bae05c7
a86a32f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fix for incorrect source code being shown in tracebacks from the Basic REPL | ||
when ``PYTHONSTARTUP`` is given. Patch by Adam Hartz. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1365,6 +1365,25 @@ run_eval_code_obj(PyThreadState *tstate, PyCodeObject *co, PyObject *globals, Py | |
return PyEval_EvalCode((PyObject*)co, globals, locals); | ||
} | ||
|
||
static PyObject * | ||
get_interactive_filename(PyObject *filename, Py_ssize_t count){ | ||
adqm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PyObject *result; | ||
Py_ssize_t len = PyUnicode_GET_LENGTH(filename); | ||
|
||
if (len >= 2 | ||
&& PyUnicode_ReadChar(filename, 0) == '<' | ||
&& PyUnicode_ReadChar(filename, len - 1) == '>') { | ||
PyObject *middle = PyUnicode_Substring(filename, 1, len-1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add error checks for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review!
Yep, I added a check there.
I think this one is already handled, on lines 1406-1408 (which happen just after
|
||
result = PyUnicode_FromFormat("<%U-%d>", middle, count); | ||
Py_DECREF(middle); | ||
} else { | ||
result = PyUnicode_FromFormat( | ||
"%U-%d", filename, count); | ||
} | ||
return result; | ||
|
||
} | ||
|
||
static PyObject * | ||
run_mod(mod_ty mod, PyObject *filename, PyObject *globals, PyObject *locals, | ||
PyCompilerFlags *flags, PyArena *arena, PyObject* interactive_src, | ||
|
@@ -1375,8 +1394,8 @@ run_mod(mod_ty mod, PyObject *filename, PyObject *globals, PyObject *locals, | |
if (interactive_src) { | ||
PyInterpreterState *interp = tstate->interp; | ||
if (generate_new_source) { | ||
interactive_filename = PyUnicode_FromFormat( | ||
"%U-%d", filename, interp->_interactive_src_count++); | ||
interactive_filename = get_interactive_filename( | ||
filename, interp->_interactive_src_count++); | ||
} else { | ||
Py_INCREF(interactive_filename); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.