[pypy-svn] r23945 - in pypy/dist/pypy/objspace/flow: . test
arigo at codespeak.net
arigo at codespeak.net
Fri Mar 3 15:25:02 CET 2006
Author: arigo
Date: Fri Mar 3 15:24:54 2006
New Revision: 23945
Modified:
pypy/dist/pypy/objspace/flow/objspace.py
pypy/dist/pypy/objspace/flow/test/test_objspace.py
Log:
Yuk! The ages-old extract_cell_content() hack is buggy. It crashes if the
nested scope cell in question contains an object with a custom __cmp__ -- it
was fine with a custom __eq__ only. Who can claim he knows the order in which
Python tries to call __cmp__ and __eq__ in all situations?
Bug found because lladdress.address has a custom __cmp__, so the flow space
crashes on any helper that gets the NULL address object via a closure.
Modified: pypy/dist/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/objspace.py (original)
+++ pypy/dist/pypy/objspace/flow/objspace.py Fri Mar 3 15:24:54 2006
@@ -508,8 +508,12 @@
the func_closure of a function object."""
# yuk! this is all I could come up with that works in Python 2.2 too
class X(object):
+ def __cmp__(self, other):
+ self.other = other
+ return 0
def __eq__(self, other):
self.other = other
+ return True
x = X()
x_cell, = (lambda: x).func_closure
x_cell == c
Modified: pypy/dist/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/test/test_objspace.py (original)
+++ pypy/dist/pypy/objspace/flow/test/test_objspace.py Fri Mar 3 15:24:54 2006
@@ -4,6 +4,7 @@
from pypy.interpreter.argument import Arguments
from pypy.translator.simplify import simplify_graph
from pypy.objspace.flow import FlowObjSpace
+from pypy.objspace.flow import objspace
import os
import operator
@@ -641,3 +642,14 @@
def user_defined_function():
pass
+
+
+def test_extract_cell_content():
+ class Strange(object):
+ def __cmp__(self, other):
+ assert False, "should not be called"
+ strange = Strange()
+ def f():
+ return strange
+ res = objspace.extract_cell_content(f.func_closure[0])
+ assert res is strange
More information about the Pypy-commit
mailing list