gh-121814: Only check f_trace_opcodes if Python frame exists (GH-121818)
(cherry picked from commit
2b1b68939b15b913080a3403e3ba18e2a1f520ef)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Co-authored-by: Matt Wozniski <godlygeek@gmail.com>
--- /dev/null
+Fixed the SegFault when :c:func:`PyEval_SetTrace` is used with no Python frame on stack.
(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;