[pypy-commit] pypy faster-rstruct: sanity check to ensure that the cast we do is actually valid. Currently it fails e.g. on win32 and 32bit ARM
antocuni
noreply at buildbot.pypy.org
Mon Nov 23 15:36:54 EST 2015
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: faster-rstruct
Changeset: r80869:0a7af3c17db0
Date: 2015-11-23 18:35 +0100
http://bitbucket.org/pypy/pypy/changeset/0a7af3c17db0/
Log: sanity check to ensure that the cast we do is actually valid.
Currently it fails e.g. on win32 and 32bit ARM
diff --git a/rpython/rlib/strstorage.py b/rpython/rlib/strstorage.py
--- a/rpython/rlib/strstorage.py
+++ b/rpython/rlib/strstorage.py
@@ -32,6 +32,18 @@
from rpython.rtyper.annlowlevel import llstr
from rpython.rlib.objectmodel import specialize
+def compute_offsetof(TP, field):
+ """
+ NOT_RPYTHON
+ """
+ obj = lltype.malloc(TP, 0)
+ baseadr = llmemory.cast_ptr_to_adr(obj)
+ offset = llmemory.offsetof(TP, field)
+ interioradr = baseadr + offset
+ return (llmemory.cast_adr_to_int(interioradr, 'forced') -
+ llmemory.cast_adr_to_int(baseadr, 'forced'))
+
+
@specialize.memo()
def rpy_string_as_type(TP):
# sanity check that STR is actually what we think it is
@@ -42,6 +54,8 @@
STR_AS_TP = lltype.GcStruct('rpy_string_as_%s' % TP,
('hash', lltype.Signed),
('chars', lltype.Array(TP, hints={'immutable': True})))
+ # sanity check
+ assert compute_offsetof(STR, 'chars') == compute_offsetof(STR_AS_TP, 'chars')
return STR_AS_TP
@specialize.ll()
More information about the pypy-commit
mailing list