Skip to content

Commit

Permalink
Make the change for private C API
Browse files Browse the repository at this point in the history
  • Loading branch information
gaogaotiantian committed May 8, 2024
1 parent c5bee13 commit 799bd72
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,15 @@ _PyFrame_GetLocals(_PyInterpreterFrame *frame)
PyCodeObject *co = _PyFrame_GetCode(frame);

if (!(co->co_flags & CO_OPTIMIZED) && !_PyFrame_HasHiddenLocals(frame)) {
if (frame->f_locals == NULL) {
// We found cases when f_locals is NULL for non-optimized code.
// We fill the f_locals with an empty dict to avoid crash until
// we find the root cause.
frame->f_locals = PyDict_New();
if (frame->f_locals == NULL) {
return NULL;
}
}
return Py_NewRef(frame->f_locals);
}

Expand Down

0 comments on commit 799bd72

Please sign in to comment.