Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
dedba1f
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 15, 2022
494a3a5
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 15, 2022
1865ac8
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 15, 2022
affb018
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 15, 2022
f15aa44
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 15, 2022
18f79a7
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 15, 2022
ed98ae3
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 15, 2022
c99b286
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 15, 2022
551256b
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 15, 2022
165d763
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 15, 2022
3e79c5c
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 15, 2022
dd4f5bb
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 15, 2022
0ce3fef
📜🤖 Added by blurb_it.
blurb-it[bot] May 16, 2022
00d8452
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 16, 2022
c6c5d9d
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 16, 2022
801b237
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 16, 2022
867b182
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 16, 2022
2f04d08
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 16, 2022
47b8756
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 16, 2022
13b9a52
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 16, 2022
0403cbb
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 16, 2022
2f3d44d
bpo-43950: Implement fine grained error locations for interactive mode
thatbirdguythatuknownot May 16, 2022
72f9079
Update peg_extension.c
thatbirdguythatuknownot May 16, 2022
847e77f
Don't try to get the source of the file
thatbirdguythatuknownot May 16, 2022
f12ac1b
Don't get the source of the file
thatbirdguythatuknownot May 16, 2022
b1fb696
Handle the case of <string>
thatbirdguythatuknownot May 17, 2022
bc5b734
Use `Py_XINCREF` instead of `Py_INCREF`
thatbirdguythatuknownot May 17, 2022
d401e86
Skip file-related operations when file is either `<stdin>` or `<string>`
thatbirdguythatuknownot May 17, 2022
a910c19
Py_INCREF the source line to prevent negative reference count
thatbirdguythatuknownot May 20, 2022
5dab69e
Get proper line from possible multilined statement
thatbirdguythatuknownot May 20, 2022
10a0796
Update traceback.c
thatbirdguythatuknownot May 20, 2022
29141b8
Get proper length of the unicode string
thatbirdguythatuknownot May 20, 2022
5345744
Merge branch 'main' into patch-22
thatbirdguythatuknownot Jun 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-43950: Implement fine grained error locations for interactive mode
  • Loading branch information
thatbirdguythatuknownot authored May 15, 2022
commit f15aa448e2374a9bb90d31495dabf6bf0c451c7f
48 changes: 38 additions & 10 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extern "C" {
/* Forward */
static void flush_io(void);
static PyObject *run_mod(mod_ty, PyObject *, PyObject *, PyObject *,
PyCompilerFlags *, PyArena *);
PyCompilerFlags *, PyObject *, PyArena *);
static PyObject *run_pyc_file(FILE *, PyObject *, PyObject *,
PyCompilerFlags *);
static int PyRun_InteractiveOneObjectEx(FILE *, PyObject *, PyCompilerFlags *);
Expand Down Expand Up @@ -237,8 +237,9 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename,
return -1;
}

mod = _PyParser_ASTFromFile(fp, filename, enc, Py_single_input,
ps1, ps2, flags, &errcode, arena);
PyObject *interactive_src = NULL;
mod = _PyParser_InteractiveASTFromFile(fp, filename, enc, Py_single_input,
ps1, ps2, flags, &errcode, &interactive_src, arena);

Py_XDECREF(v);
Py_XDECREF(w);
Expand All @@ -257,7 +258,7 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename,
return -1;
}
d = PyModule_GetDict(m);
v = run_mod(mod, filename, d, d, flags, arena);
v = run_mod(mod, filename, d, d, flags, interactive_src, arena);
_PyArena_Free(arena);
if (v == NULL) {
return -1;
Expand Down Expand Up @@ -1600,8 +1601,14 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals,
mod = _PyParser_ASTFromString(
str, &_Py_STR(anon_string), start, flags, arena);

if (mod != NULL)
ret = run_mod(mod, &_Py_STR(anon_string), globals, locals, flags, arena);
if (mod != NULL) {
PyObject *string = PyUnicode_FromString(str);
if (string == NULL) {
_PyArena_Free(arena);
return NULL;
}
ret = run_mod(mod, &_Py_STR(anon_string), globals, locals, flags, string, arena);
}
_PyArena_Free(arena);
return ret;
}
Expand All @@ -1626,7 +1633,23 @@ pyrun_file(FILE *fp, PyObject *filename, int start, PyObject *globals,

PyObject *ret;
if (mod != NULL) {
ret = run_mod(mod, filename, globals, locals, flags, arena);
/* TODO: either a better way to get the source or
do not provide a source at all */
rewind(fp);
fseek(fp, 0, SEEK_END);
Py_ssize_t size = ftell(fp);
PyObject *src = PyUnicode_New(size, 0x10ffff);
if (src == NULL) {
_PyArena_Free(arena);
return NULL;
}
Py_ssize_t read_size = fread(PyUnicode_DATA(src), sizeof(char), size, fp);
if (size != read_size) {
Py_DECREF(src);
_PyArena_Free(arena);
return NULL;
}
ret = run_mod(mod, filename, globals, locals, flags, src, arena);
}
else {
ret = NULL;
Expand Down Expand Up @@ -1719,10 +1742,10 @@ run_eval_code_obj(PyThreadState *tstate, PyCodeObject *co, PyObject *globals, Py

static PyObject *
run_mod(mod_ty mod, PyObject *filename, PyObject *globals, PyObject *locals,
PyCompilerFlags *flags, PyArena *arena)
PyCompilerFlags *flags, PyObject *src, PyArena *arena)
{
PyThreadState *tstate = _PyThreadState_GET();
PyCodeObject *co = _PyAST_Compile(mod, filename, flags, -1, arena);
PyCodeObject *co = _PyAST_Compile(mod, src, filename, flags, -1, arena);
if (co == NULL)
return NULL;

Expand Down Expand Up @@ -1799,7 +1822,12 @@ Py_CompileStringObject(const char *str, PyObject *filename, int start,
_PyArena_Free(arena);
return result;
}
co = _PyAST_Compile(mod, filename, flags, optimize, arena);
PyObject *string = PyUnicode_FromString(str);
if (string == NULL) {
_PyArena_Free(arena);
return NULL;
}
co = _PyAST_Compile(mod, string, filename, flags, optimize, arena);
_PyArena_Free(arena);
return (PyObject *)co;
}
Expand Down