Skip to content

Commit

Permalink
locale.c: Better handle the case of no localeconv()
Browse files Browse the repository at this point in the history
localeconv() is a C89 function, but we have long checked for its
absence, and returned an empty hash if missing.

Now the code has been changed so that it's trivial for us to instead
return the hash filled in as if the C locale is in effect.  This commit
does that.

There are two possible reasons for localeconv to be listed as missing.
One is if the Configure probe we've long had for it didn't find it, and
the other is that it is irreparably broken, so a hints file says don't
use it.  localeconv() historically has been buggy in various
implementations, so I think its worthwhile to retain this little bit of
code related to it's being broken.

If it truly is absent from the platform, its struct definition isn't
likely to be there either, so I added a definition for
convenience, #ifdef'd out
  • Loading branch information
khwilliamson committed Nov 22, 2023
1 parent ccdad10 commit 348c1c5
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 97 deletions.
16 changes: 7 additions & 9 deletions embed.fnc
Expand Up @@ -4396,22 +4396,20 @@ S |void |ints_to_tm |NN struct tm *my_tm \
|int yday \
|int isdst
S |bool |is_locale_utf8 |NN const char *locale
S |char * |strftime8 |NN const char *fmt \
|NN const struct tm *mytm \
|const utf8ness_t fmt_utf8ness \
|NN utf8ness_t *result_utf8ness \
|const bool came_from_sv
Sf |char * |strftime_tm |NN const char *fmt \
|NN const struct tm *mytm
# if defined(HAS_LOCALECONV)
S |HV * |my_localeconv |const int item
S |void |populate_hash_from_C_localeconv \
|NN HV *hv \
|NN const char *locale \
|const PERL_UINT_FAST8_T which_mask \
|NN const lconv_offset_t *strings[2] \
|NN const lconv_offset_t *integers[2]
# endif
S |char * |strftime8 |NN const char *fmt \
|NN const struct tm *mytm \
|const utf8ness_t fmt_utf8ness \
|NN utf8ness_t *result_utf8ness \
|const bool came_from_sv
Sf |char * |strftime_tm |NN const char *fmt \
|NN const struct tm *mytm
# if defined(USE_LOCALE)
S |const char *|calculate_LC_ALL_string \
|NULLOK const char **category_locales_list \
Expand Down
6 changes: 2 additions & 4 deletions embed.h
Expand Up @@ -1299,12 +1299,10 @@
# define get_locale_string_utf8ness_i(a,b,c,d) S_get_locale_string_utf8ness_i(aTHX_ a,b,c,d)
# define ints_to_tm(a,b,c,d,e,f,g,h,i,j) S_ints_to_tm(aTHX_ a,b,c,d,e,f,g,h,i,j)
# define is_locale_utf8(a) S_is_locale_utf8(aTHX_ a)
# define my_localeconv(a) S_my_localeconv(aTHX_ a)
# define populate_hash_from_C_localeconv(a,b,c,d,e) S_populate_hash_from_C_localeconv(aTHX_ a,b,c,d,e)
# define strftime8(a,b,c,d,e) S_strftime8(aTHX_ a,b,c,d,e)
# define strftime_tm(a,b) S_strftime_tm(aTHX_ a,b)
# if defined(HAS_LOCALECONV)
# define my_localeconv(a) S_my_localeconv(aTHX_ a)
# define populate_hash_from_C_localeconv(a,b,c,d,e) S_populate_hash_from_C_localeconv(aTHX_ a,b,c,d,e)
# endif
# if defined(USE_LOCALE)
# define calculate_LC_ALL_string(a,b,c,d) S_calculate_LC_ALL_string(aTHX_ a,b,c,d)
# define get_category_index_helper(a,b,c) S_get_category_index_helper(aTHX_ a,b,c)
Expand Down

0 comments on commit 348c1c5

Please sign in to comment.