aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Python/pythonrun.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2023-10-03 23:32:21 +0300
committershadchin <shadchin@yandex-team.com>2023-10-03 23:48:51 +0300
commit01ffd024041ac933854c367fb8d1b5682d19883f (patch)
treeb70aa497ba132a133ccece49f7763427dcd0743f /contrib/tools/python3/src/Python/pythonrun.c
parenta33fdb9a34581fd124e92535153b1f1fdeca6aaf (diff)
downloadydb-01ffd024041ac933854c367fb8d1b5682d19883f.tar.gz
Update Python 3 to 3.11.6
Diffstat (limited to 'contrib/tools/python3/src/Python/pythonrun.c')
-rw-r--r--contrib/tools/python3/src/Python/pythonrun.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/contrib/tools/python3/src/Python/pythonrun.c b/contrib/tools/python3/src/Python/pythonrun.c
index 03e366a8d0..91c2ad3a13 100644
--- a/contrib/tools/python3/src/Python/pythonrun.c
+++ b/contrib/tools/python3/src/Python/pythonrun.c
@@ -1130,21 +1130,16 @@ error:
}
static int
-print_exception_notes(struct exception_print_context *ctx, PyObject *value)
+print_exception_notes(struct exception_print_context *ctx, PyObject *notes)
{
PyObject *f = ctx->file;
- if (!PyExceptionInstance_Check(value)) {
+ if (notes == NULL) {
return 0;
}
- PyObject *notes;
- int res = _PyObject_LookupAttr(value, &_Py_ID(__notes__), &notes);
- if (res <= 0) {
- return res;
- }
if (!PySequence_Check(notes)) {
- res = 0;
+ int res = 0;
if (write_indented_margin(ctx, f) < 0) {
res = -1;
}
@@ -1157,7 +1152,6 @@ print_exception_notes(struct exception_print_context *ctx, PyObject *value)
res = PyFile_WriteObject(s, f, Py_PRINT_RAW);
Py_DECREF(s);
}
- Py_DECREF(notes);
return res;
}
Py_ssize_t num_notes = PySequence_Length(notes);
@@ -1199,17 +1193,16 @@ print_exception_notes(struct exception_print_context *ctx, PyObject *value)
}
}
- Py_DECREF(notes);
return 0;
error:
Py_XDECREF(lines);
- Py_DECREF(notes);
return -1;
}
static int
print_exception(struct exception_print_context *ctx, PyObject *value)
{
+ PyObject *notes = NULL;
PyObject *f = ctx->file;
if (!PyExceptionInstance_Check(value)) {
@@ -1223,8 +1216,11 @@ print_exception(struct exception_print_context *ctx, PyObject *value)
goto error;
}
- /* grab the type now because value can change below */
+ /* grab the type and notes now because value can change below */
PyObject *type = (PyObject *) Py_TYPE(value);
+ if (_PyObject_LookupAttr(value, &_Py_ID(__notes__), &notes) < 0) {
+ goto error;
+ }
if (print_exception_file_and_line(ctx, &value) < 0) {
goto error;
@@ -1238,14 +1234,16 @@ print_exception(struct exception_print_context *ctx, PyObject *value)
if (PyFile_WriteString("\n", f) < 0) {
goto error;
}
- if (print_exception_notes(ctx, value) < 0) {
+ if (print_exception_notes(ctx, notes) < 0) {
goto error;
}
+ Py_XDECREF(notes);
Py_DECREF(value);
assert(!PyErr_Occurred());
return 0;
error:
+ Py_XDECREF(notes);
Py_DECREF(value);
return -1;
}