From 0579e4668fe9a079644ae7bd2550db5ed8e10e68 Mon Sep 17 00:00:00 2001 From: CaS Date: Mon, 23 Apr 2001 08:55:58 +0000 Subject: [PATCH] Initialise locale early git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@9665 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ Source/GSLocale.m | 16 ++++++++++++++-- Source/NSObject.m | 5 ++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6da4bfce0..2f3d6e6ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2001-04-23 Richard Frith-Macdonald + + * Source/GSLocale.m: Only call setlocale() in GSSetLocaleC() + * Source/NSObject.m: ([+initialize]) call GSSetLocaleC() after other + initialisation, to try to ensure that locale stuff is set up early + before any attempt is made to use locale dependent code. + 2001-04-22 Nicola Pero * Testing/benchmark.m: Modified messages to give a better idea of diff --git a/Source/GSLocale.m b/Source/GSLocale.m index 74232e927..c6fbcd0da 100644 --- a/Source/GSLocale.m +++ b/Source/GSLocale.m @@ -35,6 +35,18 @@ #include #include +/* + * Function called by [NSObject +initialize] to setup locale information + * from environment variables. Must *not* use any ObjC code since it needs + * to run before any ObjC classes are fully initialised so that they can + * make use of locale information. + */ +const char* +GSSetLocaleC(const char *loc) +{ + return setlocale(LC_ALL, loc); +} + /* Set the locale for libc functions from the supplied string or from the environment if not specified. This function should be called as soon as possible after the start of the program. Passing @@ -51,7 +63,7 @@ GSSetLocale(NSString *locale) { clocale = [locale cString]; } - clocale = setlocale(LC_ALL, clocale); + clocale = GSSetLocaleC(clocale); if (clocale == NULL || strcmp(clocale, "C") == 0 || strcmp(clocale, "POSIX") == 0) @@ -154,7 +166,7 @@ GSDomainFromDefaultLocale(void) } /* FIXME: Get currency format from localeconv */ - str1 = [NSString stringWithCString: setlocale(LC_ALL, NULL)]; + str1 = GSSetLocale(nil); [dict setObject: str1 forKey: NSLocale]; str2 = GSLanguageFromLocale(str1); if (str2) diff --git a/Source/NSObject.m b/Source/NSObject.m index a07ebc562..71acee583 100644 --- a/Source/NSObject.m +++ b/Source/NSObject.m @@ -570,7 +570,10 @@ static BOOL double_release_check_enabled = NO; { if (self == [NSObject class]) { - extern void GSBuildStrings(); // See externs.m + extern void GSBuildStrings(); // See externs.m + extern const char* GSSetLocaleC(); // See GSLocale.m + + GSSetLocaleC(""); // Set up locale from environment. #ifdef __MINGW__ // See libgnustep-base-entry.m