On 8/15/06, Neil Schemenauer <[EMAIL PROTECTED]> wrote:
>
> It would be nice if someone could bytecompile Lib using
> Tools/compiler/compile.py and then run the test suite.  I'd do it
> myself but can't spare the time at the moment (I started but ran
> into what seems to be a gcc bug along the way).

Has this been done before?

# This code causes python to segfault
def foo(S):
  all(x > 42 for x in S)

# around Python/ceval.c 2167:  x = (*v->ob_type->tp_iternext)(v);
# tp_iternext is NULL

I added the changes below to Lib/compiler/pycodegen.py which are
clearly wrong.  It just crashes in a diff place.  I think the changes
to genxpr inner may be close to correct.  The changes to _makeClosure
and visitGenExpr are clearly wrong.  I was just wondering how far it
would go.  There are a bunch of differences. Some are the bytecode
optimizations or different ordering, but others are things dealing
with co_names, co_varnames.

Hopefully someone has time to look into this.  Otherwise, it will have
to wait for 2.5.1

n
--
Index: Lib/compiler/pycodegen.py
===================================================================
--- Lib/compiler/pycodegen.py   (revision 51305)
+++ Lib/compiler/pycodegen.py   (working copy)
@@ -628,9 +628,9 @@
         self.newBlock()
         self.emit('POP_TOP')

-    def _makeClosure(self, gen, args):
+    def _makeClosure(self, gen, args, gen_outer=False):
         frees = gen.scope.get_free_vars()
-        if frees:
+        if frees and not gen_outer:
             for name in frees:
                 self.emit('LOAD_CLOSURE', name)
             self.emit('BUILD_TUPLE', len(frees))
@@ -646,7 +646,7 @@
         walk(node.code, gen)
         gen.finish()
         self.set_lineno(node)
-        self._makeClosure(gen, 0)
+        self._makeClosure(gen, 0, True)
         # precomputation of outmost iterable
         self.visit(node.code.quals[0].iter)
         self.emit('GET_ITER')
@@ -655,6 +655,11 @@
     def visitGenExprInner(self, node):
         self.set_lineno(node)
         # setup list
+        after = self.newBlock()
+        start = self.newBlock()
+        self.setups.push((LOOP, start))
+        self.emit('SETUP_LOOP', after)
+        self.nextBlock(start)

         stack = []
         for i, for_ in zip(range(len(node.quals)), node.quals):
@@ -676,8 +681,12 @@
                 self.startBlock(cont)
                 self.emit('POP_TOP')
                 self.nextBlock(skip_one)
+            self.emit('POP_TOP')
             self.emit('JUMP_ABSOLUTE', start)
             self.startBlock(anchor)
+        self.emit('POP_BLOCK')
+        self.setups.pop()
+        self.nextBlock(after)
         self.emit('LOAD_CONST', None)

     def visitGenExprFor(self, node):
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to