diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2023-10-13 09:25:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-13 09:25:37 (GMT) |
commit | e1d8c65e1df990ef8d61b8912742e1a021395e78 (patch) | |
tree | 84956c1158b3baf33d9836a5a87b8fa6b57a0428 /Parser/pegen.c | |
parent | 898f531996f2c5399b13811682c578c4fd08afaa (diff) | |
download | cpython-e1d8c65e1df990ef8d61b8912742e1a021395e78.zip cpython-e1d8c65e1df990ef8d61b8912742e1a021395e78.tar.gz cpython-e1d8c65e1df990ef8d61b8912742e1a021395e78.tar.bz2 |
gh-110805: Allow the repl to show source code and complete tracebacks (#110775)
Diffstat (limited to 'Parser/pegen.c')
-rw-r--r-- | Parser/pegen.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c index 2e0b569..0c60394 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -878,7 +878,8 @@ _PyPegen_run_parser(Parser *p) mod_ty _PyPegen_run_parser_from_file_pointer(FILE *fp, int start_rule, PyObject *filename_ob, const char *enc, const char *ps1, const char *ps2, - PyCompilerFlags *flags, int *errcode, PyArena *arena) + PyCompilerFlags *flags, int *errcode, + PyObject **interactive_src, PyArena *arena) { struct tok_state *tok = _PyTokenizer_FromFile(fp, enc, ps1, ps2); if (tok == NULL) { @@ -908,6 +909,15 @@ _PyPegen_run_parser_from_file_pointer(FILE *fp, int start_rule, PyObject *filena result = _PyPegen_run_parser(p); _PyPegen_Parser_Free(p); + if (tok->fp_interactive && tok->interactive_src_start && result && interactive_src != NULL) { + *interactive_src = PyUnicode_FromString(tok->interactive_src_start); + if (!interactive_src || _PyArena_AddPyObject(arena, *interactive_src) < 0) { + Py_XDECREF(interactive_src); + result = NULL; + goto error; + } + } + error: _PyTokenizer_Free(tok); return result; |