authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-03-23 20:27:11+13:00
committergravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-03-23 20:27:11+13:00
log3d1732ef6c8ebc7edf10485f61b4ec905303cd8a
tree04f6cb679eebd178db1ca0eba2652f99c102fe73
parent7a99d63c764f3d5d92370c90f932b1bf156269f6

Fix OpqaueType usage in exported c functions

We prefer `struct typename`. If a typedef is required, this must be done manually after generation.

2 files changed, 12 insertions(+), 5 deletions(-)

src/codegen.cpp+1-5
......@@ -6592,6 +6592,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
65926592 }
65936593 }
65946594 case TypeTableEntryIdStruct:
6595 case TypeTableEntryIdOpaque:
65956596 {
65966597 buf_init_from_str(out_buf, "struct ");
65976598 buf_append_buf(out_buf, &type_entry->name);
......@@ -6609,11 +6610,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
66096610 buf_append_buf(out_buf, &type_entry->name);
66106611 return;
66116612 }
6612 case TypeTableEntryIdOpaque:
6613 {
6614 buf_init_from_buf(out_buf, &type_entry->name);
6615 return;
6616 }
66176613 case TypeTableEntryIdArray:
66186614 {
66196615 TypeTableEntryArray *array_data = &type_entry->data.array;
test/gen_h.zig+11
......@@ -51,6 +51,16 @@ pub fn addCases(cases: &tests.GenHContext) void {
5151 \\
5252 );
5353
54 cases.add("declare opaque type",
55 \\export const Foo = @OpaqueType();
56 \\
57 \\export fn entry(foo: ?&Foo) void { }
58 ,
59 \\struct Foo;
60 \\
61 \\TEST_EXPORT void entry(struct Foo * foo);
62 );
63
5464 cases.add("array field-type",
5565 \\const Foo = extern struct {
5666 \\ A: [2]i32,
......@@ -66,4 +76,5 @@ pub fn addCases(cases: &tests.GenHContext) void {
6676 \\TEST_EXPORT void entry(struct Foo foo, uint8_t bar[]);
6777 \\
6878 );
79
6980}