summaryrefslogtreecommitdiffstats
path: root/Python/_warnings.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-04-29 01:28:46 (GMT)
committerGitHub <noreply@github.com>2020-04-29 01:28:46 (GMT)
commit703647732359200c54f1d2e695cc3a06b9a96c9a (patch)
treef0ccd7a79f270fe9d7c3cba896461f3f7528131b /Python/_warnings.c
parent66abe98a816de84f89e2de4aa78cf09056227c25 (diff)
downloadcpython-703647732359200c54f1d2e695cc3a06b9a96c9a.zip
cpython-703647732359200c54f1d2e695cc3a06b9a96c9a.tar.gz
cpython-703647732359200c54f1d2e695cc3a06b9a96c9a.tar.bz2
bpo-40421: Add PyFrame_GetBack() function (GH-19765)
New PyFrame_GetBack() function: get the frame next outer frame. Replace frame->f_back with PyFrame_GetBack(frame) in most code but frameobject.c, ceval.c and genobject.c.
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 7c15ce0..4d65bb3 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -3,7 +3,7 @@
#include "pycore_interp.h" // PyInterpreterState.warnings
#include "pycore_pyerrors.h"
#include "pycore_pystate.h" // _PyThreadState_GET()
-#include "frameobject.h"
+#include "frameobject.h" // PyFrame_GetBack()
#include "clinic/_warnings.c.h"
#define MODULE_NAME "_warnings"
@@ -815,7 +815,9 @@ static PyFrameObject *
next_external_frame(PyFrameObject *frame)
{
do {
- frame = frame->f_back;
+ PyFrameObject *back = PyFrame_GetBack(frame);
+ Py_DECREF(frame);
+ frame = back;
} while (frame != NULL && is_internal_frame(frame));
return frame;
@@ -831,12 +833,15 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
PyObject *globals;
/* Setup globals, filename and lineno. */
- PyFrameObject *f = _PyThreadState_GET()->frame;
+ PyThreadState *tstate = _PyThreadState_GET();
+ PyFrameObject *f = PyThreadState_GetFrame(tstate);
// Stack level comparisons to Python code is off by one as there is no
// warnings-related stack level to avoid.
if (stack_level <= 0 || is_internal_frame(f)) {
while (--stack_level > 0 && f != NULL) {
- f = f->f_back;
+ PyFrameObject *back = PyFrame_GetBack(f);
+ Py_DECREF(f);
+ f = back;
}
}
else {
@@ -857,6 +862,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
Py_DECREF(code);
Py_INCREF(*filename);
*lineno = PyFrame_GetLineNumber(f);
+ Py_DECREF(f);
}
*module = NULL;
@@ -868,7 +874,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
if (*registry == NULL) {
int rc;
- if (PyErr_Occurred()) {
+ if (_PyErr_Occurred(tstate)) {
goto handle_error;
}
*registry = PyDict_New();
@@ -887,7 +893,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
if (*module == Py_None || (*module != NULL && PyUnicode_Check(*module))) {
Py_INCREF(*module);
}
- else if (PyErr_Occurred()) {
+ else if (_PyErr_Occurred(tstate)) {
goto handle_error;
}
else {