Skip to content

Commit 4b505c2

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 0576de5 commit 4b505c2

File tree

6 files changed

+144
-2
lines changed

6 files changed

+144
-2
lines changed

config/c-library.m4

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,34 @@ fi
325325
if test "$pgac_cv_type_locale_t" = 'yes (in xlocale.h)'; then
326326
AC_DEFINE(LOCALE_T_IN_XLOCALE, 1,
327327
[Define to 1 if `locale_t' requires <xlocale.h>.])
328-
fi])])# PGAC_HEADER_XLOCALE
328+
fi])# PGAC_TYPE_LOCALE_T
329+
330+
331+
# PGAC_FUNC_WCSTOMBS_L
332+
# --------------------
333+
# Try to find a declaration for wcstombs_l(). It might be in stdlib.h
334+
# (following the POSIX requirement for wcstombs()), or in locale.h, or in
335+
# xlocale.h. If it's in the latter, define WCSTOMBS_L_IN_XLOCALE.
336+
#
337+
AC_DEFUN([PGAC_FUNC_WCSTOMBS_L],
338+
[AC_CACHE_CHECK([for wcstombs_l declaration], pgac_cv_func_wcstombs_l,
339+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
340+
[#include <stdlib.h>
341+
#include <locale.h>],
342+
[#ifndef wcstombs_l
343+
(void) wcstombs_l;
344+
#endif])],
345+
[pgac_cv_func_wcstombs_l='yes'],
346+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
347+
[#include <stdlib.h>
348+
#include <locale.h>
349+
#include <xlocale.h>],
350+
[#ifndef wcstombs_l
351+
(void) wcstombs_l;
352+
#endif])],
353+
[pgac_cv_func_wcstombs_l='yes (in xlocale.h)'],
354+
[pgac_cv_func_wcstombs_l='no'])])])
355+
if test "$pgac_cv_func_wcstombs_l" = 'yes (in xlocale.h)'; then
356+
AC_DEFINE(WCSTOMBS_L_IN_XLOCALE, 1,
357+
[Define to 1 if `wcstombs_l' requires <xlocale.h>.])
358+
fi])# PGAC_FUNC_WCSTOMBS_L

configure

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20000,6 +20000,111 @@ _ACEOF
2000020000
fi
2000120001

2000220002

20003+
{ $as_echo "$as_me:$LINENO: checking for wcstombs_l declaration" >&5
20004+
$as_echo_n "checking for wcstombs_l declaration... " >&6; }
20005+
if test "${pgac_cv_func_wcstombs_l+set}" = set; then
20006+
$as_echo_n "(cached) " >&6
20007+
else
20008+
cat >conftest.$ac_ext <<_ACEOF
20009+
/* confdefs.h. */
20010+
_ACEOF
20011+
cat confdefs.h >>conftest.$ac_ext
20012+
cat >>conftest.$ac_ext <<_ACEOF
20013+
/* end confdefs.h. */
20014+
#include <stdlib.h>
20015+
#include <locale.h>
20016+
int
20017+
main ()
20018+
{
20019+
#ifndef wcstombs_l
20020+
(void) wcstombs_l;
20021+
#endif
20022+
;
20023+
return 0;
20024+
}
20025+
_ACEOF
20026+
rm -f conftest.$ac_objext
20027+
if { (ac_try="$ac_compile"
20028+
case "(($ac_try" in
20029+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
20030+
*) ac_try_echo=$ac_try;;
20031+
esac
20032+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
20033+
$as_echo "$ac_try_echo") >&5
20034+
(eval "$ac_compile") 2>conftest.er1
20035+
ac_status=$?
20036+
grep -v '^ *+' conftest.er1 >conftest.err
20037+
rm -f conftest.er1
20038+
cat conftest.err >&5
20039+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
20040+
(exit $ac_status); } && {
20041+
test -z "$ac_c_werror_flag" ||
20042+
test ! -s conftest.err
20043+
} && test -s conftest.$ac_objext; then
20044+
pgac_cv_func_wcstombs_l='yes'
20045+
else
20046+
$as_echo "$as_me: failed program was:" >&5
20047+
sed 's/^/| /' conftest.$ac_ext >&5
20048+
20049+
cat >conftest.$ac_ext <<_ACEOF
20050+
/* confdefs.h. */
20051+
_ACEOF
20052+
cat confdefs.h >>conftest.$ac_ext
20053+
cat >>conftest.$ac_ext <<_ACEOF
20054+
/* end confdefs.h. */
20055+
#include <stdlib.h>
20056+
#include <locale.h>
20057+
#include <xlocale.h>
20058+
int
20059+
main ()
20060+
{
20061+
#ifndef wcstombs_l
20062+
(void) wcstombs_l;
20063+
#endif
20064+
;
20065+
return 0;
20066+
}
20067+
_ACEOF
20068+
rm -f conftest.$ac_objext
20069+
if { (ac_try="$ac_compile"
20070+
case "(($ac_try" in
20071+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
20072+
*) ac_try_echo=$ac_try;;
20073+
esac
20074+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
20075+
$as_echo "$ac_try_echo") >&5
20076+
(eval "$ac_compile") 2>conftest.er1
20077+
ac_status=$?
20078+
grep -v '^ *+' conftest.er1 >conftest.err
20079+
rm -f conftest.er1
20080+
cat conftest.err >&5
20081+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
20082+
(exit $ac_status); } && {
20083+
test -z "$ac_c_werror_flag" ||
20084+
test ! -s conftest.err
20085+
} && test -s conftest.$ac_objext; then
20086+
pgac_cv_func_wcstombs_l='yes (in xlocale.h)'
20087+
else
20088+
$as_echo "$as_me: failed program was:" >&5
20089+
sed 's/^/| /' conftest.$ac_ext >&5
20090+
20091+
pgac_cv_func_wcstombs_l='no'
20092+
fi
20093+
20094+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
20095+
fi
20096+
20097+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
20098+
fi
20099+
{ $as_echo "$as_me:$LINENO: result: $pgac_cv_func_wcstombs_l" >&5
20100+
$as_echo "$pgac_cv_func_wcstombs_l" >&6; }
20101+
if test "$pgac_cv_func_wcstombs_l" = 'yes (in xlocale.h)'; then
20102+
20103+
cat >>confdefs.h <<\_ACEOF
20104+
#define WCSTOMBS_L_IN_XLOCALE 1
20105+
_ACEOF
20106+
20107+
fi
2000320108

2000420109
# Some versions of libedit contain strlcpy(), setproctitle(), and other
2000520110
# 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
@@ -1261,6 +1261,7 @@ fi
12611261
PGAC_VAR_INT_TIMEZONE
12621262
AC_FUNC_ACCEPT_ARGTYPES
12631263
PGAC_FUNC_GETTIMEOFDAY_1ARG
1264+
PGAC_FUNC_WCSTOMBS_L
12641265

12651266
# Some versions of libedit contain strlcpy(), setproctitle(), and other
12661267
# 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
@@ -812,6 +812,9 @@
812812
/* Define to select Win32-style shared memory. */
813813
#undef USE_WIN32_SHARED_MEMORY
814814

815+
/* Define to 1 if `wcstombs_l' requires <xlocale.h>. */
816+
#undef WCSTOMBS_L_IN_XLOCALE
817+
815818
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
816819
significant byte first (like Motorola and SPARC, unlike Intel). */
817820
#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
@@ -671,6 +671,9 @@
671671
/* Define to select Win32-style semaphores. */
672672
#define USE_WIN32_SEMAPHORES
673673

674+
/* Define to 1 if `wcstombs_l' requires <xlocale.h>. */
675+
/* #undef WCSTOMBS_L_IN_XLOCALE */
676+
674677
/* Number of bits in a file offset, on hosts where this is settable. */
675678
/* #undef _FILE_OFFSET_BITS */
676679

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)