Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r497:9da8decd4c42 Date: 2012-06-23 16:31 +0200 http://bitbucket.org/cffi/cffi/changeset/9da8decd4c42/
Log: Support bitfields in initializers. diff --git a/c/_ffi_backend.c b/c/_ffi_backend.c --- a/c/_ffi_backend.c +++ b/c/_ffi_backend.c @@ -699,6 +699,20 @@ return -1; } +static int /* forward */ +convert_from_object(char *data, CTypeDescrObject *ct, PyObject *init); +static int /* forward */ +convert_from_object_bitfield(char *data, CFieldObject *cf, PyObject *init); + +static int +convert_field_from_object(char *data, CFieldObject *cf, PyObject *value) +{ + if (cf->cf_bitshift >= 0) + return convert_from_object_bitfield(data, cf, value); + else + return convert_from_object(data, cf->cf_type, value); +} + static int convert_from_object(char *data, CTypeDescrObject *ct, PyObject *init) { @@ -840,10 +854,8 @@ ct->ct_name, n); return -1; } - if (bitfield_not_supported(cf) < 0) - return -1; - if (convert_from_object(data + cf->cf_offset, - cf->cf_type, items[i]) < 0) + if (convert_field_from_object(data + cf->cf_offset, + cf, items[i]) < 0) return -1; cf = cf->cf_next; } @@ -1374,10 +1386,7 @@ /* write the field 'cf' */ char *data = cd->c_data + cf->cf_offset; if (value != NULL) { - if (cf->cf_bitshift >= 0) - return convert_from_object_bitfield(data, cf, value); - else - return convert_from_object(data, cf->cf_type, value); + return convert_field_from_object(data, cf, value); } else { PyErr_SetString(PyExc_AttributeError, diff --git a/c/test_c.py b/c/test_c.py --- a/c/test_c.py +++ b/c/test_c.py @@ -841,7 +841,8 @@ BInt = new_primitive_type("int") BStruct = new_struct_type("foo") complete_struct_or_union(BStruct, [('a1', BInt, 1)]) - py.test.raises(NotImplementedError, newp, new_pointer_type(BStruct), [-1]) + p = newp(new_pointer_type(BStruct), [-1]) + assert p.a1 == -1 def test_weakref(): import weakref _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit