From 88621c104abeacbb7814cb99423dfec8256fb9f6 Mon Sep 17 00:00:00 2001 From: nicola Date: Sat, 9 Apr 2011 13:47:37 +0000 Subject: [PATCH] Improved checks for native ObjC exceptions. We now check the runtime support here, and disable them from here regardless of what gnustep-make did (this makes it easier to change the runtime without reconfiguring gnustep-make). Small update to ObjC runtime code for GCC 4.6 git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32820 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 17 +++++++ Source/Additions/GSObjCRuntime.m | 2 - base.make.in | 8 ++++ configure | 76 +++++++++++++++++++++++++------- configure.ac | 65 +++++++++++++++++++++------ 5 files changed, 137 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index b74da35ff..37516589b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2011-04-09 Nicola Pero + + * Source/Additions/GSObjCRuntime.m (GSSelectorFromNameAndTypes): + Uncommented case for __GNU_LIBOBJC__. + +2011-04-09 Nicola Pero + + * configure.ac: Updated the checks to enable native Objective-C + exceptions. If native exceptions were enabled in gnustep-make - + because the compiler supports them -, but are disabled here + because there is no uncaught exception handler in the runtime, + print an explanation without aborting; we now disable them via + base.make. + * configure: Regnerated. + * base.make.in: Set USE_OBJC_EXCEPTIONS to no if we disabled + native exceptions when configuring. + 2011-04-09 Nicola Pero * Tests/GNUmakefile: Updated comments. diff --git a/Source/Additions/GSObjCRuntime.m b/Source/Additions/GSObjCRuntime.m index aff1356ae..7950c4c13 100644 --- a/Source/Additions/GSObjCRuntime.m +++ b/Source/Additions/GSObjCRuntime.m @@ -143,10 +143,8 @@ GSSelectorFromNameAndTypes(const char *name, const char *types) { #if NeXT_RUNTIME return sel_getUid(name); -/* Don't do the next line until the function works. #elif defined (__GNU_LIBOBJC__) return sel_registerTypedName(name, types); -*/ #elif defined (__GNUSTEP_RUNTIME__) return sel_registerTypedName_np(name, types); #else diff --git a/base.make.in b/base.make.in index f220a29f9..e75972239 100644 --- a/base.make.in +++ b/base.make.in @@ -55,4 +55,12 @@ endif GNUSTEP_BASE_HAVE_MDNS=@HAVE_MDNS@ GNUSTEP_BASE_HAVE_AVAHI=@HAVE_AVAHI@ GNUSTEP_BASE_HAVE_UCI=@HAVE_UCI@ + + # If we determined that the Objective-C runtime does not support + # native Objective-C exceptions, turn them off. This overrides + # the USE_OBJC_EXCEPTIONS setting in gnustep-make's config.make. + ifeq (@BASE_NATIVE_OBJC_EXCEPTIONS@, 0) + USE_OBJC_EXCEPTIONS = no + endif + endif # BASE_MAKE_LOADED diff --git a/configure b/configure index 568d9c5ad..ad9f0a0ad 100755 --- a/configure +++ b/configure @@ -647,6 +647,7 @@ DEFINE_INT8_T INCLUDE_STDINT HAVE_PTS_STREAM_MODULES HAVE_OBJC_SYNC_ENTER +BASE_NATIVE_OBJC_EXCEPTIONS GS_MIXEDABI GS_NONFRAGILE OBJCFLAGS @@ -715,7 +716,6 @@ build_vendor build_cpu build BASE_NONFRAGILE_ABI -BASE_NATIVE_OBJC_EXCEPTIONS target_alias host_alias build_alias @@ -802,8 +802,7 @@ CFLAGS LDFLAGS LIBS CPPFLAGS -CPP -CPPFLAGS' +CPP' ac_subdirs_all='SSL' # Initialize some variables set by options. @@ -2572,16 +2571,6 @@ if test -z "$LIBRARY_COMBO"; then LIBRARY_COMBO=`gnustep-config --variable=LIBRARY_COMBO 2>&5` fi -exceptions=`gnustep-config --objc-flags | grep _NATIVE_OBJC_EXCEPTIONS 2>&5` -if test -z "$exceptions"; then - exceptions=no - BASE_NATIVE_OBJC_EXCEPTIONS=0 -else - exceptions=yes - BASE_NATIVE_OBJC_EXCEPTIONS=1 -fi - - nonfragile=`gnustep-config --objc-flags | grep _NONFRAGILE_ABI 2>&5` if test -z "$nonfragile"; then nonfragile=no @@ -6940,9 +6929,40 @@ rm -f conftest* # Don't revert any Objective-C flags as they are used in the next test + +#-------------------------------------------------------------------- +# Native Objective-C exceptions +#-------------------------------------------------------------------- + +# First of all, determine if native Objective-C exceptions are enabled +# in gnustep-make. They are enabled if the compiler supports it; they +# are disabled if it doesn't. And, of course, the user may have +# forced one behaviour or the other. Note that we go and look at the +# actual config.make file to be able to know what was configured in +# gnustep-make regardless of any gnustep-base that is currently +# installed. We can't use `gnustep-config --objc-flags` because that +# may report native exceptions as disabled because the currently +# installed gnustep-base has them disabled. +if grep USE_OBJC_EXCEPTIONS $CURRENT_GNUSTEP_MAKEFILES/$lobj_dir/config.make | grep yes >&5 2>&5; then + exceptions=yes +else + exceptions=no +fi + +# At this point, if exceptions=no, then native exceptions are disabled +# and won't be used. If exceptions=yes, we need to check if they work +# and if the runtime has proper support for them. If it does, we'll +# happily use them; if it doesn't, we'll automatically disable them +# because they don't work. ;-) + #-------------------------------------------------------------------- # One of these is needed by for handling uncaught exceptions #-------------------------------------------------------------------- + +# TODO: These checks are not really needed if native exceptions are +# disabled. So maybe we should not run them at all in that case. On +# the other hand, that case is going to become more and more unusual. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for objc_setUncaughtExceptionHandler() in runtime" >&5 $as_echo_n "checking for objc_setUncaughtExceptionHandler() in runtime... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -7018,14 +7038,38 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_unexpected" >&5 $as_echo "$have_unexpected" >&6; } +# TODO: It would also be nice to actually test that native Objective-C +# exceptions work. + if test "$exceptions" = "yes"; then - if test $have_set_unexpected = no; then - if test $have_unexpected = no; then - as_fn_error $? "Your objective-c runtime library does not appear to support any mechanism to set a handler for uncaught native exceptions. Please upgrade your runtime or re-install gnustep-make without native-objc-exceptions!" "$LINENO" 5 + if test x"$have_set_uncaught_exception_handler" = x"no"; then + if test x"$have_set_unexpected" = x"no"; then + if test x"$have_unexpected" = x"no"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: Disabling native Objective-C exceptions because the ObjC runtime" >&5 +$as_echo "$as_me: Disabling native Objective-C exceptions because the ObjC runtime" >&6;} + { $as_echo "$as_me:${as_lineno-$LINENO}: has no way to set an uncaught exception handler. Please install" >&5 +$as_echo "$as_me: has no way to set an uncaught exception handler. Please install" >&6;} + { $as_echo "$as_me:${as_lineno-$LINENO}: a recent Objective-C runtime if you want to use them." >&5 +$as_echo "$as_me: a recent Objective-C runtime if you want to use them." >&6;} + exceptions="no"; + fi fi fi fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable native Objective-C exceptions" >&5 +$as_echo_n "checking whether to enable native Objective-C exceptions... " >&6; } +if test "$exceptions" = "yes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + BASE_NATIVE_OBJC_EXCEPTIONS=1 +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + BASE_NATIVE_OBJC_EXCEPTIONS=0 +fi + + # Don't revert any Objective-C flags as they are used in the next test #-------------------------------------------------------------------- diff --git a/configure.ac b/configure.ac index 997ff0683..25bfa77d2 100644 --- a/configure.ac +++ b/configure.ac @@ -85,16 +85,6 @@ if test -z "$LIBRARY_COMBO"; then LIBRARY_COMBO=`gnustep-config --variable=LIBRARY_COMBO 2>&5` fi -exceptions=`gnustep-config --objc-flags | grep _NATIVE_OBJC_EXCEPTIONS 2>&5` -if test -z "$exceptions"; then - exceptions=no - BASE_NATIVE_OBJC_EXCEPTIONS=0 -else - exceptions=yes - BASE_NATIVE_OBJC_EXCEPTIONS=1 -fi -AC_SUBST(BASE_NATIVE_OBJC_EXCEPTIONS) - nonfragile=`gnustep-config --objc-flags | grep _NONFRAGILE_ABI 2>&5` if test -z "$nonfragile"; then nonfragile=no @@ -1700,9 +1690,40 @@ AC_EGREP_HEADER(objc_get_uninstalled_dtable, objc/objc-api.h, # Don't revert any Objective-C flags as they are used in the next test + +#-------------------------------------------------------------------- +# Native Objective-C exceptions +#-------------------------------------------------------------------- + +# First of all, determine if native Objective-C exceptions are enabled +# in gnustep-make. They are enabled if the compiler supports it; they +# are disabled if it doesn't. And, of course, the user may have +# forced one behaviour or the other. Note that we go and look at the +# actual config.make file to be able to know what was configured in +# gnustep-make regardless of any gnustep-base that is currently +# installed. We can't use `gnustep-config --objc-flags` because that +# may report native exceptions as disabled because the currently +# installed gnustep-base has them disabled. +if grep USE_OBJC_EXCEPTIONS $CURRENT_GNUSTEP_MAKEFILES/$lobj_dir/config.make | grep yes >&5 2>&5; then + exceptions=yes +else + exceptions=no +fi + +# At this point, if exceptions=no, then native exceptions are disabled +# and won't be used. If exceptions=yes, we need to check if they work +# and if the runtime has proper support for them. If it does, we'll +# happily use them; if it doesn't, we'll automatically disable them +# because they don't work. ;-) + #-------------------------------------------------------------------- # One of these is needed by for handling uncaught exceptions #-------------------------------------------------------------------- + +# TODO: These checks are not really needed if native exceptions are +# disabled. So maybe we should not run them at all in that case. On +# the other hand, that case is going to become more and more unusual. + AC_MSG_CHECKING(for objc_setUncaughtExceptionHandler() in runtime) AC_LINK_IFELSE([#include "$srcdir/config/config.setUncaughtExceptionHandler.m"], have_set_uncaught_exception_handler=yes, have_set_uncaught_exception_handler=no) @@ -1734,14 +1755,32 @@ if test $have_unexpected = yes; then fi AC_MSG_RESULT($have_unexpected) +# TODO: It would also be nice to actually test that native Objective-C +# exceptions work. + if test "$exceptions" = "yes"; then - if test $have_set_unexpected = no; then - if test $have_unexpected = no; then - AC_MSG_ERROR([Your objective-c runtime library does not appear to support any mechanism to set a handler for uncaught native exceptions. Please upgrade your runtime or re-install gnustep-make without native-objc-exceptions!]) + if test x"$have_set_uncaught_exception_handler" = x"no"; then + if test x"$have_set_unexpected" = x"no"; then + if test x"$have_unexpected" = x"no"; then + AC_MSG_NOTICE([Disabling native Objective-C exceptions because the ObjC runtime]) + AC_MSG_NOTICE([has no way to set an uncaught exception handler. Please install]) + AC_MSG_NOTICE([a recent Objective-C runtime if you want to use them.]) + exceptions="no"; + fi fi fi fi +AC_MSG_CHECKING(whether to enable native Objective-C exceptions) +if test "$exceptions" = "yes"; then + AC_MSG_RESULT(yes) + BASE_NATIVE_OBJC_EXCEPTIONS=1 +else + AC_MSG_RESULT(no) + BASE_NATIVE_OBJC_EXCEPTIONS=0 +fi +AC_SUBST(BASE_NATIVE_OBJC_EXCEPTIONS) + # Don't revert any Objective-C flags as they are used in the next test #--------------------------------------------------------------------