Skip to content

Commit e6054f7

Browse files
committed
Proxy emscripten_out* and emscripten_err* back to the main thread
+ reinstate `other.test_pthread_print_override_modularize` test (without the flaky decorators).
1 parent 4d907ad commit e6054f7

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/lib/libcore.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,10 +1967,14 @@ addToLibrary({
19671967
_exit(status);
19681968
},
19691969

1970+
emscripten_out__proxy: 'sync',
19701971
emscripten_out: (str) => out(UTF8ToString(str)),
1972+
emscripten_outn__proxy: 'sync',
19711973
emscripten_outn: (str, len) => out(UTF8ToString(str, len)),
19721974

1975+
emscripten_err__proxy: 'sync',
19731976
emscripten_err: (str) => err(UTF8ToString(str)),
1977+
emscripten_errn__proxy: 'sync',
19741978
emscripten_errn: (str, len) => err(UTF8ToString(str, len)),
19751979

19761980
#if ASSERTIONS || RUNTIME_DEBUG

test/test_other.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7235,6 +7235,38 @@ def test_modularize_instantiation_error(self):
72357235
self.assertContained('failed to asynchronously prepare wasm', output)
72367236
self.assertContained('got error: RuntimeError: Aborted', output)
72377237

7238+
@crossplatform
7239+
@node_pthreads
7240+
def test_pthread_print_override_modularize(self):
7241+
self.set_setting('EXPORT_NAME', 'Test')
7242+
self.set_setting('PROXY_TO_PTHREAD')
7243+
self.set_setting('EXIT_RUNTIME')
7244+
self.set_setting('MODULARIZE')
7245+
create_file('main.c', '''
7246+
#include <emscripten/console.h>
7247+
7248+
int main() {
7249+
emscripten_out("hello, world!");
7250+
return 0;
7251+
}
7252+
''')
7253+
create_file('main.js', '''
7254+
const Test = require('./test.js');
7255+
7256+
async function main() {
7257+
await Test({
7258+
// world -> earth
7259+
print: (text) => console.log(text.replace('world', 'earth'))
7260+
});
7261+
}
7262+
main();
7263+
''')
7264+
7265+
self.emcc('main.c', output_filename='test.js')
7266+
output = self.run_js('main.js')
7267+
self.assertNotContained('hello, world!', output)
7268+
self.assertContained('hello, earth!', output)
7269+
72387270
def test_define_modularize(self):
72397271
self.run_process([EMCC, test_file('hello_world.c'), '-sMODULARIZE', '-sASSERTIONS=0'])
72407272
src = 'var module = 0; ' + read_file('a.out.js')

0 commit comments

Comments
 (0)