From 81aba2d53c3698fd7cc2585cde08311fc58f8d7f Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 7 Sep 2025 10:08:29 +0200 Subject: [PATCH 1/2] Avoid proxying print handlers back to the main thread This partially reverts commit 97b352ee167ce798678898de38d40bb9c000e2c6. Resolves: #19683. --- src/lib/libpthread.js | 6 ------ src/runtime_pthread.js | 5 +---- test/test_other.py | 36 ------------------------------------ 3 files changed, 1 insertion(+), 46 deletions(-) diff --git a/src/lib/libpthread.js b/src/lib/libpthread.js index 44d75892c6e13..7ab90dff1a62a 100644 --- a/src/lib/libpthread.js +++ b/src/lib/libpthread.js @@ -344,12 +344,6 @@ var LibraryPThread = { #endif #if expectToReceiveOnModule('onAbort') 'onAbort', -#endif -#if expectToReceiveOnModule('print') - 'print', -#endif -#if expectToReceiveOnModule('printErr') - 'printErr', #endif ]; for (var handler of knownHandlers) { diff --git a/src/runtime_pthread.js b/src/runtime_pthread.js index a77b2d9bbcc38..b637defa380cf 100644 --- a/src/runtime_pthread.js +++ b/src/runtime_pthread.js @@ -82,7 +82,7 @@ if (ENVIRONMENT_IS_PTHREAD) { // Use `const` here to ensure that the variable is scoped only to // that iteration, allowing safe reference from a closure. for (const handler of msgData.handlers) { - // The the main module has a handler for a certain even, but no + // The main module has a handler for a certain event, but no // handler exists on the pthread worker, then proxy that handler // back to the main thread. if (!Module[handler] || Module[handler].proxy) { @@ -95,9 +95,6 @@ if (ENVIRONMENT_IS_PTHREAD) { #endif postMessage({ cmd: 'callHandler', handler, args: args }); } - // Rebind the out / err handlers if needed - if (handler == 'print') out = Module[handler]; - if (handler == 'printErr') err = Module[handler]; } #if RUNTIME_DEBUG else dbg(`worker: using thread-local handler: ${handler}`); diff --git a/test/test_other.py b/test/test_other.py index ac5bfb01aafa8..1a23b9f68ae9b 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -7235,42 +7235,6 @@ def test_modularize_instantiation_error(self): self.assertContained('failed to asynchronously prepare wasm', output) self.assertContained('got error: RuntimeError: Aborted', output) - @crossplatform - @node_pthreads - @flaky('https://github.com/emscripten-core/emscripten/issues/19683') - # The flakiness of this test is very high on macOS so just disable it - # completely. - @no_mac('https://github.com/emscripten-core/emscripten/issues/19683') - def test_pthread_print_override_modularize(self): - self.set_setting('EXPORT_NAME', 'Test') - self.set_setting('PROXY_TO_PTHREAD') - self.set_setting('EXIT_RUNTIME') - self.set_setting('MODULARIZE') - create_file('main.c', ''' - #include - - int main() { - emscripten_out("hello, world!"); - return 0; - } - ''') - create_file('main.js', ''' - const Test = require('./test.js'); - - async function main() { - await Test({ - // world -> earth - print: (text) => console.log(text.replace('world', 'earth')) - }); - } - main(); - ''') - - self.emcc('main.c', output_filename='test.js') - output = self.run_js('main.js') - self.assertNotContained('hello, world!', output) - self.assertContained('hello, earth!', output) - def test_define_modularize(self): self.run_process([EMCC, test_file('hello_world.c'), '-sMODULARIZE', '-sASSERTIONS=0']) src = 'var module = 0; ' + read_file('a.out.js') From 3d7f74a55a8827f44c2f8e2df064a49876a28713 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 7 Sep 2025 09:08:36 +0000 Subject: [PATCH 2/2] Automatic rebaseline of codesize expectations. NFC This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (2) test expectation files were updated by running the tests with `--rebaseline`: ``` code_size/test_codesize_minimal_pthreads.json: 27251 => 27205 [-46 bytes / -0.17%] code_size/test_codesize_minimal_pthreads_memgrowth.json: 27679 => 27633 [-46 bytes / -0.17%] Average change: -0.17% (-0.17% - -0.17%) ``` --- test/code_size/test_codesize_minimal_pthreads.json | 8 ++++---- .../test_codesize_minimal_pthreads_memgrowth.json | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/code_size/test_codesize_minimal_pthreads.json b/test/code_size/test_codesize_minimal_pthreads.json index dae747cce1239..90274311f5b69 100644 --- a/test/code_size/test_codesize_minimal_pthreads.json +++ b/test/code_size/test_codesize_minimal_pthreads.json @@ -1,10 +1,10 @@ { - "a.out.js": 7659, - "a.out.js.gz": 3776, + "a.out.js": 7613, + "a.out.js.gz": 3753, "a.out.nodebug.wasm": 19592, "a.out.nodebug.wasm.gz": 9060, - "total": 27251, - "total_gz": 12836, + "total": 27205, + "total_gz": 12813, "sent": [ "a (memory)", "b (emscripten_get_now)", diff --git a/test/code_size/test_codesize_minimal_pthreads_memgrowth.json b/test/code_size/test_codesize_minimal_pthreads_memgrowth.json index 521a48e365036..8c1217e1574b1 100644 --- a/test/code_size/test_codesize_minimal_pthreads_memgrowth.json +++ b/test/code_size/test_codesize_minimal_pthreads_memgrowth.json @@ -1,10 +1,10 @@ { - "a.out.js": 8086, - "a.out.js.gz": 3977, + "a.out.js": 8040, + "a.out.js.gz": 3953, "a.out.nodebug.wasm": 19593, "a.out.nodebug.wasm.gz": 9061, - "total": 27679, - "total_gz": 13038, + "total": 27633, + "total_gz": 13014, "sent": [ "a (memory)", "b (emscripten_get_now)",