Updated code to compile with GCC 4.6 and the new GNU Objective-C runtime

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31765 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Nicola Pero 2010-12-23 02:23:05 +00:00
parent 49e56309be
commit 30f098f9f8
19 changed files with 227 additions and 78 deletions

View file

@ -1,3 +1,63 @@
2010-12-23 Nicola Pero <nicola.pero@meta-innovation.com>
* configure.ac: Check for objc_setUncaughtExceptionHandler().
* configure: Regenerated.
* Headers/Additions/GNUstepBase/config.h.in: Regenerated.
* config/config..setUncaughtExceptionHandler.m: New.
* Source/Additions/GSObjCRuntime.m (GSTypesFromSelector): Use
sel_getType, not sel_getType_np, if __GNU_LIBOBJC__.
(GSSelectorFromNameAndTypes): Use sel_registerTypedName, not
sel_registerTypedName_np, if __GNU_LIBOBJC__.
* Source/objc-load.h: Do not include objc-api.h.
* Source/NSBundle.m (_bundle_load_callback): Use the new API to
iterate over classes when __GNU_LIBOBJC__.
* Source/NSConnection.m ([NSConnection
-forwardInvocation:forProxy:]): Use sel_registerTypedName, not
sel_registerTypedName_np, if __GNU_LIBOBJC__.
* Source/NSData.m ([NSData
-deserializeDataAt:ofObjCType:atCursor:context:]): Use
sel_registerTypedName, not sel_registerTypedName_np, if
__GNU_LIBOBJC__. Use sel_registerName, not
sel_registerTypedName_np, if the type is 0.
([NSDataStatic -deserializeDataAt:ofObjCType:atCursor:context:]):
Use sel_registerTypedName, not sel_registerTypedName_np, if
__GNU_LIBOBJC__.
* Source/NSDistributedNotificationCenter.m
([NSDistributedNotificationCenter
-postNotificationName:object:userInfo:selector:to:]):
Use sel_registerTypedName, not sel_registerTypedName_np, if
__GNU_LIBOBJC__.
* Source/NSException.m: Include <objc/objc-exception.h> if
HAVE_SET_UNCAUGHT_EXCEPTION_HANDLER.
([NSException +initialize]): Use objc_setUncaughtExceptionHandler
if HAVE_SET_UNCAUGHT_EXCEPTION_HANDLER.
* Source/NSMethodSignature.m: Do not include objc/encoding.h when
__GNU_LIBOBJC__.
* Source/NSObject.m ([NSObject -methodSignatureForSelector:]): Use
method_getTypeEncoding instead of accessing directly the 'types'
field.
([NSObject +poseAsClass:]): Always throw an exception since
class_pose_as is now deprecated or unavailable in most Objective-C
runtimes. If you need pose-as, and your runtime supports it, call
class_pose_as directly.
([NSObject -error:]): Use vprintf and abort directly instead of
trying to call objc_verror.
* Source/NSThread.m: Define objc_thread_callback if we are later
using it.
* Source/objc-load.m: Never include objc-api.h or objc-list.h.
(GSPrivateLoadModule): Removed 'dynamic_handles' variable, no
longer used. Do not call __objc_resolve_class_links if
__GNU_LIBOBJC__.
* Source/GSFFIInvocation.m: Include <objc/message.h> when
__GNU_LIBOBJC__.
(gs_find_best_typed_sel): Use sel_getType instead of
sel_getType_np if __GNU_LIBOBJC__.
(gs_objc_msg_forward2): Same change.
(GSFFIInvocationCallback): Same change.
* Source/NSValue.m ([NSValue +valueFromString:]): Added missing
return for NSRange values.
2010-12-22 Nicola Pero <nicola.pero@meta-innovation.co>
* Headers/Additions/GNUstepBase/preface.h.in: When using the new

View file

@ -448,6 +448,9 @@
/* Define to 1 if you have the `setsid' function. */
#undef HAVE_SETSID
/* Define if libobjc has the objc_setUncaughtExceptionHandler() function */
#undef HAVE_SET_UNCAUGHT_EXCEPTION_HANDLER
/* Define if libobjc has the objc_set_unexpected() function */
#undef HAVE_SET_UNEXPECTED

View file

