Skip to content

Commit 99a0f62

Browse files
committed
fix(wasm): guard the C --leak-seconds feature behind #ifndef __EMSCRIPTEN__
The WASM build compiles src/printable_binary.c with the CLI/buffer_free path excluded (#ifndef __EMSCRIPTEN__). My new run_leak_loop calls buffer_free but wasn't guarded, so emcc failed with 'call to undeclared function buffer_free'. Wrap the leak helpers + run_leak_loop + the main dispatch in the same guard (it's a CLI-only test feature). emcc + clang + zig cc all compile; C tests pass; nix .#printableBinaryWasm builds.
1 parent 7e4e07e commit 99a0f62

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/printable_binary.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,8 @@ static options_t parse_options(int argc, char *argv[]) {
16191619

16201620

16211621
#ifndef PRINTABLE_BINARY_NO_MAIN
1622+
/* CLI-only leak-test support: the WASM build excludes the buffer_free/CLI path. */
1623+
#ifndef __EMSCRIPTEN__
16221624
/* ---- memory-leak suite support (driven by test/leak_test via --leak-seconds) ---- */
16231625
static long pb_now_ms(void) {
16241626
struct timespec ts;
@@ -1668,8 +1670,10 @@ static void run_leak_loop(long seconds) {
16681670
printf("RSS %ld\n", pb_rss_kb());
16691671
fflush(stdout);
16701672
}
1673+
#endif /* !__EMSCRIPTEN__ */
16711674

16721675
int main(int argc, char *argv[]) {
1676+
#ifndef __EMSCRIPTEN__
16731677
// Leak-test mode (test/leak_test): long-lived encode/decode loop, then exit.
16741678
for (int ai = 1; ai < argc; ai++) {
16751679
if (strcmp(argv[ai], "--leak-seconds") == 0 && ai + 1 < argc) {
@@ -1678,6 +1682,7 @@ int main(int argc, char *argv[]) {
16781682
return 0;
16791683
}
16801684
}
1685+
#endif /* !__EMSCRIPTEN__ */
16811686
// Parse command line options first (needed for help/usage)
16821687
options_t opts = parse_options(argc, argv);
16831688
const char *program_display_name = resolve_program_name(argv[0]);

0 commit comments

Comments
 (0)