bpo-40429: PyFrame_GetCode() result cannot be NULL (GH-19772)
Add frame_nslots() to factorize duplicate code.
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 66c6ccb..071def8 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -1117,11 +1117,11 @@
}
frame = PyEval_GetFrame();
for (int i = 0; i < frame_count; ++i) {
- PyObject *frameinfo = Py_BuildValue(
- "OiO",
- frame->f_code->co_filename,
- PyFrame_GetLineNumber(frame),
- frame->f_code->co_name);
+ PyCodeObject *code = frame->f_code;
+ PyObject *frameinfo = Py_BuildValue("OiO",
+ code->co_filename,
+ PyFrame_GetLineNumber(frame),
+ code->co_name);
if (!frameinfo) {
Py_DECREF(cr_origin);
return NULL;