This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] PR libobjc/27466 unexpected exception handler V2


this patch is approved.

As far as I'm concerned, I recommend adding this tiny bug fix to GCC
4.3 too if it's not too late - it would avoid
shipping a broken GNU Objective-C exception handling support in
libobjc, and has zero impact on everything else,
so it's a safe but very useful bug fix for libobjc.

OK, I'm a bit confused since we usually commit fixes to the trunk before
we backport them to a branch, and the eminent release is 4.4 where as
you say this OK for 4.3 branch.

I did obviously mean 4.4. Sorry about that.



PS: It would be good if you could also provide a second patch which
expands the "Hook for uncaught exceptions"
comment in the public header into a couple of readable sentences. ;-)

This is what I'll add:


"This hook is called when a exception is thrown when no valid exception
handler is in place. If the function returns the result is currently
undefined."

Sounds good.


I like your idea of explicitly saying that the result is currently undefined since
we want to be free to define it in future/forthcoming releases of GCC/ libobjc
(eg, to allow recovering from uncaught exceptions in some cases). :-)


But to make it a bit less cryptic as it stands, I would suggest we go for

"This hook is called when a exception is thrown when no valid exception
handler is in place. The function is normally expected to never return.
If the function returns the result is currently undefined."


Thanks




----------------------------------------

Hello,

so here is V2 of a fix for PR27466, adding support for an unexpected
exception handler which is needed by libraries to use libobjc's
exception support.

This patch is derived from the patch posted at

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27466

yet it uses a global variables as a hook, as is usually done in libobjc.

This patch has been bootstrapped and regression tested on i686-pc-
linux-gnu.

OK to commit to trunk?

2009-02-23  Richard Frith-Macdonald  <rfm@gnu.org>
            David Ayers  <ayers@fsfe.org>

        PR libobjc/27466
        * objc/objc-api.h (_objc_unexpected_exception): Declare new
	  hook.
        * exception.c (objc_exception_throw): Use hook.
        * libobjc.def (_objc_unexpected_exception): Export hook.

2009-02-23 David Ayers <ayers@fsfe.org>

        PR libobjc/27466
        * objc/execute/exceptions/handler-1.m. New.



Index: libobjc/libobjc.def
===================================================================
--- libobjc/libobjc.def	(Revision 144360)
+++ libobjc/libobjc.def	(Arbeitskopie)
@@ -38,6 +38,7 @@
 objc_mutex_lock
 objc_mutex_trylock
 objc_mutex_unlock
+_objc_unexpected_exception
 objc_thread_detach
 objc_thread_exit
 objc_thread_get_data
Index: libobjc/exception.c
===================================================================
--- libobjc/exception.c	(Revision 144360)
+++ libobjc/exception.c	(Arbeitskopie)
@@ -86,6 +86,11 @@
   unsigned char call_site_encoding;
 };

+/* This hook allows libraries to sepecify special actions when an
+   exception is thrown without a handler in place.
+ */
+void (*_objc_unexpected_exception) (id exception); /* !T:SAFE */
+
 static const unsigned char *
 parse_lsda_header (struct _Unwind_Context *context, const unsigned
char *p,
 		   struct lsda_header_info *info)
@@ -486,5 +491,9 @@
 #endif

   /* Some sort of unwinding error.  */
+  if (_objc_unexpected_exception != 0)
+    {
+      (*_objc_unexpected_exception) (value);
+    }
   abort ();
 }
Index: libobjc/objc/objc-api.h
===================================================================
--- libobjc/objc/objc-api.h	(Revision 144360)
+++ libobjc/objc/objc-api.h	(Arbeitskopie)
@@ -430,6 +430,12 @@
 objc_EXPORT IMP (*__objc_msg_forward)(SEL);
 objc_EXPORT IMP (*__objc_msg_forward2)(id, SEL);

+/*
+**  Hook for uncaught exceptions.
+*/
+objc_EXPORT void (*_objc_unexpected_exception)(id);
+
+
 Method_t class_get_class_method(MetaClass _class, SEL aSel);

 Method_t class_get_instance_method(Class _class, SEL aSel);
Index: gcc/testsuite/objc/execute/exceptions/handler-1.m
===================================================================
--- gcc/testsuite/objc/execute/exceptions/handler-1.m	(Revision 0)
+++ gcc/testsuite/objc/execute/exceptions/handler-1.m	(Revision 0)
@@ -0,0 +1,38 @@
+/* Test custom exception handlers  */
+/* Author: David Ayers */
+
+#include <objc/objc-api.h>
+#include <objc/Object.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static unsigned int handlerExpected = 0;
+
+void
+my_exception_handler(id excp)
+{
+  /* Returning from the handler would abort.  */
+  if (handlerExpected)
+    exit(0);
+
+  abort();
+}
+
+int
+main(int argc, char *argv[])
+{
+  _objc_unexpected_exception = my_exception_handler;
+
+  @try
+    {
+      @throw [Object new];
+    }
+  @catch (id exc)
+    {
+      handlerExpected = 1;
+    }
+
+  @throw [Object new];
+  abort();
+  return 0;
+}




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]