[pypy-svn] r36073 - in pypy/dist/pypy/rlib/rctypes: . test
arigo at codespeak.net
arigo at codespeak.net
Sun Dec 31 14:16:01 CET 2006
Author: arigo
Date: Sun Dec 31 14:15:58 2006
New Revision: 36073
Modified:
pypy/dist/pypy/rlib/rctypes/rctypesobject.py
pypy/dist/pypy/rlib/rctypes/test/test_rctypesobject.py
Log:
rctypesobject: support for NULL pointers.
Modified: pypy/dist/pypy/rlib/rctypes/rctypesobject.py
==============================================================================
--- pypy/dist/pypy/rlib/rctypes/rctypesobject.py (original)
+++ pypy/dist/pypy/rlib/rctypes/rctypesobject.py Sun Dec 31 14:15:58 2006
@@ -267,6 +267,18 @@
keepalive_until_here(self)
self._keepalivememblock(0, targetmemblock)
+ def is_null(self):
+ ptr = self.ll_ref(RCTypesPtr.CDATATYPE)
+ res = not ptr[0]
+ keepalive_until_here(self)
+ return res
+
+ def set_null(self):
+ ptr = self.ll_ref(RCTypesPtr.CDATATYPE)
+ ptr[0] = lltype.nullptr(RCTypesPtr.LLTYPE.TO)
+ keepalive_until_here(self)
+ self._keepalivememblock(0, None)
+
ofs_item = llmemory.sizeof(contentscls.LLTYPE)
contentscls._ptrcls = RCTypesPtr
return RCTypesPtr
Modified: pypy/dist/pypy/rlib/rctypes/test/test_rctypesobject.py
==============================================================================
--- pypy/dist/pypy/rlib/rctypes/test/test_rctypesobject.py (original)
+++ pypy/dist/pypy/rlib/rctypes/test/test_rctypesobject.py Sun Dec 31 14:15:58 2006
@@ -240,6 +240,20 @@
res = self.do(func)
assert res == 115 + 206
+ def test_null_pointer(self):
+ P = RPointer(rc_int)
+ def func():
+ x = rc_int.allocate()
+ p = P.allocate()
+ res1 = p.is_null()
+ p.set_contents(x)
+ res2 = p.is_null()
+ p.set_null()
+ res3 = p.is_null()
+ return res1 * 100 + res2 * 10 + res3
+ res = self.do(func)
+ assert res == 101
+
POLICY = AnnotatorPolicy()
POLICY.allow_someobjects = False
More information about the Pypy-commit
mailing list