[pypy-commit] pypy faster-rstruct-2: add the compiled version of the tests. We still need to add the correct @specialize to Buffer.typed_read, although the tests pass anyway (because we always call Buffer.typed_read once)

antocuni pypy.commits at gmail.com
Wed May 3 13:10:59 EDT 2017


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: faster-rstruct-2
Changeset: r91178:29b4a2158631
Date: 2017-05-03 19:10 +0200
http://bitbucket.org/pypy/pypy/changeset/29b4a2158631/

Log:	add the compiled version of the tests. We still need to add the
	correct @specialize to Buffer.typed_read, although the tests pass
	anyway (because we always call Buffer.typed_read once)

diff --git a/rpython/rlib/test/test_buffer.py b/rpython/rlib/test/test_buffer.py
--- a/rpython/rlib/test/test_buffer.py
+++ b/rpython/rlib/test/test_buffer.py
@@ -4,7 +4,7 @@
 from rpython.rlib.buffer import StringBuffer, SubBuffer, Buffer
 from rpython.annotator.annrpython import RPythonAnnotator
 from rpython.annotator.model import SomeInteger
-
+from rpython.rtyper.test.tool import BaseRtypingTest
 
 def test_string_buffer():
     buf = StringBuffer('hello world')
@@ -114,3 +114,27 @@
         return buf.typed_read(TYPE, offset)
 
 
+class TestCompiled(BaseTypedReadTest):
+    cache = {}
+
+    def read(self, TYPE, data, offset):
+        if TYPE not in self.cache:
+            from rpython.translator.c.test.test_genc import compile
+
+            assert isinstance(TYPE, lltype.Primitive)
+            if TYPE in (lltype.Float, lltype.SingleFloat):
+                TARGET_TYPE = lltype.Float
+            else:
+                TARGET_TYPE = lltype.Signed
+
+            def llf(data, offset):
+                buf = StringBuffer(data)
+                x = buf.typed_read(TYPE, offset)
+                return lltype.cast_primitive(TARGET_TYPE, x)
+
+            fn = compile(llf, [str, int])
+            self.cache[TYPE] = fn
+        #
+        fn = self.cache[TYPE]
+        x = fn(data, offset)
+        return lltype.cast_primitive(TYPE, x)


More information about the pypy-commit mailing list