Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r177:c652e11796b0 Date: 2014-12-05 19:45 +0100 http://bitbucket.org/cffi/creflect/changeset/c652e11796b0/
Log: test and fix for structs-with-incomplete-array diff --git a/creflect/model.py b/creflect/model.py --- a/creflect/model.py +++ b/creflect/model.py @@ -471,7 +471,7 @@ else: star_p1 = None t1, q1 = self.item.inspect_type(block, inspect, qualifiers) - if star_p1 is not None: + if star_p1 is not None and self.length is not None: expr = 'cb->get_array_type(cb, %s, sizeof(%s) / sizeof(*%s))' % ( t1, star_p1, star_p1) else: diff --git a/creflect/test/codegen/struct-004b.c b/creflect/test/codegen/struct-004b.c new file mode 100644 --- /dev/null +++ b/creflect/test/codegen/struct-004b.c @@ -0,0 +1,54 @@ +struct foo_s { + int nn; + int aa[]; +}; + +# ____________________________________________________________ + +void teststruct_004b(_crx_builder_t *cb) +{ + _crx_type_t *t1, *t2, *t3, *t4; + _crx_field_t d1[2]; + t1 = cb->get_struct_type(cb, "foo_s"); + { + struct foo_s *p1; + char b[sizeof(p1->nn)]; + size_t o = ((char *)&((struct foo_s *)0)->nn) - (char *)0; /* check that 'struct foo_s::nn' is not an array */ + p1 = (void *)(((char *)b) - o); + (void)(p1->nn << 1); /* check that 'struct foo_s::nn' is an integer type */ + p1->nn = -1; /* check that 'struct foo_s::nn' is not declared 'const' */ + t2 = _CRX_INT_TYPE(cb, p1->nn, _crx_sc_int); + d1[0].name = "nn"; + d1[0].type = t2; + d1[0].qualifiers = 0; + d1[0].offset = o; + d1[0].numbits = -1; + d1[0].bitshift = -1; + } + { + struct foo_s *p1; + char b[sizeof(*p1->aa)]; /* check that 'struct foo_s::aa[]' is a valid type */ + size_t o = offsetof(struct foo_s, aa[0]); /* check that 'struct foo_s::aa' is an array */ + p1 = (void *)(((char *)b) - o); + if ((void *)&p1->aa != (void *)p1->aa) { + cb->error(cb, "type 'struct foo_s::aa' is not an array, but a pointer type"); + return; + } + (void)(*p1->aa << 1); /* check that 'struct foo_s::aa[]' is an integer type */ + *p1->aa = -1; /* check that 'struct foo_s::aa[]' is not declared 'const' */ + t3 = _CRX_INT_TYPE(cb, *p1->aa, _crx_sc_int); + t4 = cb->get_incomplete_array_type(cb, t3); + d1[1].name = "aa"; + d1[1].type = t4; + d1[1].qualifiers = 0; + d1[1].offset = o; + d1[1].numbits = -1; + d1[1].bitshift = -1; + } + cb->complete(cb, t1, sizeof(struct foo_s), + ((char *)&((struct{char a; struct foo_s b;} *)0)->b) - (char *)0, + d1, 2); +#expect STRUCT foo_s: +#expect | nn: int +#expect | aa: ARRAY[] int +} _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit