| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1074,10 +1074,10 @@ All of the following functions must be called after :c:func:`Py_Initialize`. | |||
| 1074 | 1074 | ||
| 1075 | 1075 | .. c:function:: PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate) | |
| 1076 | 1076 | ||
| 1077 | - Get a borrowed reference to the current frame of the Python thread state | ||
| 1078 | - *tstate*. | ||
| 1077 | + Get the current frame of the Python thread state *tstate*. | ||
| 1079 | 1078 | ||
| 1080 | - Return ``NULL`` if no frame is currently executing. | ||
| 1079 | + Return a strong reference. Return ``NULL`` if no frame is currently | ||
| 1080 | + executing. | ||
| 1081 | 1081 | ||
| 1082 | 1082 | See also :c:func:`PyEval_GetFrame`. | |
| 1083 | 1083 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + The :c:func:`PyThreadState_GetFrame` function now returns a strong reference | ||
| 2 | + to the frame. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -425,18 +425,16 @@ traceback_hash(traceback_t *traceback) | |||
| 425 | 425 | static void | |
| 426 | 426 | traceback_get_frames(traceback_t *traceback) | |
| 427 | 427 | { | |
| 428 | - PyThreadState *tstate; | ||
| 429 | - PyFrameObject *pyframe; | ||
| 430 | - | ||
| 431 | - tstate = PyGILState_GetThisThreadState(); | ||
| 428 | + PyThreadState *tstate = PyGILState_GetThisThreadState(); | ||
| 432 | 429 | if (tstate == NULL) { | |
| 433 | 430 | #ifdef TRACE_DEBUG | |
| 434 | 431 | tracemalloc_error("failed to get the current thread state"); | |
| 435 | 432 | #endif | |
| 436 | 433 | return; | |
| 437 | 434 | } | |
| 438 | 435 | ||
| 439 | - pyframe = PyThreadState_GetFrame(tstate); | ||
| 436 | + PyFrameObject *pyframe = PyThreadState_GetFrame(tstate); | ||
| 437 | + Py_XDECREF(pyframe); // use a borrowed reference | ||
| 440 | 438 | for (; pyframe != NULL; pyframe = pyframe->f_back) { | |
| 441 | 439 | if (traceback->nframe < _Py_tracemalloc_config.max_nframe) { | |
| 442 | 440 | tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1840,14 +1840,17 @@ _is_running(PyInterpreterState *interp) | |||
| 1840 | 1840 | "interpreter has more than one thread"); | |
| 1841 | 1841 | return -1; | |
| 1842 | 1842 | } | |
| 1843 | + | ||
| 1844 | + assert(!PyErr_Occurred()); | ||
| 1843 | 1845 | PyFrameObject *frame = PyThreadState_GetFrame(tstate); | |
| 1844 | 1846 | if (frame == NULL) { | |
| 1845 | - if (PyErr_Occurred() != NULL) { | ||
| 1846 | - return -1; | ||
| 1847 | - } | ||
| 1848 | 1847 | return 0; | |
| 1849 | 1848 | } | |
| 1850 | - return (int)(frame->f_executing); | ||
| 1849 | + | ||
| 1850 | + int executing = (int)(frame->f_executing); | ||
| 1851 | + Py_DECREF(frame); | ||
| 1852 | + | ||
| 1853 | + return executing; | ||
| 1851 | 1854 | } | |
| 1852 | 1855 | ||
| 1853 | 1856 | static int | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8108,15 +8108,16 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds) | |||
| 8108 | 8108 | /* Call super(), without args -- fill in from __class__ | |
| 8109 | 8109 | and first local variable on the stack. */ | |
| 8110 | 8110 | PyThreadState *tstate = _PyThreadState_GET(); | |
| 8111 | - PyFrameObject *f = PyThreadState_GetFrame(tstate); | ||
| 8112 | - if (f == NULL) { | ||
| 8111 | + PyFrameObject *frame = PyThreadState_GetFrame(tstate); | ||
| 8112 | + if (frame == NULL) { | ||
| 8113 | 8113 | PyErr_SetString(PyExc_RuntimeError, | |
| 8114 | 8114 | "super(): no current frame"); | |
| 8115 | 8115 | return -1; | |
| 8116 | 8116 | } | |
| 8117 | 8117 | ||
| 8118 | - PyCodeObject *code = PyFrame_GetCode(f); | ||
| 8119 | - int res = super_init_without_args(f, code, &type, &obj); | ||
| 8118 | + PyCodeObject *code = PyFrame_GetCode(frame); | ||
| 8119 | + int res = super_init_without_args(frame, code, &type, &obj); | ||
| 8120 | + Py_DECREF(frame); | ||
| 8120 | 8121 | Py_DECREF(code); | |
| 8121 | 8122 | ||
| 8122 | 8123 | if (res < 0) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1372,7 +1372,7 @@ _PyErr_WriteUnraisableMsg(const char *err_msg_str, PyObject *obj) | |||
| 1372 | 1372 | } | |
| 1373 | 1373 | ||
| 1374 | 1374 | if (exc_tb == NULL) { | |
| 1375 | - struct _frame *frame = tstate->frame; | ||
| 1375 | + PyFrameObject *frame = tstate->frame; | ||
| 1376 | 1376 | if (frame != NULL) { | |
| 1377 | 1377 | exc_tb = _PyTraceBack_FromFrame(NULL, frame); | |
| 1378 | 1378 | if (exc_tb == NULL) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1042,11 +1042,13 @@ PyThreadState_GetInterpreter(PyThreadState *tstate) | |||
| 1042 | 1042 | } | |
| 1043 | 1043 | ||
| 1044 | 1044 | ||
| 1045 | - struct _frame* | ||
| 1045 | + PyFrameObject* | ||
| 1046 | 1046 | PyThreadState_GetFrame(PyThreadState *tstate) | |
| 1047 | 1047 | { | |
| 1048 | 1048 | assert(tstate != NULL); | |
| 1049 | - return tstate->frame; | ||
| 1049 | + PyFrameObject *frame = tstate->frame; | ||
| 1050 | + Py_XINCREF(frame); | ||
| 1051 | + return frame; | ||
| 1050 | 1052 | } | |
| 1051 | 1053 | ||
| 1052 | 1054 | ||
@@ -1165,7 +1167,7 @@ _PyThread_CurrentFrames(void) | |||
| 1165 | 1167 | for (i = runtime->interpreters.head; i != NULL; i = i->next) { | |
| 1166 | 1168 | PyThreadState *t; | |
| 1167 | 1169 | for (t = i->tstate_head; t != NULL; t = t->next) { | |
| 1168 | - struct _frame *frame = t->frame; | ||
| 1170 | + PyFrameObject *frame = t->frame; | ||
| 1169 | 1171 | if (frame == NULL) { | |
| 1170 | 1172 | continue; | |
| 1171 | 1173 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments