[3.13] gh-121814: Only check f_trace_opcodes if Python frame exists (GH-121818) (#121861)

gh-121814: Only check f_trace_opcodes if Python frame exists (GH-121818)
(cherry picked from commit 2b1b68939b)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Co-authored-by: Matt Wozniski <godlygeek@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-07-16 19:13:28 +02:00 committed by GitHub
parent c11d789a4c
commit 54db42fe2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 1 deletions

View File

@ -0,0 +1 @@
Fixed the SegFault when :c:func:`PyEval_SetTrace` is used with no Python frame on stack.

View File

@ -605,7 +605,7 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
(1 << PY_MONITORING_EVENT_STOP_ITERATION);
PyFrameObject* frame = PyEval_GetFrame();
if (frame->f_trace_opcodes) {
if (frame && frame->f_trace_opcodes) {
int ret = _PyEval_SetOpcodeTrace(frame, true);
if (ret != 0) {
return ret;