Skip to content

Commit

Permalink
locale.c: Make statics of repeated string constants
Browse files Browse the repository at this point in the history
These strings are (or soon will be) used in multiple places; so have
just one definition for them.
  • Loading branch information
khwilliamson committed Apr 29, 2021
1 parent b4bd784 commit 5ee10d5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions locale.c
Expand Up @@ -126,6 +126,11 @@ static int debug_initialization = 0;
* the compiler warnings about comparing unlike signs */
#define STRLENs(s) (sizeof("" s "") - 1)

/* Default values come from the C locale */
static const char C_codeset[] = "ANSI_X3.4-1968";
static const char C_decimal_point[] = ".";
static const char C_thousands_sep[] = "";

/* Is the C string input 'name' "C" or "POSIX"? If so, and 'name' is the
* return of setlocale(), then this is extremely likely to be the C or POSIX
* locale. However, the output of setlocale() is documented to be opaque, but
Expand Down Expand Up @@ -1501,7 +1506,7 @@ S_set_numeric_radix(pTHX_ const bool use_locale)
const char * radix = (use_locale)
? my_nl_langinfo(RADIXCHAR, FALSE)
/* FALSE => already in dest locale */
: ".";
: C_decimal_point;

sv_setpv(PL_numeric_radix_sv, radix);

Expand Down Expand Up @@ -1599,9 +1604,9 @@ S_new_numeric(pTHX_ const char *newnum)
* THOUSEP can currently (but rarely) cause a race, so avoid doing that,
* and just always change the locale if not C nor POSIX on those systems */
if (! PL_numeric_standard) {
PL_numeric_standard = cBOOL(strEQ(".", my_nl_langinfo(RADIXCHAR,
PL_numeric_standard = cBOOL(strEQ(C_decimal_point, my_nl_langinfo(RADIXCHAR,
FALSE /* Don't toggle locale */ ))
&& strEQ("", my_nl_langinfo(THOUSEP, FALSE)));
&& strEQ(C_thousands_sep, my_nl_langinfo(THOUSEP, FALSE)));
}

# endif
Expand Down Expand Up @@ -3403,7 +3408,7 @@ S_my_nl_langinfo(const int item, bool toggle)
const char * name = querylocale_c(LC_CTYPE);

if (isNAME_C_OR_POSIX(name)) {
return "ANSI_X3.4-1968";
return C_codeset;
}

/* Find the dot in the locale name */
Expand Down Expand Up @@ -3746,7 +3751,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
# endif
# ifdef USE_LOCALE_NUMERIC

PL_numeric_radix_sv = newSVpvs(".");
PL_numeric_radix_sv = newSVpvn(C_decimal_point, strlen(C_decimal_point));

# endif
# ifdef LOCALE_ENVIRON_REQUIRED
Expand Down

0 comments on commit 5ee10d5

Please sign in to comment.