diff options
author | Guillaume Munch-Maccagnoni <Guillaume.Munch-Maccagnoni@Inria.fr> | 2019-09-26 23:49:51 +0200 |
---|---|---|
committer | Guillaume Munch-Maccagnoni <Guillaume.Munch-Maccagnoni@Inria.fr> | 2019-10-15 14:02:22 +0200 |
commit | 85d712aecc9a4d4bbad5d58783d571ee52d4d2c2 (patch) | |
tree | c27a56cd19bfa0adec358a2f114c11c7b94369d6 /runtime | |
parent | e64a8618fe7af46dcbfef538f85cfc6852b9f98c (diff) | |
download | ocaml-85d712aecc9a4d4bbad5d58783d571ee52d4d2c2.tar.gz |
[cleanup] Factor "if (Is_exception_result) caml_raise(Extract_exception)"
caml_raise_if_exception remains private; all public _exn functions
will be provided with a directly-raising variant to keep supporting current
programming styles.
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/callback.c | 16 | ||||
-rw-r--r-- | runtime/caml/fail.h | 2 | ||||
-rw-r--r-- | runtime/fail_byt.c | 9 | ||||
-rw-r--r-- | runtime/fail_nat.c | 6 |
4 files changed, 20 insertions, 13 deletions
diff --git a/runtime/callback.c b/runtime/callback.c index 49a5fba6e7..719363741a 100644 --- a/runtime/callback.c +++ b/runtime/callback.c @@ -196,31 +196,23 @@ CAMLexport value caml_callbackN_exn(value closure, int narg, value args[]) CAMLexport value caml_callback (value closure, value arg) { - value res = caml_callback_exn(closure, arg); - if (Is_exception_result(res)) caml_raise(Extract_exception(res)); - return res; + return caml_raise_if_exception(caml_callback_exn(closure, arg)); } CAMLexport value caml_callback2 (value closure, value arg1, value arg2) { - value res = caml_callback2_exn(closure, arg1, arg2); - if (Is_exception_result(res)) caml_raise(Extract_exception(res)); - return res; + return caml_raise_if_exception(caml_callback2_exn(closure, arg1, arg2)); } CAMLexport value caml_callback3 (value closure, value arg1, value arg2, value arg3) { - value res = caml_callback3_exn(closure, arg1, arg2, arg3); - if (Is_exception_result(res)) caml_raise(Extract_exception(res)); - return res; + return caml_raise_if_exception(caml_callback3_exn(closure, arg1, arg2, arg3)); } CAMLexport value caml_callbackN (value closure, int narg, value args[]) { - value res = caml_callbackN_exn(closure, narg, args); - if (Is_exception_result(res)) caml_raise(Extract_exception(res)); - return res; + return caml_raise_if_exception(caml_callbackN_exn(closure, narg, args)); } /* Naming of OCaml values */ diff --git a/runtime/caml/fail.h b/runtime/caml/fail.h index 8744463ebc..612b453545 100644 --- a/runtime/caml/fail.h +++ b/runtime/caml/fail.h @@ -61,6 +61,8 @@ struct longjmp_buffer { int caml_is_special_exception(value exn); +value caml_raise_if_exception(value res); + #endif /* CAML_INTERNALS */ #ifdef __cplusplus diff --git a/runtime/fail_byt.c b/runtime/fail_byt.c index 27ad42f625..a8acdf0e28 100644 --- a/runtime/fail_byt.c +++ b/runtime/fail_byt.c @@ -20,9 +20,10 @@ #include <stdio.h> #include <stdlib.h> #include "caml/alloc.h" +#include "caml/callback.h" #include "caml/fail.h" -#include "caml/io.h" #include "caml/gc.h" +#include "caml/io.h" #include "caml/memory.h" #include "caml/misc.h" #include "caml/mlvalues.h" @@ -189,6 +190,12 @@ CAMLexport void caml_raise_sys_blocked_io(void) caml_raise_constant(Field(caml_global_data, SYS_BLOCKED_IO)); } +value caml_raise_if_exception(value res) +{ + if (Is_exception_result(res)) caml_raise(Extract_exception(res)); + return res; +} + int caml_is_special_exception(value exn) { /* this function is only used in caml_format_exception to produce a more readable textual representation of some exceptions. It is diff --git a/runtime/fail_nat.c b/runtime/fail_nat.c index b54cb79994..1ef60fe0ee 100644 --- a/runtime/fail_nat.c +++ b/runtime/fail_nat.c @@ -164,6 +164,12 @@ void caml_raise_sys_blocked_io(void) caml_raise_constant((value) caml_exn_Sys_blocked_io); } +value caml_raise_if_exception(value res) +{ + if (Is_exception_result(res)) caml_raise(Extract_exception(res)); + return res; +} + /* We use a pre-allocated exception because we can't do a GC before the exception is raised (lack of stack descriptors for the ccall to [caml_array_bound_error]). */ |