Commit 68ddb594 authored by Zackery Spytz's avatar Zackery Spytz Committed by Serhiy Storchaka

[2.7] bpo-22851: Fix a segfault when accessing generator.gi_frame.f_restricted. (GH-9348)

Frame's field f_tstate is NULL when the generator is exhausted.
parent 6198976e
......@@ -56,7 +56,7 @@ PyAPI_DATA(PyTypeObject) PyFrame_Type;
#define PyFrame_Check(op) (Py_TYPE(op) == &PyFrame_Type)
#define PyFrame_IsRestricted(f) \
((f)->f_builtins != (f)->f_tstate->interp->builtins)
((f)->f_tstate && (f)->f_builtins != (f)->f_tstate->interp->builtins)
PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
PyObject *, PyObject *);
......
......@@ -1877,6 +1877,16 @@ test_generators just happened to be the test that drew these out.
"""
crash_test = """
>>> def foo(): yield
>>> gen = foo()
>>> gen.next()
>>> print gen.gi_frame.f_restricted # This would segfault.
False
"""
__test__ = {"tut": tutorial_tests,
"pep": pep_tests,
"email": email_tests,
......@@ -1886,6 +1896,7 @@ __test__ = {"tut": tutorial_tests,
"weakref": weakref_tests,
"coroutine": coroutine_tests,
"refleaks": refleaks_tests,
"crash": crash_test,
}
# Magic test name that regrtest.py invokes *after* importing this module.
......
Fix a segfault when accessing ``generator.gi_frame.f_restricted`` when the
generator is exhausted. Patch by Zackery Spytz.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment