Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0e9b899

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 101fd93 commit 0e9b899

File tree

6 files changed

+92
-2
lines changed

6 files changed

+92
-2
lines changed

config/c-library.m4

+31-1
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,34 @@ fi
316316
if test "$pgac_cv_type_locale_t" = 'yes (in xlocale.h)'; then
317317
AC_DEFINE(LOCALE_T_IN_XLOCALE, 1,
318318
[Define to 1 if `locale_t' requires <xlocale.h>.])
319-
fi])])# PGAC_HEADER_XLOCALE
319+
fi])# PGAC_TYPE_LOCALE_T
320+
321+
322+
# PGAC_FUNC_WCSTOMBS_L
323+
# --------------------
324+
# Try to find a declaration for wcstombs_l(). It might be in stdlib.h
325+
# (following the POSIX requirement for wcstombs()), or in locale.h, or in
326+
# xlocale.h. If it's in the latter, define WCSTOMBS_L_IN_XLOCALE.
327+
#
328+
AC_DEFUN([PGAC_FUNC_WCSTOMBS_L],
329+
[AC_CACHE_CHECK([for wcstombs_l declaration], pgac_cv_func_wcstombs_l,
330+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
331+
[#include <stdlib.h>
332+
#include <locale.h>],
333+
[#ifndef wcstombs_l
334+
(void) wcstombs_l;
335+
#endif])],
336+
[pgac_cv_func_wcstombs_l='yes'],
337+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
338+
[#include <stdlib.h>
339+
#include <locale.h>
340+
#include <xlocale.h>],
341+
[#ifndef wcstombs_l
342+
(void) wcstombs_l;
343+
#endif])],
344+
[pgac_cv_func_wcstombs_l='yes (in xlocale.h)'],
345+
[pgac_cv_func_wcstombs_l='no'])])])
346+
if test "$pgac_cv_func_wcstombs_l" = 'yes (in xlocale.h)'; then
347+
AC_DEFINE(WCSTOMBS_L_IN_XLOCALE, 1,
348+
[Define to 1 if `wcstombs_l' requires <xlocale.h>.])
349+
fi])# PGAC_FUNC_WCSTOMBS_L

configure

+53
Original file line numberDiff line numberDiff line change
@@ -12364,6 +12364,59 @@ $as_echo "#define GETTIMEOFDAY_1ARG 1" >>confdefs.h
1236412364

1236512365
fi
1236612366

12367+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for wcstombs_l declaration" >&5
12368+
$as_echo_n "checking for wcstombs_l declaration... " >&6; }
12369+
if ${pgac_cv_func_wcstombs_l+:} false; then :
12370+
$as_echo_n "(cached) " >&6
12371+
else
12372+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
12373+
/* end confdefs.h. */
12374+
#include <stdlib.h>
12375+
#include <locale.h>
12376+
int
12377+
main ()
12378+
{
12379+
#ifndef wcstombs_l
12380+
(void) wcstombs_l;
12381+
#endif
12382+
;
12383+
return 0;
12384+
}
12385+
_ACEOF
12386+
if ac_fn_c_try_compile "$LINENO"; then :
12387+
pgac_cv_func_wcstombs_l='yes'
12388+
else
12389+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
12390+
/* end confdefs.h. */
12391+
#include <stdlib.h>
12392+
#include <locale.h>
12393+
#include <xlocale.h>
12394+
int
12395+
main ()
12396+
{
12397+
#ifndef wcstombs_l
12398+
(void) wcstombs_l;
12399+
#endif
12400+
;
12401+
return 0;
12402+
}
12403+
_ACEOF
12404+
if ac_fn_c_try_compile "$LINENO"; then :
12405+
pgac_cv_func_wcstombs_l='yes (in xlocale.h)'
12406+
else
12407+
pgac_cv_func_wcstombs_l='no'
12408+
fi
12409+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
12410+
fi
12411+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
12412+
fi
12413+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_func_wcstombs_l" >&5
12414+
$as_echo "$pgac_cv_func_wcstombs_l" >&6; }
12415+
if test "$pgac_cv_func_wcstombs_l" = 'yes (in xlocale.h)'; then
12416+
12417+
$as_echo "#define WCSTOMBS_L_IN_XLOCALE 1" >>confdefs.h
12418+
12419+
fi
1236712420

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

configure.in

+1
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,7 @@ fi
14231423
PGAC_VAR_INT_TIMEZONE
14241424
AC_FUNC_ACCEPT_ARGTYPES
14251425
PGAC_FUNC_GETTIMEOFDAY_1ARG
1426+
PGAC_FUNC_WCSTOMBS_L
14261427

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

src/include/pg_config.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,9 @@
851851
/* Define to select Win32-style shared memory. */
852852
#undef USE_WIN32_SHARED_MEMORY
853853

854+
/* Define to 1 if `wcstombs_l' requires <xlocale.h>. */
855+
#undef WCSTOMBS_L_IN_XLOCALE
856+
854857
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
855858
significant byte first (like Motorola and SPARC, unlike Intel). */
856859
#if defined AC_APPLE_UNIVERSAL_BUILD

src/include/pg_config.h.win32

+3
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,9 @@
657657
/* Define to select Win32-style semaphores. */
658658
#define USE_WIN32_SEMAPHORES 1
659659

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

src/include/utils/pg_locale.h

+1-1
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)