2
0
Эх сурвалжийг харах

Make uncaught exception printing consistent (#799)

Add a hl_print_uncaught_exception function
and use it everywhere an uncaught exception is printed.
Zeta 1 сар өмнө
parent
commit
4fe1be545d
5 өөрчлөгдсөн 14 нэмэгдсэн , 21 устгасан
  1. 1 0
      src/hl.h
  2. 1 7
      src/hlc_main.c
  3. 1 7
      src/main.c
  4. 10 0
      src/std/error.c
  5. 1 7
      src/std/thread.c

+ 1 - 0
src/hl.h

@@ -643,6 +643,7 @@ HL_API void hl_setup_longjump( void *j );
 HL_API void hl_setup_exception( void *resolve_symbol, void *capture_stack );
 HL_API void hl_dump_stack( void );
 HL_API bool hl_maybe_print_custom_stack( vdynamic *exc );
+HL_API void hl_print_uncaught_exception( vdynamic *exc );
 HL_API varray *hl_exception_stack( void );
 HL_API bool hl_detect_debugger( void );
 

+ 1 - 7
src/hlc_main.c

@@ -175,13 +175,7 @@ int main(int argc, char *argv[]) {
 	cl.fun = hl_entry_point;
 	ret = hl_dyn_call_safe(&cl, NULL, 0, &isExc);
 	if( isExc ) {
-		uprintf(USTR("Uncaught exception: %s\n"), hl_to_string(ret));
-		if( !hl_maybe_print_custom_stack(ret) ) {
-			varray *a = hl_exception_stack();
-			int i;
-			for( i = 0; i < a->size; i++ )
-				uprintf(USTR("Called from %s\n"), hl_aptr(a, uchar*)[i]);
-		}
+		hl_print_uncaught_exception(ret);
 	}
 	hl_global_free();
 	sys_global_exit();

+ 1 - 7
src/main.c

@@ -242,13 +242,7 @@ int main(int argc, pchar *argv[]) {
 	ctx.ret = hl_dyn_call_safe(&cl,NULL,0,&isExc);
 	hl_profile_end();
 	if( isExc ) {
-		uprintf(USTR("Uncaught exception: %s\n"), hl_to_string(ctx.ret));
-		if( !hl_maybe_print_custom_stack(ctx.ret) ) {
-			varray *a = hl_exception_stack();
-			int i;
-			for( i = 0; i < a->size; i++ )
-				uprintf(USTR("Called from %s\n"), hl_aptr(a, uchar*)[i]);
-		}
+		hl_print_uncaught_exception(ctx.ret);
 		hl_debug_break();
 		hl_global_free();
 		return 1;

+ 10 - 0
src/std/error.c

@@ -162,6 +162,16 @@ HL_PRIM bool hl_maybe_print_custom_stack( vdynamic *exc ) {
 	return false;
 }
 
+HL_PRIM void hl_print_uncaught_exception(vdynamic *exc) {
+	uprintf(USTR("Uncaught exception: %s\n"), hl_to_string(exc));
+	if (!hl_maybe_print_custom_stack(exc)) {
+		varray *a = hl_exception_stack();
+		for (int i = 0; i < a->size; i++)
+			uprintf(USTR("Called from %s\n"), hl_aptr(a, uchar *)[i]);
+	}
+	fflush(stdout);
+}
+
 HL_PRIM varray *hl_exception_stack() {
 	hl_thread_info *t = hl_get_thread();
 	varray *a = hl_alloc_array(&hlt_bytes, t->exc_stack_count);

+ 1 - 7
src/std/thread.c

@@ -907,16 +907,10 @@ HL_PRIM hl_thread *hl_thread_start( void *callback, void *param, bool withGC ) {
 
 static void hl_run_thread( vclosure *c ) {
 	bool isExc;
-	varray *a;
-	int i;
 	vdynamic *exc = hl_dyn_call_safe(c,NULL,0,&isExc);
 	if( !isExc )
 		return;
-	a = hl_exception_stack();
-	uprintf(USTR("Uncaught exception: %s\n"), hl_to_string(exc));
-	for(i=0;i<a->size;i++)
-		uprintf(USTR("Called from %s\n"), hl_aptr(a,uchar*)[i]);
-	fflush(stdout);
+	hl_print_uncaught_exception(exc);
 }
 
 HL_PRIM hl_thread *hl_thread_create( vclosure *c ) {