diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 1998-10-01 12:32:20 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 1998-10-01 12:32:20 +0000 |
commit | 629e5a5de38065a50ac76c64aeae0a3cd32b33a1 (patch) | |
tree | b026a84e45f060a94d7399fd1a82a99d888797b2 | |
parent | ae4f361ddf2fb5ef0b1dd73c1712ec947063d70e (diff) |
Meilleur traitement de Out_of_memory
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2103 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | byterun/fail.c | 21 | ||||
-rw-r--r-- | byterun/fail.h | 1 | ||||
-rw-r--r-- | byterun/startup.c | 4 |
3 files changed, 18 insertions, 8 deletions
diff --git a/byterun/fail.c b/byterun/fail.c index ffbb2e93a..6dc7ff6be 100644 --- a/byterun/fail.c +++ b/byterun/fail.c @@ -18,6 +18,7 @@ #include "io.h" #include "gc.h" #include "memory.h" +#include "misc.h" #include "mlvalues.h" #include "signals.h" #include "stacks.h" @@ -74,20 +75,18 @@ void invalid_argument (char *msg) } /* Problem: we can't use raise_constant, because it allocates and - we're out of memory... The following is a terrible hack that works - because global_data[OUT_OF_MEMORY_EXN] is in the old generation - (because global_data was read with intern_val), hence stays at - a fixed address */ + we're out of memory... Here, we allocate statically the exn bucket + for Out_of_memory. */ static struct { header_t hdr; value exn; -} out_of_memory_bucket; +} out_of_memory_bucket = { 0, 0 }; void raise_out_of_memory(void) { - out_of_memory_bucket.hdr = Make_header(1, 0, White); - out_of_memory_bucket.exn = Field(global_data, OUT_OF_MEMORY_EXN); + if (out_of_memory_bucket.exn == 0) + fatal_error("Fatal eror: out of memory while raising Out_of_memory\n"); mlraise((value) &(out_of_memory_bucket.exn)); } @@ -116,3 +115,11 @@ void raise_not_found(void) raise_constant(Field(global_data, NOT_FOUND_EXN)); } +/* Initialization of statically-allocated exception buckets */ + +void init_exceptions(void) +{ + out_of_memory_bucket.hdr = Make_header(1, 0, White); + out_of_memory_bucket.exn = Field(global_data, OUT_OF_MEMORY_EXN); + register_global_root(&out_of_memory_bucket.exn); +} diff --git a/byterun/fail.h b/byterun/fail.h index 5764102b5..e72bb03bc 100644 --- a/byterun/fail.h +++ b/byterun/fail.h @@ -57,5 +57,6 @@ void raise_end_of_file (void) Noreturn; void raise_zero_divide (void) Noreturn; void raise_not_found (void) Noreturn; void fatal_uncaught_exception (value) Noreturn; +void init_exceptions (void); #endif /* _fail_ */ diff --git a/byterun/startup.c b/byterun/startup.c index ff6c0dca5..acb069ca5 100644 --- a/byterun/startup.c +++ b/byterun/startup.c @@ -291,7 +291,8 @@ void caml_main(char **argv) close_channel(chan); /* Ensure that the globals are in the major heap. */ oldify(global_data, &global_data); - /* Record the command-line arguments */ + /* Initialize system libraries */ + init_exceptions(); sys_init(argv + pos); /* Execute the program */ debugger(PROGRAM_START); @@ -334,6 +335,7 @@ void caml_startup_code(code_t code, asize_t code_size, char *data, char **argv) /* Ensure that the globals are in the major heap. */ oldify(global_data, &global_data); /* Run the code */ + init_exceptions(); sys_init(argv); interprete(start_code, code_size); } else { |