diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-11-25 22:43:08 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-11-25 22:43:08 +0000 |
commit | e3269cab31613d3e11522e7c8009736f2b3797ec (patch) | |
tree | 2b43bf63fdb380ed4960da40bcf27ff60cbc2cec /src/backend/utils/adt/cash.c | |
parent | 74dc04a034bc32f45738541f88e2d5e9e322cf59 (diff) |
Make PGLC_setlocale() static, and document that it can't be used safely
for any other purpose than PGLC_localeconv()'s internal save/restore of
locale settings. Fix cash.c to call PGLC_localeconv() rather than
making a direct call to localeconv() --- the old way, if PGLC_localeconv()
had already cached a locale result, it would be overwritten by the first
cash_in or cash_out operation, leading to wrong-locale results later.
Probably no demonstrable bug today, since we only appear to be looking
at the LC_MONETARY results which should be the same anyway, but definitely
a gotcha waiting to strike.
Diffstat (limited to 'src/backend/utils/adt/cash.c')
-rw-r--r-- | src/backend/utils/adt/cash.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c index f081e2568c2..f340fe6aae9 100644 --- a/src/backend/utils/adt/cash.c +++ b/src/backend/utils/adt/cash.c @@ -9,18 +9,23 @@ * workings can be found in the book "Software Solutions in C" by * Dale Schumacher, Academic Press, ISBN: 0-12-632360-7. * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.47 2000/11/25 20:33:52 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.48 2000/11/25 22:43:08 tgl Exp $ */ +#include "postgres.h" + #include <limits.h> #include <ctype.h> #include <math.h> +#ifdef USE_LOCALE #include <locale.h> +#endif -#include "postgres.h" #include "miscadmin.h" #include "utils/builtins.h" #include "utils/cash.h" +#include "utils/pg_locale.h" + static const char *num_word(Cash value); @@ -31,11 +36,6 @@ static const char *num_word(Cash value); #define LAST_PAREN (TERMINATOR - 1) #define LAST_DIGIT (LAST_PAREN - 1) -#ifdef USE_LOCALE -static struct lconv *lconvert = NULL; - -#endif - /* * Cash is a pass-by-ref SQL type, so we must pass and return pointers. @@ -82,11 +82,11 @@ cash_in(PG_FUNCTION_ARGS) ssymbol, psymbol, *nsymbol; - #ifdef USE_LOCALE - if (lconvert == NULL) - lconvert = localeconv(); + struct lconv *lconvert = PGLC_localeconv(); +#endif +#ifdef USE_LOCALE /* * frac_digits will be CHAR_MAX in some locales, notably C. However, * just testing for == CHAR_MAX is risky, because of compilers like @@ -238,11 +238,11 @@ cash_out(PG_FUNCTION_ARGS) dsymbol, *nsymbol; char convention; - #ifdef USE_LOCALE - if (lconvert == NULL) - lconvert = localeconv(); + struct lconv *lconvert = PGLC_localeconv(); +#endif +#ifdef USE_LOCALE /* see comments about frac_digits in cash_in() */ points = lconvert->frac_digits; if (points < 0 || points > 10) |