+#include <string.h> /* For memcpy */
+
+/* This hook allows libraries to sepecify special actions when an
+ exception is thrown without a handler in place. This is deprecated
+ in favour of objc_set_uncaught_exception_handler ().
+ */
+void (*_objc_unexpected_exception) (id exception); /* !T:SAFE */
+
+
+/* 'is_kind_of_exception_matcher' is our default exception matcher -
+ it determines if the object 'exception' is of class 'catch_class',
+ or of a subclass.
+*/
+static int
+is_kind_of_exception_matcher (Class catch_class, id exception)
+{
+ /* NULL catch_class is catch-all (eg, @catch (id object)). */
+ if (catch_class == Nil)
+ return 1;
+
+ /* If exception is nil (eg, @throw nil;), then it can only be catched
+ * by a catch-all (eg, @catch (id object)).
+ */
+ if (exception != nil)
+ {
+ Class c;
+
+ for (c = exception->class_pointer; c != Nil;
+ c = class_getSuperclass (c))
+ if (c == catch_class)
+ return 1;
+ }
+ return 0;
+}
+
+/* The exception matcher currently in use. */
+static objc_exception_matcher
+__objc_exception_matcher = is_kind_of_exception_matcher;
+
+objc_exception_matcher
+objc_setExceptionMatcher (objc_exception_matcher new_matcher)
+{
+ objc_exception_matcher old_matcher = __objc_exception_matcher;
+ __objc_exception_matcher = new_matcher;
+ return old_matcher;
+}
+
+/* The uncaught exception handler currently in use. */
+static objc_uncaught_exception_handler
+__objc_uncaught_exception_handler = NULL;
+
+objc_uncaught_exception_handler
+objc_setUncaughtExceptionHandler (objc_uncaught_exception_handler
+ new_handler)
+{
+ objc_uncaught_exception_handler old_handler
+ = __objc_uncaught_exception_handler;
+ __objc_uncaught_exception_handler = new_handler;
+ return old_handler;
+}
+