Skip to content

Commit 4b45323

Browse files
committed
Keep runtime alive while async ccall is running
1 parent 9fdeb89 commit 4b45323

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/preamble.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,14 @@ function ccall(ident, returnType, argTypes, args, opts) {
130130
}
131131
var ret = func.apply(null, cArgs);
132132
function onDone(ret) {
133+
#if ASYNCIFY
134+
runtimeKeepalivePop();
135+
#endif
133136
if (stack !== 0) stackRestore(stack);
134137
return convertReturnValue(ret);
135138
}
136139
#if ASYNCIFY
140+
runtimeKeepalivePush();
137141
var asyncMode = opts && opts.async;
138142
// Check if we started an async operation just now.
139143
if (Asyncify.currData) {

tests/test_core.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7447,11 +7447,15 @@ def test_async_ccall_good(self):
74477447
self.emcc_args += ['--pre-js', 'pre.js']
74487448
self.do_runf('main.c', 'HelloWorld')
74497449

7450-
def test_async_ccall_promise(self):
7451-
print('check ccall promise')
7450+
@parameterized({
7451+
'': (False,),
7452+
'exit_runti,e': (True,),
7453+
})
7454+
def test_async_ccall_promise(self, exit_runtime):
74527455
self.set_setting('ASYNCIFY')
74537456
self.set_setting('ASSERTIONS')
74547457
self.set_setting('INVOKE_RUN', 0)
7458+
self.set_setting('EXIT_RUNTIME', exit_runtime)
74557459
self.set_setting('EXPORTED_FUNCTIONS', ['_stringf', '_floatf'])
74567460
create_file('main.c', r'''
74577461
#include <stdio.h>

0 commit comments

Comments
 (0)