[pypy-svn] pypy jitypes2: don't crash if you try to get the repr of a box containing an AddressToInt which comes from rpython but it's wrapped as ll2ctypes.
antocuni
commits-noreply at bitbucket.org
Wed Dec 22 12:20:34 CET 2010
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r40177:0235a5956ac2
Date: 2010-12-22 12:20 +0100
http://bitbucket.org/pypy/pypy/changeset/0235a5956ac2/
Log: don't crash if you try to get the repr of a box containing an
AddressToInt which comes from rpython but it's wrapped as ll2ctypes.
This finally fixes test_slonglong_args in
metainterp/test/test_fficall.py
diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py
--- a/pypy/jit/metainterp/history.py
+++ b/pypy/jit/metainterp/history.py
@@ -678,10 +678,14 @@
return -2 # xxx risk of changing hash...
def make_hashable_int(i):
+ from pypy.rpython.lltypesystem.ll2ctypes import NotCtypesAllocatedStructure
if not we_are_translated() and isinstance(i, llmemory.AddressAsInt):
# Warning: such a hash changes at the time of translation
adr = heaptracker.int2adr(i)
- return llmemory.cast_adr_to_int(adr, "emulated")
+ try:
+ return llmemory.cast_adr_to_int(adr, "emulated")
+ except NotCtypesAllocatedStructure:
+ return 12345 # use an arbitrary number for the hash
return i
def get_const_ptr_for_string(s):
diff --git a/pypy/jit/metainterp/test/test_history.py b/pypy/jit/metainterp/test/test_history.py
--- a/pypy/jit/metainterp/test/test_history.py
+++ b/pypy/jit/metainterp/test/test_history.py
@@ -1,5 +1,5 @@
from pypy.jit.metainterp.history import *
-from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.lltypesystem import lltype, llmemory, rffi
def test_repr():
@@ -9,3 +9,15 @@
s = lltype.cast_pointer(lltype.Ptr(S), t)
const = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s))
assert const._getrepr_() == "*T"
+
+def test_repr_ll2ctypes():
+ ptr = lltype.malloc(rffi.VOIDPP.TO, 10, flavor='raw')
+ # force it to be a ll2ctypes object
+ ptr = rffi.cast(rffi.VOIDPP, rffi.cast(rffi.LONG, ptr))
+ adr = llmemory.cast_ptr_to_adr(ptr)
+ lltype.free(ptr, flavor='raw')
+ intval = llmemory.cast_adr_to_int(adr, 'symbolic')
+ box = BoxInt(intval)
+ s = box.repr_rpython()
+ assert s.startswith('12345/') # the arbitrary hash value used by
+ # make_hashable_int
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
@@ -411,6 +411,9 @@
instance._storage = ctypes_storage
assert ctypes_storage # null pointer?
+class NotCtypesAllocatedStructure(ValueError):
+ pass
+
class _parentable_mixin(object):
"""Mixin added to _parentable containers when they become ctypes-based.
(This is done by changing the __class__ of the instance to reference
@@ -429,7 +432,7 @@
def _addressof_storage(self):
"Returns the storage address as an int"
if self._storage is None or self._storage is True:
- raise ValueError("Not a ctypes allocated structure")
+ raise NotCtypesAllocatedStructure("Not a ctypes allocated structure")
return intmask(ctypes.cast(self._storage, ctypes.c_void_p).value)
def _free(self):
More information about the Pypy-commit
mailing list