summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-04-28 23:28:13 (GMT)
committerGitHub <noreply@github.com>2020-04-28 23:28:13 (GMT)
commit8852ad4208e34825f74e24945edb5bcf055d94fe (patch)
tree157f239ba46634301e136f4662b1646f7258357e /Python
parent5e8c691594d68925213d36296ce7c4b3e90bcb1d (diff)
downloadcpython-8852ad4208e34825f74e24945edb5bcf055d94fe.zip
cpython-8852ad4208e34825f74e24945edb5bcf055d94fe.tar.gz
cpython-8852ad4208e34825f74e24945edb5bcf055d94fe.tar.bz2
bpo-40429: PyFrame_GetCode() now returns a strong reference (GH-19773)
Diffstat (limited to 'Python')
-rw-r--r--Python/_warnings.c6
-rw-r--r--Python/import.c1
-rw-r--r--Python/traceback.c13
3 files changed, 12 insertions, 8 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 7a620dc..7c15ce0 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -785,6 +785,8 @@ is_internal_frame(PyFrameObject *frame)
PyCodeObject *code = PyFrame_GetCode(frame);
PyObject *filename = code->co_filename;
+ Py_DECREF(code);
+
if (filename == NULL) {
return 0;
}
@@ -850,7 +852,9 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
}
else {
globals = f->f_globals;
- *filename = PyFrame_GetCode(f)->co_filename;
+ PyCodeObject *code = PyFrame_GetCode(f);
+ *filename = code->co_filename;
+ Py_DECREF(code);
Py_INCREF(*filename);
*lineno = PyFrame_GetLineNumber(f);
}
diff --git a/Python/import.c b/Python/import.c
index 9142ebb..8c94e0e 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1557,6 +1557,7 @@ remove_importlib_frames(PyThreadState *tstate)
else {
prev_link = (PyObject **) &traceback->tb_next;
}
+ Py_DECREF(code);
tb = next;
}
done:
diff --git a/Python/traceback.c b/Python/traceback.c
index 1ea6cba..438a2c4 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -581,6 +581,7 @@ tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit)
err = PyErr_CheckSignals();
}
}
+ Py_DECREF(code);
tb = tb->tb_next;
}
if (err == 0 && cnt > TB_RECURSIVE_CUTOFF) {
@@ -752,12 +753,9 @@ _Py_DumpASCII(int fd, PyObject *text)
static void
dump_frame(int fd, PyFrameObject *frame)
{
- PyCodeObject *code;
- int lineno;
-
- code = PyFrame_GetCode(frame);
+ PyCodeObject *code = PyFrame_GetCode(frame);
PUTS(fd, " File ");
- if (code != NULL && code->co_filename != NULL
+ if (code->co_filename != NULL
&& PyUnicode_Check(code->co_filename))
{
PUTS(fd, "\"");
@@ -768,7 +766,7 @@ dump_frame(int fd, PyFrameObject *frame)
}
/* PyFrame_GetLineNumber() was introduced in Python 2.7.0 and 3.2.0 */
- lineno = PyCode_Addr2Line(code, frame->f_lasti);
+ int lineno = PyCode_Addr2Line(code, frame->f_lasti);
PUTS(fd, ", line ");
if (lineno >= 0) {
_Py_DumpDecimal(fd, (unsigned long)lineno);
@@ -778,7 +776,7 @@ dump_frame(int fd, PyFrameObject *frame)
}
PUTS(fd, " in ");
- if (code != NULL && code->co_name != NULL
+ if (code->co_name != NULL
&& PyUnicode_Check(code->co_name)) {
_Py_DumpASCII(fd, code->co_name);
}
@@ -787,6 +785,7 @@ dump_frame(int fd, PyFrameObject *frame)
}
PUTS(fd, "\n");
+ Py_DECREF(code);
}
static void