[pypy-commit] pypy faster-rstruct-2: add a new test flag to disallow fast paths
antocuni
pypy.commits at gmail.com
Thu May 18 11:13:35 EDT 2017
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: faster-rstruct-2
Changeset: r91332:274be07c41af
Date: 2017-05-18 12:01 +0200
http://bitbucket.org/pypy/pypy/changeset/274be07c41af/
Log: add a new test flag to disallow fast paths
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
@@ -19,6 +19,7 @@
USE_FASTPATH = True # set to False by some tests
ALLOW_SLOWPATH = True # set to False by some tests
+ALLOW_FASTPATH = True # set to False by some tests
native_is_bigendian = struct.pack("=i", 1) == struct.pack(">i", 1)
native_is_ieee754 = float.__getformat__('double').startswith('IEEE')
@@ -39,6 +40,8 @@
pos % size != 0):
raise CannotWrite
#
+ if not ALLOW_FASTPATH:
+ raise ValueError("fastpath not allowed :(")
# typed_write() might raise CannotWrite
fmtiter.wbuf.typed_write(TYPE, fmtiter.pos, value)
fmtiter.advance(size)
@@ -208,6 +211,8 @@
# *and* it is not supported.
raise CannotRead
#
+ if not ALLOW_FASTPATH:
+ raise ValueError("fastpath not allowed :(")
# typed_read does not do any bound check, so we must call it only if
# we are sure there are at least "size" bytes to read
if fmtiter.can_advance(size):
diff --git a/rpython/rlib/rstruct/test/test_pack.py b/rpython/rlib/rstruct/test/test_pack.py
--- a/rpython/rlib/rstruct/test/test_pack.py
+++ b/rpython/rlib/rstruct/test/test_pack.py
@@ -44,14 +44,17 @@
USE_FASTPATH = True
ALLOW_SLOWPATH = True
+ ALLOW_FASTPATH = True
def setup_method(self, meth):
standardfmttable.USE_FASTPATH = self.USE_FASTPATH
standardfmttable.ALLOW_SLOWPATH = self.ALLOW_SLOWPATH
+ standardfmttable.ALLOW_FASTPATH = self.ALLOW_FASTPATH
def teardown_method(self, meth):
standardfmttable.USE_FASTPATH = True
standardfmttable.ALLOW_SLOWPATH = True
+ standardfmttable.ALLOW_FASTPATH = True
def mypack(self, fmt, value):
size = struct.calcsize(fmt)
@@ -94,6 +97,16 @@
expected = struct.pack('i', 42)
assert self.mypack('i', 42) == expected
+class TestAllowFastPath(PackSupport):
+ ALLOW_FASTPATH = False
+ bigendian = nativefmttable.native_is_bigendian
+ fmttable = standardfmttable.standard_fmttable
+
+ def test_fastpath_not_allowed(self):
+ # we are using a native endianess but ALLOW_FASTPATH is False, so
+ # the following MUST raise
+ pytest.raises(ValueError, "self.mypack('i', 42)")
+
class BaseTestPack(PackSupport):
More information about the pypy-commit
mailing list