Skip to content

Commit

Permalink
wasm2c: Avoid unnecessary extern in function decls. NFC (#1910)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Apr 29, 2022
1 parent 64c0857 commit d6dfa01
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/c-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2379,8 +2379,8 @@ void CWriter::WriteCHeader() {
Write(s_header_top);
WriteMultivalueTypes();
WriteImports();
Write("extern void ", module_prefix_, "_init(void);", Newline());
Write("extern void ", module_prefix_, "_free(void);", Newline());
Write("void ", module_prefix_, "_init(void);", Newline());
Write("void ", module_prefix_, "_free(void);", Newline());
WriteExports(WriteExportsKind::Declarations);
Write(s_header_bottom);
Write(Newline(), "#endif /* ", guard, " */", Newline());
Expand Down
24 changes: 12 additions & 12 deletions wasm2c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ The generated header file looks something like this:
extern "C" {
#endif

extern void Z_fac_init(void);
extern void Z_fac_free(void);
void Z_fac_init(void);
void Z_fac_free(void);

/* export: 'fac' */
extern u32 (*Z_facZ_fac)(u32);
Expand Down Expand Up @@ -241,15 +241,15 @@ A C implementation of these functions is defined in
```c
void wasm_rt_init(void);
void wasm_rt_free(void);
extern void wasm_rt_trap(wasm_rt_trap_t) __attribute__((noreturn));
void wasm_rt_trap(wasm_rt_trap_t) __attribute__((noreturn));
const char* wasm_rt_strerror(wasm_rt_trap_t trap);
extern uint32_t wasm_rt_register_func_type(uint32_t params, uint32_t results, ...);
extern void wasm_rt_allocate_memory(wasm_rt_memory_t*, uint32_t initial_pages, uint32_t max_pages);
extern uint32_t wasm_rt_grow_memory(wasm_rt_memory_t*, uint32_t pages);
extern void wasm_rt_free_memory(wasm_rt_memory_t*);
extern void wasm_rt_allocate_table(wasm_rt_table_t*, uint32_t elements, uint32_t max_elements);
extern void wasm_rt_free_table(wasm_rt_table_t*);
extern uint32_t wasm_rt_call_stack_depth; /* on platforms that don't use the signal handler to detect exhaustion */
uint32_t wasm_rt_register_func_type(uint32_t params, uint32_t results, ...);
void wasm_rt_allocate_memory(wasm_rt_memory_t*, uint32_t initial_pages, uint32_t max_pages);
uint32_t wasm_rt_grow_memory(wasm_rt_memory_t*, uint32_t pages);
void wasm_rt_free_memory(wasm_rt_memory_t*);
void wasm_rt_allocate_table(wasm_rt_table_t*, uint32_t elements, uint32_t max_elements);
void wasm_rt_free_table(wasm_rt_table_t*);
uint32_t wasm_rt_call_stack_depth; /* on platforms that don't use the signal handler to detect exhaustion */
```
`wasm_rt_trap` is a function that is called when the module traps. Some
Expand Down Expand Up @@ -295,8 +295,8 @@ must be called before the module can be used, and `free`, which frees
the module's state (its memory and table instances).
```c
extern void Z_fac_init(void);
extern void Z_fac_free(void);
void Z_fac_init(void);
void Z_fac_free(void);
/* export: 'fac' */
extern u32 (*Z_facZ_fac)(u32);
Expand Down
4 changes: 2 additions & 2 deletions wasm2c/examples/fac/fac.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ typedef double f64;
extern "C" {
#endif

extern void Z_fac_init(void);
extern void Z_fac_free(void);
void Z_fac_init(void);
void Z_fac_free(void);

/* export: 'fac' */
extern u32 (*Z_facZ_fac)(u32);
Expand Down
22 changes: 10 additions & 12 deletions wasm2c/wasm-rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ const char* wasm_rt_strerror(wasm_rt_trap_t trap);
* wasm_rt_register_func_type(2, 1, WASM_RT_I32, WASM_RT_F32, WASM_RT_I64);
* => returns 1
* ``` */
extern uint32_t wasm_rt_register_func_type(uint32_t params,
uint32_t results,
...);
uint32_t wasm_rt_register_func_type(uint32_t params, uint32_t results, ...);

/** Initialize a Memory object with an initial page size of `initial_pages` and
* a maximum page size of `max_pages`.
Expand All @@ -211,9 +209,9 @@ extern uint32_t wasm_rt_register_func_type(uint32_t params,
* // 1 initial page (65536 bytes), and a maximum of 2 pages.
* wasm_rt_allocate_memory(&my_memory, 1, 2);
* ``` */
extern void wasm_rt_allocate_memory(wasm_rt_memory_t*,
uint32_t initial_pages,
uint32_t max_pages);
void wasm_rt_allocate_memory(wasm_rt_memory_t*,
uint32_t initial_pages,
uint32_t max_pages);

/** Grow a Memory object by `pages`, and return the previous page count. If