r20189 - gnucash/trunk/src/backend/dbi - Handle localization-ignorance bug in libdbi by setting LC_NUMERIC locale

Christian Stimming stimming at tuhh.de
Sat Jan 29 04:48:18 EST 2011


Am Samstag, 29. Januar 2011 schrieb Christian Stimming:
> > Trac: http://svn.gnucash.org/trac/changeset/20189
> > 
> > Modified:
> >    gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
> 
> I believe unfortunately it doesn't work this easy way: The returned value
> of setlocale( ) might point to static storage, which will subsequently be
> overwritten by setlocale("C"), so you won't be setting it to the original
> value by the third setlocale. Instead, unfortunately you will have to
> g_strdup the returned value of setlocale() immediately, then change the
> locale, then do the broken libdbi stuff, then setlocale() back to the
> original value, then g_free the original value.
> 
> Seems like this is asking for some refactoring into separate functions...

Oh, and the very same thing is already done in two other gnucash files:

src/app-utils/gnc-ui-util.c:            const char *thislocale = 
setlocale(LC_ALL, NULL);
src/app-utils/gnc-ui-util.c:    saved_locale = g_strdup (setlocale (LC_ALL, 
NULL));
src/app-utils/gnc-ui-util.c:    setlocale (LC_ALL, locale);
src/app-utils/gnc-ui-util.c:    setlocale (LC_ALL, saved_locale);
src/gnome/druid-hierarchy.c:    locale = g_strdup(setlocale(LC_MESSAGES, 
NULL));
src/gnome/druid-hierarchy.c:    /* On win32, setlocale() doesn't say anything 
useful. Use
src/gnome/druid-hierarchy.c:     * setlocale can sometimes return NULL instead 
of "C"
src/gnome/druid-hierarchy.c:    locale = g_strdup(setlocale(LC_ALL, NULL) ?
src/gnome/druid-hierarchy.c:                      setlocale(LC_ALL, NULL) : 
"C");

So I guess you should refactor the common code parts into some function in, 
say, core-utils or similar...

Regards,

Christian


More information about the gnucash-devel mailing list