diff --git a/ChangeLog b/ChangeLog index 66e0e7248..d682bfeda 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-03-14 Nicola Pero + + * Source/NSUserDefaults.m ([+standardUserDefaults]): Manually + lookup gnustep-base language resources without using NSBundle to + break the bootstrap chicken-and-egg problem between NSBundle and + NSUserDefaults. + 2007-03-14 Richard Frith-Macdonald * Source/Additions/GSXML.m: Fix memory leak caused by url handle diff --git a/Source/NSBundle.m b/Source/NSBundle.m index cf68c069c..a302c5dbe 100644 --- a/Source/NSBundle.m +++ b/Source/NSBundle.m @@ -2196,6 +2196,10 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory) + (NSBundle *) bundleForLibrary: (NSString *)libraryName version: (NSString *)interfaceVersion { + /* Important: if you change this code, make sure to also + * change NSUserDefault's manual gnustep-base resource + * lookup to match. + */ NSArray *paths; NSEnumerator *enumerator; NSString *path; diff --git a/Source/NSUserDefaults.m b/Source/NSUserDefaults.m index 3d487a4a2..598e9fad6 100644 --- a/Source/NSUserDefaults.m +++ b/Source/NSUserDefaults.m @@ -498,15 +498,44 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */ enumerator = [uL objectEnumerator]; while ((lang = [enumerator nextObject])) { - NSString *path; - NSDictionary *dict; - NSBundle *gbundle; - - gbundle = [NSBundle bundleForClass: [NSObject class]]; - path = [gbundle pathForResource: lang - ofType: nil - inDirectory: @"Languages"]; - dict = nil; + /* We lookup gnustep-base resources manually here to prevent + * bootstrap problems. NSBundle's lookup routines depend on + * having NSUserDefaults already bootstrapped, but we're still + * bootstrapping here! So we can't really use NSBundle without + * incurring massive bootstrap complications (btw, most of the + * times we're here as a consequence of [NSBundle +initialize] + * creating the gnustep-base bundle! So trying to use the + * gnustep-base bundle here wouldn't really work.). + */ + /* + * We are looking for: + * + * GNUSTEP_LIBRARY/Libraries/gnustep-base/Versions//Resources/Languages/ + */ + NSDictionary *dict = nil; + NSString *path = nil; + NSFileManager *fm = [NSFileManager defaultManager]; + NSString *tail = [[[[[[@"Libraries" stringByAppendingPathComponent: @"gnustep-base"] + stringByAppendingPathComponent: @"Versions"] + stringByAppendingPathComponent: OBJC_STRINGIFY(GNUSTEP_BASE_MAJOR_VERSION.GNUSTEP_BASE_MINOR_VERSION)] + stringByAppendingPathComponent: @"Resources"] + stringByAppendingPathComponent: @"Languages"] + stringByAppendingPathComponent: lang]; + NSArray *paths = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory, + NSAllDomainsMask, YES); + enumerator = [paths objectEnumerator]; + while ((path = [enumerator nextObject]) != nil) + { + BOOL isDir; + path = [path stringByAppendingPathComponent: tail]; + + if ([fm fileExistsAtPath: path isDirectory: &isDir]) + { + /* Path found! */ + break; + } + } + if (path != nil) { dict = [NSDictionary dictionaryWithContentsOfFile: path];