Skip to content

Commit

Permalink
C: Add extern to header files for provided functions (#664)
Browse files Browse the repository at this point in the history
Help syntactically show which functions are implemented by users and
which are imported from the environment. I don't think `extern` actually
does anything here and most of the functions actually have shims in the
C files generated, but I also don't believe that `extern` harms anything
either.

Closes #663
  • Loading branch information
alexcrichton authored Sep 11, 2023
1 parent 1590709 commit 3ffbdd3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crates/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ impl C {

uwriteln!(
h_str,
"void {borrow_namespace}_{snake}_drop_borrow({borrow_name});"
"extern void {borrow_namespace}_{snake}_drop_borrow({borrow_name});"
);

uwriteln!(
Expand All @@ -589,7 +589,7 @@ impl C {

uwriteln!(
h_str,
"{own_name} {namespace}_{snake}_new({namespace}_{snake}_t*);"
"extern {own_name} {namespace}_{snake}_new({namespace}_{snake}_t*);"
);

uwriteln!(
Expand All @@ -604,7 +604,7 @@ impl C {

uwriteln!(
h_str,
"{namespace}_{snake}_t* {namespace}_{snake}_rep({own_name});"
"extern {namespace}_{snake}_t* {namespace}_{snake}_rep({own_name});"
);

uwriteln!(
Expand Down Expand Up @@ -1585,6 +1585,7 @@ impl InterfaceGenerator<'_> {
);
let name = self.c_func_name(interface_name, func);
let import_name = self.gen.names.tmp(&format!("__wasm_import_{name}",));
self.src.c_fns("extern ");
match sig.results.len() {
0 => self.src.c_fns("void"),
1 => self.src.c_fns(wasm_type(sig.results[0])),
Expand All @@ -1606,6 +1607,7 @@ impl InterfaceGenerator<'_> {

// Print the public facing signature into the header, and since that's
// what we are defining also print it into the C file.
self.src.h_fns("extern ");
let c_sig = self.print_sig(interface_name, func, !self.gen.opts.no_sig_flattening);
self.src.c_adapters("\n");
self.src.c_adapters(&c_sig.sig);
Expand Down

0 comments on commit 3ffbdd3

Please sign in to comment.