@ -149,7 +149,11 @@ GSSelectorFromNameAndTypes(const char *name, const char *types)
}
else
{
#ifdef __GNU_LIBOBJC__
return sel_registerTypedName(name, types);
#else
return sel_registerTypedName_np(name, types);
#endif
}
#endif
}
@ -161,8 +165,12 @@ GSTypesFromSelector(SEL sel)
#else
if (sel == 0)
return 0;
#ifdef __GNU_LIBOBJC__
return sel_getType(sel);
#else
return sel_getType_np(sel);
#endif
#endif
}
void
GSFlushMethodCacheForClass (Class cls)

View file

@ -33,13 +33,10 @@
static GSLazyRecursiveLock *local_lock = nil;
/*
This class only exists to provide
a thread safe mechanism to initialize local_lock
as +initialize is called under a lock in ObjC runtimes.
User code should resort to GS_INITIALIZED_LOCK(),
which uses the +newLockAt: extension.
*/
/* This class only exists to provide a thread safe mechanism to
initialize local_lock as +initialize is called under a lock in ObjC
runtimes. User code should resort to GS_INITIALIZED_LOCK(), which
uses the +newLockAt: extension. */
@interface _GSLockInitializer : NSObject
@end
@ -48,9 +45,8 @@ static GSLazyRecursiveLock *local_lock = nil;
{
if (local_lock == nil)
{
/* As we do not know whether creating custom locks
may implicitly create other locks,
we use a recursive lock. */
/* As we do not know whether creating custom locks may
implicitly create other locks, we use a recursive lock. */
local_lock = [GSLazyRecursiveLock new];
}
}

View file

