From aa0e1c23756600a1610d1f229848653d0666d7ee Mon Sep 17 00:00:00 2001 From: fedor Date: Fri, 12 Sep 1997 17:54:10 +0000 Subject: [PATCH] DO patches (Sep 12 from Richard Frith-MacDonald) git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2419 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 42 +++++++++++++- NSBundle.README | 2 +- Source/NSAttributedString.m | 9 +++ Source/NSDistantObject.m | 6 +- Source/NSGAttributedString.m | 18 ++++++ Source/NSGCString.m | 9 +++ Source/NSGString.m | 10 ++++ Source/NSHData.m | 9 +++ Source/NSProxy.m | 4 ++ Source/NSRunLoop.m | 107 ++++++++++++++++++----------------- Source/NSString.m | 11 ++++ 11 files changed, 168 insertions(+), 59 deletions(-) diff --git a/ChangeLog b/ChangeLog index d27f1e341..01175869a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,40 @@ +Fri Sep 12 12:27:00 1997 Richard Frith-Macdonald + + * src/NSString.m: Added [-classForPortCoder:]) method for + NXConstantString to prevent minor DO memory leak. + +Fri Sep 12 6:15:00 1997 Richard Frith-Macdonald + + * src/NSAttributedString.m: Added the [-classForPortCoder:] and + [-replacementObjectForPortCoder:] methods to ensure that strings + are always sent over DO bycopy. + + * src/NSDistantObject.m: Fixed the types of the parameters to a few + methods to avoid compiler warnings. + + * src/NSGAttributedString.m: Added the [-classForPortCoder:] and + [-replacementObjectForPortCoder:] methods to ensure that strings + are always sent over DO bycopy. + + * src/NSGCString.m: Added the [-classForPortCoder:] and + [-replacementObjectForPortCoder:] methods to ensure that strings + are always sent over DO bycopy. + + * src/NSGString.m: Added the [-classForPortCoder:] and + [-replacementObjectForPortCoder:] methods to ensure that strings + are always sent over DO bycopy. + + * src/NSHData.m: Added the [-classForPortCoder:] and + [-replacementObjectForPortCoder:] methods to ensure that data + objects are always sent over DO bycopy. + + * src/NSProxy.m: Commented out a couple of methods whose OPENSTEP + style implementation was incomplete so that the old (working) + GNUstep implementation is used. + + * src/NSRunLoop.m: Moved some code around to fix problems with + earlier patch being applied in wrong place. + Wed Sep 10 18:03:22 1997 Scott Christley * config.guess: Update. @@ -27,8 +64,9 @@ Tue Sep 9 10:15:00 1997 Richard Frith-Macdonald * src/TcpPort.m: Fixed a minor retain/release problem. * src/UnixFileHandle.m: Added loads of checks so that attempts to - use a file handle which has been closed will fail/generate an exception - rather than crashing things! Also modified for changes to NSRunLoop. + use a file handle which has been closed will fail/generate an + exception rather than crashing things! Also modified for changes + to NSRunLoop. * src/include/NSRunLoop.h: Modified the interface for adding watchers for events with a count of the number of times they have been added. diff --git a/NSBundle.README b/NSBundle.README index 710e15f8c..58e8cc567 100644 --- a/NSBundle.README +++ b/NSBundle.README @@ -71,4 +71,4 @@ set-up correctly, or that the GNUstep Base Library did not link in the correct header file to use dynamic linking. Diagnosing and fixing these problems is not trivial and requires some knowledge of dynamic linking, object file formats and the Objective-C runtime. Contact Adam -Fedor for help. +Fedor for help. diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index d46078a74..83a74d738 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -102,6 +102,15 @@ static Class NSMutableAttributedString_concrete_class; return [super initWithCoder:aDecoder]; } +- (Class) classForPortCoder: (NSPortCoder*)aCoder +{ + return [self class]; +} +- replacementObjectForPortCoder:(NSPortCoder*)aCoder +{ + return self; +} + //NSCopying protocol - copyWithZone: (NSZone*)zone { diff --git a/Source/NSDistantObject.m b/Source/NSDistantObject.m index 34bf581f9..f5958f5a0 100644 --- a/Source/NSDistantObject.m +++ b/Source/NSDistantObject.m @@ -570,17 +570,17 @@ format: @"NSDistantObject objects only encode with PortEncoder class"]; argFrame: frame]; } -- classForCoder: aRmc; +- classForCoder: (NSCoder*)aCoder; { return object_get_class (self); } -- classForPortCoder: aRmc +- classForPortCoder: (NSPortCoder*)aCoder { return object_get_class (self); } -- replacementObjectForCoder:(NSPortCoder*)aCoder +- replacementObjectForCoder:(NSCoder*)aCoder { return self; } diff --git a/Source/NSGAttributedString.m b/Source/NSGAttributedString.m index 319b33839..798989541 100644 --- a/Source/NSGAttributedString.m +++ b/Source/NSGAttributedString.m @@ -139,6 +139,15 @@ NSDictionary *_attributesAtIndexEffectiveRange( return nil; } +- (Class) classForPortCoder: (NSPortCoder*)aCoder +{ + return [self class]; +} +- replacementObjectForPortCoder:(NSPortCoder*)aCoder +{ + return self; +} + - (void) encodeWithCoder: aCoder { [super encodeWithCoder:aCoder]; @@ -194,6 +203,15 @@ NSDictionary *_attributesAtIndexEffectiveRange( @implementation NSGMutableAttributedString +- (Class) classForPortCoder: (NSPortCoder*)aCoder +{ + return [self class]; +} +- replacementObjectForPortCoder:(NSPortCoder*)aCoder +{ + return self; +} + - (void) encodeWithCoder: aCoder { [super encodeWithCoder:aCoder]; diff --git a/Source/NSGCString.m b/Source/NSGCString.m index d6c934772..e05bb07c9 100644 --- a/Source/NSGCString.m +++ b/Source/NSGCString.m @@ -83,6 +83,15 @@ return [self class]; } +- (Class) classForPortCoder: (NSPortCoder*)aCoder +{ + return [self class]; +} +- replacementObjectForPortCoder:(NSPortCoder*)aCoder +{ + return self; +} + - (void) encodeWithCoder: aCoder { [aCoder encodeValueOfObjCType:@encode(char*) at:&_contents_chars diff --git a/Source/NSGString.m b/Source/NSGString.m index 09acd42f4..556ea9633 100644 --- a/Source/NSGString.m +++ b/Source/NSGString.m @@ -225,6 +225,16 @@ return [self class]; } +- (Class) classForPortCoder: (NSPortCoder*)aCoder +{ + return [self class]; +} +- replacementObjectForPortCoder:(NSPortCoder*)aCoder +{ + return self; +} + + // FOR IndexedCollection SUPPORT; - objectAtIndex: (unsigned)index diff --git a/Source/NSHData.m b/Source/NSHData.m index ed56560c9..40a141f76 100644 --- a/Source/NSHData.m +++ b/Source/NSHData.m @@ -188,6 +188,11 @@ static void unchar_func(void *s, int c) return (const void*)buffer; } +- classForPortCoder: (NSPortCoder*)aCoder +{ + return object_get_class (self); +} + - (id) copyWithZone: (NSZone*)zone { NSHData* obj = [[NSHData class] allocWithZone:zone]; @@ -1040,6 +1045,10 @@ static void unchar_func(void *s, int c) autorelease]; } +- replacementObjectForPortCoder:(NSPortCoder*)aCoder +{ + return self; +} - (void) rewindStream { diff --git a/Source/NSProxy.m b/Source/NSProxy.m index e3768d1f8..7060f9681 100644 --- a/Source/NSProxy.m +++ b/Source/NSProxy.m @@ -91,6 +91,7 @@ return object_get_class(self); } +#if 0 - (BOOL) conformsToProtocol: (Protocol*)aProtocol { NSInvocation* inv; @@ -105,6 +106,7 @@ [inv getReturnValue: &result]; return result; } +#endif - (void) dealloc { @@ -220,6 +222,7 @@ } } +#if 0 - (BOOL) respondsToSelector: (SEL)aSelector { NSInvocation* inv; @@ -234,6 +237,7 @@ [inv getReturnValue: &result]; return result; } +#endif - retain { diff --git a/Source/NSRunLoop.m b/Source/NSRunLoop.m index 5913638bc..e7eadd563 100644 --- a/Source/NSRunLoop.m +++ b/Source/NSRunLoop.m @@ -830,6 +830,60 @@ static int debug_run_loop = 0; return when; } +- (RunLoopWatcher*) _getWatcher: (void*)data + type: (RunLoopEventType)type + forMode: (NSString*)mode +{ + NSArray *watchers; + RunLoopWatcher *info; + int count; + + if (mode == nil) + mode = _current_mode; + + watchers = NSMapGet (_mode_2_watchers, mode); + if (watchers == nil) { + return nil; + } + for (count = 0; count < [watchers count]; count++) { + info = [watchers objectAtIndex: count]; + + if ([info getType] == type) { + if ([info getData] == data) { + return info; + } + } + } + return nil; +} + +- (void) _removeWatcher: (void*)data + type: (RunLoopEventType)type + forMode: (NSString*)mode +{ + NSMutableArray *watchers; + + if (mode == nil ) + mode = _current_mode; + + watchers = NSMapGet (_mode_2_watchers, mode); + if (watchers) { + int i; + + for (i = [watchers count]; i > 0; i--) { + RunLoopWatcher* info; + + info = (RunLoopWatcher*)[watchers objectAtIndex:(i-1)]; + if ([info getType] == type && [info getData] == data) { + [info invalidate]; + [watchers removeObject: info]; + } + } + } +} + + + /* Listen to input sources. If LIMIT_DATE is nil, then don't wait; i.e. call select() with 0 timeout */ @@ -909,59 +963,6 @@ static int debug_run_loop = 0; wfd_2_object = NSCreateMapTable (NSIntMapKeyCallBacks, NSObjectMapValueCallBacks, 0); -- (RunLoopWatcher*) _getWatcher: (void*)data - type: (RunLoopEventType)type - forMode: (NSString*)mode -{ - NSArray *watchers; - RunLoopWatcher *info; - int count; - - if (mode == nil) - mode = _current_mode; - - watchers = NSMapGet (_mode_2_watchers, mode); - if (watchers == nil) { - return nil; - } - for (count = 0; count < [watchers count]; count++) { - info = [watchers objectAtIndex: count]; - - if ([info getType] == type) { - if ([info getData] == data) { - return info; - } - } - } - return nil; -} - -- (void) _removeWatcher: (void*)data - type: (RunLoopEventType)type - forMode: (NSString*)mode -{ - NSMutableArray *watchers; - - if (mode == nil ) - mode = _current_mode; - - watchers = NSMapGet (_mode_2_watchers, mode); - if (watchers) { - int i; - - for (i = [watchers count]; i > 0; i--) { - RunLoopWatcher* info; - - info = (RunLoopWatcher*)[watchers objectAtIndex:(i-1)]; - if ([info getType] == type && [info getData] == data) { - [info invalidate]; - [watchers removeObject: info]; - } - } - } -} - - /* Do the pre-listening set-up for the file descriptors of this mode. */ { NSArray *watchers; diff --git a/Source/NSString.m b/Source/NSString.m index 1d58c53aa..711a359f5 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -2326,6 +2326,17 @@ else @implementation NXConstantString +/* + * NXConstantString overrides [-dealloc] so that it is never deallocated. + * If we pass an NXConstantString to another process it will never get + * deallocated in the other process - causing a memory leak. So we tell + * the DO system to use the super class instead. + */ +- (Class)classForPortCoder: (NSPortCoder*)aCoder +{ + return [self superclass]; +} + - (void)dealloc { }