Skip to content

Commit a39eb9c

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 <tgl@sss.pgh.pa.us> Co-authored-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://postgr.es/m/385134.1743523038@sss.pgh.pa.us Backpatch-through: 13
1 parent 8d4cd3b commit a39eb9c

File tree

6 files changed

+50
-25
lines changed

6 files changed

+50
-25
lines changed

configure

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15715,7 +15715,7 @@ fi
1571515715
LIBS_including_readline="$LIBS"
1571615716
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
1571715717

15718-
for ac_func in backtrace_symbols copyfile getifaddrs getpeerucred inet_pton kqueue mbstowcs_l memset_s posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strchrnul strsignal syncfs sync_file_range uselocale wcstombs_l
15718+
for ac_func in backtrace_symbols copyfile getifaddrs getpeerucred inet_pton kqueue mbstowcs_l memset_s posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strsignal syncfs sync_file_range uselocale wcstombs_l
1571915719
do :
1572015720
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1572115721
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -16279,6 +16279,18 @@ esac
1627916279

1628016280
fi
1628116281

16282+
ac_fn_c_check_decl "$LINENO" "strchrnul" "ac_cv_have_decl_strchrnul" "#include <string.h>
16283+
"
16284+
if test "x$ac_cv_have_decl_strchrnul" = xyes; then :
16285+
ac_have_decl=1
16286+
else
16287+
ac_have_decl=0
16288+
fi
16289+
16290+
cat >>confdefs.h <<_ACEOF
16291+
#define HAVE_DECL_STRCHRNUL $ac_have_decl
16292+
_ACEOF
16293+
1628216294

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

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,6 @@ AC_CHECK_FUNCS(m4_normalize([
18091809
pthread_is_threaded_np
18101810
setproctitle
18111811
setproctitle_fast
1812-
strchrnul
18131812
strsignal
18141813
syncfs
18151814
sync_file_range
@@ -1849,6 +1848,7 @@ AC_CHECK_DECLS([strlcat, strlcpy, strnlen])
18491848
# won't handle deployment target restrictions on macOS
18501849
AC_CHECK_DECLS([preadv], [], [AC_LIBOBJ(preadv)], [#include <sys/uio.h>])
18511850
AC_CHECK_DECLS([pwritev], [], [AC_LIBOBJ(pwritev)], [#include <sys/uio.h>])
1851+
AC_CHECK_DECLS([strchrnul], [], [], [#include <string.h>])
18521852

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

meson.build

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,6 +2323,7 @@ decl_checks = [
23232323
decl_checks += [
23242324
['preadv', 'sys/uio.h'],
23252325
['pwritev', 'sys/uio.h'],
2326+
['strchrnul', 'string.h'],
23262327
]
23272328

23282329
foreach c : decl_checks
@@ -2331,8 +2332,23 @@ foreach c : decl_checks
23312332
args = c.get(2, {})
23322333
varname = 'HAVE_DECL_' + func.underscorify().to_upper()
23332334

2334-
found = cc.has_header_symbol(header, func,
2335-
args: test_c_args, include_directories: postgres_inc,
2335+
found = cc.compiles('''
2336+
#include <@0@>
2337+
2338+
int main()
2339+
{
2340+
#ifndef @1@
2341+
(void) @1@;
2342+
#endif
2343+
2344+
return 0;
2345+
}
2346+
'''.format(header, func),
2347+
name: 'test whether @0@ is declared'.format(func),
2348+
# need to add cflags_warn to get at least
2349+
# -Werror=unguarded-availability-new if applicable
2350+
args: test_c_args + cflags_warn,
2351+
include_directories: postgres_inc,
23362352
kwargs: args)
23372353
cdata.set10(varname, found, description:
23382354
'''Define to 1 if you have the declaration of `@0@', and to 0 if you
@@ -2579,7 +2595,6 @@ func_checks = [
25792595
['shm_unlink', {'dependencies': [rt_dep], 'define': false}],
25802596
['shmget', {'dependencies': [cygipc_dep], 'define': false}],
25812597
['socket', {'dependencies': [socket_dep], 'define': false}],
2582-
['strchrnul'],
25832598
['strerror_r', {'dependencies': [thread_dep]}],
25842599
['strlcat'],
25852600
['strlcpy'],

src/include/pg_config.h.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@
128128
don't. */
129129
#undef HAVE_DECL_PWRITEV
130130

131+
/* Define to 1 if you have the declaration of `strchrnul', and to 0 if you
132+
don't. */
133+
#undef HAVE_DECL_STRCHRNUL
134+
131135
/* Define to 1 if you have the declaration of `strlcat', and to 0 if you
132136
don't. */
133137
#undef HAVE_DECL_STRLCAT
@@ -409,9 +413,6 @@
409413
/* Define to 1 if you have the <stdlib.h> header file. */
410414
#undef HAVE_STDLIB_H
411415

412-
/* Define to 1 if you have the `strchrnul' function. */
413-
#undef HAVE_STRCHRNUL
414-
415416
/* Define to 1 if you have the `strerror_r' function. */
416417
#undef HAVE_STRERROR_R
417418

src/port/snprintf.c

Lines changed: 13 additions & 16 deletions
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
/*

src/tools/msvc/Solution.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ sub GenerateFiles
241241
HAVE_DECL_POSIX_FADVISE => 0,
242242
HAVE_DECL_PREADV => 0,
243243
HAVE_DECL_PWRITEV => 0,
244+
HAVE_DECL_STRCHRNUL => 0,
244245
HAVE_DECL_STRLCAT => 0,
245246
HAVE_DECL_STRLCPY => 0,
246247
HAVE_DECL_STRNLEN => 1,
@@ -332,7 +333,6 @@ sub GenerateFiles
332333
HAVE_SSL_CTX_SET_NUM_TICKETS => undef,
333334
HAVE_STDINT_H => 1,
334335
HAVE_STDLIB_H => 1,
335-
HAVE_STRCHRNUL => undef,
336336
HAVE_STRERROR_R => undef,
337337
HAVE_STRINGS_H => undef,
338338
HAVE_STRING_H => 1,

0 commit comments

Comments
 (0)