Skip to content

Commit 00fd434

Browse files
committed
Cope if platform declares mbstowcs_l(), but not locale_t, in <xlocale.h>.
Previously, we included <xlocale.h> only if necessary to get the definition of type locale_t. According to notes in PGAC_TYPE_LOCALE_T, this is important because on some versions of glibc that file supplies an incompatible declaration of locale_t. (This info may be obsolete, because on my RHEL6 box that seems to be the *only* definition of locale_t; but there may still be glibc's in the wild for which it's a live concern.) It turns out though that on FreeBSD and maybe other BSDen, you can get locale_t from stdlib.h or locale.h but mbstowcs_l() and friends only from <xlocale.h>. This was leaving us compiling calls to mbstowcs_l() and friends with no visible prototype, which causes a warning and could possibly cause actual trouble, since it's not declared to return int. Hence, adjust the configure checks so that we'll include <xlocale.h> either if it's necessary to get type locale_t or if it's necessary to get a declaration of mbstowcs_l(). Report and patch by Aleksander Alekseev, somewhat whacked around by me. Back-patch to all supported branches, since we have been using mbstowcs_l() since 9.1.
1 parent 13108dd commit 00fd434

File tree

6 files changed

+92
-2
lines changed

6 files changed

+92
-2
lines changed

config/c-library.m4

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,34 @@ fi
366366
if test "$pgac_cv_type_locale_t" = 'yes (in xlocale.h)'; then
367367
AC_DEFINE(LOCALE_T_IN_XLOCALE, 1,
368368
[Define to 1 if `locale_t' requires <xlocale.h>.])
369-
fi])])# PGAC_HEADER_XLOCALE
369+
fi])# PGAC_TYPE_LOCALE_T
370+
371+
372+
# PGAC_FUNC_WCSTOMBS_L
373+
# --------------------
374+
# Try to find a declaration for wcstombs_l(). It might be in stdlib.h
375+
# (following the POSIX requirement for wcstombs()), or in locale.h, or in
376+
# xlocale.h. If it's in the latter, define WCSTOMBS_L_IN_XLOCALE.
377+
#
378+
AC_DEFUN([PGAC_FUNC_WCSTOMBS_L],
379+
[AC_CACHE_CHECK([for wcstombs_l declaration], pgac_cv_func_wcstombs_l,
380+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
381+
[#include <stdlib.h>
382+
#include <locale.h>],
383+
[#ifndef wcstombs_l
384+
(void) wcstombs_l;
385+
#endif])],
386+
[pgac_cv_func_wcstombs_l='yes'],
387+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
388+
[#include <stdlib.h>
389+
#include <locale.h>
390+
#include <xlocale.h>],
391+
[#ifndef wcstombs_l
392+
(void) wcstombs_l;
393+
#endif])],
394+
[pgac_cv_func_wcstombs_l='yes (in xlocale.h)'],
395+
[pgac_cv_func_wcstombs_l='no'])])])
396+
if test "$pgac_cv_func_wcstombs_l" = 'yes (in xlocale.h)'; then
397+
AC_DEFINE(WCSTOMBS_L_IN_XLOCALE, 1,
398+
[Define to 1 if `wcstombs_l' requires <xlocale.h>.])
399+
fi])# PGAC_FUNC_WCSTOMBS_L

configure

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11419,6 +11419,59 @@ $as_echo "#define GETTIMEOFDAY_1ARG 1" >>confdefs.h
1141911419

1142011420
fi
1142111421

11422+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for wcstombs_l declaration" >&5
11423+
$as_echo_n "checking for wcstombs_l declaration... " >&6; }
11424+
if ${pgac_cv_func_wcstombs_l+:} false; then :
11425+
$as_echo_n "(cached) " >&6
11426+
else
11427+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
11428+
/* end confdefs.h. */
11429+
#include <stdlib.h>
11430+
#include <locale.h>
11431+
int
11432+
main ()
11433+
{
11434+
#ifndef wcstombs_l
11435+
(void) wcstombs_l;
11436+
#endif
11437+
;
11438+
return 0;
11439+
}
11440+
_ACEOF
11441+
if ac_fn_c_try_compile "$LINENO"; then :
11442+
pgac_cv_func_wcstombs_l='yes'
11443+
else
11444+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
11445+
/* end confdefs.h. */
11446+
#include <stdlib.h>
11447+
#include <locale.h>
11448+
#include <xlocale.h>
11449+
int
11450+
main ()
11451+
{
11452+
#ifndef wcstombs_l
11453+
(void) wcstombs_l;
11454+
#endif
11455+
;
11456+
return 0;
11457+
}
11458+
_ACEOF
11459+
if ac_fn_c_try_compile "$LINENO"; then :
11460+
pgac_cv_func_wcstombs_l='yes (in xlocale.h)'
11461+
else
11462+
pgac_cv_func_wcstombs_l='no'
11463+
fi
11464+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
11465+
fi
11466+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
11467+
fi
11468+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_func_wcstombs_l" >&5
11469+
$as_echo "$pgac_cv_func_wcstombs_l" >&6; }
11470+
if test "$pgac_cv_func_wcstombs_l" = 'yes (in xlocale.h)'; then
11471+
11472+
$as_echo "#define WCSTOMBS_L_IN_XLOCALE 1" >>confdefs.h
11473+
11474+
fi
1142211475

1142311476
# Some versions of libedit contain strlcpy(), setproctitle(), and other
1142411477
# symbols that that library has no business exposing to the world. Pending

configure.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,7 @@ fi
12911291
PGAC_VAR_INT_TIMEZONE
12921292
AC_FUNC_ACCEPT_ARGTYPES
12931293
PGAC_FUNC_GETTIMEOFDAY_1ARG
1294+
PGAC_FUNC_WCSTOMBS_L
12941295

12951296
# Some versions of libedit contain strlcpy(), setproctitle(), and other
12961297
# symbols that that library has no business exposing to the world. Pending

src/include/pg_config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,9 @@
815815
/* Define to select Win32-style shared memory. */
816816
#undef USE_WIN32_SHARED_MEMORY
817817

818+
/* Define to 1 if `wcstombs_l' requires <xlocale.h>. */
819+
#undef WCSTOMBS_L_IN_XLOCALE
820+
818821
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
819822
significant byte first (like Motorola and SPARC, unlike Intel). */
820823
#if defined AC_APPLE_UNIVERSAL_BUILD

src/include/pg_config.h.win32

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,9 @@
656656
/* Define to select Win32-style semaphores. */
657657
#define USE_WIN32_SEMAPHORES 1
658658

659+
/* Define to 1 if `wcstombs_l' requires <xlocale.h>. */
660+
/* #undef WCSTOMBS_L_IN_XLOCALE */
661+
659662
/* Number of bits in a file offset, on hosts where this is settable. */
660663
/* #undef _FILE_OFFSET_BITS */
661664

src/include/utils/pg_locale.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define _PG_LOCALE_
1414

1515
#include <locale.h>
16-
#ifdef LOCALE_T_IN_XLOCALE
16+
#if defined(LOCALE_T_IN_XLOCALE) || defined(WCSTOMBS_L_IN_XLOCALE)
1717
#include <xlocale.h>
1818
#endif
1919

0 commit comments

Comments
 (0)