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:
Richard Frith-MacDonald 2009-01-12 18:36:37 +00:00
parent 952af9c197
commit b830b55dee
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>
* Source/NSIndexPath.m:

View file

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

View file

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

View file

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

View file

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

View file

@ -171,10 +171,13 @@ extern "C" {
Class isa;
}
#if OS_API_VERSION(GS_API_NONE, GS_API_NONE)
#if GS_WITH_GC
+ (BOOL) requiresTypedMemory;
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
/** On a system which performs garbage collection, you should implement
* this method to execute code when the receiver is collected.<br />
* You must not call this method yourself (except when a subclass
* calls the superclass method within its own implementation).
*/
- (void) finalize;
#endif
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
@ -364,18 +367,6 @@ GS_EXPORT NSRecursiveLock *gnustep_global_lock;
#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>
/**
* 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>
*/
@interface NSSocketPort : NSPort <GCFinalization>
@interface NSSocketPort : NSPort
{
NSRecursiveLock *myLock;
NSHost *host; /* OpenStep host for this port. */
@ -266,7 +266,7 @@ typedef SOCKET NSSocketNativeHandle;
* which can be used for interthread/interprocess communications
* on the same host, but not between different hosts.
*/
@interface NSMessagePort : NSPort <GCFinalization>
@interface NSMessagePort : NSPort
{
void *_internal;
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -92,6 +92,8 @@ static IMP autorelease_imp;
#include <gc.h>
#include <gc_typed.h>
static SEL finalize_sel;
static IMP finalize_imp;
#endif
static Class NSConstantStringClass;
@ -672,7 +674,7 @@ GSObjCZone(NSObject *object)
static void
GSFinalize(void* object, void* data)
{
[(id)object gcFinalize];
[(id)object finalize];
#ifndef NDEBUG
GSDebugAllocationRemove(((id)object)->class_pointer, (id)object);
#endif
@ -687,9 +689,16 @@ NSAllocateObject(Class aClass, unsigned extraBytes, NSZone *zone)
NSCAssert((CLS_ISCLASS(aClass)), @"Bad class for new object");
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())
{
new = NSZoneMalloc(zone, size);
new = NSZoneCalloc(zone, 1, size);
}
else
{
@ -697,25 +706,22 @@ NSAllocateObject(Class aClass, unsigned extraBytes, NSZone *zone)
if (gc_type == 0)
{
new = NSZoneMalloc(zone, size);
new = NSZoneCalloc(zone, 1, size);
NSLog(@"No garbage collection information for '%s'",
GSNameFromClass(aClass));
}
else if ([aClass requiresTypedMemory])
else
{
new = GC_calloc_explicitly_typed(1, size, gc_type);
}
else
{
new = NSZoneMalloc(zone, size);
}
}
if (new != nil)
{
memset(new, 0, size);
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
/*
@ -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
* time. If class has a superclass, its implementation of +initialize is
@ -1087,6 +1083,11 @@ GSDescriptionForClassMethod(pcl self, SEL aSel)
gnustep_base_socket_init();
#else
#if GS_WITH_GC
finalize_sel = @selector(finalize);
finalize_imp = get_imp(self, finalize_sel);
#endif
#ifdef SIGPIPE
/*
* If SIGPIPE is not handled or ignored, we will abort on any attempt
@ -1426,6 +1427,11 @@ GSDescriptionForClassMethod(pcl self, SEL aSel)
NSDeallocateObject (self);
}
- (void) finalize
{
return;
}
/**
* 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
* messages which are due to be sent to objects at a particular time.
*/
@interface GSTimedPerformer: NSObject <GCFinalization>
@interface GSTimedPerformer: NSObject
{
@public
SEL selector;
@ -168,7 +168,7 @@ static NSDate *theFuture = nil;
- (void) dealloc
{
[self gcFinalize];
[self finalize];
TEST_RELEASE(timer);
RELEASE(target);
RELEASE(argument);
@ -183,7 +183,7 @@ static NSDate *theFuture = nil;
removeObjectIdenticalTo: self];
}
- (void) gcFinalize
- (void) finalize
{
[self invalidate];
}
@ -755,11 +755,11 @@ static inline BOOL timerInvalidated(NSTimer *t)
- (void) dealloc
{
[self gcFinalize];
[self finalize];
[super dealloc];
}
- (void) gcFinalize
- (void) finalize
{
#ifdef HAVE_POLL_F
if (_extra != 0)

View file

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

View file

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