@@ -51,26 +51,13 @@ static void init_callback_code(void)
51
51
callback_code_inited = 1 ;
52
52
}
53
53
54
- static int is_async_exn (value exn )
55
- {
56
- const value * break_exn ;
57
-
58
- if (caml_global_data == 0 ) return 0 ;
59
-
60
- if (exn == Field (caml_global_data , STACK_OVERFLOW_EXN )) return 1 ;
61
-
62
- /* "Sys.Break" must match stdlib/sys.mlp. */
63
- break_exn = caml_named_value ("Sys.Break" );
64
- if (break_exn != NULL && exn == * break_exn ) return 1 ;
65
-
66
- return 0 ;
67
- }
54
+ /* Functions that return all exceptions, including asynchronous ones */
68
55
69
56
static value caml_callbackN_exn0 (value closure , int narg , value args [],
70
- int catch_async_exns )
57
+ int * returning_async_exn )
71
58
{
72
59
int i ;
73
- value res , exn ;
60
+ value res ;
74
61
75
62
CAMLassert (narg + 4 <= 256 );
76
63
@@ -83,90 +70,119 @@ static value caml_callbackN_exn0(value closure, int narg, value args[],
83
70
if (!callback_code_inited ) init_callback_code ();
84
71
callback_code [1 ] = narg + 3 ;
85
72
callback_code [3 ] = narg ;
86
- res = caml_interprete (callback_code , sizeof (callback_code ));
73
+ res = caml_interprete (callback_code , sizeof (callback_code ),
74
+ returning_async_exn );
87
75
if (Is_exception_result (res )) Caml_state -> extern_sp += narg + 4 ; /* PR#3419 */
88
76
89
- if (!Is_exception_result (res )) return res ;
90
-
91
- exn = Extract_exception (res );
92
-
93
- /* When not called from [Sys.with_async_exns], any asynchronous exceptions
94
- must be reraised here, rather than being returned as the result of one
95
- of the [caml_callback*] functions. This will cause them to arrive only
96
- at any [Sys.with_async_exns] and toplevel uncaught exception handler
97
- sites. */
98
- if (!catch_async_exns && is_async_exn (exn )) caml_raise_async (exn );
99
-
100
77
return res ;
101
78
}
102
79
103
80
CAMLexport value caml_callbackN_exn (value closure , int narg , value args [])
104
81
{
105
- return caml_callbackN_exn0 (closure , narg , args , 0 );
82
+ return caml_callbackN_exn0 (closure , narg , args , NULL );
106
83
}
107
84
108
85
CAMLexport value caml_callback_exn (value closure , value arg1 )
109
86
{
110
87
value arg [1 ];
111
88
arg [0 ] = arg1 ;
112
- return caml_callbackN_exn (closure , 1 , arg );
89
+ return caml_callbackN_exn0 (closure , 1 , arg , NULL );
113
90
}
114
91
115
92
CAMLexport value caml_callback2_exn (value closure , value arg1 , value arg2 )
116
93
{
117
94
value arg [2 ];
118
95
arg [0 ] = arg1 ;
119
96
arg [1 ] = arg2 ;
120
- return caml_callbackN_exn (closure , 2 , arg );
97
+ return caml_callbackN_exn0 (closure , 2 , arg , NULL );
121
98
}
122
99
123
100
CAMLexport value caml_callback3_exn (value closure ,
124
- value arg1 , value arg2 , value arg3 )
101
+ value arg1 , value arg2 , value arg3 )
125
102
{
126
103
value arg [3 ];
127
104
arg [0 ] = arg1 ;
128
105
arg [1 ] = arg2 ;
129
106
arg [2 ] = arg3 ;
130
- return caml_callbackN_exn (closure , 3 , arg );
107
+ return caml_callbackN_exn0 (closure , 3 , arg , NULL );
108
+ }
109
+
110
+ /* Functions that propagate all exceptions, with any asynchronous exceptions
111
+ also being propagated asynchronously. */
112
+
113
+ CAMLexport value caml_callbackN (value closure , int narg , value args [])
114
+ {
115
+ value res ;
116
+ int returning_async_exn ;
117
+
118
+ res = caml_callbackN_exn0 (closure , narg , args , & returning_async_exn );
119
+ if (Is_exception_result (res )) {
120
+ value exn = Extract_exception (res );
121
+ if (returning_async_exn ) caml_raise_async (exn );
122
+ else caml_raise (exn );
123
+ }
124
+
125
+ return res ;
131
126
}
132
127
133
- CAMLexport value caml_callback_async_exn (value closure , value arg1 )
128
+ CAMLexport value caml_callback (value closure , value arg1 )
134
129
{
135
130
value arg [1 ];
136
131
arg [0 ] = arg1 ;
132
+ return caml_callbackN (closure , 1 , arg );
133
+ }
134
+
135
+ CAMLexport value caml_callback2 (value closure , value arg1 , value arg2 )
136
+ {
137
+ value arg [2 ];
138
+ arg [0 ] = arg1 ;
139
+ arg [1 ] = arg2 ;
140
+ return caml_callbackN (closure , 2 , arg );
141
+ }
137
142
138
- return caml_callbackN_exn0 (closure , 1 , arg , 1 );
143
+ CAMLexport value caml_callback3 (value closure ,
144
+ value arg1 , value arg2 , value arg3 )
145
+ {
146
+ value arg [3 ];
147
+ arg [0 ] = arg1 ;
148
+ arg [1 ] = arg2 ;
149
+ arg [2 ] = arg3 ;
150
+ return caml_callbackN (closure , 3 , arg );
139
151
}
140
152
141
153
#else
142
154
143
155
/* Native-code callbacks. */
144
156
145
157
typedef value (callback_stub )(caml_domain_state * state , value closure ,
146
- value * args );
158
+ value * args , int catch_async_exns );
147
159
148
160
callback_stub caml_callback_asm , caml_callback2_asm , caml_callback3_asm ;
149
161
150
- CAMLexport value caml_callback_exn (value closure , value arg )
162
+ /* First we build functions that allow control as to whether an asynchronous
163
+ exception trap frame is installed. */
164
+
165
+ static value callback (value closure , value arg , int catch_async_exns )
151
166
{
152
- return caml_callback_asm (Caml_state , closure , & arg );
167
+ return caml_callback_asm (Caml_state , closure , & arg , catch_async_exns );
153
168
}
154
169
155
- CAMLexport value caml_callback2_exn (value closure , value arg1 , value arg2 )
170
+ static value callback2 (value closure , value arg1 , value arg2 ,
171
+ int catch_async_exns )
156
172
{
157
173
value args [] = {arg1 , arg2 };
158
- return caml_callback2_asm (Caml_state , closure , args );
174
+ return caml_callback2_asm (Caml_state , closure , args , catch_async_exns );
159
175
}
160
176
161
- CAMLexport value caml_callback3_exn (value closure ,
162
- value arg1 , value arg2 , value arg3 )
177
+ static value callback3 (value closure , value arg1 , value arg2 , value arg3 ,
178
+ int catch_async_exns )
163
179
{
164
180
value args [] = {arg1 , arg2 , arg3 };
165
- return caml_callback3_asm (Caml_state , closure , args );
181
+ return caml_callback3_asm (Caml_state , closure , args , catch_async_exns );
166
182
}
167
183
168
-
169
- CAMLexport value caml_callbackN_exn ( value closure , int narg , value args [] )
184
+ static value callbackN ( value closure , int narg , value args [],
185
+ int catch_async_exns )
170
186
{
171
187
CAMLparam1 (closure );
172
188
CAMLxparamN (args , narg );
@@ -178,17 +194,17 @@ CAMLexport value caml_callbackN_exn(value closure, int narg, value args[])
178
194
/* Pass as many arguments as possible */
179
195
switch (narg - i ) {
180
196
case 1 :
181
- res = caml_callback_exn (res , args [i ]);
197
+ res = callback (res , args [i ], catch_async_exns );
182
198
if (Is_exception_result (res )) CAMLreturn (res );
183
199
i += 1 ;
184
200
break ;
185
201
case 2 :
186
- res = caml_callback2_exn (res , args [i ], args [i + 1 ]);
202
+ res = callback2 (res , args [i ], args [i + 1 ], catch_async_exns );
187
203
if (Is_exception_result (res )) CAMLreturn (res );
188
204
i += 2 ;
189
205
break ;
190
206
default :
191
- res = caml_callback3_exn (res , args [i ], args [i + 1 ], args [i + 2 ]);
207
+ res = callback3 (res , args [i ], args [i + 1 ], args [i + 2 ], catch_async_exns );
192
208
if (Is_exception_result (res )) CAMLreturn (res );
193
209
i += 3 ;
194
210
break ;
@@ -197,39 +213,65 @@ CAMLexport value caml_callbackN_exn(value closure, int narg, value args[])
197
213
CAMLreturn (res );
198
214
}
199
215
200
- extern value (caml_callback_asm_async_exn )
201
- (caml_domain_state * state , value closure , value * args );
216
+ /* Functions that return all exceptions, including asynchronous ones */
202
217
203
- CAMLexport value caml_callback_async_exn (value closure , value arg )
218
+ CAMLexport value caml_callback_exn (value closure , value arg )
204
219
{
205
- return caml_callback_asm_async_exn ( Caml_state , closure , & arg );
220
+ return callback ( closure , arg , 1 );
206
221
}
207
222
208
- #endif
223
+ CAMLexport value caml_callback2_exn (value closure , value arg1 , value arg2 )
224
+ {
225
+ return callback2 (closure , arg1 , arg2 , 1 );
226
+ }
227
+
228
+ CAMLexport value caml_callback3_exn (value closure ,
229
+ value arg1 , value arg2 , value arg3 )
230
+ {
231
+ return callback3 (closure , arg1 , arg2 , arg3 , 1 );
232
+ }
233
+
234
+ CAMLexport value caml_callbackN_exn (value closure , int narg , value args [])
235
+ {
236
+ return callbackN (closure , narg , args , 1 );
237
+ }
209
238
210
- /* Exception-propagating variants of the above */
239
+ /* Functions that propagate all exceptions, with any asynchronous exceptions
240
+ also being propagated asynchronously. In these cases we do not install
241
+ an asynchronous exception trap frame, avoiding any need to perform
242
+ comparisons on exception values to determine if they represent asynchronous
243
+ exceptions (which would be problematic for [Sys.Break], thus likely
244
+ necessitating these being wrapped in another constructor). */
211
245
212
- CAMLexport value caml_callback (value closure , value arg )
246
+ static value raise_if_exception (value res )
213
247
{
214
- return caml_raise_if_exception (caml_callback_exn (closure , arg ));
248
+ if (Is_exception_result (res )) caml_raise (Extract_exception (res ));
249
+ return res ;
215
250
}
216
251
217
- CAMLexport value caml_callback2 (value closure , value arg1 , value arg2 )
252
+ CAMLexport value caml_callback (value closure , value arg )
218
253
{
219
- return caml_raise_if_exception ( caml_callback2_exn (closure , arg1 , arg2 ));
254
+ return raise_if_exception ( callback (closure , arg , 0 ));
220
255
}
221
256
222
- CAMLexport value caml_callback3 (value closure , value arg1 , value arg2 ,
223
- value arg3 )
257
+ CAMLexport value caml_callback2 (value closure , value arg1 , value arg2 )
224
258
{
225
- return caml_raise_if_exception (caml_callback3_exn (closure , arg1 , arg2 , arg3 ));
259
+ return raise_if_exception (callback2 (closure , arg1 , arg2 , 0 ));
260
+ }
261
+
262
+ CAMLexport value caml_callback3 (value closure ,
263
+ value arg1 , value arg2 , value arg3 )
264
+ {
265
+ return raise_if_exception (callback3 (closure , arg1 , arg2 , arg3 , 0 ));
226
266
}
227
267
228
268
CAMLexport value caml_callbackN (value closure , int narg , value args [])
229
269
{
230
- return caml_raise_if_exception ( caml_callbackN_exn (closure , narg , args ));
270
+ return raise_if_exception ( callbackN (closure , narg , args , 0 ));
231
271
}
232
272
273
+ #endif
274
+
233
275
/* Naming of OCaml values */
234
276
235
277
struct named_value {
0 commit comments