1 /* This file is part of NIT ( http://www.nitlanguage.org ).
3 * Copyright 2006-2009 Jean Privat <jean@pryen.org>
5 * This file is free software, which comes along with NIT. This software is
6 * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
8 * PARTICULAR PURPOSE. You can modify it is you want, provided this header
9 * is kept unaltered, and a notification of the changes is added.
10 * You are allowed to redistribute it and sell it, alone or is a part of
14 #include "nit_common.h"
17 bigint object_id_counter
= 1000000;
23 void *simple_alloc(size_t s0
);
24 void *alloc(size_t s0
)
26 if (!nolibgc
) { return GC_MALLOC(s0
); }
27 else return simple_alloc(s0
);
29 #define alloc simple_alloc
32 void * alloc(size_t s0
)
34 static char * alloc_pos
= NULL
;
35 static size_t alloc_size
= 0;
37 size_t s
= ((s0
+3)/4)*4;
39 alloc_size
= s
+ 1024*1024;
40 alloc_pos
= (char *)calloc(alloc_size
, 1);
52 void exithandler(int s
) {
53 fprintf(stderr
, "Recieved signal %d\n", s
);
56 void prepare_signals(void) {
58 nolibgc
= (getenv("NIT_NOLIBGC") != NULL
);
63 signal(SIGINT
,exithandler
);
64 signal(SIGABRT
,exithandler
);
65 signal(SIGSEGV
,exithandler
);
66 signal(SIGILL
, exithandler
);
67 signal(SIGFPE
, exithandler
);
68 signal(SIGTERM
,exithandler
);
69 signal(SIGBUS
, exithandler
);
71 struct trace_t
*tracehead
= NULL
;
72 void nit_exit(int i
) {
73 fprintf(stderr
, ",---- Stack trace -- - - -\n");
74 while(tracehead
!= NULL
) {
75 fprintf(stderr
, "| %s (%s:%d)\n", tracehead
->meth
, tracehead
->file
, tracehead
->line
);
76 if (tracehead
== tracehead
->prev
) break;
77 tracehead
= tracehead
->prev
;
79 fprintf(stderr
, "`------------------- - - -\n");