[pypy-commit] pypy faster-rstruct: fix rstruct.unpack q and Q on systems which do not support str_storage_getitem, such as win32 and probably ARM 32 bit

antocuni noreply at buildbot.pypy.org
Mon Nov 23 15:36:56 EST 2015


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: faster-rstruct
Changeset: r80870:f856371c182b
Date: 2015-11-23 20:56 +0100
http://bitbucket.org/pypy/pypy/changeset/f856371c182b/

Log:	fix rstruct.unpack q and Q on systems which do not support
	str_storage_getitem, such as win32 and probably ARM 32 bit

diff --git a/rpython/rlib/rstruct/standardfmttable.py b/rpython/rlib/rstruct/standardfmttable.py
--- a/rpython/rlib/rstruct/standardfmttable.py
+++ b/rpython/rlib/rstruct/standardfmttable.py
@@ -12,7 +12,7 @@
 from rpython.rlib.rstruct import ieee
 from rpython.rlib.rstruct.error import StructError, StructOverflowError
 from rpython.rlib.unroll import unrolling_iterable
-from rpython.rlib.strstorage import str_storage_getitem
+from rpython.rlib.strstorage import str_storage_getitem, str_storage_supported
 from rpython.rlib import rarithmetic
 from rpython.rtyper.lltypesystem import rffi
 
@@ -229,7 +229,7 @@
 
     @specialize.argtype(0)
     def unpack_int_fastpath_maybe(fmtiter):
-        if fmtiter.bigendian != native_is_bigendian:
+        if fmtiter.bigendian != native_is_bigendian or not str_storage_supported(TYPE):
             return False
         try:
             intvalue = unpack_fastpath(TYPE)(fmtiter)
diff --git a/rpython/rlib/strstorage.py b/rpython/rlib/strstorage.py
--- a/rpython/rlib/strstorage.py
+++ b/rpython/rlib/strstorage.py
@@ -58,6 +58,15 @@
     assert compute_offsetof(STR, 'chars') == compute_offsetof(STR_AS_TP, 'chars')
     return STR_AS_TP
 
+ at specialize.memo()
+def str_storage_supported(TP):
+    try:
+        rpy_string_as_type(TP)
+    except AssertionError:
+        return False
+    else:
+        return True
+
 @specialize.ll()
 def str_storage_getitem(TP, s, index):
     STR_AS_TP = rpy_string_as_type(TP)


More information about the pypy-commit mailing list