[pypy-svn] r45306 - in pypy/dist/pypy/rpython/lltypesystem: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Jul 24 18:17:54 CEST 2007
Author: arigo
Date: Tue Jul 24 18:17:53 2007
New Revision: 45306
Modified:
pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
NULL pointers support in ll2ctypes.
Modified: pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py Tue Jul 24 18:17:53 2007
@@ -281,6 +281,9 @@
T = lltype.typeOf(llobj)
if isinstance(T, lltype.Ptr):
+ if not llobj: # NULL pointer
+ return get_ctypes_type(T)()
+
container = llobj._obj
if isinstance(T.TO, lltype.FuncType):
if not hasattr(container, '_callable'):
@@ -332,6 +335,8 @@
'T' is the expected lltype type.
"""
if isinstance(T, lltype.Ptr):
+ if not cobj: # NULL pointer
+ return lltype.nullptr(T.TO)
if isinstance(T.TO, lltype.Struct):
# XXX var-sized structs
container = lltype._struct(T.TO)
Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Tue Jul 24 18:17:53 2007
@@ -29,6 +29,13 @@
res = lltype2ctypes(llmemory.sizeof(S))
assert res == struct.calcsize("ll")
+ p = lltype.nullptr(S)
+ cptr = lltype2ctypes(p)
+ assert not cptr
+ py.test.raises(ValueError, 'cptr.contents') # NULL pointer access
+ res = ctypes2lltype(lltype.Ptr(S), cptr)
+ assert res == p
+
def test_simple_struct(self):
S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Signed))
s = lltype.malloc(S, flavor='raw')
More information about the Pypy-commit
mailing list