[pypy-svn] r60772 - in pypy/branch/oo-jit/pypy/rpython/lltypesystem: . test
fijal at codespeak.net
fijal at codespeak.net
Sun Jan 4 19:48:19 CET 2009
Author: fijal
Date: Sun Jan 4 19:48:17 2009
New Revision: 60772
Modified:
pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
A test and a fix for negative addresses
Modified: pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py Sun Jan 4 19:48:17 2009
@@ -886,14 +886,19 @@
# use ll2ctypes to obtain a real ctypes-based representation of
# the memory, and cast that address as an integer
if addr.ptr is None:
- return 0
+ res = 0
else:
c = lltype2ctypes(addr.ptr)
c = ctypes.cast(c, ctypes.c_void_p)
assert c.value
- return c.value
+ res = c.value
else:
- return addr._cast_to_int()
+ res = addr._cast_to_int()
+ if res > sys.maxint:
+ res = res - 2*sys.maxint
+ assert int(res) == res
+ return int(res)
+ return res
# ____________________________________________________________
# errno
Modified: pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Sun Jan 4 19:48:17 2009
@@ -6,7 +6,7 @@
from pypy.rpython.lltypesystem.ll2ctypes import lltype2ctypes, ctypes2lltype
from pypy.rpython.lltypesystem.ll2ctypes import standard_c_lib, get_ctypes_type
from pypy.rpython.lltypesystem.ll2ctypes import uninitialized2ctypes
-from pypy.rpython.lltypesystem.ll2ctypes import ALLOCATED
+from pypy.rpython.lltypesystem.ll2ctypes import ALLOCATED, cast_adr_to_int
from pypy.rpython.annlowlevel import llhelper
from pypy.rlib import rposix
from pypy.translator.tool.cbuild import ExternalCompilationInfo
@@ -914,3 +914,12 @@
pc2 = lltype2ctypes(p)
assert pc2.contents.value == 42
assert pc2.contents.next.contents.value == 42
+
+ def test_cast_adr_to_int(self):
+ class someaddr(object):
+ def _cast_to_int(self):
+ return sys.maxint/2 * 3
+
+ res = cast_adr_to_int(someaddr())
+ assert isinstance(res, int)
+ assert res == -sys.maxint/2 - 1
More information about the Pypy-commit
mailing list