ext="_savo _sav" # Default flavor to reuse
out="a.out" # Default output binary filename
dir="" # Default tmp dir
+nolibgc="false" # Try to use libgc ?
CKSUM="cksum" # Tool that perfors checksum. cksum seems to be very portable
usage()
-I path Add a include directory
-o name Call name the executable
-d Create temporary files in a specific directory
+-nolibgc Do not include libgc
-h This help
END
}
+test_libgc() {
+cat > .tmp.c <<END
+#include <stdlib.h>
+#include <gc/gc.h>
+int main(void) {
+ void *r = GC_malloc(1);
+ return r == NULL;
+ }
+END
+gcc .tmp.c -lgc -o .tmp.bin 2> /dev/null
+res=$?
+rm .tmp.c
+if [ $res = 0 ]; then
+ ./.tmp.bin
+ res=$?
+ rm .tmp.bin
+fi
+return $res
+}
+
stop=false
while [ $stop = false ]; do
case $1 in
-I) OPTS="$OPTS -I $2"; shift; shift;;
-o) out="$2"; shift; shift;;
-d) dir="$2/"; shift; shift;;
+ --nolibgc) nolibgc=true; shift;;
-x) OPTS="$OPTS $2"; shift; shift;;
-h|"") usage; exit;;
*) stop=true
esac
done
+if [ $nolibgc != true ] && test_libgc; then
+ OPTS="$OPTS -DWITH_LIBGC -lgc"
+fi
+
for i in "$@"; do
j=`basename "$i" .c`
found="false"
- cksum=`gcc -E $i 2> /dev/null | $CKSUM`
+ cksum=`gcc -E $OPTS $i 2> /dev/null | $CKSUM`
for e in $ext; do
o="$dir$j.$e.o"
cksumfile="$dir$j.$e.cksum"
--- /dev/null
+* GC **************************************************************************
+
+If Bohem's GC is available, it will be automatically used within compiled NIT
+programs.
+
+On GC enabled NIT program, GC can be dynamically disabled if the NIT_NOGC envvar is set.
+
#include <stdio.h>
#include <string.h>
+#ifdef WITH_LIBGC
+#include <gc/gc.h>
+#define malloc(x) GC_MALLOC((x))
+#define calloc(x,y) GC_MALLOC((x)*(y))
+#endif
+
/* *** Types *** */
typedef int (*fun_t)(int); /* generic function pointer */
typedef unsigned int cid_t; /* class identifier */
#include <signal.h>
#include <stdarg.h>
+#ifdef WITH_LIBGC
+#define GC_DEBUG
+#include <gc/gc.h>
+int nolibgc = 0;
+void *simple_alloc(size_t s0);
+void *alloc(size_t s0)
+{
+ if (!nolibgc) { return GC_MALLOC(s0); }
+ else return simple_alloc(s0);
+}
+#define alloc simple_alloc
+#endif
+
void * alloc(size_t s0)
{
static char * alloc_pos = NULL;
nit_exit(1);
}
void prepare_signals(void) {
+#if WITH_LIBGC
+ nolibgc = (getenv("NIT_NOLIBGC") != NULL);
+ if (!nolibgc) GC_INIT();
+#endif
signal(SIGINT,exithandler);
signal(SIGABRT,exithandler);
signal(SIGSEGV,exithandler);