Author: Armin Rigo <[email protected]>
Branch: use-gc-del-3
Changeset: r84220:e2d01729c202
Date: 2016-05-05 17:39 +0200
http://bitbucket.org/pypy/pypy/changeset/e2d01729c202/
Log: Remove GeneratorIteratorWithDel
diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -1,6 +1,7 @@
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.pyopcode import LoopBlock
+from pypy.interpreter.pycode import CO_YIELD_INSIDE_TRY
from rpython.rlib import jit
@@ -13,6 +14,8 @@
self.frame = frame # turned into None when frame_finished_execution
self.pycode = frame.pycode
self.running = False
+ if self.pycode.co_flags & CO_YIELD_INSIDE_TRY:
+ self.register_finalizer(self.space)
def descr__repr__(self, space):
if self.pycode is None:
@@ -139,7 +142,6 @@
def descr_close(self):
"""x.close(arg) -> raise GeneratorExit inside generator."""
- assert isinstance(self, GeneratorIterator)
space = self.space
try:
w_retval = self.throw(space.w_GeneratorExit, space.w_None,
@@ -212,25 +214,21 @@
unpack_into = _create_unpack_into()
unpack_into_w = _create_unpack_into()
-
-class GeneratorIteratorWithDel(GeneratorIterator):
-
- def __del__(self):
- # Only bother enqueuing self to raise an exception if the frame is
- # still not finished and finally or except blocks are present.
- self.clear_all_weakrefs()
+ def _finalize_(self):
+ # This is only called if the CO_YIELD_INSIDE_TRY flag is set
+ # on the code object. If the frame is still not finished and
+ # finally or except blocks are present at the current
+ # position, then raise a GeneratorExit. Otherwise, there is
+ # no point.
if self.frame is not None:
block = self.frame.lastblock
while block is not None:
if not isinstance(block, LoopBlock):
- self.enqueue_for_destruction(self.space,
- GeneratorIterator.descr_close,
- "interrupting generator of ")
+ self.descr_close()
break
block = block.previous
-
def get_printable_location_genentry(bytecode):
return '%s <generator>' % (bytecode.get_repr(),)
generatorentry_driver = jit.JitDriver(greens=['pycode'],
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -241,12 +241,8 @@
def run(self):
"""Start this frame's execution."""
if self.getcode().co_flags & pycode.CO_GENERATOR:
- if self.getcode().co_flags & pycode.CO_YIELD_INSIDE_TRY:
- from pypy.interpreter.generator import GeneratorIteratorWithDel
- return self.space.wrap(GeneratorIteratorWithDel(self))
- else:
- from pypy.interpreter.generator import GeneratorIterator
- return self.space.wrap(GeneratorIterator(self))
+ from pypy.interpreter.generator import GeneratorIterator
+ return self.space.wrap(GeneratorIterator(self))
else:
return self.execute_frame()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit