classification
Title: 2.7 core crashes with generator.gi_frame.f_restricted
Type: Stage: needs patch
Components: Interpreter Core Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, doko, eryksun, haypo, terry.reedy
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 > x.py
def foo(): yield
gen = foo()
print gen.gi_frame.f_restricted
for i in gen: pass
print gen.gi_frame
gen = foo()
print gen.next()
print gen.gi_frame.f_restricted

$ python x.py 
False
None
None
Segmentation fault

Program received signal SIGSEGV, Segmentation fault.
0x0000000000462b44 in frame_getrestricted (
    f=Frame 0x7ffff7f58410, for file x.py, 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 x.py, 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 (haypo) * (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
http://hg.python.org/cpython/rev/aa324af42c0e
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.
History
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:50hayposetmessages: + msg231075
2014-11-12 11:38:14eryksunsetnosy: + eryksun
messages: + msg231072
2014-11-12 10:26:19hayposetnosy: + haypo
2014-11-12 10:20:31dokocreate