zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 60ea87340e7a7157bedbb43d60804ff0fb191ef9 (tree)
parent 8d6004769731deaabbed014c79b4066bd9e380e8
Author: Soren <soren@disroot.org>
Date:   Sun, 16 Aug 2020 12:08:34 -0700

Fix opaque structs and C++ mangling

Diffstat:
Msrc/codegen.cpp | 14+++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/codegen.cpp b/src/codegen.cpp @@ -10252,9 +10252,11 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e gen_h->types_to_declare.append(type_entry); return; case ZigTypeIdStruct: - for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) { - TypeStructField *field = type_entry->data.structure.fields[i]; - prepend_c_type_to_decl_list(g, gen_h, field->type_entry); + if(type_entry->data.structure.layout == ContainerLayoutExtern) { + for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) { + TypeStructField *field = type_entry->data.structure.fields[i]; + prepend_c_type_to_decl_list(g, gen_h, field->type_entry); + } } gen_h->types_to_declare.append(type_entry); return; @@ -10687,21 +10689,19 @@ static void gen_h_file(CodeGen *g) { fprintf(out_h, "\n"); } - fprintf(out_h, "%s", buf_ptr(&types_buf)); - fprintf(out_h, "#ifdef __cplusplus\n"); fprintf(out_h, "extern \"C\" {\n"); fprintf(out_h, "#endif\n"); fprintf(out_h, "\n"); + fprintf(out_h, "%s", buf_ptr(&types_buf)); fprintf(out_h, "%s\n", buf_ptr(&fns_buf)); + fprintf(out_h, "%s\n", buf_ptr(&vars_buf)); fprintf(out_h, "#ifdef __cplusplus\n"); fprintf(out_h, "} // extern \"C\"\n"); fprintf(out_h, "#endif\n\n"); - fprintf(out_h, "%s\n", buf_ptr(&vars_buf)); - fprintf(out_h, "#endif // %s\n", buf_ptr(ifdef_dance_name)); if (fclose(out_h))