mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-04 02:20:48 +00:00
make code more robust when there's no autorelease pool.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35706 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
27c13ff71d
commit
fcd6be710e
8 changed files with 88 additions and 73 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2012-10-17 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSBundle.m:
|
||||||
|
* Source/NSCalendarDate.m:
|
||||||
|
* Source/NSFileManager.m:
|
||||||
|
* Source/NSJSONSerialization.m:
|
||||||
|
* Source/NSMessagePort.m:
|
||||||
|
* Source/NSMessagePortNameServer.m:
|
||||||
|
* Source/NSPropertyList.m:
|
||||||
|
Avoid autoreleasing things in +initialize when there may be no
|
||||||
|
autorelease pool present ... we don't want to either leak or
|
||||||
|
cause recursive loops when we want to log any leaks.
|
||||||
|
|
||||||
2012-10-15 Eric Wasylishen <ewasylishen@gmail.com>
|
2012-10-15 Eric Wasylishen <ewasylishen@gmail.com>
|
||||||
|
|
||||||
* Tests/base/NSArchiver/stringEncoding.m: add test for last commit
|
* Tests/base/NSArchiver/stringEncoding.m: add test for last commit
|
||||||
|
|
|
@ -1059,6 +1059,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
||||||
if (self == [NSBundle class])
|
if (self == [NSBundle class])
|
||||||
{
|
{
|
||||||
extern const char *GSPathHandling(const char *);
|
extern const char *GSPathHandling(const char *);
|
||||||
|
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||||
NSString *file;
|
NSString *file;
|
||||||
const char *mode;
|
const char *mode;
|
||||||
NSDictionary *env;
|
NSDictionary *env;
|
||||||
|
@ -1067,7 +1068,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
||||||
/* Ensure we do 'right' path handling while initializing core paths.
|
/* Ensure we do 'right' path handling while initializing core paths.
|
||||||
*/
|
*/
|
||||||
mode = GSPathHandling("right");
|
mode = GSPathHandling("right");
|
||||||
_emptyTable = RETAIN([NSDictionary dictionary]);
|
_emptyTable = [NSDictionary new];
|
||||||
|
|
||||||
/* Create basic mapping dictionaries for bootstrapping and
|
/* Create basic mapping dictionaries for bootstrapping and
|
||||||
* for use if the full ductionaries can't be loaded from the
|
* for use if the full ductionaries can't be loaded from the
|
||||||
|
@ -1127,6 +1128,15 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
||||||
*/
|
*/
|
||||||
manager();
|
manager();
|
||||||
|
|
||||||
|
/* Set up tables for bundle lookups
|
||||||
|
*/
|
||||||
|
_bundles = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||||
|
NSNonOwnedPointerMapValueCallBacks, 0);
|
||||||
|
_byClass = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
|
||||||
|
NSNonOwnedPointerMapValueCallBacks, 0);
|
||||||
|
_byIdentifier = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||||
|
NSNonOwnedPointerMapValueCallBacks, 0);
|
||||||
|
|
||||||
pathCacheLock = [NSLock new];
|
pathCacheLock = [NSLock new];
|
||||||
pathCache = [NSMutableDictionary new];
|
pathCache = [NSMutableDictionary new];
|
||||||
|
|
||||||
|
@ -1216,6 +1226,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
||||||
_loadingBundle = nil;
|
_loadingBundle = nil;
|
||||||
#endif
|
#endif
|
||||||
GSPathHandling(mode);
|
GSPathHandling(mode);
|
||||||
|
[pool release];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1226,17 +1237,15 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
||||||
+ (NSArray *) allBundles
|
+ (NSArray *) allBundles
|
||||||
{
|
{
|
||||||
NSMutableArray *array = [NSMutableArray arrayWithCapacity: 2];
|
NSMutableArray *array = [NSMutableArray arrayWithCapacity: 2];
|
||||||
|
NSMapEnumerator enumerate;
|
||||||
|
void *key;
|
||||||
|
NSBundle *bundle;
|
||||||
|
|
||||||
[load_lock lock];
|
[load_lock lock];
|
||||||
if (!_mainBundle)
|
if (!_mainBundle)
|
||||||
{
|
{
|
||||||
[self mainBundle];
|
[self mainBundle];
|
||||||
}
|
}
|
||||||
if (_bundles != 0)
|
|
||||||
{
|
|
||||||
NSMapEnumerator enumerate;
|
|
||||||
void *key;
|
|
||||||
NSBundle *bundle;
|
|
||||||
|
|
||||||
enumerate = NSEnumerateMapTable(_bundles);
|
enumerate = NSEnumerateMapTable(_bundles);
|
||||||
while (NSNextMapEnumeratorPair(&enumerate, &key, (void **)&bundle))
|
while (NSNextMapEnumeratorPair(&enumerate, &key, (void **)&bundle))
|
||||||
|
@ -1251,7 +1260,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NSEndMapTableEnumeration(&enumerate);
|
NSEndMapTableEnumeration(&enumerate);
|
||||||
}
|
|
||||||
[load_lock unlock];
|
[load_lock unlock];
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
@ -1631,6 +1640,7 @@ IF_NO_GC(
|
||||||
- (id) initWithPath: (NSString*)path
|
- (id) initWithPath: (NSString*)path
|
||||||
{
|
{
|
||||||
NSString *identifier;
|
NSString *identifier;
|
||||||
|
NSBundle *bundle;
|
||||||
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
|
@ -1698,10 +1708,7 @@ IF_NO_GC(
|
||||||
|
|
||||||
/* check if we were already initialized for this directory */
|
/* check if we were already initialized for this directory */
|
||||||
[load_lock lock];
|
[load_lock lock];
|
||||||
if (_bundles)
|
bundle = (NSBundle *)NSMapGet(_bundles, path);
|
||||||
{
|
|
||||||
NSBundle *bundle = (NSBundle *)NSMapGet(_bundles, path);
|
|
||||||
|
|
||||||
if (bundle != nil)
|
if (bundle != nil)
|
||||||
{
|
{
|
||||||
IF_NO_GC([bundle retain];)
|
IF_NO_GC([bundle retain];)
|
||||||
|
@ -1709,7 +1716,6 @@ IF_NO_GC(
|
||||||
[self dealloc];
|
[self dealloc];
|
||||||
return bundle;
|
return bundle;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
[load_lock unlock];
|
[load_lock unlock];
|
||||||
|
|
||||||
if (bundle_directory_readable(path) == nil)
|
if (bundle_directory_readable(path) == nil)
|
||||||
|
@ -1723,7 +1729,14 @@ IF_NO_GC(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* OK ... this is a new bundle ... need to insert it in the global map
|
||||||
|
* to be found by this path so that a leter call to -bundleIdentifier
|
||||||
|
* can work.
|
||||||
|
*/
|
||||||
_path = [path copy];
|
_path = [path copy];
|
||||||
|
[load_lock lock];
|
||||||
|
NSMapInsert(_bundles, _path, self);
|
||||||
|
[load_lock unlock];
|
||||||
|
|
||||||
if ([[[_path lastPathComponent] pathExtension] isEqual: @"framework"] == YES)
|
if ([[[_path lastPathComponent] pathExtension] isEqual: @"framework"] == YES)
|
||||||
{
|
{
|
||||||
|
@ -1740,27 +1753,12 @@ IF_NO_GC(
|
||||||
identifier = [self bundleIdentifier];
|
identifier = [self bundleIdentifier];
|
||||||
|
|
||||||
[load_lock lock];
|
[load_lock lock];
|
||||||
if (!_bundles)
|
|
||||||
{
|
|
||||||
_bundles = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
||||||
NSNonOwnedPointerMapValueCallBacks, 0);
|
|
||||||
}
|
|
||||||
if (!_byClass)
|
|
||||||
{
|
|
||||||
/* Used later by framework code.
|
|
||||||
*/
|
|
||||||
_byClass = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
|
|
||||||
NSNonOwnedPointerMapValueCallBacks, 0);
|
|
||||||
}
|
|
||||||
if (!_byIdentifier)
|
|
||||||
{
|
|
||||||
_byIdentifier = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
||||||
NSNonOwnedPointerMapValueCallBacks, 0);
|
|
||||||
}
|
|
||||||
if (identifier != nil)
|
if (identifier != nil)
|
||||||
{
|
{
|
||||||
NSBundle *bundle = (NSBundle *)NSMapGet(_byIdentifier, identifier);
|
NSBundle *bundle = (NSBundle *)NSMapGet(_byIdentifier, identifier);
|
||||||
|
|
||||||
|
if (bundle != self)
|
||||||
|
{
|
||||||
if (bundle != nil)
|
if (bundle != nil)
|
||||||
{
|
{
|
||||||
IF_NO_GC([bundle retain];)
|
IF_NO_GC([bundle retain];)
|
||||||
|
@ -1770,7 +1768,7 @@ IF_NO_GC(
|
||||||
}
|
}
|
||||||
NSMapInsert(_byIdentifier, identifier, self);
|
NSMapInsert(_byIdentifier, identifier, self);
|
||||||
}
|
}
|
||||||
NSMapInsert(_bundles, _path, self);
|
}
|
||||||
[load_lock unlock];
|
[load_lock unlock];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
|
@ -349,8 +349,10 @@ GSPrivateTimeNow(void)
|
||||||
|
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
if (self == [NSCalendarDate class])
|
if (self == [NSCalendarDate class] && nil == NSCalendarDateClass)
|
||||||
{
|
{
|
||||||
|
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||||
|
|
||||||
NSCalendarDateClass = self;
|
NSCalendarDateClass = self;
|
||||||
[self setVersion: 1];
|
[self setVersion: 1];
|
||||||
localTZ = RETAIN([NSTimeZone localTimeZone]);
|
localTZ = RETAIN([NSTimeZone localTimeZone]);
|
||||||
|
@ -375,6 +377,7 @@ GSPrivateTimeNow(void)
|
||||||
[absClass instanceMethodForSelector: abrSEL];
|
[absClass instanceMethodForSelector: abrSEL];
|
||||||
|
|
||||||
GSObjCAddClassBehavior(self, [NSGDate class]);
|
GSObjCAddClassBehavior(self, [NSGDate class]);
|
||||||
|
[pool release];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3116,7 +3116,7 @@ static NSSet *fileKeys = nil;
|
||||||
{
|
{
|
||||||
if (fileKeys == nil)
|
if (fileKeys == nil)
|
||||||
{
|
{
|
||||||
fileKeys = [NSSet setWithObjects:
|
fileKeys = [[NSSet alloc] initWithObjects:
|
||||||
NSFileAppendOnly,
|
NSFileAppendOnly,
|
||||||
NSFileCreationDate,
|
NSFileCreationDate,
|
||||||
NSFileDeviceIdentifier,
|
NSFileDeviceIdentifier,
|
||||||
|
@ -3136,7 +3136,6 @@ static NSSet *fileKeys = nil;
|
||||||
NSFileSystemNumber,
|
NSFileSystemNumber,
|
||||||
NSFileType,
|
NSFileType,
|
||||||
nil];
|
nil];
|
||||||
IF_NO_GC([fileKeys retain];)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -721,7 +721,7 @@ static Class NSNullClass;
|
||||||
static Class NSNumberClass;
|
static Class NSNumberClass;
|
||||||
static Class NSStringClass;
|
static Class NSStringClass;
|
||||||
|
|
||||||
static NSCharacterSet *escapeSet;
|
static NSMutableCharacterSet *escapeSet;
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
writeTabs(NSMutableString *output, NSInteger tabs)
|
writeTabs(NSMutableString *output, NSInteger tabs)
|
||||||
|
@ -902,10 +902,10 @@ writeObject(id obj, NSMutableString *output, NSInteger tabs)
|
||||||
NSStringClass = [NSString class];
|
NSStringClass = [NSString class];
|
||||||
NSDictionaryClass = [NSDictionary class];
|
NSDictionaryClass = [NSDictionary class];
|
||||||
NSNumberClass = [NSNumber class];
|
NSNumberClass = [NSNumber class];
|
||||||
escapeSet
|
escapeSet = [NSMutableCharacterSet new];
|
||||||
= [[NSCharacterSet characterSetWithCharactersInString: @"\"\\"] retain];
|
[escapeSet addCharactersInString: @"\"\\"];
|
||||||
boolN = [[NSNumber numberWithBool: NO] retain];
|
boolN = [[NSNumber alloc] initWithBool: NO];
|
||||||
boolY = [[NSNumber numberWithBool: YES] retain];
|
boolY = [[NSNumber alloc] initWithBool: YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSData*) dataWithJSONObject: (id)obj
|
+ (NSData*) dataWithJSONObject: (id)obj
|
||||||
|
|
|
@ -1130,6 +1130,7 @@ typedef struct {
|
||||||
{
|
{
|
||||||
if (self == [NSMessagePort class])
|
if (self == [NSMessagePort class])
|
||||||
{
|
{
|
||||||
|
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||||
NSFileManager *mgr;
|
NSFileManager *mgr;
|
||||||
NSString *path;
|
NSString *path;
|
||||||
NSString *pref;
|
NSString *pref;
|
||||||
|
@ -1180,6 +1181,7 @@ typedef struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
[pool release];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,7 @@ static void clean_up_names(void)
|
||||||
{
|
{
|
||||||
if (self == [NSMessagePortNameServer class])
|
if (self == [NSMessagePortNameServer class])
|
||||||
{
|
{
|
||||||
|
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||||
NSFileManager *mgr;
|
NSFileManager *mgr;
|
||||||
NSString *path;
|
NSString *path;
|
||||||
NSString *pref;
|
NSString *pref;
|
||||||
|
@ -177,6 +178,7 @@ static void clean_up_names(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
[pool release];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -591,30 +591,28 @@ static NSCharacterSet *xmlQuotables = nil;
|
||||||
|
|
||||||
static void setupQuotables(void)
|
static void setupQuotables(void)
|
||||||
{
|
{
|
||||||
if (oldQuotables == nil)
|
if (nil == oldQuotables)
|
||||||
{
|
{
|
||||||
NSMutableCharacterSet *s;
|
NSMutableCharacterSet *s;
|
||||||
|
|
||||||
/* The '$', '.', '/' and '_' characters used to be OK to use in
|
/* The '$', '.', '/' and '_' characters used to be OK to use in
|
||||||
* property lists, but OSX now quotes them, so we follow suite.
|
* property lists, but OSX now quotes them, so we follow suite.
|
||||||
*/
|
*/
|
||||||
s = [[NSCharacterSet characterSetWithCharactersInString:
|
s = [NSMutableCharacterSet new];
|
||||||
|
[s addCharactersInString:
|
||||||
@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
@"abcdefghijklmnopqrstuvwxyz"]
|
@"abcdefghijklmnopqrstuvwxyz"];
|
||||||
mutableCopy];
|
|
||||||
[s invert];
|
[s invert];
|
||||||
oldQuotables = [s copy];
|
oldQuotables = s;
|
||||||
RELEASE(s);
|
|
||||||
|
|
||||||
s = [[NSCharacterSet characterSetWithCharactersInString:
|
s = [NSMutableCharacterSet new];
|
||||||
@"&<>'\\\""] mutableCopy];
|
[s addCharactersInString: @"&<>'\\\""];
|
||||||
[s addCharactersInRange: NSMakeRange(0x0001, 0x001f)];
|
[s addCharactersInRange: NSMakeRange(0x0001, 0x001f)];
|
||||||
[s removeCharactersInRange: NSMakeRange(0x0009, 0x0002)];
|
[s removeCharactersInRange: NSMakeRange(0x0009, 0x0002)];
|
||||||
[s removeCharactersInRange: NSMakeRange(0x000D, 0x0001)];
|
[s removeCharactersInRange: NSMakeRange(0x000D, 0x0001)];
|
||||||
[s addCharactersInRange: NSMakeRange(0xD800, 0x07FF)];
|
[s addCharactersInRange: NSMakeRange(0xD800, 0x07FF)];
|
||||||
[s addCharactersInRange: NSMakeRange(0xFFFE, 0x0002)];
|
[s addCharactersInRange: NSMakeRange(0xFFFE, 0x0002)];
|
||||||
xmlQuotables = [s copy];
|
xmlQuotables = s;
|
||||||
RELEASE(s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue