File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -742,6 +742,15 @@ frame_getlocals(PyFrameObject *f, void *closure)
742742 PyCodeObject * co = _PyFrame_GetCode (f -> f_frame );
743743
744744 if (!(co -> co_flags & CO_OPTIMIZED ) && !_PyFrame_HasHiddenLocals (f -> f_frame )) {
745+ if (f -> f_frame -> f_locals == NULL ) {
746+ // We found cases when f_locals is NULL for non-optimized code.
747+ // We fill the f_locals with an empty dict to avoid crash until
748+ // we find the root cause.
749+ f -> f_frame -> f_locals = PyDict_New ();
750+ if (f -> f_frame -> f_locals == NULL ) {
751+ return NULL ;
752+ }
753+ }
745754 return Py_NewRef (f -> f_frame -> f_locals );
746755 }
747756
@@ -1937,6 +1946,15 @@ _PyFrame_GetLocals(_PyInterpreterFrame *frame)
19371946 PyCodeObject * co = _PyFrame_GetCode (frame );
19381947
19391948 if (!(co -> co_flags & CO_OPTIMIZED ) && !_PyFrame_HasHiddenLocals (frame )) {
1949+ if (frame -> f_locals == NULL ) {
1950+ // We found cases when f_locals is NULL for non-optimized code.
1951+ // We fill the f_locals with an empty dict to avoid crash until
1952+ // we find the root cause.
1953+ frame -> f_locals = PyDict_New ();
1954+ if (frame -> f_locals == NULL ) {
1955+ return NULL ;
1956+ }
1957+ }
19401958 return Py_NewRef (frame -> f_locals );
19411959 }
19421960
You can’t perform that action at this time.
0 commit comments