X-Git-Url: http://nitlanguage.org diff --git a/clib/nit_main.c b/clib/nit_main.c index b578658..630847f 100644 --- a/clib/nit_main.c +++ b/clib/nit_main.c @@ -17,7 +17,7 @@ #include "gc.h" bigint object_id_counter = 1000000; -enum gc_option { large, boehm, nitgc } gc_option; +enum gc_option { large, gc_opt_malloc, boehm, nitgc } gc_option; #ifdef WITH_LIBGC #define GC_DEBUG @@ -27,7 +27,8 @@ enum gc_option { large, boehm, nitgc } gc_option; void *raw_alloc(size_t s0) { switch (gc_option) { - case nitgc: return malloc(s0); break; + case nitgc: return malloc(s0); + case gc_opt_malloc: return malloc(s0); default: return alloc(s0); } } @@ -64,6 +65,7 @@ void * alloc(size_t s0) case boehm: return GC_MALLOC(s0); #endif case nitgc: return Nit_gc_malloc(s0); + case gc_opt_malloc: return calloc(1, s0); case large: default: return large_alloc(s0); } @@ -79,10 +81,13 @@ void exithandler(int s) { } void initialize_gc_option(void) { /* GC default */ + char *def; #ifdef WITH_LIBGC gc_option = boehm; + def = "boehm"; #else gc_option = nitgc; + def = "nitgc"; #endif /* Process GC runtime selection */ @@ -92,14 +97,23 @@ void initialize_gc_option(void) { #ifdef WITH_LIBGC gc_option = boehm; #else - fprintf(stderr, "Compiled without Boehm GC support. Using default.\n"); + fprintf(stderr, "Compiled without Boehm GC support. Using default '%s'.\n", def); #endif } else if (strcmp(opt, "nitgc")==0) { gc_option = nitgc; + } else if (strcmp(opt, "malloc")==0) { + gc_option = gc_opt_malloc; } else if (strcmp(opt, "large")==0) { gc_option = large; + } else if (strcmp(opt, "help")==0) { + fprintf(stderr, "NIT_GC_OPTION accepts 'nitgc'" +#ifdef WITH_LIBGC + ", 'boehm'" +#endif + ", 'large', 'malloc'. Default is '%s'.\n", def); + exit(1); } else { - fprintf(stderr, "Invalid GC option in NIT_GC_OPTION environment variable. Using default.\n"); + fprintf(stderr, "Invalid GC option in NIT_GC_OPTION environment variable. Using default '%s'.\n", def); } } @@ -125,12 +139,23 @@ void prepare_signals(void) { } struct stack_frame_t *stack_frame_head = NULL; void nit_exit(int i) { - fprintf(stderr, ",---- Stack trace -- - - -\n"); - while(stack_frame_head != NULL) { - fprintf(stderr, "| %s (%s:%d)\n", stack_frame_head->meth, stack_frame_head->file, stack_frame_head->line); - if (stack_frame_head == stack_frame_head->prev) break; - stack_frame_head = stack_frame_head->prev; + char *opt=getenv("NIT_NO_STACK"); + if (opt == NULL || strcmp(opt, "0")==0) { + fprintf(stderr, ",---- Stack trace -- - - -\n"); + while(stack_frame_head != NULL) { + fprintf(stderr, "| %s (%s:%d)\n", stack_frame_head->meth, stack_frame_head->file, stack_frame_head->line); + if (stack_frame_head == stack_frame_head->prev) break; + stack_frame_head = stack_frame_head->prev; + } + fprintf(stderr, "`------------------- - - -\n"); } - fprintf(stderr, "`------------------- - - -\n"); exit(i); } + +void nit_abort(const char* s, const char* msg, const char* loc, int line) { + fprintf(stderr, s, msg); + fprintf(stderr, " (%s", loc); + if (line != 0) fprintf(stderr, ":%d", line); + fprintf(stderr, ")\n"); + nit_exit(1); +}