Author: Armin Rigo <ar...@tunes.org> Branch: cffi-1.0 Changeset: r1962:d09c84106ff9 Date: 2015-05-10 13:53 +0200 http://bitbucket.org/cffi/cffi/changeset/d09c84106ff9/
Log: Fix issues with uncomputed alignment diff --git a/_cffi1/realize_c_type.c b/_cffi1/realize_c_type.c --- a/_cffi1/realize_c_type.c +++ b/_cffi1/realize_c_type.c @@ -329,10 +329,7 @@ if (s->first_field_index >= 0) { ct = (CTypeDescrObject *)x; ct->ct_size = (Py_ssize_t)s->size; - if (s->alignment == 0) - ct->ct_length = 1; /* guess; should not really matter */ - else - ct->ct_length = s->alignment; + ct->ct_length = s->alignment; /* may be -1 */ ct->ct_flags &= ~CT_IS_OPAQUE; ct->ct_flags |= CT_LAZY_FIELD_LIST; ct->ct_extra = builder; @@ -678,9 +675,9 @@ if (s->flags & _CFFI_F_PACKED) sflags |= SF_PACKED; - args = Py_BuildValue("(OOOnni)", ct, fields, Py_None, + args = Py_BuildValue("(OOOnii)", ct, fields, Py_None, (Py_ssize_t)s->size, - s->alignment ? (Py_ssize_t)s->alignment : -1, + s->alignment, sflags); Py_DECREF(fields); if (args == NULL) diff --git a/_cffi1/recompiler.py b/_cffi1/recompiler.py --- a/_cffi1/recompiler.py +++ b/_cffi1/recompiler.py @@ -606,7 +606,7 @@ else: if named_ptr is not None: size = 'sizeof(*(%s)0)' % (named_ptr.name,) - align = '0 /* unknown */' + align = '-1 /* unknown alignment */' else: size = 'sizeof(%s)' % (cname,) align = 'offsetof(struct _cffi_align_%s, y)' % (approxname,) diff --git a/_cffi1/test_recompiler.py b/_cffi1/test_recompiler.py --- a/_cffi1/test_recompiler.py +++ b/_cffi1/test_recompiler.py @@ -573,6 +573,7 @@ lib = verify(ffi, "test_include_5", "typedef struct {int x[2]; int y; } *mystruct_p; //usually #include\n" "mystruct_p ff5(mystruct_p p) { p->x[1] += 42; return p; }") + assert ffi.alignof(ffi.typeof("mystruct_p").item) == 4 assert ffi1.typeof("mystruct_p") is ffi.typeof("mystruct_p") p = ffi.new("mystruct_p", [[5, 10], -17]) q = lib.ff5(p) diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -1496,6 +1496,10 @@ if ((ct->ct_flags & (CT_PRIMITIVE_ANY|CT_STRUCT|CT_UNION)) && !(ct->ct_flags & CT_IS_OPAQUE)) { align = ct->ct_length; + if (align == -1 && (ct->ct_flags & CT_LAZY_FIELD_LIST)) { + force_lazy_struct(ct); + align = ct->ct_length; + } } else if (ct->ct_flags & (CT_POINTER|CT_FUNCTIONPTR)) { struct aligncheck_ptr { char x; char *y; }; _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit