Skip to content
Prev Previous commit
Next Next commit
Move initialization of frame->previous to init_frame.
Use self.assertEquals instead of assert.
  • Loading branch information
byllyfish committed Dec 13, 2022
commit d6797833bcb0fb6195de0fb23b4c2643122af69f
2 changes: 1 addition & 1 deletion Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ _PyFrame_InitializeSpecials(
frame->f_locals = locals;
frame->stacktop = code->co_nlocalsplus;
frame->frame_obj = NULL;
frame->previous = NULL;
frame->prev_instr = _PyCode_CODE(code) - 1;
frame->yield_offset = 0;
frame->owner = FRAME_OWNED_BY_THREAD;
// frame->previous: initialized when frame is linked into the frame stack
Comment thread
kumaraditya303 marked this conversation as resolved.
Outdated
}

/* Gets the pointer to the locals array
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_ctypes/test_python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def dummy():
)

# The following line should not cause a segmentation fault.
assert frame.f_back is None
self.assertEqual(frame.f_back, None)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Initialize frame->previous in _PyFrame_InitializeSpecials.
Initialize frame->previous in frameobject.c to fix a segmentation fault when
accessing frames created by ctypes.
Comment thread
kumaraditya303 marked this conversation as resolved.
Outdated
1 change: 1 addition & 0 deletions Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,7 @@ init_frame(_PyInterpreterFrame *frame, PyFunctionObject *func, PyObject *locals)
PyCodeObject *code = (PyCodeObject *)func->func_code;
_PyFrame_InitializeSpecials(frame, (PyFunctionObject*)Py_NewRef(func),
Py_XNewRef(locals), code);
frame->previous = NULL;
for (Py_ssize_t i = 0; i < code->co_nlocalsplus; i++) {
frame->localsplus[i] = NULL;
}
Expand Down