From b79bc438aadeda878eaa2a26c72129edffba4be7 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 18 Aug 2017 06:38:30 -0700 Subject: Revising out-of-memory handling. We don't want to be aborting on OOM, but throwing an exception. * lib.c (alloc_error_s): New symbol variable. (oom_realloc): Global variable removed. (oom): New static function. (chk_malloc, chk_malloc_gc_more, chk_calloc, chk_realloc): Call oom instead of removed oom_realloc handler. (env): Throw alloc-error rather than error by calling oom. (obj_init): Initialize alloc_error_s. (init): Drop function pointer argument; do not initialize removed oom_realloc. * lib.h (alloc_error_s): Declared. (oom_realloc): Declaration removed. (init): Declaration updated. * txr.1: Type tree diagram includes alloc-error. --- txr.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'txr.c') diff --git a/txr.c b/txr.c index 16cecb63..2591b339 100644 --- a/txr.c +++ b/txr.c @@ -68,19 +68,6 @@ int opt_compat; int opt_dbg_expansion; val stdlib_path; -/* - * Can implement an emergency allocator here from a fixed storage - * pool, which sets an OOM flag. Program can check flag - * and gracefully terminate instead of aborting like this. - */ -static mem_t *oom_realloc_handler(mem_t *old, size_t size) -{ - format(std_error, lit("~a: out of memory\n"), prog_string, nao); - if (opt_print_bindings) - put_line(lit("false"), std_output); - abort(); -} - static void help(void) { val text = lit( @@ -375,7 +362,7 @@ int main(int argc, char **argv) repress_privilege(); progname = utf8_dup_from(argv[0] ? argv[0]: "txr"); progname_u8 = argv[0]; - init(oom_realloc_handler, &stack_bottom); + init(&stack_bottom); match_init(); debug_init(); sysroot_init(); -- cgit v1.2.3