Author: Armin Rigo <[email protected]>
Branch:
Changeset: r84:5ffaa9b7d90c
Date: 2014-11-18 19:25 +0100
http://bitbucket.org/cffi/creflect/changeset/5ffaa9b7d90c/
Log: next test
diff --git a/creflect/model.py b/creflect/model.py
--- a/creflect/model.py
+++ b/creflect/model.py
@@ -581,9 +581,8 @@
arraylevels += 1
checktype = checktype.item
if arraylevels:
- block.add_include('stddef.h')
comment = ""
- if arraylevels >= 1:
+ if arraylevels > 1:
comment = " (%dx)" % arraylevels
comment = inspect.get_comment(0, False, "an array%s" % comment)
o_decl = "size_t o = offsetof(%s, %s%s);%s" % (
diff --git a/test/codegen/struct-004.c b/test/codegen/struct-004.c
--- a/test/codegen/struct-004.c
+++ b/test/codegen/struct-004.c
@@ -3,33 +3,34 @@
};
# ____________________________________________________________
-#include <stddef.h>
-static void __creflect1(void r(char *, void**, int))
+void teststruct_004(crx_builder_t *cb)
{
- void *a[4];
- __CREFLECT_PREV(r);
- a[0] = (void *)sizeof(struct foo_s); /* size */
- a[1] = &((struct{char a; struct foo_s b;}*)0)->b; /* align */
- r("struct foo_s", a, 2);
+ crx_type_t *t1, *t2, *t3;
+ crx_field_t d1[1];
+ t1 = cb->get_struct_type(cb, "foo_s");
{
struct foo_s *p1;
- void *o = (void *)offsetof(struct foo_s, aa[0]); /* offset */
char b[sizeof(*p1->aa)]; /* check that 'struct foo_s::aa[]' is a
valid type */
- a[1] = o;
- p1 = (void *)(((char *)b) - (long)o);
+ 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) {
- r("E:type 'struct foo_s::aa' is not an array, but a pointer type",
0, 0);
- goto f1;
+ 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;
- a[2] = (void *)(*p1->aa > 0 ? sizeof(*p1->aa) : -sizeof(*p1->aa));
- a[3] = (void *)(sizeof(p1->aa) / sizeof(*p1->aa));
+ *p1->aa = -1; /* check that 'struct foo_s::aa[]' is not declared
'const' */
+ t2 = CRX_INT_TYPE(cb, *p1->aa, "int");
+ t3 = cb->get_array_type(cb, t2, sizeof(p1->aa) / sizeof(*p1->aa));
+ d1[0].name = "aa";
+ d1[0].type = t3;
+ d1[0].offset = o;
+ d1[0].numbits = -1;
+ d1[0].bitshift = -1;
}
- r("{aa:int?[?]", a, 4);
- f1:;
+ cb->complete(cb, t1, sizeof(struct foo_s),
+ ((char *)&((struct{char a; struct foo_s b;} *)0)->b) - (char
*)0,
+ d1, 1);
+#expect STRUCT foo_s:
+#expect | aa: ARRAY[27] int
}
-
-#expect struct foo_s 108 4
-#expect {aa:int?[?] 99 0 -4 27
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit