From edfee7c3a3c78c5b721a73031b449de258e5a618 Mon Sep 17 00:00:00 2001 From: slava Date: Sat, 18 Mar 2006 03:15:16 +0000 Subject: [PATCH] Fix Objective C exception handling instability --- native/macosx/run.m | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 } }