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"
22 void *simple_alloc(size_t s0
);
23 void *alloc(size_t s0
)
25 if (!nolibgc
) { return GC_MALLOC(s0
); }
26 else return simple_alloc(s0
);
28 #define alloc simple_alloc
31 void * alloc(size_t s0
)
33 static char * alloc_pos
= NULL
;
34 static size_t alloc_size
= 0;
36 size_t s
= ((s0
+3)/4)*4;
38 alloc_size
= s
+ 1024*1024;
39 alloc_pos
= (char *)calloc(alloc_size
, 1);
51 void exithandler(int s
) {
52 fprintf(stderr
, "Recieved signal %d\n", s
);
55 void prepare_signals(void) {
57 nolibgc
= (getenv("NIT_NOLIBGC") != NULL
);
62 signal(SIGINT
,exithandler
);
63 signal(SIGABRT
,exithandler
);
64 signal(SIGSEGV
,exithandler
);
65 signal(SIGILL
, exithandler
);
66 signal(SIGFPE
, exithandler
);
67 signal(SIGTERM
,exithandler
);
68 signal(SIGBUS
, exithandler
);
70 struct trace_t
*tracehead
= NULL
;
71 void nit_exit(int i
) {
72 fprintf(stderr
, ",---- Stack trace -- - - -\n");
73 while(tracehead
!= NULL
) {
74 fprintf(stderr
, "| %s (%s:%d)\n", tracehead
->meth
, tracehead
->file
, tracehead
->line
);
75 if (tracehead
== tracehead
->prev
) break;
76 tracehead
= tracehead
->prev
;
78 fprintf(stderr
, "`------------------- - - -\n");