[pypy-commit] pypy ffistruct: adjust the total size according to the alignment: this makes more tests passing

antocuni noreply at buildbot.pypy.org
Wed Nov 9 13:51:09 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: ffistruct
Changeset: r48998:f73603fe9a7d
Date: 2011-11-08 14:10 +0100
http://bitbucket.org/pypy/pypy/changeset/f73603fe9a7d/

Log:	adjust the total size according to the alignment: this makes more
	tests passing

diff --git a/pypy/module/_ffi/interp_struct.py b/pypy/module/_ffi/interp_struct.py
--- a/pypy/module/_ffi/interp_struct.py
+++ b/pypy/module/_ffi/interp_struct.py
@@ -16,6 +16,9 @@
         self.w_ffitype = w_ffitype
         self.offset = -1
 
+    def __repr__(self):
+        return '<Field %s %s>' % (self.name, self.w_ffitype.name)
+
 @unwrap_spec(name=str)
 def descr_new_field(space, w_type, name, w_ffitype):
     w_ffitype = space.interp_w(W_FFIType, w_ffitype)
@@ -88,6 +91,8 @@
         w_field.offset = size
         size += fieldsize
         fields_w2.append(w_field)
+    #
+    size = round_up(size, alignment)
     return size, alignment, fields_w2
 
 
diff --git a/pypy/module/_ffi/test/test_struct.py b/pypy/module/_ffi/test/test_struct.py
--- a/pypy/module/_ffi/test/test_struct.py
+++ b/pypy/module/_ffi/test/test_struct.py
@@ -30,10 +30,10 @@
         assert self.sizeof([T.sbyte, T.sbyte, T.slonglong]) == llong_align + llong_size
         assert self.sizeof([T.sbyte, T.sbyte, T.sbyte, T.slonglong]) == llong_align + llong_size
         assert self.sizeof([T.sbyte, T.sbyte, T.sbyte, T.sbyte, T.slonglong]) == llong_align + llong_size
-        ## assert self.sizeof([T.slonglong, T.sbyte]) == llong_size + llong_align
-        ## assert self.sizeof([T.slonglong, T.sbyte, T.sbyte]) == llong_size + llong_align
-        ## assert self.sizeof([T.slonglong, T.sbyte, T.sbyte, T.sbyte]) == llong_size + llong_align
-        ## assert self.sizeof([T.slonglong, T.sbyte, T.sbyte, T.sbyte, T.sbyte]) == llong_size + llong_align
+        assert self.sizeof([T.slonglong, T.sbyte]) == llong_size + llong_align
+        assert self.sizeof([T.slonglong, T.sbyte, T.sbyte]) == llong_size + llong_align
+        assert self.sizeof([T.slonglong, T.sbyte, T.sbyte, T.sbyte]) == llong_size + llong_align
+        assert self.sizeof([T.slonglong, T.sbyte, T.sbyte, T.sbyte, T.sbyte]) == llong_size + llong_align
 
 
 class AppTestStruct(BaseAppTestFFI):


More information about the pypy-commit mailing list