Selaa lähdekoodia

added set_error_handler

Nicolas Cannasse 9 vuotta sitten
vanhempi
commit
8b85c268be
3 muutettua tiedostoa jossa 20 lisäystä ja 2 poistoa
  1. 1 0
      src/alloc.c
  2. 1 1
      src/module.c
  3. 18 1
      src/std/error.c

+ 1 - 0
src/alloc.c

@@ -588,6 +588,7 @@ static void gc_mark() {
 		gc_pheader *page;
 		if( !p ) continue;
 		page = GC_GET_PAGE(p);
+		if( !page ) continue; // the value was set to a not gc allocated ptr
 		// don't check if valid ptr : it's a manual added root, so should be valid
 		int bid = ((unsigned char*)p - (unsigned char*)page) / page->block_size;
 		if( (page->bmp[bid>>3] & (1<<(bid&7))) == 0 ) {

+ 1 - 1
src/module.c

@@ -204,7 +204,7 @@ int hl_module_init( hl_module *m ) {
 			append_type(&p,n->t);
 			*p++ = 0;
 			if( memcmp(sign,tmp,strlen(sign)+1) != 0 )
-				hl_fatal4("Invalid signature for function %s@%s : %s required but %s found",n->lib,n->name,tmp,sign);
+				hl_fatal4("Invalid signature for function %s@%s : %s required but %s found in hdll",n->lib,n->name,tmp,sign);
 		}
 	}
 	// INIT indexes

+ 18 - 1
src/std/error.c

@@ -128,12 +128,23 @@ typedef int (*capture_stack_type)( void **stack, int size );
 
 static resolve_symbol_type resolve_symbol_func = hl_resolve_symbol;
 static capture_stack_type capture_stack_func = hl_capture_stack;
+static vclosure *hl_error_handler = NULL;
 
 HL_PRIM void hl_exception_setup( void *resolve_symbol, void *capture_stack ) {
 	resolve_symbol_func = resolve_symbol;
 	capture_stack_func = capture_stack;
 }
 
+HL_PRIM void hl_set_error_handler( vclosure *d ) {
+	if( d == hl_error_handler )
+		return;
+	hl_error_handler = d;
+	if( d )
+		hl_add_root(&hl_error_handler);
+	else
+		hl_remove_root(&hl_error_handler);
+}
+
 HL_PRIM void hl_throw( vdynamic *v ) {
 	hl_trap_ctx *t = hl_current_trap;
 	if( v != stack_last_exc ) {
@@ -142,7 +153,10 @@ HL_PRIM void hl_throw( vdynamic *v ) {
 	}
 	hl_current_exc = v;
 	hl_current_trap = t->prev;
-	if( hl_current_trap == NULL ) hl_debug_break();
+	if( hl_current_trap == NULL ) {
+		hl_debug_break();
+		if( hl_error_handler ) hl_dyn_call(hl_error_handler,&v,1);
+	}
 	longjmp(t->buf,1);
 }
 
@@ -190,3 +204,6 @@ HL_PRIM void hl_fatal_fmt( const char *file, int line, const char *fmt, ...) {
 	va_end(args);
 	hl_fatal_error(buf,file,line);
 }
+
+DEFINE_PRIM(_ARR,exception_stack,_NO_ARG);
+DEFINE_PRIM(_VOID,set_error_handler,_FUN(_VOID,_DYN));