[pypy-commit] pypy faster-rstruct-2: WIP: add a failing test which show why the current way to detect alignement is buggy
antocuni
pypy.commits at gmail.com
Thu May 18 11:13:38 EDT 2017
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: faster-rstruct-2
Changeset: r91334:6bed52a9d7c6
Date: 2017-05-18 16:26 +0200
http://bitbucket.org/pypy/pypy/changeset/6bed52a9d7c6/
Log: WIP: add a failing test which show why the current way to detect
alignement is buggy
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
@@ -2,6 +2,7 @@
from rpython.rlib.rarithmetic import r_ulonglong
from rpython.rlib.rstruct import standardfmttable, nativefmttable
from rpython.rlib.rstruct.error import StructOverflowError
+from rpython.rlib.buffer import SubBuffer
from rpython.rlib.mutbuffer import MutableStringBuffer
import struct
@@ -215,3 +216,17 @@
assert fake_fmtiter.pos == wbuf.getlength()
got = wbuf.finish()
assert got == expected
+
+ def test_subbuffer(self):
+ # to force a non-aligned 'i'
+ expected = struct.pack('=BBi', 0xAB, 0xCD, 0x1234)
+ size = len(expected)
+ #
+ wbuf = MutableStringBuffer(size)
+ wsubbuf = SubBuffer(wbuf, 2, size-4)
+ wbuf.setitem(0, chr(0xAB))
+ wbuf.setitem(1, chr(0xCD))
+ fake_fmtiter = self.mypack_into('i', wsubbuf, 0x1234)
+ assert fake_fmtiter.pos == wbuf.getlength()
+ got = wbuf.finish()
+ assert got == expected
More information about the pypy-commit
mailing list