Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6da2ba1

Browse files
tglsfdcpetere
andcommitted
Fix detection and handling of strchrnul() for macOS 15.4.
As of 15.4, macOS has strchrnul(), but access to it is blocked behind a check for MACOSX_DEPLOYMENT_TARGET >= 15.4. But our does-it-link configure check finds it, so we try to use it, and fail with the present default deployment target (namely 15.0). This accounts for today's buildfarm failures on indri and sifaka. This is the identical problem that we faced some years ago when Apple introduced preadv and pwritev in the same way. We solved that in commit f014b1b by using AC_CHECK_DECLS instead of AC_CHECK_FUNCS to check the functions' availability. So do the same now for strchrnul(). Interestingly, we already had a workaround for "the link check doesn't agree with <string.h>" cases with glibc, which we no longer need since only the header declaration is being checked. Testing this revealed that the meson version of this check has never worked, because it failed to use "-Werror=unguarded-availability-new". (Apparently nobody's tried to build with meson on macOS versions that lack preadv/pwritev as standard.) Adjust that while at it. Also, we had never put support for "-Werror=unguarded-availability-new" into v13, but we need that now. Co-authored-by: Tom Lane <[email protected]> Co-authored-by: Peter Eisentraut <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 13
1 parent c313fa4 commit 6da2ba1

File tree

5 files changed

+49
-24
lines changed

5 files changed

+49
-24
lines changed

configure

+13-1
Original file line numberDiff line numberDiff line change
@@ -15401,7 +15401,7 @@ fi
1540115401
LIBS_including_readline="$LIBS"
1540215402
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
1540315403

15404-
for ac_func in backtrace_symbols copyfile copy_file_range elf_aux_info getauxval getifaddrs getpeerucred inet_pton kqueue localeconv_l mbstowcs_l memset_s posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strchrnul strsignal syncfs sync_file_range uselocale wcstombs_l
15404+
for ac_func in backtrace_symbols copyfile copy_file_range elf_aux_info getauxval getifaddrs getpeerucred inet_pton kqueue localeconv_l mbstowcs_l memset_s posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strsignal syncfs sync_file_range uselocale wcstombs_l
1540515405
do :
1540615406
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1540715407
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -15955,6 +15955,18 @@ cat >>confdefs.h <<_ACEOF
1595515955
#define HAVE_DECL_PWRITEV $ac_have_decl
1595615956
_ACEOF
1595715957

15958+
ac_fn_c_check_decl "$LINENO" "strchrnul" "ac_cv_have_decl_strchrnul" "#include <string.h>
15959+
"
15960+
if test "x$ac_cv_have_decl_strchrnul" = xyes; then :
15961+
ac_have_decl=1
15962+
else
15963+
ac_have_decl=0
15964+
fi
15965+
15966+
cat >>confdefs.h <<_ACEOF
15967+
#define HAVE_DECL_STRCHRNUL $ac_have_decl
15968+
_ACEOF
15969+
1595815970

1595915971
# This is probably only present on macOS, but may as well check always
1596015972
ac_fn_c_check_decl "$LINENO" "F_FULLFSYNC" "ac_cv_have_decl_F_FULLFSYNC" "#include <fcntl.h>

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,6 @@ AC_CHECK_FUNCS(m4_normalize([
17721772
pthread_is_threaded_np
17731773
setproctitle
17741774
setproctitle_fast
1775-
strchrnul
17761775
strsignal
17771776
syncfs
17781777
sync_file_range
@@ -1812,6 +1811,7 @@ AC_CHECK_DECLS([strlcat, strlcpy, strnlen, strsep])
18121811
# won't handle deployment target restrictions on macOS
18131812
AC_CHECK_DECLS([preadv], [], [], [#include <sys/uio.h>])
18141813
AC_CHECK_DECLS([pwritev], [], [], [#include <sys/uio.h>])
1814+
AC_CHECK_DECLS([strchrnul], [], [], [#include <string.h>])
18151815

18161816
# This is probably only present on macOS, but may as well check always
18171817
AC_CHECK_DECLS(F_FULLFSYNC, [], [], [#include <fcntl.h>])

meson.build

+18-3
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,7 @@ decl_checks = [
25772577
decl_checks += [
25782578
['preadv', 'sys/uio.h'],
25792579
['pwritev', 'sys/uio.h'],
2580+
['strchrnul', 'string.h'],
25802581
]
25812582

25822583
# Check presence of some optional LLVM functions.
@@ -2593,8 +2594,23 @@ foreach c : decl_checks
25932594
args = c.get(2, {})
25942595
varname = 'HAVE_DECL_' + func.underscorify().to_upper()
25952596

2596-
found = cc.has_header_symbol(header, func,
2597-
args: test_c_args, include_directories: postgres_inc,
2597+
found = cc.compiles('''
2598+
#include <@0@>
2599+
2600+
int main()
2601+
{
2602+
#ifndef @1@
2603+
(void) @1@;
2604+
#endif
2605+
2606+
return 0;
2607+
}
2608+
'''.format(header, func),
2609+
name: 'test whether @0@ is declared'.format(func),
2610+
# need to add cflags_warn to get at least
2611+
# -Werror=unguarded-availability-new if applicable
2612+
args: test_c_args + cflags_warn,
2613+
include_directories: postgres_inc,
25982614
kwargs: args)
25992615
cdata.set10(varname, found, description:
26002616
'''Define to 1 if you have the declaration of `@0@', and to 0 if you
@@ -2802,7 +2818,6 @@ func_checks = [
28022818
['shm_unlink', {'dependencies': [rt_dep], 'define': false}],
28032819
['shmget', {'dependencies': [cygipc_dep], 'define': false}],
28042820
['socket', {'dependencies': [socket_dep], 'define': false}],
2805-
['strchrnul'],
28062821
['strerror_r', {'dependencies': [thread_dep]}],
28072822
['strlcat'],
28082823
['strlcpy'],

src/include/pg_config.h.in

+4-3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@
103103
don't. */
104104
#undef HAVE_DECL_PWRITEV
105105

106+
/* Define to 1 if you have the declaration of `strchrnul', and to 0 if you
107+
don't. */
108+
#undef HAVE_DECL_STRCHRNUL
109+
106110
/* Define to 1 if you have the declaration of `strlcat', and to 0 if you
107111
don't. */
108112
#undef HAVE_DECL_STRLCAT
@@ -373,9 +377,6 @@
373377
/* Define to 1 if you have the <stdlib.h> header file. */
374378
#undef HAVE_STDLIB_H
375379

376-
/* Define to 1 if you have the `strchrnul' function. */
377-
#undef HAVE_STRCHRNUL
378-
379380
/* Define to 1 if you have the `strerror_r' function. */
380381
#undef HAVE_STRERROR_R
381382

src/port/snprintf.c

+13-16
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,22 @@ static void leading_pad(int zpad, int signvalue, int *padlen,
338338
static void trailing_pad(int padlen, PrintfTarget *target);
339339

340340
/*
341-
* If strchrnul exists (it's a glibc-ism), it's a good bit faster than the
342-
* equivalent manual loop. If it doesn't exist, provide a replacement.
341+
* If strchrnul exists (it's a glibc-ism, but since adopted by some other
342+
* platforms), it's a good bit faster than the equivalent manual loop.
343+
* Use it if possible, and if it doesn't exist, use this replacement.
343344
*
344345
* Note: glibc declares this as returning "char *", but that would require
345346
* casting away const internally, so we don't follow that detail.
347+
*
348+
* Note: macOS has this too as of Sequoia 15.4, but it's hidden behind
349+
* a deployment-target check that causes compile errors if the deployment
350+
* target isn't high enough. So !HAVE_DECL_STRCHRNUL may mean "yes it's
351+
* declared, but it doesn't compile". To avoid failing in that scenario,
352+
* use a macro to avoid matching <string.h>'s name.
346353
*/
347-
#ifndef HAVE_STRCHRNUL
354+
#if !HAVE_DECL_STRCHRNUL
355+
356+
#define strchrnul pg_strchrnul
348357

349358
static inline const char *
350359
strchrnul(const char *s, int c)
@@ -354,19 +363,7 @@ strchrnul(const char *s, int c)
354363
return s;
355364
}
356365

357-
#else
358-
359-
/*
360-
* glibc's <string.h> declares strchrnul only if _GNU_SOURCE is defined.
361-
* While we typically use that on glibc platforms, configure will set
362-
* HAVE_STRCHRNUL whether it's used or not. Fill in the missing declaration
363-
* so that this file will compile cleanly with or without _GNU_SOURCE.
364-
*/
365-
#ifndef _GNU_SOURCE
366-
extern char *strchrnul(const char *s, int c);
367-
#endif
368-
369-
#endif /* HAVE_STRCHRNUL */
366+
#endif /* !HAVE_DECL_STRCHRNUL */
370367

371368

372369
/*

0 commit comments

Comments
 (0)