diff --git a/Makefile b/Makefile index d36bb83fb7..b3db92479c 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ DISK_IMAGE = Factor-$(VERSION).dmg LIBPATH = -L/usr/X11R6/lib ifdef DEBUG - CFLAGS = -g + CFLAGS = -g -std=gnu99 STRIP = touch else CFLAGS = -Wall -O3 -ffast-math -std=gnu99 $(SITE_CFLAGS) diff --git a/core/compiler/amd64/architecture.factor b/core/compiler/amd64/architecture.factor index e8aeffbce6..43d833531c 100644 --- a/core/compiler/amd64/architecture.factor +++ b/core/compiler/amd64/architecture.factor @@ -46,5 +46,4 @@ M: float-regs fastcall-regs vregs ; : %prologue ( n -- ) \ stack-reserve set stack-reg stack-increment SUB ; -: %epilogue ( -- ) - stack-reg stack-increment ADD ; +: %epilogue ( -- ) stack-reg stack-increment ADD ; diff --git a/core/compiler/test/stack-trace.factor b/core/compiler/test/stack-trace.factor index de1c5c828c..daf8afacc9 100644 --- a/core/compiler/test/stack-trace.factor +++ b/core/compiler/test/stack-trace.factor @@ -1,12 +1,28 @@ IN: temporary -USING: errors compiler test namespaces sequences kernel-internals ; +USING: errors compiler test namespaces sequences +kernel-internals kernel math ; + +: nice-stack-trace + error-stack-trace get symbolic-stack-trace [ second ] map ; : foo 3 throw 7 ; : bar foo 4 ; : baz bar 5 ; \ baz compile [ 3 ] [ [ baz ] catch ] unit-test -[ { foo bar baz } ] [ - error-stack-trace get symbolic-stack-trace - [ second ] map [ ] subset +[ { foo bar baz } ] [ nice-stack-trace ] unit-test + +: bleh [ 3 + ] map [ 0 > ] subset ; +\ bleh compile + +: stack-trace-contains? nice-stack-trace memq? ; + +[ t ] [ + [ { 1 "hi" } bleh ] catch drop \ + stack-trace-contains? +] unit-test + +[ f t ] [ + [ { C{ 1 2 } } bleh ] catch drop + \ + stack-trace-contains? + \ > stack-trace-contains? ] unit-test diff --git a/vm/cpu-amd64.S b/vm/cpu-amd64.S index eb3c1009ac..9d4946ae2c 100644 --- a/vm/cpu-amd64.S +++ b/vm/cpu-amd64.S @@ -9,5 +9,4 @@ void *native_stack_pointer(void) */ .globl MANGLE(native_stack_pointer) MANGLE(native_stack_pointer): mov %rsp,%rax - add $8,%rax ret diff --git a/vm/cpu-amd64.h b/vm/cpu-amd64.h index 99318ab687..55d845c48b 100644 --- a/vm/cpu-amd64.h +++ b/vm/cpu-amd64.h @@ -8,10 +8,7 @@ INLINE void flush_icache(CELL start, CELL len) {} void *native_stack_pointer(void); -typedef struct _F_STACK_FRAME { - struct _F_STACK_FRAME *previous; - CELL return_address; -} F_STACK_FRAME; +typedef CELL F_STACK_FRAME; -#define PREVIOUS_FRAME(frame) (frame->previous) -#define RETURN_ADDRESS(frame) (frame->return_address) +#define PREVIOUS_FRAME(frame) (frame + 1) +#define RETURN_ADDRESS(frame) (*(frame)) diff --git a/vm/run.c b/vm/run.c index a247ab9327..1cf4a55c2e 100644 --- a/vm/run.c +++ b/vm/run.c @@ -276,14 +276,16 @@ CELL allot_native_stack_trace(void) GROWABLE_ADD(array,cell); } - if(PREVIOUS_FRAME(frame) <= frame) + F_STACK_FRAME *prev = PREVIOUS_FRAME(frame); + + if(prev <= frame) { fprintf(stderr,"*** Unusual C stack layout (why?)\n"); fflush(stderr); break; } - frame = PREVIOUS_FRAME(frame); + frame = prev; } GROWABLE_TRIM(array); diff --git a/vm/types.c b/vm/types.c index 387d12b085..bbeb90ff8b 100644 --- a/vm/types.c +++ b/vm/types.c @@ -46,8 +46,13 @@ F_ARRAY *allot_array(CELL type, F_FIXNUM capacity, CELL fill) /* size is in bytes this time */ F_ARRAY *allot_byte_array(F_FIXNUM size) { - F_FIXNUM byte_size = (F_FIXNUM)(size + sizeof(CELL) - 1) - / (F_FIXNUM)sizeof(CELL); + if(size < 0) + { + general_error(ERROR_NEGATIVE_ARRAY_SIZE,allot_integer(size),F,true); + return NULL; + } + + CELL byte_size = (size + sizeof(CELL) - 1) / sizeof(CELL); return allot_array(BYTE_ARRAY_TYPE,byte_size,0); }