Skip to content

Commit 0980dc8

Browse files
DinoVfacebook-github-bot
authored andcommitted
Fix re-entrancy problem while initialization interpreter frame
Summary: Fixes S544229 There is some surprise re-entrancy below `_PyFrame_InitializeExternalFrame`. The allocation can presumably release the GIL or cause GC and therefore the function can be initialized before we try calling it a 2nd time. This causes us to only perform the initialization if the object is still a non-function. D78124674 would presumably fix this as well in that we're not replacing the function object anymore, so we'd just update it. But w/ D78124674 someone else's reifier could say they don't want to update the function in which case this is the right fix. Reviewed By: diansheng92 Differential Revision: D78930696 fbshipit-source-id: bbc37bee98744c1e04939baea84b3108d046b8cf
1 parent 65e8bb0 commit 0980dc8

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Python/frame.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ _PyFrame_InitializeExternalFrame(_PyInterpreterFrame *frame) {
167167
if (frame_addr == NULL) {
168168
return -1;
169169
}
170+
if (PyFunction_Check(frame->f_funcobj)) {
171+
// re-entrancy during the allocation caused the frame to be initialized
172+
return 0;
173+
}
170174
PyObject *tmp = PyObject_Vectorcall(frame->f_funcobj, &frame_addr, 1, NULL);
171175
Py_DECREF(frame_addr);
172176
if (tmp == NULL) {

0 commit comments

Comments
 (0)