mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Generate extern "C" in the .c, not just the .h.
This commit is contained in:
1 parent
71a3ad6563
commit
cc9aeb63c1
2 files changed
+21
-17
No files matched your search
+13
-17
@@ -26,10 +26,7 @@ func (g *Generator) Generate(pkgName string, m *t.IDMap, files []*a.File) ([]byt
|
||||
// Write preamble.
|
||||
fmt.Fprintf(b, "// Code generated by puffs-gen-%c. DO NOT EDIT.\n\n", g.Extension)
|
||||
b.WriteString(preamble)
|
||||
b.WriteByte('\n')
|
||||
if g.Extension == 'h' {
|
||||
b.WriteString("#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n")
|
||||
}
|
||||
b.WriteString("\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n")
|
||||
|
||||
b.WriteString("// ---------------- Status Codes\n\n")
|
||||
b.WriteString("typedef enum {\n")
|
||||
@@ -60,24 +57,23 @@ func (g *Generator) Generate(pkgName string, m *t.IDMap, files []*a.File) ([]byt
|
||||
}
|
||||
}
|
||||
|
||||
if g.Extension != 'h' {
|
||||
b.WriteString("// ---------------- Constructor and Destructor Implementations\n\n")
|
||||
for _, f := range files {
|
||||
for _, n := range f.TopLevelDecls() {
|
||||
if n.Kind() == a.KStruct {
|
||||
if err := writeCtorImpls(b, pkgName, m, n.Struct()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Finish up the header, which is also the first part of the .c file.
|
||||
b.WriteString("\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n")
|
||||
if g.Extension == 'h' {
|
||||
return format(b)
|
||||
}
|
||||
|
||||
b.WriteString("// ---------------- Constructor and Destructor Implementations\n\n")
|
||||
for _, f := range files {
|
||||
for _, n := range f.TopLevelDecls() {
|
||||
if n.Kind() == a.KStruct {
|
||||
if err := writeCtorImpls(b, pkgName, m, n.Struct()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write postamble.
|
||||
if g.Extension == 'h' {
|
||||
b.WriteString("\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n")
|
||||
}
|
||||
|
||||
return format(b)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
#error "Puffs requires a word size of at least 32 bits"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
typedef enum {
|
||||
@@ -39,6 +43,10 @@ void puffs_gif_lzw_decoder_constructor(puffs_gif_lzw_decoder* self);
|
||||
|
||||
void puffs_gif_lzw_decoder_destructor(puffs_gif_lzw_decoder* self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// ---------------- Constructor and Destructor Implementations
|
||||
|
||||
void puffs_gif_lzw_decoder_constructor(puffs_gif_lzw_decoder* self) {
|
||||
|
||||
Reference in new issue
Block a user