summaryrefslogtreecommitdiffstats
path: root/asmrun/fail.c
diff options
context:
space:
mode:
authorAlain Frisch <alain@frisch.fr>2013-11-08 16:18:21 +0000
committerAlain Frisch <alain@frisch.fr>2013-11-08 16:18:21 +0000
commitb9117544349c5cf41463db6160e7f16ef61626a0 (patch)
treed047705e10fea7af87b6db150e84452c73e0cd66 /asmrun/fail.c
parent7bb3e641606fe0718640e359b2f108f25d1b01b2 (diff)
Simplify special logic for array bound error (allocate the exception value from Pervasives).
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/raise_variants@14275 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'asmrun/fail.c')
-rw-r--r--asmrun/fail.c45
1 files changed, 11 insertions, 34 deletions
diff --git a/asmrun/fail.c b/asmrun/fail.c
index 24a456d13..beb3713e0 100644
--- a/asmrun/fail.c
+++ b/asmrun/fail.c
@@ -13,6 +13,7 @@
/* Raising exceptions from C. */
+#include <stdio.h>
#include <signal.h>
#include "alloc.h"
#include "fail.h"
@@ -150,46 +151,22 @@ void caml_raise_sys_blocked_io(void)
caml_raise_constant((value) caml_exn_Sys_blocked_io);
}
-/* We allocate statically the bucket for the exception because we can't
+/* 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]. */
+ for the ccall to [caml_array_bound_error]). */
-#define BOUND_MSG "index out of bounds"
-#define BOUND_MSG_LEN (sizeof(BOUND_MSG) - 1)
-
-static struct {
- header_t hdr;
- value exn;
- value arg;
-} array_bound_error_bucket;
-
-static struct {
- header_t hdr;
- char data[BOUND_MSG_LEN + sizeof(value)];
-} array_bound_error_msg = { 0, BOUND_MSG };
-
-static int array_bound_error_bucket_inited = 0;
+static value * caml_array_bound_error_exn = NULL;
void caml_array_bound_error(void)
{
- if (! array_bound_error_bucket_inited) {
- mlsize_t wosize = (BOUND_MSG_LEN + sizeof(value)) / sizeof(value);
- mlsize_t offset_index = Bsize_wsize(wosize) - 1;
- array_bound_error_msg.hdr = Make_header(wosize, String_tag, Caml_white);
- array_bound_error_msg.data[offset_index] = offset_index - BOUND_MSG_LEN;
- array_bound_error_bucket.hdr = Make_header(2, 0, Caml_white);
- array_bound_error_bucket.exn = (value) caml_exn_Invalid_argument;
- array_bound_error_bucket.arg = (value) array_bound_error_msg.data;
- array_bound_error_bucket_inited = 1;
- caml_page_table_add(In_static_data,
- &array_bound_error_msg,
- &array_bound_error_msg + 1);
- caml_page_table_add(In_static_data,
- &array_bound_error_bucket,
- &array_bound_error_bucket + 1);
- array_bound_error_bucket_inited = 1;
+ if (caml_array_bound_error_exn == NULL) {
+ caml_array_bound_error_exn = caml_named_value("Pervasives.array_bound_error");
+ if (caml_array_bound_error_exn == NULL) {
+ fprintf(stderr, "Fatal error: exception Invalid_argument(\"index out of bounds\")\n");
+ exit(2);
+ }
}
- caml_raise((value) &array_bound_error_bucket.exn);
+ caml_raise(*caml_array_bound_error_exn);
}
int caml_is_special_exception(value exn) {