Skip to content

Commit

Permalink
Fix exporting a specific dynCall_* method (emscripten-core#6046)
Browse files Browse the repository at this point in the history
* add a test for calling dynCall_[specific]
  • Loading branch information
kripken authored Jan 12, 2018
1 parent 50b0e6a commit 003a287
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,15 @@ function exportRuntime() {
runtimeElements.push('intArrayFromBase64');
runtimeElements.push('tryParseAsDataURI');
}
// dynCall_* methods are not hardcoded here, as they
// depend on the file being compiled. check for them
// and add them.
for (var name in EXPORTED_RUNTIME_METHODS_SET) {
if (/^dynCall_/.test(name)) {
// a specific dynCall; add to the list
runtimeElements.push(name);
}
}
var runtimeNumbers = [
'ALLOC_NORMAL',
'ALLOC_STACK',
Expand Down
26 changes: 26 additions & 0 deletions tests/core/dyncall_specific.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <emscripten.h>

void waka(int x, int y, int z) {
EM_ASM({
Module['print']('received ' + [$0, $1, $2] + '.');
}, x, y, z);
}

int main() {
EM_ASM({
#if DIRECT
dynCall_viii($0, 1, 4, 9);
return;
#endif
#if EXPORTED
Module['dynCall_viii']($0, 1, 4, 9);
return;
#endif
#if FROM_OUTSIDE
eval("Module['dynCall_viii'](" + $0 + ", 1, 4, 9)");
return;
#endif
throw "no test mode";
}, &waka);
}

1 change: 1 addition & 0 deletions tests/core/dyncall_specific.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
received 1,4,9.
12 changes: 12 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5997,6 +5997,18 @@ def test_dyncall(self):
Settings.EXTRA_EXPORTED_RUNTIME_METHODS = ['dynCall', 'addFunction']
self.do_run_in_out_file_test('tests', 'core', 'dyncall')

def test_dyncall_specific(self):
emcc_args = self.emcc_args[:]
for which, exported_runtime_methods in [
('DIRECT', []),
('EXPORTED', []),
('FROM_OUTSIDE', ['dynCall_viii'])
]:
print(which)
self.emcc_args = emcc_args + ['-D' + which]
Settings.EXTRA_EXPORTED_RUNTIME_METHODS = exported_runtime_methods
self.do_run_in_out_file_test('tests', 'core', 'dyncall_specific')

def test_getValue_setValue(self):
# these used to be exported, but no longer are by default
def test(output_prefix='', args=[]):
Expand Down

0 comments on commit 003a287

Please sign in to comment.