[pypy-svn] pypy 32ptr-on-64bit: More tests, and introduce _llgcopaque32.
arigo
commits-noreply at bitbucket.org
Thu Apr 14 22:11:48 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: 32ptr-on-64bit
Changeset: r43367:23a5f19495cb
Date: 2011-04-14 22:11 +0200
http://bitbucket.org/pypy/pypy/changeset/23a5f19495cb/
Log: More tests, and introduce _llgcopaque32.
diff --git a/pypy/rpython/lltypesystem/ll2ctypes.py b/pypy/rpython/lltypesystem/ll2ctypes.py
--- a/pypy/rpython/lltypesystem/ll2ctypes.py
+++ b/pypy/rpython/lltypesystem/ll2ctypes.py
@@ -622,6 +622,8 @@
# otherwise it came from integer and we want a c_void_p with
# the same value
elif T == llmemory.HiddenGcRef32:
+ if isinstance(llobj._obj, _llgcopaque32):
+ return ctypes.c_uint32(llobj._obj.uint32val)
p = llobj._obj.container._as_ptr()
p = lltype.normalizeptr(p)
container = p._as_obj()
@@ -778,7 +780,9 @@
if T is lltype.Void:
return None
if isinstance(T, lltype.Ptr):
- if not cobj or not ctypes.cast(cobj, ctypes.c_void_p).value: # NULL pointer
+ if not cobj or (
+ not isinstance(cobj, ctypes.c_uint32)
+ and not ctypes.cast(cobj, ctypes.c_void_p).value): # NULL pointer
# CFunctionType.__nonzero__ is broken before Python 2.6
return lltype.nullptr(T.TO)
if isinstance(T.TO, lltype.Struct):
@@ -830,6 +834,8 @@
elif isinstance(T.TO, lltype.OpaqueType):
if T == llmemory.GCREF:
container = _llgcopaque(cobj)
+ elif T == llmemory.HiddenGcRef32:
+ container = _llgcopaque32(cobj)
else:
container = lltype._opaque(T.TO)
cbuf = ctypes.cast(cobj, ctypes.c_void_p)
@@ -1300,6 +1306,35 @@
return hop.genop('cast_adr_to_int', [adr],
resulttype = lltype.Signed)
+class _llgcopaque32(lltype._container):
+ _TYPE = llmemory.HiddenGcRef32.TO
+ _name = "_llgcopaque32"
+
+ def __init__(self, uint32):
+ if not isinstance(uint32, int):
+ uint32 = int(uint32.value)
+ assert isinstance(uint32, int)
+ self.uint32val = uint32
+
+ def __eq__(self, other):
+ if isinstance(other, _llgcopaque32):
+ return self.uint32val == other.uint32val
+ storage = object()
+ if hasattr(other, 'container'):
+ storage = other.container._storage
+ else:
+ storage = other._storage
+
+ if storage in (None, True):
+ return False
+ return force_cast(rffi.UINT, other._as_ptr()) == self.uint32val
+
+ def __ne__(self, other):
+ return not self == other
+
+## def _cast_to_ptr(self, PTRTYPE):
+## return force_cast(PTRTYPE, self.intval)
+
# ____________________________________________________________
# errno
diff --git a/pypy/rpython/lltypesystem/test/test_ll2ctypes.py b/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
--- a/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
+++ b/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
@@ -1320,6 +1320,57 @@
back2 = rffi.cast(llmemory.HiddenGcRef32, rffi.cast(rffi.UINT, 0))
assert not llop.show_from_ptr32(lltype.Ptr(NODE), back2)
+ def test_hiddengcref32_forth_and_back(self):
+ cp = ctypes.c_uint32(3 * 10**9)
+ v = ctypes2lltype(llmemory.HiddenGcRef32, cp)
+ assert lltype.typeOf(v) == llmemory.HiddenGcRef32
+ assert lltype2ctypes(v).value == cp.value
+ v1 = ctypes2lltype(llmemory.HiddenGcRef32, cp)
+ assert v == v1
+ assert v
+ v2 = ctypes2lltype(llmemory.HiddenGcRef32, ctypes.c_uint32(1234567))
+ assert v2 != v
+
+ def test_hiddengcref32_type(self):
+ NODE = lltype.GcStruct('NODE')
+ node = lltype.malloc(NODE)
+ ref = lltype.cast_opaque_ptr(llmemory.HiddenGcRef32, node)
+ v = lltype2ctypes(ref)
+ assert isinstance(v, ctypes.c_uint32)
+ assert v
+
+ def test_hiddengcref32_null(self):
+ ref = lltype.nullptr(llmemory.HiddenGcRef32.TO)
+ v = lltype2ctypes(ref)
+ assert isinstance(v, ctypes.c_uint32)
+ assert not v
+
+ def test_cast_null_hiddengcref32(self):
+ ref = lltype.nullptr(llmemory.HiddenGcRef32.TO)
+ value = rffi.cast(rffi.UINT, ref)
+ assert rffi.cast(lltype.Signed, value) == 0
+
+ def test_hiddengcref32_truth(self):
+ p0 = ctypes.c_uint32(0)
+ ref0 = ctypes2lltype(llmemory.HiddenGcRef32, p0)
+ assert not ref0
+
+ p1234567 = ctypes.c_uint32(1234567)
+ ref1234567 = ctypes2lltype(llmemory.HiddenGcRef32, p1234567)
+ assert p1234567
+
+ def test_hiddengcref32_casts(self):
+ from pypy.rpython.lltypesystem.lloperation import llop
+ p0 = ctypes.c_uint32(0)
+ ref0 = ctypes2lltype(llmemory.HiddenGcRef32, p0)
+
+ NODE = lltype.GcStruct('NODE')
+ assert llop.show_from_ptr32(lltype.Ptr(NODE), ref0) == lltype.nullptr(NODE)
+
+ node = lltype.malloc(NODE)
+ ref1 = llop.hide_into_ptr32(llmemory.HiddenGcRef32, node)
+
+
class TestPlatform(object):
def test_lib_on_libpaths(self):
from pypy.translator.platform import platform
More information about the Pypy-commit
mailing list