@ -35,10 +35,15 @@
#import <pthread.h>
#import "cifframe.h"
#import "GSPrivate.h"
#ifdef __GNUSTEP_RUNTIME__
#include <objc/hooks.h>
#endif
#ifdef __GNU_LIBOBJC__
#include <objc/message.h>
#endif
#ifndef INLINE
#define INLINE inline
#endif
@ -51,11 +56,10 @@ typedef void (*f_fun) ();
static void GSFFIInvocationCallback(ffi_cif*, void*, void **, void*);
/*
* If we are using the GNU ObjC runtime we could
* simplify this function quite a lot because this
* function is already present in the ObjC runtime.
* However, it is not part of the public API, so
* we work around it.
* If we are using the GNU ObjC runtime we could simplify this
* function quite a lot because this function is already present in
* the ObjC runtime. However, it is not part of the public API, so we
* work around it.
*/
static INLINE GSMethod
@ -75,19 +79,16 @@ gs_method_for_receiver_and_selector (id receiver, SEL sel)
/*
* Selectors are not unique, and not all selectors have
* type information. This method tries to find the
* best equivalent selector with type information.
* Selectors are not unique, and not all selectors have type
* information. This method tries to find the best equivalent
* selector with type information.
*
* the conversion sel -> name -> sel
* is not what we want. However
* I can not see a way to dispose of the
* name, except if we can access the
* internal data structures of the runtime.
* the conversion sel -> name -> sel is not what we want. However I
* can not see a way to dispose of the name, except if we can access
* the internal data structures of the runtime.
*
* If we can access the private data structures
* we can also check for incompatible
* return types between all equivalent selectors.
* If we can access the private data structures we can also check for
* incompatible return types between all equivalent selectors.
*/
/*
@ -99,14 +100,22 @@ gs_method_for_receiver_and_selector (id receiver, SEL sel)
static INLINE SEL
gs_find_best_typed_sel (SEL sel)
{
#ifdef __GNU_LIBOBJC__
if (!sel_getType(sel))
#else
if (!sel_getType_np(sel))
#endif
{
const char *name = sel_getName(sel);
if (name)
{
SEL tmp_sel = sel_get_any_typed_uid(name);
#ifdef __GNU_LIBOBJC__
if (sel_getType(tmp_sel))
#else
if (sel_getType_np(tmp_sel))
#endif
return tmp_sel;
}
}
@ -153,7 +162,11 @@ static IMP gs_objc_msg_forward2 (id receiver, SEL sel)
in the callback, but only under limited circumstances.
*/
sel = gs_find_best_typed_sel(sel);
#ifdef __GNU_LIBOBJC__
sel_type = sel_getType(sel);
#else
sel_type = sel_getType_np(sel);
#endif
if (sel_type)
{
sig = [NSMethodSignature signatureWithObjCTypes: sel_type];
@ -233,9 +246,9 @@ BOOL class_isMetaClass(Class cls);
BOOL class_respondsToSelector(Class cls, SEL sel);
/**
* Runtime hook used to provide message redirections. If lookup fails but this
* function returns non-nil then the lookup will be retried with the returned
* value.
* Runtime hook used to provide message redirections with libobjc2.
* If lookup fails but this function returns non-nil then the lookup
* will be retried with the returned value.
*
* Note: Every message sent by this function MUST be understood by the
* receiver. If this is not the case then there is a potential for infinite
@ -246,6 +259,9 @@ static id gs_objc_proxy_lookup(id receiver, SEL op)
id cls = object_getClass(receiver);
BOOL resolved = NO;
/* Note that __GNU_LIBOBJC__ implements +resolveClassMethod: and
+resolveInstanceMethod: directly in the runtime instead. */
/* Let the class try to add a method for this thing. */
if (class_isMetaClass(cls))
{
@ -539,10 +555,17 @@ GSFFIInvocationCallback(ffi_cif *cif, void *retp, void **args, void *user)
}
sig = nil;
#ifdef __GNU_LIBOBJC__
if (gs_protocol_selector(sel_getType(selector)) == YES)
{
sig = [NSMethodSignature signatureWithObjCTypes: sel_getType(selector)];
}
#else
if (gs_protocol_selector(sel_getType_np(selector)) == YES)
{
sig = [NSMethodSignature signatureWithObjCTypes: sel_getType_np(selector)];
}
#endif
if (sig == nil)
{
sig = [obj methodSignatureForSelector: selector];
@ -555,13 +578,21 @@ GSFFIInvocationCallback(ffi_cif *cif, void *retp, void **args, void *user)
if (sig != nil)
{
const char *receiverTypes = [sig methodType];
#ifdef __GNU_LIBOBJC__
const char *runtimeTypes = sel_getType(selector);
#else
const char *runtimeTypes = sel_getType_np(selector);
#endif
if (runtimeTypes == 0 || strcmp(receiverTypes, runtimeTypes) != 0)
{
const char *runtimeName = sel_getName(selector);
#ifdef __GNU_LIBOBJC__
selector = sel_registerTypedName(runtimeName, receiverTypes);
#else
selector = sel_registerTypedName_np(runtimeName, receiverTypes);
#endif
if (runtimeTypes != 0)
{
/*
@ -583,11 +614,19 @@ GSFFIInvocationCallback(ffi_cif *cif, void *retp, void **args, void *user)
{
selector = gs_find_best_typed_sel (selector);
#ifdef __GNU_LIBOBJC__
if (sel_getType(selector) != 0)
{
sig = [NSMethodSignature signatureWithObjCTypes:
sel_getType(selector)];
}
#else
if (sel_getType_np(selector) != 0)
{
sig = [NSMethodSignature signatureWithObjCTypes:
sel_getType_np(selector)];
sel_getType_np(selector)];
}
#endif
}
if (sig == nil)

View file

@ -873,15 +873,16 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
handle = objc_open_main_module(stderr);
printf("%08x\n", handle);
#endif
#if NeXT_RUNTIME || defined(__GNUSTEP_RUNTIME__)
#if NeXT_RUNTIME || defined(__GNUSTEP_RUNTIME__) || defined(__GNU_LIBOBJC__)
{
int i, numClasses = 0, newNumClasses = objc_getClassList(NULL, 0);
Class *classes = NULL;
while (numClasses < newNumClasses) {
numClasses = newNumClasses;
classes = objc_realloc(classes, sizeof(Class) * numClasses);
newNumClasses = objc_getClassList(classes, numClasses);
}
while (numClasses < newNumClasses)
{
numClasses = newNumClasses;
classes = objc_realloc(classes, sizeof(Class) * numClasses);
newNumClasses = objc_getClassList(classes, numClasses);
}
for (i = 0; i < numClasses; i++)
{
[self _addFrameworkFromClass: classes[i]];

View file

@ -1991,7 +1991,11 @@ static NSLock *cached_proxies_gate = nil;
type = [[object methodSignatureForSelector: [inv selector]] methodType];
if (type)
{
#ifdef __GNU_LIBOBJC__
sel_registerTypedName(sel_getName([inv selector]), type);
#else
sel_registerTypedName_np(sel_getName([inv selector]), type);
#endif
}
}
NSParameterAssert(type);

View file

@ -1160,11 +1160,15 @@ failure:
if (lt)
{
#ifdef __GNU_LIBOBJC__
sel = sel_registerTypedName(name, types);
#else
sel = sel_registerTypedName_np(name, types);
#endif
}
else
{
sel = sel_registerTypedName_np(name, 0);
sel = sel_registerName(name);
}
if (sel == 0)
{
@ -2803,7 +2807,11 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
if (lt)
{
#ifdef __GNU_LIBOBJC__
sel = sel_registerTypedName(name, types);
#else
sel = sel_registerTypedName_np(name, types);
#endif
}
else
{

View file

@ -811,8 +811,13 @@ static NSDistributedNotificationCenter *netCenter = nil;
notification = [NSNotification notificationWithName: name
object: object
userInfo: userInfo];
#ifdef __GNU_LIBOBJC__
[recipient performSelector: sel_registerTypedName([aSelector cString], 0)
withObject: notification];
#else
[recipient performSelector: sel_registerTypedName_np([aSelector cString], 0)
withObject: notification];
#endif
}
@end

View file

@ -44,6 +44,10 @@
#include <objc/hooks.h>
#endif
#ifdef HAVE_SET_UNCAUGHT_EXCEPTION_HANDLER
#include <objc/objc-exception.h>
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
@ -802,12 +806,14 @@ callUncaughtHandler(id value)
}
NSLog(@"WARNING this copy of gnustep-base has been built with libbfd to provide symbolic stacktrace support. This means that the license of this copy of gnustep-base is GPL rather than the normal LGPL license (since libbfd is released under the GPL license). If this is not what you want, please obtain a copy of gnustep-base which was not configured with the --enable-bfd option");
#endif /* USE_BINUTILS */
#if defined(_NATIVE_OBJC_EXCEPTIONS)
#if defined(HAVE_UNEXPECTED)
#if defined(_NATIVE_OBJC_EXCEPTIONS)
# ifdef HAVE_SET_UNCAUGHT_EXCEPTION_HANDLER
objc_setUncaughtExceptionHandler(callUncaughtHandler);
# elif defined(HAVE_UNEXPECTED)
_objc_unexpected_exception = callUncaughtHandler;
#elif defined(HAVE_SET_UNEXPECTED)
# elif defined(HAVE_SET_UNEXPECTED)
objc_set_unexpected(callUncaughtHandler);
#endif
# endif
#endif
return;
}

View file

@ -28,7 +28,9 @@
*/
#import "common.h"
#ifndef __GNU_LIBOBJC__
#include <objc/encoding.h>
#endif
#define EXPOSE_NSMethodSignature_IVARS 1
#import "Foundation/NSMethodSignature.h"

View file

@ -1432,8 +1432,8 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
types = slot->types;
#else
struct objc_method *mth =
GSGetMethod(c, aSelector, GSObjCIsInstance(self), YES);
types = mth->method_types;
GSGetMethod(c, aSelector, GSObjCIsInstance(self), YES);
types = method_getTypeEncoding (mth);
#endif
}
@ -1469,16 +1469,8 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
*/
+ (void) poseAsClass: (Class)aClassObject
{
#ifdef __GNUSTEP_RUNTIME__
[NSException raise: NSInternalInconsistencyException
format: @"Class posing is not supported"];
#else
class_pose_as(self, aClassObject);
#endif
/*
* We may have replaced a class in the cache, or may have replaced one
* which had cached methods, so we must rebuild the cache.
*/
}
/**
@ -1990,7 +1982,6 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
*/
- (id) error: (const char *)aString, ...
{
#if !defined(NeXT_RUNTIME) && !defined(__GNUSTEP_RUNTIME__)
#define FMT "error: %s (%s)\n%s\n"
char fmt[(strlen((char*)FMT)+strlen((char*)GSClassNameFromObject(self))
+((aString!=NULL)?strlen((char*)aString):0)+8)];
@ -2000,11 +1991,10 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
GSObjCIsInstance(self)?"instance":"class",
(aString!=NULL)?aString:"");
va_start(ap, aString);
/* xxx What should `code' argument be? Current 0. */
objc_verror (self, 0, fmt, ap);
vfprintf (stderr, fmt, ap);
abort ();
va_end(ap);
#undef FMT
#endif
return nil;
}

View file

@ -88,6 +88,11 @@
#define PTHREAD_MIN_PRIORITY 0
#endif
#if !defined(__GNUSTEP_RUNTIME__) && !defined(NeXT_RUNTIME)
typedef void (*objc_thread_callback) (void);
objc_thread_callback objc_set_thread_callback (objc_thread_callback func);
#endif
extern NSTimeInterval GSTimeNow(void);
@interface NSAutoreleasePool (NSThread)

View file

@ -278,6 +278,7 @@ static NSLock *placeholderLock;
NSRange range;
range = NSMakeRange([[dict objectForKey: @"location"] intValue],
[[dict objectForKey: @"length"] intValue]);
return [abstractClass valueWithRange: range];
}
else if ([dict objectForKey: @"width"] && [dict objectForKey: @"x"])
{

View file

@ -31,7 +31,6 @@
#define __objc_load_h_INCLUDE
#include <stdio.h>
#include <objc/objc-api.h>
#include <Foundation/NSString.h>
#ifdef HAVE_DLADDR

View file

@ -22,23 +22,15 @@
Boston, MA 02111 USA.
*/
/*
CAVEATS:
- unloading modules not implemented
- would like to raise exceptions without having to turn this into
a .m file (right now NSBundle does this for us, ok?)
*/
/* PS: Unloading modules is not implemented. */
#import "common.h"
#include <stdio.h>
#include <objc/objc-api.h>
#if !defined(NeXT_RUNTIME) && !defined(__GNUSTEP_RUNTIME__)
# include <objc/objc-list.h>
#elif defined(NeXT_RUNTIME)
#if defined(NeXT_RUNTIME)
# include <objc/objc-load.h>
#endif
#ifdef __GNUSTEP_RUNTIME__
# include <objc/hooks.h>
#endif
@ -57,11 +49,6 @@ static BOOL dynamic_loaded;
/* Our current callback function */
static void (*_objc_load_load_callback)(Class, struct objc_category *) = 0;
/* List of modules we have loaded (by handle) */
#if !defined(NeXT_RUNTIME) && !defined(__GNUSTEP_RUNTIME__)
static struct objc_list *dynamic_handles = NULL;
#endif
/* Check to see if there are any undefined symbols. Print them out.
*/
static int
@ -190,10 +177,6 @@ GSPrivateLoadModule(NSString *filename, FILE *errorStream,
return 1;
}
#if !defined(NeXT_RUNTIME) && !defined(__GNUSTEP_RUNTIME__)
dynamic_handles = list_cons(handle, dynamic_handles);
#endif
/* If there are any undefined symbols, we can't load the bundle */
if (objc_check_undefineds(errorStream))
{
@ -228,7 +211,7 @@ GSPrivateLoadModule(NSString *filename, FILE *errorStream,
}
#endif /* not __ELF__ */
#ifndef __GNUSTEP_RUNTIME__
#if !defined(__GNUSTEP_RUNTIME__) && !defined(__GNU_LIBOBJC__)
__objc_resolve_class_links(); /* fill in subclass_list and sibling_class */
#endif
_objc_load_callback = 0;

View file

@ -0,0 +1,9 @@
#include "objc-common.g"
#include <objc/objc-exception.h>
int main (void)
{
objc_setUncaughtExceptionHandler (0);
return 0;
}

21
configure vendored
View file

@ -6568,6 +6568,27 @@ rm -f conftest*
#--------------------------------------------------------------------
# One of these is needed by for handling uncaught exceptions
#--------------------------------------------------------------------
{ $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
/* end confdefs.h. */
#include "$srcdir/config/config.setUncaughtExceptionHandler.m"
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
have_set_uncaught_exception_handler=yes
else
have_set_uncaught_exception_handler=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
if test $have_set_uncaught_exception_handler = yes; then
$as_echo "#define HAVE_SET_UNCAUGHT_EXCEPTION_HANDLER 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_set_uncaught_exception_handler" >&5
$as_echo "$have_set_uncaught_exception_handler" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for objc_set_unexpected() in runtime" >&5
$as_echo_n "checking for objc_set_unexpected() in runtime... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext

View file

@ -1624,6 +1624,15 @@ AC_EGREP_HEADER(objc_get_uninstalled_dtable, objc/objc-api.h,
#--------------------------------------------------------------------
# One of these is needed by for handling uncaught exceptions
#--------------------------------------------------------------------
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)
if test $have_set_uncaught_exception_handler = yes; then
AC_DEFINE(HAVE_SET_UNCAUGHT_EXCEPTION_HANDLER,1,
[Define if libobjc has the objc_setUncaughtExceptionHandler() function])
fi
AC_MSG_RESULT($have_set_uncaught_exception_handler)
AC_MSG_CHECKING(for objc_set_unexpected() in runtime)
AC_LINK_IFELSE([#include "$srcdir/config/config.set_unexpected.m"],
have_set_unexpected=yes, have_set_unexpected=no)