* Source/Additions/GCArray.m: Replace retain/release by

RETAIN/RELEASE macros.
* Source/Additions/GCDictionary.m: Idem.
* Source/Additions/GSCompatibility.h: Add NSBundle category.
* Source/Additions/GSCompatibility.m (GSEncodingName): New.
Add -[NSBundle pathForGNUstepResource:ofType:inDirectory:].
* Source/Additions/GSObjCRuntime.m: Include GNUstep.h.
(GSObjCMethodNames): Cast method_name to const char *.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@16309 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fedor 2003-04-01 04:27:18 +00:00
parent 0b307df52b
commit 8017719129
6 changed files with 86 additions and 20 deletions

View file

@ -1,3 +1,16 @@
2003-03-31 Stephane Corthesy <stephane@sente.ch>
* Source/Additions/GCArray.m: Replace retain/release by
RETAIN/RELEASE macros.
* Source/Additions/GCDictionary.m: Idem.
* Source/Additions/GSCompatibility.h: Add NSBundle category.
* Source/Additions/GSCompatibility.m (GSEncodingName): New.
Add -[NSBundle pathForGNUstepResource:ofType:inDirectory:].
* Source/Additions/GSObjCRuntime.m: Include GNUstep.h.
(GSObjCMethodNames): Cast method_name to const char *.
2003-03-31 Adam Fedor <fedor@gnu.org> 2003-03-31 Adam Fedor <fedor@gnu.org>
* Headers/gnustep/base/Foundation.h: Add GSCategories.h * Headers/gnustep/base/Foundation.h: Add GSCategories.h

View file

