diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-09-04 18:37:53 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-09-04 18:37:53 -0700 |
commit | cacea4eceec4f82c2a991fdae710864f63d01bad (patch) | |
tree | 79138592020762ff68d8eab68ac7643608fa1a5e | |
parent | ce8acc241ac5638f4c4914c05c6ff615cf3937eb (diff) |
longjmp test across asm modules
-rw-r--r-- | src/jsifier.js | 2 | ||||
-rw-r--r-- | tests/test_core.py | 64 |
2 files changed, 65 insertions, 1 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 0bf484bc..f5682a1b 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1409,7 +1409,7 @@ function JSify(data, functionsOnly, givenFunctions) { var extCall = false; if (ASM_JS && funcData.setjmpTable) forceByPointer = true; // in asm.js mode, we must do an invoke for each call - if (ASM_JS && DLOPEN_SUPPORT && !invoke) extCall = true; // go out, to be able to access other modules TODO: optimize + if (ASM_JS && DLOPEN_SUPPORT && !invoke && !funcData.setjmpTable) extCall = true; // go out, to be able to access other modules TODO: optimize ident = Variables.resolveAliasToIdent(ident); var shortident = ident.slice(1); diff --git a/tests/test_core.py b/tests/test_core.py index 0df4eeef..ff768b5c 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -6226,6 +6226,70 @@ ok Settings.EXPORTED_FUNCTIONS = ['_main', '_malloc', '_free'] self.do_run(src, '''*294,153*''', force_c=True, post_build=self.dlfcn_post_build) + def test_dlfcn_longjmp(self): + if not self.can_dlfcn(): return + + self.prep_dlfcn_lib() + lib_src = r''' + #include <setjmp.h> + + void jumpy(jmp_buf buf) { + static int i = 0; + i++; + if (i == 10) longjmp(buf, i); + printf("pre %d\n", i); + } + ''' + Settings.EXPORTED_FUNCTIONS = ['_jumpy'] + dirname = self.get_dir() + filename = os.path.join(dirname, 'liblib.c') + self.build(lib_src, dirname, filename) + shutil.move(filename + '.o.js', os.path.join(dirname, 'liblib.so')) + + self.prep_dlfcn_main() + src = r''' + #include <assert.h> + #include <stdio.h> + #include <dlfcn.h> + #include <setjmp.h> + + typedef void (*jumpfunc)(jmp_buf); + + int main() { + printf("go!\n"); + + void *lib_handle; + lib_handle = dlopen("liblib.so", RTLD_NOW); + assert(lib_handle != NULL); + + jumpfunc jumpy = (jumpfunc)dlsym(lib_handle, "jumpy"); + assert(jumpy); + + jmp_buf buf; + int jmpval = setjmp(buf); + if (jmpval == 0) { + while (1) jumpy(buf); + } else { + printf("out!\n"); + } + + return 0; + } + ''' + Settings.EXPORTED_FUNCTIONS = ['_main', '_malloc', '_free'] + self.do_run(src, '''go! +pre 1 +pre 2 +pre 3 +pre 4 +pre 5 +pre 6 +pre 7 +pre 8 +pre 9 +out! +''', post_build=self.dlfcn_post_build, force_c=True) + def zzztest_dlfcn_exceptions(self): # TODO: make this work. need to forward tempRet0 across modules if not self.can_dlfcn(): return |