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

antocuni at codespeak.net antocuni at codespeak.net
Tue May 5 10:19:25 CEST 2009


Author: antocuni
Date: Tue May  5 10:19:23 2009
New Revision: 65047

Modified:
   pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/ooopimpl.py
   pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/ootype.py
   pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_oortype.py
   pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_ootype.py
Log:
make sure that bool(ootype.nullruntimeclass) == False


Modified: pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/ooopimpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/ooopimpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/ooopimpl.py	Tue May  5 10:19:23 2009
@@ -54,9 +54,10 @@
 
 def is_inst(inst):
     T = ootype.typeOf(inst)
-    return T is ootype.Object or isinstance(T, (ootype.Instance,
-                                                ootype.BuiltinType,
-                                                ootype.StaticMethod,))
+    return T is ootype.Object or T is ootype.Class or\
+        isinstance(T, (ootype.Instance,
+                       ootype.BuiltinType,
+                       ootype.StaticMethod,))
 
 def checkinst(inst):
     assert is_inst(inst)

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	Tue May  5 10:19:23 2009
@@ -906,6 +906,9 @@
     def __repr__(self):
         return '%s(%s)' % (self.__class__.__name__, self._INSTANCE)
 
+    def __nonzero__(self):
+        return self._INSTANCE is not None
+
 nullruntimeclass = _class(None)
 Class._null = nullruntimeclass
 

Modified: pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_oortype.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_oortype.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_oortype.py	Tue May  5 10:19:23 2009
@@ -449,3 +449,18 @@
 
     res = interpret(fn, [0], type_system='ootype')
     assert res == '4'
+
+def test_bool_class():
+    A = Instance("Foo", ROOT)
+    cls = runtimeClass(A)
+    def fn(x):
+        if x:
+            obj = cls
+        else:
+            obj = nullruntimeclass
+        return bool(obj)
+
+    res = interpret(fn, [0], type_system='ootype')
+    assert not res
+    res = interpret(fn, [1], type_system='ootype')
+    assert res

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	Tue May  5 10:19:23 2009
@@ -644,3 +644,8 @@
     b = oonewarray(A, 10)
     assert ooidentityhash(a) != ooidentityhash(b)
 
+def test_bool_class():
+    A = Instance("Foo", ROOT)
+    cls = runtimeClass(A)
+    assert bool(cls)
+    assert not bool(nullruntimeclass)



More information about the Pypy-commit mailing list