Skip to content

Commit

Permalink
only #include <xlocale.h> when it is actually needed
Browse files Browse the repository at this point in the history
This header was originally only needed for builds on darwin and
FreeBSD, but was being included whenever it was detected.

This has caused problems when what was an internal header was
removed (from glibc) and in general wasn't needed anyway.

On FreeBSD only localeconv_l() requires xlocale.h, so we test
specifically for that.
  • Loading branch information
tonycoz committed Jun 28, 2021
1 parent 3bd97ba commit fcaf0ac
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 7 deletions.
50 changes: 50 additions & 0 deletions Configure
Expand Up @@ -1401,6 +1401,7 @@ installvendorscript=''
vendorscript=''
vendorscriptexp=''
versiononly=''
xlocale_needed=''
yacc=''
yaccflags=''
CONFIG=''
Expand Down Expand Up @@ -16095,6 +16096,54 @@ eval $inlibc
set localeconv_l d_localeconv_l
eval $inlibc

: if we have xlocale.h, check whether it is needed
case "$i_xlocale$d_newlocale$xlocale_needed" in
"$define$define")
echo "Checking if xlocale.h is needed..." >&4
$cat >try.c <<EOF
#include <locale.h>
#include <stdio.h>
#ifdef TRY_XLOCALE
#include <xlocale.h>
#endif
#$d_localeconv_l HAVE_LOCALECONV_L

#ifdef HAVE_LOCALECONV_L
struct lconv *(*lcptr)(locale_t) = localeconv_l;
#endif

int main(void) {
locale_t lc = newlocale(LC_ALL_MASK, "C", (locale_t)0);

#ifdef HAVE_LOCALECONV_L
/* FreeBSD hides only localeconv_l() in xlocale.h */
struct lconv *lcbuf = localeconv_l(lc);
printf("decimal: %s\n", lcbuf->decimal_point);
#endif

freelocale(lc);
return 0;
}
EOF
set try
if eval $compile && $run ./try > /dev/null 2>&1 ; then
echo "xlocale.h isn't needed" >&4
xlocale_needed=$undef
else
set try -DTRY_XLOCALE
if eval $compile && $run ./try > /dev/null 2>&1 ; then
xlocale_needed=$define
echo "xlocale.h is needed" >&4
else
echo "I can't build my test either way" >&4
xlocale_needed=$undef
fi
fi
$rm_try
;;
*) xlocale_needed=$undef ;;
esac