@ -35,6 +35,7 @@
#include <gnustep/base/GSObjCRuntime.h> #include <gnustep/base/GSObjCRuntime.h>
#include <gnustep/base/GCObject.h> #include <gnustep/base/GCObject.h>
#include <gnustep/base/GNUstep.h>
@implementation GCArray @implementation GCArray
@ -79,7 +80,7 @@ static Class gcClass = 0;
{ {
if (_isGCObject[c] == NO) if (_isGCObject[c] == NO)
{ {
[_contents[c] release]; DESTROY(_contents[c]);
} }
} }
} }
@ -87,7 +88,7 @@ static Class gcClass = 0;
{ {
while (c-- > 0) while (c-- > 0)
{ {
[_contents[c] release]; DESTROY(_contents[c]);
} }
} }
@ -139,7 +140,7 @@ static Class gcClass = 0;
_count = 0; _count = 0;
while (_count < count) while (_count < count)
{ {
_contents[_count] = [objects[_count] retain]; _contents[_count] = RETAIN(objects[_count]);
if (_contents[_count] == nil) if (_contents[_count] == nil)
{ {
[self release]; [self release];
@ -164,7 +165,7 @@ static Class gcClass = 0;
_count = 0; _count = 0;
while (_count < count) while (_count < count)
{ {
_contents[_count] = [[anotherArray objectAtIndex: _count] retain]; _contents[_count] = RETAIN([anotherArray objectAtIndex: _count]);
_isGCObject[_count] = [_contents[_count] isKindOfClass: gcClass]; _isGCObject[_count] = [_contents[_count] isKindOfClass: gcClass];
_count++; _count++;
} }
@ -250,7 +251,7 @@ static Class gcClass = 0;
{ {
while (_count < count) while (_count < count)
{ {
_contents[_count] = [[anotherArray objectAtIndex: _count] retain]; _contents[_count] = RETAIN([anotherArray objectAtIndex: _count]);
_isGCObject[_count] = [_contents[_count] isKindOfClass: gcClass]; _isGCObject[_count] = [_contents[_count] isKindOfClass: gcClass];
_count++; _count++;
} }
@ -279,7 +280,7 @@ static Class gcClass = 0;
{ {
while (_count < count) while (_count < count)
{ {
_contents[_count] = [objects[_count] retain]; _contents[_count] = RETAIN(objects[_count]);
if (_contents[_count] == nil) if (_contents[_count] == nil)
{ {
[self release]; [self release];
@ -337,7 +338,7 @@ static Class gcClass = 0;
_contents[i] = _contents[i - 1]; _contents[i] = _contents[i - 1];
_isGCObject[i] = _isGCObject[i - 1]; _isGCObject[i] = _isGCObject[i - 1];
} }
_contents[index] = [anObject retain]; _contents[index] = RETAIN(anObject);
_isGCObject[index] = [anObject isKindOfClass: gcClass]; _isGCObject[index] = [anObject isKindOfClass: gcClass];
_count++; _count++;
} }
@ -375,7 +376,7 @@ static Class gcClass = 0;
} }
for (i = range.location; i < NSMaxRange(range); i++) for (i = range.location; i < NSMaxRange(range); i++)
{ {
[_contents[i] release]; RELEASE(_contents[i]);
} }
for (i = NSMaxRange(range); i < _count; i++, range.location++) for (i = NSMaxRange(range); i < _count; i++, range.location++)
{ {
@ -399,9 +400,7 @@ static Class gcClass = 0;
format: @"[%@-%@]: bad index %u", format: @"[%@-%@]: bad index %u",
NSStringFromClass([self class]), NSStringFromSelector(_cmd), index]; NSStringFromClass([self class]), NSStringFromSelector(_cmd), index];
} }
[anObject retain]; ASSIGN(_contents[index], anObject);
[_contents[index] release];
_contents[index] = anObject;
_isGCObject[index] = [anObject isKindOfClass: gcClass]; _isGCObject[index] = [anObject isKindOfClass: gcClass];
} }

View file

@ -61,7 +61,7 @@ typedef struct {
- (void) dealloc - (void) dealloc
{ {
NSEndMapTableEnumeration(&enumerator); NSEndMapTableEnumeration(&enumerator);
[dict release]; DESTROY(dict);
[super dealloc]; [super dealloc];
} }
- (id) nextObject - (id) nextObject
@ -104,7 +104,7 @@ _GCRetainObjects(NSMapTable *table, const void *ptr)
{ {
GCInfo *objectStruct = (GCInfo*)ptr; GCInfo *objectStruct = (GCInfo*)ptr;
[objectStruct->object retain]; RETAIN(objectStruct->object);
} }
static void static void
@ -116,12 +116,12 @@ _GCReleaseObjects(NSMapTable *table, const void *ptr)
{ {
if (objectStruct->isGCObject == NO) if (objectStruct->isGCObject == NO)
{ {
[objectStruct->object release]; DESTROY(objectStruct->object);
} }
} }
else else
{ {
[objectStruct->object release]; DESTROY(objectStruct->object);
} }
NSZoneFree(NSDefaultMallocZone(), objectStruct); NSZoneFree(NSDefaultMallocZone(), objectStruct);
} }
@ -316,7 +316,7 @@ static Class gcClass = 0;
e = [_GCDictionaryKeyEnumerator alloc]; e = [_GCDictionaryKeyEnumerator alloc];
e->dict = [self retain]; e->dict = [self retain];
e->enumerator = NSEnumerateMapTable(_map); e->enumerator = NSEnumerateMapTable(_map);
return [e autorelease]; return AUTORELEASE(e);
} }
- (NSEnumerator*) objectEnumerator - (NSEnumerator*) objectEnumerator
@ -326,7 +326,7 @@ static Class gcClass = 0;
e = [_GCDictionaryObjectEnumerator alloc]; e = [_GCDictionaryObjectEnumerator alloc];
e->dict = [self retain]; e->dict = [self retain];
e->enumerator = NSEnumerateMapTable(_map); e->enumerator = NSEnumerateMapTable(_map);
return [e autorelease]; return AUTORELEASE(e);
} }
- (id) mutableCopyWithZone: (NSZone*)zone - (id) mutableCopyWithZone: (NSZone*)zone

View file

