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...@@ -6592,6 +6592,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
6592 }6592 }
6593 }6593 }
6594 case TypeTableEntryIdStruct:6594 case TypeTableEntryIdStruct:
6595 case TypeTableEntryIdOpaque:
6595 {6596 {
6596 buf_init_from_str(out_buf, "struct ");6597 buf_init_from_str(out_buf, "struct ");
6597 buf_append_buf(out_buf, &type_entry->name);6598 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...@@ -6609,11 +6610,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
6609 buf_append_buf(out_buf, &type_entry->name);6610 buf_append_buf(out_buf, &type_entry->name);
6610 return;6611 return;
6611 }6612 }
6612 case TypeTableEntryIdOpaque:
6613 {
6614 buf_init_from_buf(out_buf, &type_entry->name);
6615 return;
6616 }
6617 case TypeTableEntryIdArray:6613 case TypeTableEntryIdArray:
6618 {6614 {
6619 TypeTableEntryArray *array_data = &type_entry->data.array;6615 TypeTableEntryArray *array_data = &type_entry->data.array;
test/gen_h.zig+11
...@@ -51,6 +51,16 @@ pub fn addCases(cases: &tests.GenHContext) void {...@@ -51,6 +51,16 @@ pub fn addCases(cases: &tests.GenHContext) void {
51 \\51 \\
52 );52 );
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
54 cases.add("array field-type",64 cases.add("array field-type",
55 \\const Foo = extern struct {65 \\const Foo = extern struct {
56 \\ A: [2]i32,66 \\ A: [2]i32,
...@@ -66,4 +76,5 @@ pub fn addCases(cases: &tests.GenHContext) void {...@@ -66,4 +76,5 @@ pub fn addCases(cases: &tests.GenHContext) void {
66 \\TEST_EXPORT void entry(struct Foo foo, uint8_t bar[]);76 \\TEST_EXPORT void entry(struct Foo foo, uint8_t bar[]);
67 \\77 \\
68 );78 );
79
69}80}