: see if localtime_r exists
set localtime_r d_localtime_r
eval $inlibc
Expand Down Expand Up @@ -25368,6 +25417,7 @@ version_patchlevel_string='$version_patchlevel_string'
versiononly='$versiononly'
vi='$vi'
xlibpth='$xlibpth'
xlocale_needed='$xlocale_needed'
yacc='$yacc'
yaccflags='$yaccflags'
zcat='$zcat'
Expand Down
1 change: 1 addition & 0 deletions Cross/config.sh-arm-linux
Expand Up @@ -1189,6 +1189,7 @@ version_patchlevel_string='version 35 subversion 2'
versiononly='undef'
vi=''
xlibpth='/usr/lib/386 /lib/386'
xlocale_needed='undef'
yacc='yacc'
yaccflags=''
zcat=''
Expand Down
1 change: 1 addition & 0 deletions Cross/config.sh-arm-linux-n770
Expand Up @@ -1187,6 +1187,7 @@ version_patchlevel_string='version 35 subversion 2'
versiononly='undef'
vi=''
xlibpth='/usr/lib/386 /lib/386'
xlocale_needed='undef'
yacc='yacc'
yaccflags=''
zcat=''
Expand Down
1 change: 1 addition & 0 deletions NetWare/config.wc
Expand Up @@ -1140,6 +1140,7 @@ vendorprefixexp=''
version='~VERSION~'
vi=''
xlibpth='/usr/lib/386 /lib/386'
xlocale_needed='undef'
zcat=''
zip='zip'
PERL_REVISION='~PERL_REVISION~'
Expand Down
1 change: 1 addition & 0 deletions Porting/config.sh
Expand Up @@ -1225,6 +1225,7 @@ version_patchlevel_string='version 35 subversion 2'
versiononly='define'
vi=''
xlibpth='/usr/lib/386 /lib/386'
xlocale_needed='undef'
yacc='yacc'
yaccflags=''
zcat=''
Expand Down
9 changes: 7 additions & 2 deletions config_h.SH
Expand Up @@ -3142,15 +3142,20 @@ sed <<!GROK!THIS! >$CONFIG_H -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un
* available to return the name of the locale for a category mask.
*/
/* I_XLOCALE:
* This symbol, if defined, indicates to the C program that it should
* include <xlocale.h> to get uselocale() and its friends.
* This symbol, if defined, indicates to the C program that the
* xlocale.h header is available. See also NEED_XLOCALE_H.
*/
/* NEED_XLOCALE_H:
* This symbol, if defined, indicates that the C program should
* include <xlocale.h> to get newlocale() and its friends.
*/
#$d_newlocale HAS_NEWLOCALE /**/
#$d_freelocale HAS_FREELOCALE /**/
#$d_uselocale HAS_USELOCALE /**/
#$d_duplocale HAS_DUPLOCALE /**/
#$d_querylocale HAS_QUERYLOCALE /**/
#$i_xlocale I_XLOCALE /**/
#$xlocale_needed NEED_XLOCALE_H /**/
/* HAS_NEXTAFTER:
* This symbol, if defined, indicates that the nextafter routine is
Expand Down
1 change: 1 addition & 0 deletions configure.com
Expand Up @@ -6790,6 +6790,7 @@ $ WC "i_vfork='undef'"
$ WC "i_wchar='define'"
$ WC "i_wctype='define'"
$ WC "i_xlocale='undef'"
$ WC "xlocale_needed='undef'"
$ WC "inc_version_list='0'"
$ WC "inc_version_list_init='0'"
$ WC "installarchlib='" + installarchlib + "'"
Expand Down
2 changes: 1 addition & 1 deletion perl.h
Expand Up @@ -919,7 +919,7 @@ Example usage:
# include <locale.h>
#endif

#ifdef I_XLOCALE
#ifdef NEED_XLOCALE_H
# include <xlocale.h>
#endif

Expand Down
1 change: 1 addition & 0 deletions plan9/config_sh.sample
Expand Up @@ -1150,6 +1150,7 @@ version_patchlevel_string='version 35 subversion 2'
versiononly='undef'
vi=''
xlibpth=''
xlocale_needed='undef'
yacc='yacc'
yaccflags=''
zcat=''
Expand Down
13 changes: 9 additions & 4 deletions uconfig.h
Expand Up @@ -3107,15 +3107,20 @@
* available to return the name of the locale for a category mask.
*/
/* I_XLOCALE:
* This symbol, if defined, indicates to the C program that it should
* include <xlocale.h> to get uselocale() and its friends.
* This symbol, if defined, indicates to the C program that the
* xlocale.h header is available. See also NEED_XLOCALE_H.
*/
/* NEED_XLOCALE_H:
* This symbol, if defined, indicates that the C program should
* include <xlocale.h> to get newlocale() and its friends.
*/
/*#define HAS_NEWLOCALE / **/
/*#define HAS_FREELOCALE / **/
/*#define HAS_USELOCALE / **/
/*#define HAS_DUPLOCALE / **/
/*#define HAS_QUERYLOCALE / **/
/*#define I_XLOCALE / **/
/*#define NEED_XLOCALE_H / **/

/* HAS_NEXTAFTER:
* This symbol, if defined, indicates that the nextafter routine is
Expand Down Expand Up @@ -5313,6 +5318,6 @@
#endif

/* Generated from:
* 55a531381747550c11c2c61b9a9da2dacde4df465b874df55a9c923e495deb3a config_h.SH
* 2fece1e405c60ae089fe55acaa42471b6fba78b7ab4cefc6d5e18a94b72fc2c4 uconfig.sh
* c0ae90ad8256740b1a7872cebe079e964a7a9a5c8128038a60de0ab610d9e9fe config_h.SH
* 24570f2ff38b22b436d34127ff85a3f3a075a4dea1359c56f16196bdbe376b1c uconfig.sh
* ex: set ro: */
1 change: 1 addition & 0 deletions uconfig.sh
Expand Up @@ -922,4 +922,5 @@ vendorarchexp=''
vendorlib_stem=''
vendorlibexp=''
versiononly='undef'
xlocale_needed='undef'
zip=''
1 change: 1 addition & 0 deletions uconfig64.sh
Expand Up @@ -922,4 +922,5 @@ vendorarchexp=''
vendorlib_stem=''
vendorlibexp=''
versiononly='undef'
xlocale_needed='undef'
zip=''
1 change: 1 addition & 0 deletions win32/config.gc
Expand Up @@ -1184,6 +1184,7 @@ version_patchlevel_string=''
versiononly='undef'
vi=''
xlibpth='/usr/lib/386 /lib/386'
xlocale_needed='undef'
yacc='yacc'
yaccflags=''
zcat=''
Expand Down
1 change: 1 addition & 0 deletions win32/config.vc
Expand Up @@ -1183,6 +1183,7 @@ version_patchlevel_string=''
versiononly='undef'
vi=''
xlibpth='/usr/lib/386 /lib/386'
xlocale_needed='undef'
yacc='yacc'
yaccflags=''
zcat=''
Expand Down

0 comments on commit fcaf0ac

Please sign in to comment.