File tree 4 files changed +43
-0
lines changed
4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,14 @@ thread_local struct __WasmLongjmpArgs __wasm_longjmp_args;
90
90
// TODO Consider switching to throwing two values at the same time later.
91
91
void __wasm_longjmp (void * env , int val ) {
92
92
__wasm_longjmp_args .env = env ;
93
+ /*
94
+  * C standard:
95
+  * The longjmp function cannot cause the setjmp macro to return
96
+  * the value 0; if val is 0, the setjmp macro returns the value 1.
97
+  */
98
+ if (val == 0 ) {
99
+ val = 1 ;
100
+ }
93
101
__wasm_longjmp_args .val = val ;
94
102
__builtin_wasm_throw (C_LONGJMP , & __wasm_longjmp_args );
95
103
}
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2016 The Emscripten Authors. All rights reserved.
3
+ * Emscripten is available under two separate licenses, the MIT license and the
4
+ * University of Illinois/NCSA Open Source License. Both these licenses can be
5
+ * found in the LICENSE file.
6
+ */
7
+
8
+ #include <stdio.h>
9
+ #include <setjmp.h>
10
+
11
+ int main () {
12
+ printf ("start\n" );
13
+ jmp_buf b1 ;
14
+ int val = setjmp (b1 );
15
+ if (val ) {
16
+ printf ("success\n" );
17
+ return 0 ;
18
+ }
19
+ /*
20
+ * C standard:
21
+ * > The longjmp function cannot cause the setjmp macro to return
22
+ * > the value 0; if val is 0, the setjmp macro returns the value 1.
23
+ */
24
+ printf ("longjmp\n" );
25
+ longjmp (b1 , 0 );
26
+ __builtin_trap ();
27
+ return 0 ;
28
+ }
Original file line number Diff line number Diff line change
1
+ start
2
+ longjmp
3
+ success
Original file line number Diff line number Diff line change @@ -892,6 +892,10 @@ def test_longjmp_standalone(self):
892
892
def test_longjmp (self ):
893
893
self .do_core_test ('test_longjmp.c' )
894
894
895
+ @with_both_sjlj
896
+ def test_longjmp_zero (self ):
897
+ self .do_core_test ('test_longjmp_zero.c' )
898
+
895
899
def test_longjmp_with_and_without_exceptions (self ):
896
900
# Emscripten SjLj with and without Emscripten EH support
897
901
self .set_setting ('SUPPORT_LONGJMP' , 'emscripten' )
You can’t perform that action at this time.
0 commit comments