Change finalization to match MacOS-X

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27581 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2009-01-12 18:36:37 +00:00
parent d304d9ee34
commit f8441e1092
22 changed files with 116 additions and 95 deletions

View file

@ -1,3 +1,29 @@
2009-01-12 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSSocketPort.m:
* Source/NSRunLoop.m:
* Source/NSMessagePort.m:
* Source/NSNotificationCenter.m:
* Source/GSAttributedString.m:
* Source/NSObject.m:
* Source/Additions/GSLock.m:
* Source/NSConnection.m:
* Source/GSFileHandle.m:
* Source/NSLock.m:
* Source/NSDistantObject.m:
* Source/NSTask.m:
* SSL/GSSSLHandle.m:
* Documentation/Base.ispell:
* Headers/Foundation/NSObject.h:
* Headers/Foundation/NSNotification.h:
* Headers/Foundation/NSRunLoop.h:
* Headers/Foundation/NSPort.h:
* Headers/Foundation/NSLock.h:
* Headers/Foundation/NSTask.h:
* Headers/Additions/GNUstepBase/GSFileHandle.h:
Change GC finalization API to match MacOS-X ... abandon libFoundation
compatibility in GC behavior.
2009-01-12 Richard Frith-Macdonald <rfm@gnu.org> 2009-01-12 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSIndexPath.m: * Source/NSIndexPath.m:

View file

@ -837,8 +837,6 @@ ftp
func func
functionName functionName
gcc gcc
GCFinalization
gcFinalize
gcontext gcontext
gdnc gdnc
GDNCHost GDNCHost

View file

@ -36,7 +36,7 @@
#include <zlib.h> #include <zlib.h>
#endif #endif
@interface GSFileHandle : NSFileHandle <RunLoopEvents, GCFinalization> @interface GSFileHandle : NSFileHandle <RunLoopEvents>
{ {
int descriptor; int descriptor;
BOOL closeOnDealloc; BOOL closeOnDealloc;

View file

@ -59,7 +59,7 @@ extern "C" {
/** /**
* Simplest lock for protecting critical sections of code. * Simplest lock for protecting critical sections of code.
*/ */
@interface NSLock : NSObject <NSLocking, GCFinalization> @interface NSLock : NSObject <NSLocking>
{ {
@private @private
void *_mutex; void *_mutex;
@ -103,7 +103,7 @@ extern "C" {
* condition is equal to a particular value. The condition is set on * condition is equal to a particular value. The condition is set on
* initialization and whenever the lock is relinquished. * initialization and whenever the lock is relinquished.
*/ */
@interface NSConditionLock : NSObject <NSLocking, GCFinalization> @interface NSConditionLock : NSObject <NSLocking>
{ {
@private @private
void *_condition; void *_condition;
@ -195,7 +195,7 @@ extern "C" {
* thread must also unlock it (n) times before another thread * thread must also unlock it (n) times before another thread
* can acquire the lock. * can acquire the lock.
*/ */
@interface NSRecursiveLock : NSObject <NSLocking, GCFinalization> @interface NSRecursiveLock : NSObject <NSLocking>
{ {
@private @private
void *_mutex; void *_mutex;

View file

@ -63,7 +63,7 @@ extern "C" {
@interface NSNotificationCenter : NSObject <GCFinalization> @interface NSNotificationCenter : NSObject
{ {
void *_table; void *_table;
} }

View file

@ -171,10 +171,13 @@ extern "C" {
Class isa; Class isa;
} }
#if OS_API_VERSION(GS_API_NONE, GS_API_NONE) #if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
#if GS_WITH_GC /** On a system which performs garbage collection, you should implement
+ (BOOL) requiresTypedMemory; * this method to execute code when the receiver is collected.<br />
#endif * You must not call this method yourself (except when a subclass
* calls the superclass method within its own implementation).
*/
- (void) finalize;
#endif #endif
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
@ -364,18 +367,6 @@ GS_EXPORT NSRecursiveLock *gnustep_global_lock;
#endif #endif
/**
* Protocol for garbage collection finalization - same as libFoundation
* for compatibility.
*/
@protocol GCFinalization
/**
* Called before receiver is deallocated by garbage collector. If you want
* to do anything special before [NSObject -dealloc] is called, do it here.
*/
- (void) gcFinalize;
@end
#import <Foundation/NSDate.h> #import <Foundation/NSDate.h>
/** /**
* Declares some methods for sending messages to self after a fixed delay. * Declares some methods for sending messages to self after a fixed delay.

View file

@ -195,7 +195,7 @@ typedef SOCKET NSSocketNativeHandle;
* *
* <p>Note that this class is incompatible with the latest OS X version.</p> * <p>Note that this class is incompatible with the latest OS X version.</p>
*/ */
@interface NSSocketPort : NSPort <GCFinalization> @interface NSSocketPort : NSPort
{ {
NSRecursiveLock *myLock; NSRecursiveLock *myLock;
NSHost *host; /* OpenStep host for this port. */ NSHost *host; /* OpenStep host for this port. */
@ -266,7 +266,7 @@ typedef SOCKET NSSocketNativeHandle;
* which can be used for interthread/interprocess communications * which can be used for interthread/interprocess communications
* on the same host, but not between different hosts. * on the same host, but not between different hosts.
*/ */
@interface NSMessagePort : NSPort <GCFinalization> @interface NSMessagePort : NSPort
{ {
void *_internal; void *_internal;
} }

View file

@ -41,7 +41,7 @@ extern "C" {
*/ */
GS_EXPORT NSString * const NSDefaultRunLoopMode; GS_EXPORT NSString * const NSDefaultRunLoopMode;
@interface NSRunLoop : NSObject <GCFinalization> @interface NSRunLoop : NSObject
{ {
@private @private
NSString *_currentMode; NSString *_currentMode;

View file

@ -36,7 +36,7 @@
extern "C" { extern "C" {
#endif #endif
@interface NSTask : NSObject <GCFinalization> @interface NSTask : NSObject
{ {
NSString *_currentDirectoryPath; NSString *_currentDirectoryPath;
NSString *_launchPath; NSString *_launchPath;

View file

@ -107,7 +107,7 @@ sslError(int err)
} }
@interface GSSSLHandle : GSFileHandle <GCFinalization> @interface GSSSLHandle : GSFileHandle
{ {
SSL_CTX *ctx; SSL_CTX *ctx;
SSL *ssl; SSL *ssl;
@ -149,10 +149,10 @@ sslError(int err)
[super closeFile]; [super closeFile];
} }
- (void) gcFinalize - (void) finalize
{ {
[self sslDisconnect]; [self sslDisconnect];
[super gcFinalize]; [super finalize];
} }
- (int) read: (void*)buf length: (int)len - (int) read: (void*)buf length: (int)len

View file

@ -75,14 +75,14 @@
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
[super dealloc]; [super dealloc];
} }
- (void) gcFinalize - (void) finalize
{ {
[[NSNotificationCenter defaultCenter] removeObserver: self]; [[NSNotificationCenter defaultCenter] removeObserver: self];
[super gcFinalize]; [super finalize];
} }
- (id) init - (id) init
@ -226,14 +226,14 @@
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
[super dealloc]; [super dealloc];
} }
- (void) gcFinalize - (void) finalize
{ {
[[NSNotificationCenter defaultCenter] removeObserver: self]; [[NSNotificationCenter defaultCenter] removeObserver: self];
[super gcFinalize]; [super finalize];
} }
- (id) init - (id) init

View file

@ -173,7 +173,7 @@ unCacheAttributes(NSDictionary *attrs)
@interface GSAttrInfo : NSObject <GCFinalization> @interface GSAttrInfo : NSObject
{ {
@public @public
unsigned loc; unsigned loc;
@ -202,7 +202,7 @@ unCacheAttributes(NSDictionary *attrs)
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
NSDeallocateObject(self); NSDeallocateObject(self);
GSNOSUPERDEALLOC; GSNOSUPERDEALLOC;
} }
@ -219,7 +219,7 @@ unCacheAttributes(NSDictionary *attrs)
[aCoder encodeValueOfObjCType: @encode(id) at: &attrs]; [aCoder encodeValueOfObjCType: @encode(id) at: &attrs];
} }
- (void) gcFinalize - (void) finalize
{ {
unCacheAttributes(attrs); unCacheAttributes(attrs);
DESTROY(attrs); DESTROY(attrs);

View file

@ -249,14 +249,14 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
RELEASE(service); RELEASE(service);
RELEASE(protocol); RELEASE(protocol);
[self gcFinalize]; [self finalize];
RELEASE(readInfo); RELEASE(readInfo);
RELEASE(writeInfo); RELEASE(writeInfo);
[super dealloc]; [super dealloc];
} }
- (void) gcFinalize - (void) finalize
{ {
if (self == fh_stdin) if (self == fh_stdin)
fh_stdin = nil; fh_stdin = nil;

View file

@ -111,8 +111,8 @@ GSRunLoopForThread(NSThread *aThread)
- (NSMutableArray*) _components; - (NSMutableArray*) _components;
@end @end
@interface NSConnection (GNUstepExtensions) <GCFinalization> @interface NSConnection (GNUstepExtensions)
- (void) gcFinalize; - (void) finalize;
- (retval_t) forwardForProxy: (NSDistantObject*)object - (retval_t) forwardForProxy: (NSDistantObject*)object
selector: (SEL)sel selector: (SEL)sel
argFrame: (arglist_t)argframe; argFrame: (arglist_t)argframe;
@ -766,7 +766,7 @@ static NSLock *cached_proxies_gate = nil;
{ {
if (debug_connection) if (debug_connection)
NSLog(@"deallocating %@", self); NSLog(@"deallocating %@", self);
[self gcFinalize]; [self finalize];
[super dealloc]; [super dealloc];
} }
@ -1742,7 +1742,7 @@ static NSLock *cached_proxies_gate = nil;
return conn; return conn;
} }
- (void) gcFinalize - (void) finalize
{ {
CREATE_AUTORELEASE_POOL(arp); CREATE_AUTORELEASE_POOL(arp);

View file

@ -40,11 +40,11 @@
#include <objc/Protocol.h> #include <objc/Protocol.h>
@interface NSDistantObject(GNUstepExtensions) <GCFinalization> @interface NSDistantObject(GNUstepExtensions)
- (Class) classForPortCoder; - (Class) classForPortCoder;
- (const char *) selectorTypeForProxy: (SEL)selector; - (const char *) selectorTypeForProxy: (SEL)selector;
- (id) forward: (SEL)aSel :(arglist_t)frame; - (id) forward: (SEL)aSel :(arglist_t)frame;
- (void) gcFinalize; - (void) finalize;
@end @end
#define DO_FORWARD_INVOCATION(_SELX, _ARG1) ({ \ #define DO_FORWARD_INVOCATION(_SELX, _ARG1) ({ \
@ -446,7 +446,7 @@ enum proxyLocation
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
[super dealloc]; [super dealloc];
} }
@ -825,7 +825,7 @@ enum proxyLocation
/** /**
* Used by the garbage collection system to tidy up when a proxy is destroyed. * Used by the garbage collection system to tidy up when a proxy is destroyed.
*/ */
- (void) gcFinalize - (void) finalize
{ {
if (_connection) if (_connection)
{ {

View file

@ -163,7 +163,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
[super dealloc]; [super dealloc];
} }
@ -175,7 +175,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
[super description], _name]; [super description], _name];
} }
- (void) gcFinalize - (void) finalize
{ {
if (_mutex != 0) if (_mutex != 0)
{ {
@ -321,7 +321,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
[super dealloc]; [super dealloc];
} }
@ -333,7 +333,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
[super description], _name]; [super description], _name];
} }
- (void) gcFinalize - (void) finalize
{ {
if (_condition != 0) if (_condition != 0)
{ {
@ -642,7 +642,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
[super dealloc]; [super dealloc];
} }
@ -654,7 +654,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
[super description], _name]; [super description], _name];
} }
- (void) gcFinalize - (void) finalize
{ {
if (_mutex != 0) if (_mutex != 0)
{ {

View file

@ -230,7 +230,7 @@ typedef enum {
GS_H_CONNECTED // Currently connected. GS_H_CONNECTED // Currently connected.
} GSHandleState; } GSHandleState;
@interface GSMessageHandle : NSObject <GCFinalization, RunLoopEvents> @interface GSMessageHandle : NSObject <RunLoopEvents>
{ {
int desc; /* File descriptor for I/O. */ int desc; /* File descriptor for I/O. */
unsigned wItem; /* Index of item being written. */ unsigned wItem; /* Index of item being written. */
@ -459,7 +459,7 @@ static Class runLoopClass;
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
DESTROY(rData); DESTROY(rData);
DESTROY(rItems); DESTROY(rItems);
DESTROY(wMsgs); DESTROY(wMsgs);
@ -478,7 +478,7 @@ static Class runLoopClass;
return desc; return desc;
} }
- (void) gcFinalize - (void) finalize
{ {
[self invalidate]; [self invalidate];
(void)close(desc); (void)close(desc);
@ -1368,7 +1368,7 @@ typedef struct {
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
[super dealloc]; [super dealloc];
} }
@ -1381,7 +1381,7 @@ typedef struct {
return desc; return desc;
} }
- (void) gcFinalize - (void) finalize
{ {
NSDebugMLLog(@"NSMessagePort", @"NSMessagePort 0x%x finalized", self); NSDebugMLLog(@"NSMessagePort", @"NSMessagePort 0x%x finalized", self);
[self invalidate]; [self invalidate];

View file

@ -607,12 +607,12 @@ static NSNotificationCenter *default_center = nil;
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
[super dealloc]; [super dealloc];
} }
- (void) gcFinalize - (void) finalize
{ {
if (self == default_center) if (self == default_center)
{ {

View file

@ -92,6 +92,8 @@ static IMP autorelease_imp;
#include <gc.h> #include <gc.h>
#include <gc_typed.h> #include <gc_typed.h>
static SEL finalize_sel;
static IMP finalize_imp;
#endif #endif
static Class NSConstantStringClass; static Class NSConstantStringClass;
@ -672,7 +674,7 @@ GSObjCZone(NSObject *object)
static void static void
GSFinalize(void* object, void* data) GSFinalize(void* object, void* data)
{ {
[(id)object gcFinalize]; [(id)object finalize];
#ifndef NDEBUG #ifndef NDEBUG
GSDebugAllocationRemove(((id)object)->class_pointer, (id)object); GSDebugAllocationRemove(((id)object)->class_pointer, (id)object);
#endif #endif
@ -687,9 +689,16 @@ NSAllocateObject(Class aClass, unsigned extraBytes, NSZone *zone)
NSCAssert((CLS_ISCLASS(aClass)), @"Bad class for new object"); NSCAssert((CLS_ISCLASS(aClass)), @"Bad class for new object");
size = aClass->instance_size + extraBytes; size = aClass->instance_size + extraBytes;
if (size % sizeof(void*) != 0)
{
/* Size must be a multiple of pointer size for the garbage collector
* to be able to allocate explicitly typed memory.
*/
size += sizeof(void*) - size % sizeof(void*);
}
if (zone == GSAtomicMallocZone()) if (zone == GSAtomicMallocZone())
{ {
new = NSZoneMalloc(zone, size); new = NSZoneCalloc(zone, 1, size);
} }
else else
{ {
@ -697,25 +706,22 @@ NSAllocateObject(Class aClass, unsigned extraBytes, NSZone *zone)
if (gc_type == 0) if (gc_type == 0)
{ {
new = NSZoneMalloc(zone, size); new = NSZoneCalloc(zone, 1, size);
NSLog(@"No garbage collection information for '%s'", NSLog(@"No garbage collection information for '%s'",
GSNameFromClass(aClass)); GSNameFromClass(aClass));
} }
else if ([aClass requiresTypedMemory]) else
{ {
new = GC_calloc_explicitly_typed(1, size, gc_type); new = GC_calloc_explicitly_typed(1, size, gc_type);
} }
else
{
new = NSZoneMalloc(zone, size);
}
} }
if (new != nil) if (new != nil)
{ {
memset(new, 0, size); memset(new, 0, size);
new->class_pointer = aClass; new->class_pointer = aClass;
if (__objc_responds_to(new, @selector(gcFinalize))) if (get_imp(aClass, finalize_sel) != finalize_imp
&& __objc_responds_to(new, finalize_sel))
{ {
#ifndef NDEBUG #ifndef NDEBUG
/* /*
@ -1060,16 +1066,6 @@ GSDescriptionForClassMethod(pcl self, SEL aSel)
} }
} }
#if GS_WITH_GC
/**
* A utility method used when garbage collection is enabled. Can be ignored.
*/
+ (BOOL) requiresTypedMemory
{
return NO;
}
#endif
/** /**
* This message is sent to a class once just before it is used for the first * This message is sent to a class once just before it is used for the first
* time. If class has a superclass, its implementation of +initialize is * time. If class has a superclass, its implementation of +initialize is
@ -1087,6 +1083,11 @@ GSDescriptionForClassMethod(pcl self, SEL aSel)
gnustep_base_socket_init(); gnustep_base_socket_init();
#else #else
#if GS_WITH_GC
finalize_sel = @selector(finalize);
finalize_imp = get_imp(self, finalize_sel);
#endif
#ifdef SIGPIPE #ifdef SIGPIPE
/* /*
* If SIGPIPE is not handled or ignored, we will abort on any attempt * If SIGPIPE is not handled or ignored, we will abort on any attempt
@ -1426,6 +1427,11 @@ GSDescriptionForClassMethod(pcl self, SEL aSel)
NSDeallocateObject (self); NSDeallocateObject (self);
} }
- (void) finalize
{
return;
}
/** /**
* This method is an anachronism. Do not use it. * This method is an anachronism. Do not use it.
*/ */

View file

@ -147,7 +147,7 @@ static NSDate *theFuture = nil;
* The GSTimedPerformer class is used to hold information about * The GSTimedPerformer class is used to hold information about
* messages which are due to be sent to objects at a particular time. * messages which are due to be sent to objects at a particular time.
*/ */
@interface GSTimedPerformer: NSObject <GCFinalization> @interface GSTimedPerformer: NSObject
{ {
@public @public
SEL selector; SEL selector;
@ -168,7 +168,7 @@ static NSDate *theFuture = nil;
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
TEST_RELEASE(timer); TEST_RELEASE(timer);
RELEASE(target); RELEASE(target);
RELEASE(argument); RELEASE(argument);
@ -183,7 +183,7 @@ static NSDate *theFuture = nil;
removeObjectIdenticalTo: self]; removeObjectIdenticalTo: self];
} }
- (void) gcFinalize - (void) finalize
{ {
[self invalidate]; [self invalidate];
} }
@ -755,11 +755,11 @@ static inline BOOL timerInvalidated(NSTimer *t)
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
[super dealloc]; [super dealloc];
} }
- (void) gcFinalize - (void) finalize
{ {
#ifdef HAVE_POLL_F #ifdef HAVE_POLL_F
if (_extra != 0) if (_extra != 0)

View file

@ -188,7 +188,7 @@ typedef enum {
GS_H_CONNECTED // Currently connected. GS_H_CONNECTED // Currently connected.
} GSHandleState; } GSHandleState;
@interface GSTcpHandle : NSObject <GCFinalization, RunLoopEvents> @interface GSTcpHandle : NSObject <RunLoopEvents>
{ {
SOCKET desc; /* File descriptor for I/O. */ SOCKET desc; /* File descriptor for I/O. */
unsigned wItem; /* Index of item being written. */ unsigned wItem; /* Index of item being written. */
@ -676,7 +676,7 @@ static Class runLoopClass;
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
DESTROY(defaultAddress); DESTROY(defaultAddress);
DESTROY(rData); DESTROY(rData);
DESTROY(rItems); DESTROY(rItems);
@ -703,7 +703,7 @@ static Class runLoopClass;
} }
#endif #endif
- (void) gcFinalize - (void) finalize
{ {
[self invalidate]; [self invalidate];
(void)close(desc); (void)close(desc);
@ -1797,7 +1797,7 @@ static Class tcpPortClass;
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
[super dealloc]; [super dealloc];
} }
@ -1819,7 +1819,7 @@ static Class tcpPortClass;
return desc; return desc;
} }
- (void) gcFinalize - (void) finalize
{ {
NSDebugMLLog(@"NSPort", @"NSSocketPort 0x%x finalized", self); NSDebugMLLog(@"NSPort", @"NSSocketPort 0x%x finalized", self);
[self invalidate]; [self invalidate];

View file

@ -285,7 +285,7 @@ pty_slave(const char* name)
return AUTORELEASE(task); return AUTORELEASE(task);
} }
- (void) gcFinalize - (void) finalize
{ {
[tasksLock lock]; [tasksLock lock];
NSMapRemove(activeTasks, (void*)(intptr_t)_taskId); NSMapRemove(activeTasks, (void*)(intptr_t)_taskId);
@ -294,7 +294,7 @@ pty_slave(const char* name)
- (void) dealloc - (void) dealloc
{ {
[self gcFinalize]; [self finalize];
RELEASE(_arguments); RELEASE(_arguments);
RELEASE(_environment); RELEASE(_environment);
RELEASE(_launchPath); RELEASE(_launchPath);
@ -954,9 +954,9 @@ GSPrivateCheckTasks()
return found; return found;
} }
- (void) gcFinalize - (void) finalize
{ {
[super gcFinalize]; [super finalize];
if (wThread != NULL) if (wThread != NULL)
{ {
CloseHandle(wThread); CloseHandle(wThread);