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)
742
742
PyCodeObject * co = _PyFrame_GetCode (f -> f_frame );
743
743
744
744
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
+ }
745
754
return Py_NewRef (f -> f_frame -> f_locals );
746
755
}
747
756
@@ -1937,6 +1946,15 @@ _PyFrame_GetLocals(_PyInterpreterFrame *frame)
1937
1946
PyCodeObject * co = _PyFrame_GetCode (frame );
1938
1947
1939
1948
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
+ }
1940
1958
return Py_NewRef (frame -> f_locals );
1941
1959
}
1942
1960
You can’t perform that action at this time.
0 commit comments