Title: 2.7 core crashes with generator.gi_frame.f_restricted
Type: Stage: needs patch
Components: Interpreter Core Versions: Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, doko, eryksun, terry.reedy, vstinner
Priority: normal Keywords:

Created on 2014-11-12 10:20 by doko, last changed 2014-11-15 00:20 by Arfrever.

Messages (5)
msg231069 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2014-11-12 10:20
seen with the current 2.7 branch:

$ cat >
def foo(): yield
gen = foo()
print gen.gi_frame.f_restricted
for i in gen: pass
print gen.gi_frame
gen = foo()
print gen.gi_frame.f_restricted

$ python 
Segmentation fault

Program received signal SIGSEGV, Segmentation fault.
0x0000000000462b44 in frame_getrestricted (
    f=Frame 0x7ffff7f58410, for file, line 1, in foo (), closure=0x0)
    at ../Objects/frameobject.c:383
383     ../Objects/frameobject.c: No such file or directory.
(gdb) bt
#0  0x0000000000462b44 in frame_getrestricted (
    f=Frame 0x7ffff7f58410, for file, line 1, in foo (), closure=0x0)
    at ../Objects/frameobject.c:383
msg231072 - (view) Author: Eryk Sun (eryksun) * Date: 2014-11-12 11:38
This is related to the fix for issue 14432. gen_send_ex sets f->f_tstate to NULL, so PyFrame_IsRestricted segfaults: 

    #define PyFrame_IsRestricted(f) \
        ((f)->f_builtins != (f)->f_tstate->interp->builtins)
msg231075 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-11-12 12:57
Related change:

New changeset aa324af42c0e by Victor Stinner in branch '2.7':
Issue #14432: Generator now clears the borrowed reference to the thread state
msg231186 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-11-14 21:16
This appears to be 2.7 only as 3.4.2 stops on the first print with AttributeError: 'frame' object has no attribute 'f_restricted', which is not a crash.
msg231193 - (view) Author: Eryk Sun (eryksun) * Date: 2014-11-14 22:20
The fix for issue 14432 was applied to 3.3, but I'm pretty sure 2.x PyFrame_IsRestricted is the only problem. Nothing else should see f_tstate when it's NULL. Also, f_tstate was dropped from PyFrameObject in 3.4.
Date User Action Args
2014-11-15 00:20:17Arfreversetnosy: + Arfrever
2014-11-14 22:20:32eryksunsetmessages: + msg231193
2014-11-14 21:16:38terry.reedysetnosy: + terry.reedy
title: core crashes -> 2.7 core crashes with generator.gi_frame.f_restricted
messages: + msg231186

stage: needs patch
2014-11-12 12:57:50vstinnersetmessages: + msg231075
2014-11-12 11:38:14eryksunsetnosy: + eryksun
messages: + msg231072
2014-11-12 10:26:19vstinnersetnosy: + vstinner
2014-11-12 10:20:31dokocreate