aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Python
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2023-12-13 02:43:57 +0300
committershadchin <shadchin@yandex-team.com>2023-12-13 03:08:48 +0300
commit5b48aabc614c6d407f885f3b228dc484ad4c5ba9 (patch)
tree602eb5cc5d85bf730c1de1fa50a13c2ee552830d /contrib/tools/python3/src/Python
parent35d7049b38602e8cbfcd3f96257329a1abce947e (diff)
downloadydb-5b48aabc614c6d407f885f3b228dc484ad4c5ba9.tar.gz
Update Python 3 to 3.11.7
Diffstat (limited to 'contrib/tools/python3/src/Python')
-rw-r--r--contrib/tools/python3/src/Python/ceval.c19
-rw-r--r--contrib/tools/python3/src/Python/deepfreeze/deepfreeze.c95
-rw-r--r--contrib/tools/python3/src/Python/getargs.c2
-rw-r--r--contrib/tools/python3/src/Python/import.c15
-rw-r--r--contrib/tools/python3/src/Python/traceback.c73
5 files changed, 142 insertions, 62 deletions
diff --git a/contrib/tools/python3/src/Python/ceval.c b/contrib/tools/python3/src/Python/ceval.c
index df11de084d..bb6bb35030 100644
--- a/contrib/tools/python3/src/Python/ceval.c
+++ b/contrib/tools/python3/src/Python/ceval.c
@@ -1060,7 +1060,9 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
}
if (match_self) {
// Easy. Copy the subject itself, and move on to kwargs.
- PyList_Append(attrs, subject);
+ if (PyList_Append(attrs, subject) < 0) {
+ goto fail;
+ }
}
else {
for (Py_ssize_t i = 0; i < nargs; i++) {
@@ -1076,7 +1078,10 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
if (attr == NULL) {
goto fail;
}
- PyList_Append(attrs, attr);
+ if (PyList_Append(attrs, attr) < 0) {
+ Py_DECREF(attr);
+ goto fail;
+ }
Py_DECREF(attr);
}
}
@@ -1089,7 +1094,10 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
if (attr == NULL) {
goto fail;
}
- PyList_Append(attrs, attr);
+ if (PyList_Append(attrs, attr) < 0) {
+ Py_DECREF(attr);
+ goto fail;
+ }
Py_DECREF(attr);
}
Py_SETREF(attrs, PyList_AsTuple(attrs));
@@ -3310,13 +3318,14 @@ handle_eval_breaker:
&PEEK(2*oparg), 2,
&PEEK(2*oparg - 1), 2,
oparg);
- if (map == NULL)
- goto error;
while (oparg--) {
Py_DECREF(POP());
Py_DECREF(POP());
}
+ if (map == NULL) {
+ goto error;
+ }
PUSH(map);
DISPATCH();
}
diff --git a/contrib/tools/python3/src/Python/deepfreeze/deepfreeze.c b/contrib/tools/python3/src/Python/deepfreeze/deepfreeze.c
index 10274f6b5b..d704c00486 100644
--- a/contrib/tools/python3/src/Python/deepfreeze/deepfreeze.c
+++ b/contrib/tools/python3/src/Python/deepfreeze/deepfreeze.c
@@ -72164,46 +72164,6 @@ const_str_SEEK_END = {
};
static
struct {
- PyGC_Head _gc_head;
- struct {
- PyObject_VAR_HEAD
- PyObject *ob_item[19];
- }_object;
- }
-io_toplevel_consts_2 = {
- ._object = {
- .ob_base = {
- .ob_base = {
- .ob_refcnt = 999999999,
- .ob_type = &PyTuple_Type,
- },
- .ob_size = 19,
- },
- .ob_item = {
- & const_str_BlockingIOError._ascii.ob_base,
- &_Py_ID(open),
- & const_str_open_code._ascii.ob_base,
- & const_str_IOBase._ascii.ob_base,
- & const_str_RawIOBase._ascii.ob_base,
- & const_str_FileIO._ascii.ob_base,
- & const_str_BytesIO._ascii.ob_base,
- & const_str_StringIO._ascii.ob_base,
- & const_str_BufferedIOBase._ascii.ob_base,
- & const_str_BufferedReader._ascii.ob_base,
- & const_str_BufferedWriter._ascii.ob_base,
- & const_str_BufferedRWPair._ascii.ob_base,
- & const_str_BufferedRandom._ascii.ob_base,
- & const_str_TextIOBase._ascii.ob_base,
- &_Py_ID(TextIOWrapper),
- & const_str_UnsupportedOperation._ascii.ob_base,
- & const_str_SEEK_SET._ascii.ob_base,
- & const_str_SEEK_CUR._ascii.ob_base,
- & const_str_SEEK_END._ascii.ob_base,
- },
- },
-};
-static
- struct {
PyASCIIObject _ascii;
uint8_t _data[20];
}
@@ -72251,6 +72211,49 @@ static
PyGC_Head _gc_head;
struct {
PyObject_VAR_HEAD
+ PyObject *ob_item[22];
+ }_object;
+ }
+io_toplevel_consts_2 = {
+ ._object = {
+ .ob_base = {
+ .ob_base = {
+ .ob_refcnt = 999999999,
+ .ob_type = &PyTuple_Type,
+ },
+ .ob_size = 22,
+ },
+ .ob_item = {
+ & const_str_BlockingIOError._ascii.ob_base,
+ &_Py_ID(open),
+ & const_str_open_code._ascii.ob_base,
+ & const_str_IOBase._ascii.ob_base,
+ & const_str_RawIOBase._ascii.ob_base,
+ & const_str_FileIO._ascii.ob_base,
+ & const_str_BytesIO._ascii.ob_base,
+ & const_str_StringIO._ascii.ob_base,
+ & const_str_BufferedIOBase._ascii.ob_base,
+ & const_str_BufferedReader._ascii.ob_base,
+ & const_str_BufferedWriter._ascii.ob_base,
+ & const_str_BufferedRWPair._ascii.ob_base,
+ & const_str_BufferedRandom._ascii.ob_base,
+ & const_str_TextIOBase._ascii.ob_base,
+ &_Py_ID(TextIOWrapper),
+ & const_str_UnsupportedOperation._ascii.ob_base,
+ & const_str_SEEK_SET._ascii.ob_base,
+ & const_str_SEEK_CUR._ascii.ob_base,
+ & const_str_SEEK_END._ascii.ob_base,
+ & const_str_DEFAULT_BUFFER_SIZE._ascii.ob_base,
+ & const_str_text_encoding._ascii.ob_base,
+ & const_str_IncrementalNewlineDecoder._ascii.ob_base,
+ },
+ },
+};
+static
+ struct {
+ PyGC_Head _gc_head;
+ struct {
+ PyObject_VAR_HEAD
PyObject *ob_item[15];
}_object;
}
@@ -72509,7 +72512,7 @@ io_toplevel_consts_6 = {
.co_posonlyargcount = 0,
.co_kwonlyargcount = 0,
.co_stacksize = 6,
- .co_firstlineno = 60,
+ .co_firstlineno = 61,
.co_nlocalsplus = 2,
.co_nlocals = 2,
.co_nplaincellvars = 0,
@@ -72657,7 +72660,7 @@ io_toplevel_consts_10 = {
.co_posonlyargcount = 0,
.co_kwonlyargcount = 0,
.co_stacksize = 1,
- .co_firstlineno = 87,
+ .co_firstlineno = 88,
.co_nlocalsplus = 0,
.co_nlocals = 0,
.co_nplaincellvars = 0,
@@ -72783,7 +72786,7 @@ io_toplevel_consts_13 = {
.co_posonlyargcount = 0,
.co_kwonlyargcount = 0,
.co_stacksize = 1,
- .co_firstlineno = 90,
+ .co_firstlineno = 91,
.co_nlocalsplus = 0,
.co_nlocals = 0,
.co_nplaincellvars = 0,
@@ -72909,7 +72912,7 @@ io_toplevel_consts_15 = {
.co_posonlyargcount = 0,
.co_kwonlyargcount = 0,
.co_stacksize = 1,
- .co_firstlineno = 93,
+ .co_firstlineno = 94,
.co_nlocalsplus = 0,
.co_nlocals = 0,
.co_nplaincellvars = 0,
@@ -73035,7 +73038,7 @@ io_toplevel_consts_17 = {
.co_posonlyargcount = 0,
.co_kwonlyargcount = 0,
.co_stacksize = 1,
- .co_firstlineno = 96,
+ .co_firstlineno = 97,
.co_nlocalsplus = 0,
.co_nlocals = 0,
.co_nplaincellvars = 0,
@@ -73255,7 +73258,7 @@ io_toplevel_linetable = {
.ob_size = 713,
},
.ob_shash = -1,
- .ob_sval = "\xf0\x03\x01\x01\x01\xf0\x02\x21\x01\x04\xf0\x00\x21\x01\x04\xf0\x48\x01\x05\x0f\x38\x80\x0a\xf0\x0e\x04\x0b\x47\x01\xf0\x00\x04\x0b\x47\x01\xf0\x00\x04\x0b\x47\x01\x80\x07\xf0\x0e\x00\x01\x0b\x80\x0a\x80\x0a\x80\x0a\xd8\x00\x0a\x80\x0a\x80\x0a\x80\x0a\xf0\x04\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x0c\x0d\x01\x4b\x01\xf0\x00\x0d\x01\x4b\x01\xf0\x00\x0d\x01\x4b\x01\xf0\x22\x00\x23\x27\xd0\x00\x14\xd4\x00\x1f\xf0\x06\x00\x0c\x0d\x80\x08\xd8\x0b\x0c\x80\x08\xd8\x0b\x0c\x80\x08\xf0\x0a\x01\x01\x22\xf0\x00\x01\x01\x22\xf0\x00\x01\x01\x22\xf0\x00\x01\x01\x22\xf0\x00\x01\x01\x22\x88\x53\x8c\x5b\xa0\x43\xa4\x4b\xf0\x00\x01\x01\x22\xf1\x00\x01\x01\x22\xf4\x00\x01\x01\x22\xf0\x00\x01\x01\x22\xf0\x06\x01\x01\x25\xf0\x00\x01\x01\x25\xf0\x00\x01\x01\x25\xf0\x00\x01\x01\x25\xf0\x00\x01\x01\x25\x90\x03\x94\x0e\xa0\x06\xf1\x00\x01\x01\x25\xf4\x00\x01\x01\x25\xf0\x00\x01\x01\x25\xf0\x06\x01\x01\x2a\xf0\x00\x01\x01\x2a\xf0\x00\x01\x01\x2a\xf0\x00\x01\x01\x2a\xf0\x00\x01\x01\x2a\x90\x53\xd4\x15\x28\xa8\x26\xf1\x00\x01\x01\x2a\xf4\x00\x01\x01\x2a\xf0\x00\x01\x01\x2a\xf0\x06\x01\x01\x26\xf0\x00\x01\x01\x26\xf0\x00\x01\x01\x26\xf0\x00\x01\x01\x26\xf0\x00\x01\x01\x26\x90\x13\x94\x1f\xa0\x26\xf1\x00\x01\x01\x26\xf4\x00\x01\x01\x26\xf0\x00\x01\x01\x26\xf0\x06\x00\x01\x0a\xd7\x00\x12\xd2\x00\x12\x90\x36\xd1\x00\x1a\xd4\x00\x1a\xd0\x00\x1a\xe0\x0e\x15\x90\x7e\xa0\x7e\xb0\x7e\xd8\x0e\x1c\xf0\x03\x01\x0e\x1e\xf0\x00\x02\x01\x23\xf0\x00\x02\x01\x23\x80\x45\xe0\x04\x12\xd7\x04\x1b\xd2\x04\x1b\x98\x45\xd1\x04\x22\xd4\x04\x22\xd0\x04\x22\xd0\x04\x22\xe0\x0e\x16\x98\x0d\xd0\x0d\x26\xf0\x00\x01\x01\x1f\xf0\x00\x01\x01\x1f\x80\x45\xd8\x04\x0e\xd7\x04\x17\xd2\x04\x17\x98\x05\xd1\x04\x1e\xd4\x04\x1e\xd0\x04\x1e\xd0\x04\x1e\xd8\x04\x09\xf0\x04\x05\x01\x2a\xd8\x04\x25\xd0\x04\x25\xd0\x04\x25\xd0\x04\x25\xd0\x04\x25\xd0\x04\x25\xf0\x08\x00\x05\x0e\xd7\x04\x16\xd2\x04\x16\xd0\x17\x28\xd1\x04\x29\xd4\x04\x29\xd0\x04\x29\xd0\x04\x29\xd0\x04\x29\xf8\xf0\x07\x00\x08\x13\xf0\x00\x01\x01\x09\xf0\x00\x01\x01\x09\xf0\x00\x01\x01\x09\xd8\x04\x08\x80\x44\x80\x44\xf0\x03\x01\x01\x09\xf8\xf8\xf8",
+ .ob_sval = "\xf0\x03\x01\x01\x01\xf0\x02\x21\x01\x04\xf0\x00\x21\x01\x04\xf0\x48\x01\x05\x0f\x38\x80\x0a\xf0\x0e\x05\x0b\x50\x01\xf0\x00\x05\x0b\x50\x01\xf0\x00\x05\x0b\x50\x01\x80\x07\xf0\x10\x00\x01\x0b\x80\x0a\x80\x0a\x80\x0a\xd8\x00\x0a\x80\x0a\x80\x0a\x80\x0a\xf0\x04\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x00\x03\x01\x4a\x01\xf0\x0c\x0d\x01\x4b\x01\xf0\x00\x0d\x01\x4b\x01\xf0\x00\x0d\x01\x4b\x01\xf0\x22\x00\x23\x27\xd0\x00\x14\xd4\x00\x1f\xf0\x06\x00\x0c\x0d\x80\x08\xd8\x0b\x0c\x80\x08\xd8\x0b\x0c\x80\x08\xf0\x0a\x01\x01\x22\xf0\x00\x01\x01\x22\xf0\x00\x01\x01\x22\xf0\x00\x01\x01\x22\xf0\x00\x01\x01\x22\x88\x53\x8c\x5b\xa0\x43\xa4\x4b\xf0\x00\x01\x01\x22\xf1\x00\x01\x01\x22\xf4\x00\x01\x01\x22\xf0\x00\x01\x01\x22\xf0\x06\x01\x01\x25\xf0\x00\x01\x01\x25\xf0\x00\x01\x01\x25\xf0\x00\x01\x01\x25\xf0\x00\x01\x01\x25\x90\x03\x94\x0e\xa0\x06\xf1\x00\x01\x01\x25\xf4\x00\x01\x01\x25\xf0\x00\x01\x01\x25\xf0\x06\x01\x01\x2a\xf0\x00\x01\x01\x2a\xf0\x00\x01\x01\x2a\xf0\x00\x01\x01\x2a\xf0\x00\x01\x01\x2a\x90\x53\xd4\x15\x28\xa8\x26\xf1\x00\x01\x01\x2a\xf4\x00\x01\x01\x2a\xf0\x00\x01\x01\x2a\xf0\x06\x01\x01\x26\xf0\x00\x01\x01\x26\xf0\x00\x01\x01\x26\xf0\x00\x01\x01\x26\xf0\x00\x01\x01\x26\x90\x13\x94\x1f\xa0\x26\xf1\x00\x01\x01\x26\xf4\x00\x01\x01\x26\xf0\x00\x01\x01\x26\xf0\x06\x00\x01\x0a\xd7\x00\x12\xd2\x00\x12\x90\x36\xd1\x00\x1a\xd4\x00\x1a\xd0\x00\x1a\xe0\x0e\x15\x90\x7e\xa0\x7e\xb0\x7e\xd8\x0e\x1c\xf0\x03\x01\x0e\x1e\xf0\x00\x02\x01\x23\xf0\x00\x02\x01\x23\x80\x45\xe0\x04\x12\xd7\x04\x1b\xd2\x04\x1b\x98\x45\xd1\x04\x22\xd4\x04\x22\xd0\x04\x22\xd0\x04\x22\xe0\x0e\x16\x98\x0d\xd0\x0d\x26\xf0\x00\x01\x01\x1f\xf0\x00\x01\x01\x1f\x80\x45\xd8\x04\x0e\xd7\x04\x17\xd2\x04\x17\x98\x05\xd1\x04\x1e\xd4\x04\x1e\xd0\x04\x1e\xd0\x04\x1e\xd8\x04\x09\xf0\x04\x05\x01\x2a\xd8\x04\x25\xd0\x04\x25\xd0\x04\x25\xd0\x04\x25\xd0\x04\x25\xd0\x04\x25\xf0\x08\x00\x05\x0e\xd7\x04\x16\xd2\x04\x16\xd0\x17\x28\xd1\x04\x29\xd4\x04\x29\xd0\x04\x29\xd0\x04\x29\xd0\x04\x29\xf8\xf0\x07\x00\x08\x13\xf0\x00\x01\x01\x09\xf0\x00\x01\x01\x09\xf0\x00\x01\x01\x09\xd8\x04\x08\x80\x44\x80\x44\xf0\x03\x01\x01\x09\xf8\xf8\xf8",
};
static
struct {
diff --git a/contrib/tools/python3/src/Python/getargs.c b/contrib/tools/python3/src/Python/getargs.c
index 3105bd556c..e18d771992 100644
--- a/contrib/tools/python3/src/Python/getargs.c
+++ b/contrib/tools/python3/src/Python/getargs.c
@@ -522,7 +522,7 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
}
else if (c == ':' || c == ';' || c == '\0')
break;
- else if (level == 0 && Py_ISALPHA(c))
+ else if (level == 0 && Py_ISALPHA(c) && c != 'e')
n++;
}
diff --git a/contrib/tools/python3/src/Python/import.c b/contrib/tools/python3/src/Python/import.c
index 3c3e76ca43..f1c9b478b2 100644
--- a/contrib/tools/python3/src/Python/import.c
+++ b/contrib/tools/python3/src/Python/import.c
@@ -951,11 +951,22 @@ PyImport_GetImporter(PyObject *path)
{
PyThreadState *tstate = _PyThreadState_GET();
PyObject *path_importer_cache = PySys_GetObject("path_importer_cache");
+ if (path_importer_cache == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "lost sys.path_importer_cache");
+ return NULL;
+ }
+ Py_INCREF(path_importer_cache);
PyObject *path_hooks = PySys_GetObject("path_hooks");
- if (path_importer_cache == NULL || path_hooks == NULL) {
+ if (path_hooks == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "lost sys.path_hooks");
+ Py_DECREF(path_importer_cache);
return NULL;
}
- return get_path_importer(tstate, path_importer_cache, path_hooks, path);
+ Py_INCREF(path_hooks);
+ PyObject *importer = get_path_importer(tstate, path_importer_cache, path_hooks, path);
+ Py_DECREF(path_hooks);
+ Py_DECREF(path_importer_cache);
+ return importer;
}
#if defined(__EMSCRIPTEN__) && defined(PY_CALL_TRAMPOLINE)
diff --git a/contrib/tools/python3/src/Python/traceback.c b/contrib/tools/python3/src/Python/traceback.c
index c4f5ec877b..722f007459 100644
--- a/contrib/tools/python3/src/Python/traceback.c
+++ b/contrib/tools/python3/src/Python/traceback.c
@@ -112,6 +112,29 @@ tb_next_get(PyTracebackObject *self, void *Py_UNUSED(_))
}
static int
+tb_get_lineno(PyTracebackObject* tb) {
+ PyFrameObject* frame = tb->tb_frame;
+ assert(frame != NULL);
+ PyCodeObject *code = PyFrame_GetCode(frame);
+ int lineno = PyCode_Addr2Line(code, tb->tb_lasti);
+ Py_DECREF(code);
+ return lineno;
+}
+
+static PyObject *
+tb_lineno_get(PyTracebackObject *self, void *Py_UNUSED(_))
+{
+ int lineno = self->tb_lineno;
+ if (lineno == -1) {
+ lineno = tb_get_lineno(self);
+ if (lineno < 0) {
+ Py_RETURN_NONE;
+ }
+ }
+ return PyLong_FromLong(lineno);
+}
+
+static int
tb_next_set(PyTracebackObject *self, PyObject *new_next, void *Py_UNUSED(_))
{
if (!new_next) {
@@ -157,12 +180,12 @@ static PyMethodDef tb_methods[] = {
static PyMemberDef tb_memberlist[] = {
{"tb_frame", T_OBJECT, OFF(tb_frame), READONLY|PY_AUDIT_READ},
{"tb_lasti", T_INT, OFF(tb_lasti), READONLY},
- {"tb_lineno", T_INT, OFF(tb_lineno), READONLY},
{NULL} /* Sentinel */
};
static PyGetSetDef tb_getsetters[] = {
{"tb_next", (getter)tb_next_get, (setter)tb_next_set, NULL, NULL},
+ {"tb_lineno", (getter)tb_lineno_get, NULL, NULL, NULL},
{NULL} /* Sentinel */
};
@@ -241,8 +264,7 @@ _PyTraceBack_FromFrame(PyObject *tb_next, PyFrameObject *frame)
assert(tb_next == NULL || PyTraceBack_Check(tb_next));
assert(frame != NULL);
int addr = _PyInterpreterFrame_LASTI(frame->f_frame) * sizeof(_Py_CODEUNIT);
- return tb_create_raw((PyTracebackObject *)tb_next, frame, addr,
- PyFrame_GetLineNumber(frame));
+ return tb_create_raw((PyTracebackObject *)tb_next, frame, addr, -1);
}
@@ -907,8 +929,39 @@ tb_displayline(PyTracebackObject* tb, PyObject *f, PyObject *filename, int linen
goto done;
}
- if (print_error_location_carets(f, truncation, start_offset, end_offset,
- right_start_offset, left_end_offset,
+ // Convert all offsets to display offsets (e.g. the space they would take up if printed
+ // on the screen).
+ Py_ssize_t dp_start = _PyPegen_calculate_display_width(source_line, start_offset);
+ if (dp_start < 0) {
+ err = ignore_source_errors() < 0;
+ goto done;
+ }
+
+ Py_ssize_t dp_end = _PyPegen_calculate_display_width(source_line, end_offset);
+ if (dp_end < 0) {
+ err = ignore_source_errors() < 0;
+ goto done;
+ }
+
+ Py_ssize_t dp_left_end = -1;
+ Py_ssize_t dp_right_start = -1;
+ if (has_secondary_ranges) {
+ dp_left_end = _PyPegen_calculate_display_width(source_line, left_end_offset);
+ if (dp_left_end < 0) {
+ err = ignore_source_errors() < 0;
+ goto done;
+ }
+
+ dp_right_start = _PyPegen_calculate_display_width(source_line, right_start_offset);
+ if (dp_right_start < 0) {
+ err = ignore_source_errors() < 0;
+ goto done;
+ }
+ }
+
+
+ if (print_error_location_carets(f, truncation, dp_start, dp_end,
+ dp_right_start, dp_left_end,
primary_error_char, secondary_error_char) < 0) {
err = -1;
goto done;
@@ -959,9 +1012,13 @@ tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit,
}
while (tb != NULL) {
code = PyFrame_GetCode(tb->tb_frame);
+ int tb_lineno = tb->tb_lineno;
+ if (tb_lineno == -1) {
+ tb_lineno = tb_get_lineno(tb);
+ }
if (last_file == NULL ||
code->co_filename != last_file ||
- last_line == -1 || tb->tb_lineno != last_line ||
+ last_line == -1 || tb_lineno != last_line ||
last_name == NULL || code->co_name != last_name) {
if (cnt > TB_RECURSIVE_CUTOFF) {
if (tb_print_line_repeated(f, cnt) < 0) {
@@ -969,13 +1026,13 @@ tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit,
}
}
last_file = code->co_filename;
- last_line = tb->tb_lineno;
+ last_line = tb_lineno;
last_name = code->co_name;
cnt = 0;
}
cnt++;
if (cnt <= TB_RECURSIVE_CUTOFF) {
- if (tb_displayline(tb, f, code->co_filename, tb->tb_lineno,
+ if (tb_displayline(tb, f, code->co_filename, tb_lineno,
tb->tb_frame, code->co_name, indent, margin) < 0) {
goto error;
}