[pypy-svn] r65082 - in pypy/branch/pyjitpl5/pypy/rpython: ootypesystem ootypesystem/test test

antocuni at codespeak.net antocuni at codespeak.net
Wed May 6 12:00:20 CEST 2009


Author: antocuni
Date: Wed May  6 12:00:19 2009
New Revision: 65082

Modified:
   pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/ootype.py
   pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_ootype.py
   pypy/branch/pyjitpl5/pypy/rpython/test/test_rpbc.py
Log:
for the series "how could have it ever worked": make sure that if sm is a
_static_method, bool(ootype.null(sm)) == False



Modified: pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/ootype.py	Wed May  6 12:00:19 2009
@@ -277,7 +277,7 @@
     def __init__(self, args, result):
         self.ARGS = tuple(args)
         self.RESULT = result
-        self._null = _static_meth(self, _callable=None)
+        self._null = _null_static_meth(self)
 
     def _example(self):
         _retval = self.RESULT._example()
@@ -1188,6 +1188,14 @@
    def _as_ptr(self):
        return self
 
+class _null_static_meth(_null_mixin(_static_meth), _static_meth):
+
+    def __init__(self, STATICMETHOD):
+        self.__dict__["_TYPE"] = STATICMETHOD
+        self.__dict__["_name"] = "? (null)"
+        self.__dict__["_callable"] = None
+
+
 class _forward_static_meth(_static_meth):
    allowed_types = (StaticMethod, ForwardReference)
 

Modified: pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_ootype.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_ootype.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_ootype.py	Wed May  6 12:00:19 2009
@@ -649,3 +649,8 @@
     cls = runtimeClass(A)
     assert bool(cls)
     assert not bool(nullruntimeclass)
+
+def test_bool_default_sm():
+    SM = StaticMethod([], Void)
+    sm = SM._defl()
+    assert not bool(sm)

Modified: pypy/branch/pyjitpl5/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/test/test_rpbc.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/test/test_rpbc.py	Wed May  6 12:00:19 2009
@@ -1594,6 +1594,24 @@
 
         self.interpret(f, [int])
 
+
+    def test_funcpointer_default_value(self):
+        def foo(x): return x+1
+        class Foo:
+            func = None
+            def __init__(self, n):
+                if n == 1:
+                    self.func = foo
+
+        def fn(n):
+            a = Foo(n)
+            if a.func:
+                return a.func(n)
+            return -1
+        
+        res = self.interpret(fn, [0])
+        assert res == -1
+
 class TestLLtype(BaseTestRPBC, LLRtypeMixin):
     pass
 



More information about the Pypy-commit mailing list