Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
d099cfe2
Commit
d099cfe2
authored
Mar 29, 2012
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix generator's frame object cycle
parent
b93b19c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
6 deletions
+61
-6
Cython/Utility/Generator.c
Cython/Utility/Generator.c
+31
-6
tests/run/test_generator_frame_cycle.py
tests/run/test_generator_frame_cycle.py
+30
-0
No files found.
Cython/Utility/Generator.c
View file @
d099cfe2
...
...
@@ -23,6 +23,7 @@ static CYTHON_INLINE PyObject* __Pyx_Generator_Yield_From(__pyx_GeneratorObject
//////////////////// Generator.proto ////////////////////
#define __Pyx_Generator_USED
#include <structmember.h>
#include <frameobject.h>
typedef
PyObject
*
(
*
__pyx_generator_body_t
)(
PyObject
*
,
PyObject
*
);
...
...
@@ -186,19 +187,43 @@ PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) {
}
if
(
value
)
__Pyx_ExceptionSwap
(
&
self
->
exc_type
,
&
self
->
exc_value
,
&
self
->
exc_traceback
);
else
if
(
value
)
{
/* Generators always return to their most recent caller, not
* necessarily their creator. */
if
(
self
->
exc_traceback
)
{
PyThreadState
*
tstate
=
PyThreadState_GET
();
PyTracebackObject
*
tb
=
(
PyTracebackObject
*
)
self
->
exc_traceback
;
PyFrameObject
*
f
=
tb
->
tb_frame
;
Py_XINCREF
(
tstate
->
frame
);
assert
(
f
->
f_back
==
NULL
);
f
->
f_back
=
tstate
->
frame
;
}
__Pyx_ExceptionSwap
(
&
self
->
exc_type
,
&
self
->
exc_value
,
&
self
->
exc_traceback
);
}
else
{
__Pyx_Generator_ExceptionClear
(
self
);
}
self
->
is_running
=
1
;
retval
=
self
->
body
((
PyObject
*
)
self
,
value
);
self
->
is_running
=
0
;
if
(
retval
)
__Pyx_ExceptionSwap
(
&
self
->
exc_type
,
&
self
->
exc_value
,
&
self
->
exc_traceback
);
else
if
(
retval
)
{
__Pyx_ExceptionSwap
(
&
self
->
exc_type
,
&
self
->
exc_value
,
&
self
->
exc_traceback
);
/* Don't keep the reference to f_back any longer than necessary. It
* may keep a chain of frames alive or it could create a reference
* cycle. */
if
(
self
->
exc_traceback
)
{
PyTracebackObject
*
tb
=
(
PyTracebackObject
*
)
self
->
exc_traceback
;
PyFrameObject
*
f
=
tb
->
tb_frame
;
Py_CLEAR
(
f
->
f_back
);
}
}
else
{
__Pyx_Generator_ExceptionClear
(
self
);
}
return
retval
;
}
...
...
tests/run/test_generator_frame_cycle.py
0 → 100644
View file @
d099cfe2
# mode: run
# tags: generator
import
sys
def
_next
(
it
):
if
sys
.
version_info
[
0
]
>=
3
:
return
next
(
it
)
else
:
return
it
.
next
()
def
test_generator_frame_cycle
():
"""
>>> test_generator_frame_cycle()
("I'm done",)
"""
testit
=
[]
def
whoo
():
try
:
yield
except
:
yield
finally
:
testit
.
append
(
"I'm done"
)
g
=
whoo
()
_next
(
g
)
# Frame object cycle
eval
(
'g.throw(ValueError)'
,
{
'g'
:
g
})
del
g
return
tuple
(
testit
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment