Author: Armin Rigo <[email protected]>
Branch: ffi-backend
Changeset: r56627:0f692101e5a9
Date: 2012-08-07 11:12 +0200
http://bitbucket.org/pypy/pypy/changeset/0f692101e5a9/
Log: Obscure: simulate some alignment in the structures, otherwise
_cffi_backend/ctypefunc.py tests fail.
diff --git a/pypy/rpython/memory/lltypelayout.py
b/pypy/rpython/memory/lltypelayout.py
--- a/pypy/rpython/memory/lltypelayout.py
+++ b/pypy/rpython/memory/lltypelayout.py
@@ -37,6 +37,8 @@
elif isinstance(TYPE, lltype.Struct):
curr = 0
for name in TYPE._names:
+ align = fixed_align_estimate(TYPE._flds[name])
+ curr = (curr + align-1) & ~ (align-1)
layout[name] = curr
curr += get_fixed_size(TYPE._flds[name])
layout["_size"] = curr
@@ -105,6 +107,13 @@
else:
return fixedsize + i * varsize
+def fixed_align_estimate(TYPE):
+ size = get_fixed_size(TYPE)
+ for i in [8, 4, 2]:
+ if i <= memory_alignment and (size % i) == 0:
+ return i
+ return 1
+
def convert_offset_to_int(offset):
if isinstance(offset, llmemory.FieldOffset):
layout = get_layout(offset.TYPE)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit