@@ -51,10 +51,12 @@ static void init_callback_code(void)
51
51
callback_code_inited = 1 ;
52
52
}
53
53
54
+ /* Functions that return all exceptions, including asynchronous ones */
55
+
54
56
static value caml_callbackN_exn0 (value closure , int narg , value args [],
55
57
int * returning_async_exn )
56
58
{
57
- int i , returning_async_exn ;
59
+ int i ;
58
60
value res ;
59
61
60
62
CAMLassert (narg + 4 <= 256 );
@@ -84,15 +86,15 @@ CAMLexport value caml_callback_exn(value closure, value arg1)
84
86
{
85
87
value arg [1 ];
86
88
arg [0 ] = arg1 ;
87
- return caml_callbackN_exn (closure , 1 , arg );
89
+ return caml_callbackN_exn0 (closure , 1 , arg , NULL );
88
90
}
89
91
90
92
CAMLexport value caml_callback2_exn (value closure , value arg1 , value arg2 )
91
93
{
92
94
value arg [2 ];
93
95
arg [0 ] = arg1 ;
94
96
arg [1 ] = arg2 ;
95
- return caml_callbackN_exn0 (closure , 2 , arg );
97
+ return caml_callbackN_exn0 (closure , 2 , arg , NULL );
96
98
}
97
99
98
100
CAMLexport value caml_callback3_exn (value closure ,
@@ -102,10 +104,11 @@ CAMLexport value caml_callback3_exn(value closure,
102
104
arg [0 ] = arg1 ;
103
105
arg [1 ] = arg2 ;
104
106
arg [2 ] = arg3 ;
105
- return caml_callbackN_exn0 (closure , 3 , arg );
107
+ return caml_callbackN_exn0 (closure , 3 , arg , NULL );
106
108
}
107
109
108
- /* Exception-propagating variants of the above */
110
+ /* Functions that propagate all exceptions, with any asynchronous exceptions
111
+ also being propagated asynchronously. */
109
112
110
113
CAMLexport value caml_callbackN (value closure , int narg , value args [])
111
114
{
@@ -122,23 +125,23 @@ CAMLexport value caml_callbackN(value closure, int narg, value args[])
122
125
return res ;
123
126
}
124
127
125
- CAMLexport value caml_callback_exn (value closure , value arg1 )
128
+ CAMLexport value caml_callback (value closure , value arg1 )
126
129
{
127
130
value arg [1 ];
128
131
arg [0 ] = arg1 ;
129
132
return caml_callbackN (closure , 1 , arg );
130
133
}
131
134
132
- CAMLexport value caml_callback2_exn (value closure , value arg1 , value arg2 )
135
+ CAMLexport value caml_callback2 (value closure , value arg1 , value arg2 )
133
136
{
134
137
value arg [2 ];
135
138
arg [0 ] = arg1 ;
136
139
arg [1 ] = arg2 ;
137
140
return caml_callbackN (closure , 2 , arg );
138
141
}
139
142
140
- CAMLexport value caml_callback3_exn (value closure ,
141
- value arg1 , value arg2 , value arg3 )
143
+ CAMLexport value caml_callback3 (value closure ,
144
+ value arg1 , value arg2 , value arg3 )
142
145
{
143
146
value arg [3 ];
144
147
arg [0 ] = arg1 ;
@@ -152,29 +155,34 @@ CAMLexport value caml_callback3_exn(value closure,
152
155
/* Native-code callbacks. */
153
156
154
157
typedef value (callback_stub )(caml_domain_state * state , value closure ,
155
- value * args );
158
+ value * args , int catch_async_exns );
156
159
157
160
callback_stub caml_callback_asm , caml_callback2_asm , caml_callback3_asm ;
158
161
159
- 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 )
160
166
{
161
- return caml_callback_asm (Caml_state , closure , & arg );
167
+ return caml_callback_asm (Caml_state , closure , & arg , catch_async_exns );
162
168
}
163
169
164
- 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 )
165
172
{
166
173
value args [] = {arg1 , arg2 };
167
- return caml_callback2_asm (Caml_state , closure , args );
174
+ return caml_callback2_asm (Caml_state , closure , args , catch_async_exns );
168
175
}
169
176
170
- CAMLexport value caml_callback3_exn (value closure ,
171
- value arg1 , value arg2 , value arg3 )
177
+ static value callback3 (value closure , value arg1 , value arg2 , value arg3 ,
178
+ int catch_async_exns )
172
179
{
173
180
value args [] = {arg1 , arg2 , arg3 };
174
- return caml_callback3_asm (Caml_state , closure , args );
181
+ return caml_callback3_asm (Caml_state , closure , args , catch_async_exns );
175
182
}
176
183
177
- 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 )
178
186
{
179
187
CAMLparam1 (closure );
180
188
CAMLxparamN (args , narg );
@@ -186,17 +194,17 @@ CAMLexport value caml_callbackN_exn(value closure, int narg, value args[])
186
194
/* Pass as many arguments as possible */
187
195
switch (narg - i ) {
188
196
case 1 :
189
- res = caml_callback_exn (res , args [i ]);
197
+ res = callback (res , args [i ], catch_async_exns );
190
198
if (Is_exception_result (res )) CAMLreturn (res );
191
199
i += 1 ;
192
200
break ;
193
201
case 2 :
194
- res = caml_callback2_exn (res , args [i ], args [i + 1 ]);
202
+ res = callback2 (res , args [i ], args [i + 1 ], catch_async_exns );
195
203
if (Is_exception_result (res )) CAMLreturn (res );
196
204
i += 2 ;
197
205
break ;
198
206
default :
199
- 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 );
200
208
if (Is_exception_result (res )) CAMLreturn (res );
201
209
i += 3 ;
202
210
break ;
@@ -205,27 +213,61 @@ CAMLexport value caml_callbackN_exn(value closure, int narg, value args[])
205
213
CAMLreturn (res );
206
214
}
207
215
208
- /* Exception-propagating variants of the above */
216
+ /* Functions that return all exceptions, including asynchronous ones */
217
+
218
+ CAMLexport value caml_callback_exn (value closure , value arg )
219
+ {
220
+ return callback (closure , arg , 1 );
221
+ }
222
+
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
+ }
238
+
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). */
245
+
246
+ static value raise_if_exception (value res )
247
+ {
248
+ if (Is_exception_result (res )) caml_raise (Extract_exception (res ));
249
+ return res ;
250
+ }
209
251
210
- CAMLexport value caml_callback (value closure , value arg )
252
+ CAMLexport value caml_callback (value closure , value arg )
211
253
{
212
- return caml_raise_if_exception ( caml_callback_exn (closure , arg ));
254
+ return raise_if_exception ( callback (closure , arg , 0 ));
213
255
}
214
256
215
- CAMLexport value caml_callback2 (value closure , value arg1 , value arg2 )
257
+ CAMLexport value caml_callback2 (value closure , value arg1 , value arg2 )
216
258
{
217
- return caml_raise_if_exception ( caml_callback2_exn (closure , arg1 , arg2 ));
259
+ return raise_if_exception ( callback2 (closure , arg1 , arg2 , 0 ));
218
260
}
219
261
220
- CAMLexport value caml_callback3 (value closure , value arg1 , value arg2 ,
221
- value arg3 )
262
+ CAMLexport value caml_callback3 (value closure ,
263
+ value arg1 , value arg2 , value arg3 )
222
264
{
223
- return caml_raise_if_exception ( caml_callback3_exn (closure , arg1 , arg2 , arg3 ));
265
+ return raise_if_exception ( callback3 (closure , arg1 , arg2 , arg3 , 0 ));
224
266
}
225
267
226
268
CAMLexport value caml_callbackN (value closure , int narg , value args [])
227
269
{
228
- return caml_raise_if_exception ( caml_callbackN_exn (closure , narg , args ));
270
+ return raise_if_exception ( callbackN (closure , narg , args , 0 ));
229
271
}
230
272
231
273
#endif
0 commit comments