diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-04-22 20:38:00 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-04-22 20:38:00 -0700 |
commit | 40edec0ec80f07b5ce2e351e67137f7908a0ea1e (patch) | |
tree | c333f1238f2084916652baa72be7a03666331fa6 /tests | |
parent | 29a9d8b2c5d5032ef6c980b5256982f66ac23d5b (diff) |
use invoke when doing a setjmp-guarding call via a function pointer
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/runner.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py index 2e01226f..33a2ef67 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -2489,6 +2489,41 @@ Calling longjmp the second time! Exception execution path of first function! 1 ''') + def test_longjmp_funcptr(self): + src = r''' + #include <stdio.h> + #include <setjmp.h> + + static jmp_buf buf; + + void (*fp)() = NULL; + + void second(void) { + printf("second\n"); // prints + longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1 + } + + void first(void) { + fp(); + printf("first\n"); // does not print + } + + int main(int argc, char **argv) { + fp = argc == 200 ? NULL : second; + + volatile int x = 0; + if ( ! setjmp(buf) ) { + x++; + first(); // when executed, setjmp returns 0 + } else { // when longjmp jumps back, setjmp returns 1 + printf("main: %d\n", x); // prints + } + + return 0; + } + ''' + self.do_run(src, 'second\nmain: 1\n') + def test_setjmp_many(self): src = r''' #include <stdio.h> |