diff options
author | Victor Stinner <vstinner@python.org> | 2020-04-28 17:01:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-28 17:01:31 (GMT) |
commit | a42ca74fa30227e2f89a619332557cf093a937d5 (patch) | |
tree | a3097e76897d8f8a0f054cab0736fd3cff80f8da /Python/_warnings.c | |
parent | b8f704d2190125a7750b50cd9b67267b9c20fd43 (diff) | |
download | cpython-a42ca74fa30227e2f89a619332557cf093a937d5.zip cpython-a42ca74fa30227e2f89a619332557cf093a937d5.tar.gz cpython-a42ca74fa30227e2f89a619332557cf093a937d5.tar.bz2 |
bpo-40421: Add PyFrame_GetCode() function (GH-19757)
PyFrame_GetCode(frame): return a borrowed reference to the frame
code.
Replace frame->f_code with PyFrame_GetCode(frame) in most code,
except in frameobject.c, genobject.c and ceval.c.
Also add PyFrame_GetLineNumber() to the limited C API.
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r-- | Python/_warnings.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index f4ef0bb..91c611c 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -762,7 +762,6 @@ is_internal_frame(PyFrameObject *frame) { static PyObject *importlib_string = NULL; static PyObject *bootstrap_string = NULL; - PyObject *filename; int contains; if (importlib_string == NULL) { @@ -780,14 +779,23 @@ is_internal_frame(PyFrameObject *frame) Py_INCREF(bootstrap_string); } - if (frame == NULL || frame->f_code == NULL || - frame->f_code->co_filename == NULL) { + if (frame == NULL) { + return 0; + } + + PyCodeObject *code = PyFrame_GetCode(frame); + if (code == NULL) { + return 0; + } + + PyObject *filename = code->co_filename; + if (filename == NULL) { return 0; } - filename = frame->f_code->co_filename; if (!PyUnicode_Check(filename)) { return 0; } + contains = PyUnicode_Contains(filename, importlib_string); if (contains < 0) { return 0; @@ -846,7 +854,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, } else { globals = f->f_globals; - *filename = f->f_code->co_filename; + *filename = PyFrame_GetCode(f)->co_filename; Py_INCREF(*filename); *lineno = PyFrame_GetLineNumber(f); } |