@ -163,6 +163,12 @@ GS_EXPORT NSRecursiveLock *gnustep_global_lock;
- (id) initWithArray: (NSArray*)array copyItems: (BOOL)shouldCopy; - (id) initWithArray: (NSArray*)array copyItems: (BOOL)shouldCopy;
@end @end
@interface NSBundle(GSCompatibility)
+ (NSString *) pathForGNUstepResource: (NSString *)name
ofType: (NSString *)ext
inDirectory: (NSString *)bundlePath;
@end
@interface NSDistantObject (GSCompatibility) @interface NSDistantObject (GSCompatibility)
+ (void) setDebug: (int)val; + (void) setDebug: (int)val;
@end @end

View file

@ -26,11 +26,18 @@
#include <objc/objc-class.h> #include <objc/objc-class.h>
#include "GSCompatibility.h" #include "GSCompatibility.h"
#include "gnustep/base/GSCategories.h" #include "gnustep/base/GSCategories.h"
#include "gnustep/base/GCObject.h"
/* FIXME: Need to initialize this */ /* FIXME: Need to initialize this */
NSRecursiveLock *gnustep_global_lock = NULL; NSRecursiveLock *gnustep_global_lock = NULL;
NSString *GetEncodingName(NSStringEncoding availableEncodingValue) NSString *GetEncodingName(NSStringEncoding availableEncodingValue)
{
// Deprecated
return GSEncodingName(availableEncodingValue);
}
NSString *GSEncodingName(NSStringEncoding availableEncodingValue)
{ {
return (NSString *)CFStringGetNameOfEncoding(CFStringConvertNSStringEncodingToEncoding(availableEncodingValue)); return (NSString *)CFStringGetNameOfEncoding(CFStringConvertNSStringEncodingToEncoding(availableEncodingValue));
} }
@ -211,6 +218,47 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
} }
else else
{ {
}
@end
@implementation NSBundle(GSCompatibility)
// In NSBundle.m
+ (NSString *) pathForGNUstepResource: (NSString *)name
ofType: (NSString *)ext
inDirectory: (NSString *)bundlePath
{
NSString *path = nil;
NSString *bundle_path = nil;
NSArray *paths;
NSBundle *bundle;
NSEnumerator *enumerator;
/* Gather up the paths */
// Originally, looks up in GSLibrariesDirectory, i.e. "Libraries"
paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSAllDomainsMask, YES);
enumerator = [paths objectEnumerator];
while ((path == nil) && (bundle_path = [enumerator nextObject]))
{
bundle = [self bundleWithPath: bundle_path];
path = [bundle pathForResource: name
ofType: ext
inDirectory: bundlePath];
}
// New for OSX: looks in framework
if(path == nil){
if([bundlePath hasPrefix:@"Resources/"])
bundlePath = [bundlePath substringFromIndex:10];
path = [[NSBundle bundleForClass:[GCObject class]] pathForResource: name
ofType: ext
inDirectory: bundlePath];
}
return path;
return NO; return NO;
} }
} }

View file

@ -45,8 +45,10 @@
#include <Foundation/Foundation.h> #include <Foundation/Foundation.h>
#endif #endif
#include <gnustep/base/GSObjCRuntime.h> #include <gnustep/base/GSObjCRuntime.h>
#include "gnustep/base/GNUstep.h"
#include <string.h> #include <string.h>
@class NSNull; @class NSNull;
/** Deprecated ... use GSObjCFindVariable() */ /** Deprecated ... use GSObjCFindVariable() */
@ -151,7 +153,7 @@ GSObjCMethodNames(id obj)
NSString *name; NSString *name;
name = [[NSString alloc] initWithUTF8String: name = [[NSString alloc] initWithUTF8String:
method->method_name]; (const char *)method->method_name];
[set addObject: name]; [set addObject: name];
RELEASE(name); RELEASE(name);
} }
@ -831,8 +833,6 @@ GSObjCAddClassBehavior(Class receiver, Class behavior)
#ifndef NeXT_Foundation_LIBRARY #ifndef NeXT_Foundation_LIBRARY
#include <Foundation/NSValue.h> #include <Foundation/NSValue.h>
#include <Foundation/NSKeyValueCoding.h> #include <Foundation/NSKeyValueCoding.h>
#else
#include <Foundation/Foundation.h>
#endif #endif
/** Deprecated ... use GSObjCGetValue() */ /** Deprecated ... use GSObjCGetValue() */