diff --git a/native/macosx/run.m b/native/macosx/run.m index cc68a8c7fc..3fadf44a25 100644 --- a/native/macosx/run.m +++ b/native/macosx/run.m @@ -3,19 +3,30 @@ #include "../factor.h" #import "Foundation/NSException.h" +/* This code is convoluted because Cocoa places restrictions on longjmp and +exception handling. In particular, a longjmp can never cross an NS_DURING, +NS_HANDLER or NS_ENDHANDLER. */ void platform_run() { + CELL error = F; + for(;;) { +NS_DURING SETJMP(stack_chain->toplevel); handle_error(); -NS_DURING + + if(error != F) + { + CELL e = error; + error = F; + general_error(ERROR_OBJECTIVE_C,error,true); + } + run(); NS_VOIDRETURN; NS_HANDLER - general_error(ERROR_OBJECTIVE_C, - tag_object(make_alien(F,(CELL)localException)), - true); + error = tag_object(make_alien(F,(CELL)localException)); NS_ENDHANDLER } }