Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r496:d5a0cbf8a551 Date: 2012-06-23 15:42 +0200 http://bitbucket.org/cffi/cffi/changeset/d5a0cbf8a551/
Log: alignof() on a non-completed struct diff --git a/c/_ffi_backend.c b/c/_ffi_backend.c --- a/c/_ffi_backend.c +++ b/c/_ffi_backend.c @@ -962,7 +962,8 @@ { int align; retry: - if (ct->ct_flags & (CT_PRIMITIVE_ANY|CT_STRUCT|CT_UNION)) { + if ((ct->ct_flags & (CT_PRIMITIVE_ANY|CT_STRUCT|CT_UNION)) && + !(ct->ct_flags & CT_IS_OPAQUE)) { align = ct->ct_length; } else if (ct->ct_flags & (CT_POINTER|CT_FUNCTIONPTR)) { @@ -980,7 +981,7 @@ } if ((align < 1) || (align & (align-1))) { - PyErr_Format(PyExc_TypeError, + PyErr_Format(PyExc_SystemError, "found for ctype '%s' bogus alignment '%d'", ct->ct_name, align); return -1; @@ -2361,6 +2362,7 @@ return NULL; td->ct_size = -1; + td->ct_length = -1; td->ct_flags = flag | CT_IS_OPAQUE; memcpy(td->ct_name, kind, kindlen); td->ct_name[kindlen] = ' '; diff --git a/c/test_c.py b/c/test_c.py --- a/c/test_c.py +++ b/c/test_c.py @@ -450,6 +450,7 @@ assert repr(BStruct) == "<ctype 'struct foo'>" BPtr = new_pointer_type(BStruct) assert repr(BPtr) == "<ctype 'struct foo *'>" + py.test.raises(TypeError, alignof, BStruct) def test_new_union_type(): BUnion = new_union_type("foo") _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit