Skip to content

Commit d949e0a

Browse files
committed
[#26668] YSQL: Import pg commit: Fix detection and handling of strchrnul() for macOS 15.4.
Summary: Import upstream postgres commit `0de9560ba9b8fc4f0de8c5784303db82156279a6` from REL_15_STABLE. Master commit: 6da2ba1d8a031984eb016fed6741bb2ac945f19d **Conflict resolution** None **Upstream commit message** ``` 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 f014b1b9b 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 ``` (cherry picked from commit 0de9560ba9b8fc4f0de8c5784303db82156279a6) Jira: DB-16048 Test Plan: Jenkins Reviewers: jason Reviewed By: jason Subscribers: yql, ybase Differential Revision: https://phorge.dev.yugabyte.com/D43002
1 parent 52f41b6 commit d949e0a

File tree

6 files changed

+33
-23
lines changed

6 files changed

+33
-23
lines changed

src/lint/upstream_repositories.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local_path,upstream_path,repository,commit
2-
src/postgres,,https://github.com/yugabyte/postgres,aed0fe08b8b80a38b9b9a3ed9e66f932ec326caa
2+
src/postgres,,https://github.com/yugabyte/postgres,b47a672a4bf184b43f91ffd8d2514d063655bba5
33
src/postgres/contrib/passwordcheck,passwordcheck_extra,https://github.com/michaelpq/pg_plugins,66a75ea0ca0706bef7b1e17055aa5fd364189fec
44
src/postgres/third-party-extensions/hypopg,,https://github.com/HypoPG/hypopg,97026c0bff16b905c555acdd82e15979fa6b9781
55
src/postgres/third-party-extensions/orafce,,https://github.com/orafce/orafce,6adbd66c429dabb828f10d764d356824efeb8396

src/postgres/configure

+13-1
Original file line numberDiff line numberDiff line change
@@ -16163,7 +16163,7 @@ fi
1616316163
LIBS_including_readline="$LIBS"
1616416164
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
1616516165

16166-
for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred getrlimit inet_pton kqueue mbstowcs_l memset_s poll posix_fallocate ppoll pstat pthread_is_threaded_np readlink readv setproctitle setproctitle_fast setsid shm_open strchrnul strsignal symlink syncfs sync_file_range uselocale wcstombs_l writev
16166+
for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred getrlimit inet_pton kqueue mbstowcs_l memset_s poll posix_fallocate ppoll pstat pthread_is_threaded_np readlink readv setproctitle setproctitle_fast setsid shm_open strsignal symlink syncfs sync_file_range uselocale wcstombs_l writev
1616716167
do :
1616816168
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1616916169
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -16785,6 +16785,18 @@ esac
1678516785

1678616786
fi
1678716787

16788+
ac_fn_c_check_decl "$LINENO" "strchrnul" "ac_cv_have_decl_strchrnul" "#include <string.h>
16789+
"
16790+
if test "x$ac_cv_have_decl_strchrnul" = xyes; then :
16791+
ac_have_decl=1
16792+
else
16793+
ac_have_decl=0
16794+
fi
16795+
16796+
cat >>confdefs.h <<_ACEOF
16797+
#define HAVE_DECL_STRCHRNUL $ac_have_decl
16798+
_ACEOF
16799+
1678816800

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

src/postgres/configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,6 @@ AC_CHECK_FUNCS(m4_normalize([
18241824
setproctitle_fast
18251825
setsid
18261826
shm_open
1827-
strchrnul
18281827
strsignal
18291828
symlink
18301829
syncfs
@@ -1893,6 +1892,7 @@ AC_CHECK_DECLS([strlcat, strlcpy, strnlen])
18931892
# won't handle deployment target restrictions on macOS
18941893
AC_CHECK_DECLS([preadv], [], [AC_LIBOBJ(preadv)], [#include <sys/uio.h>])
18951894
AC_CHECK_DECLS([pwritev], [], [AC_LIBOBJ(pwritev)], [#include <sys/uio.h>])
1895+
AC_CHECK_DECLS([strchrnul], [], [], [#include <string.h>])
18961896

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

src/postgres/src/include/pg_config.h.in

+4-3
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@
153153
don't. */
154154
#undef HAVE_DECL_SIGWAIT
155155

156+
/* Define to 1 if you have the declaration of `strchrnul', and to 0 if you
157+
don't. */
158+
#undef HAVE_DECL_STRCHRNUL
159+
156160
/* Define to 1 if you have the declaration of `strlcat', and to 0 if you
157161
don't. */
158162
#undef HAVE_DECL_STRLCAT
@@ -523,9 +527,6 @@
523527
/* Define to 1 if you have the <stdlib.h> header file. */
524528
#undef HAVE_STDLIB_H
525529

526-
/* Define to 1 if you have the `strchrnul' function. */
527-
#undef HAVE_STRCHRNUL
528-
529530
/* Define to 1 if you have the `strerror_r' function. */
530531
#undef HAVE_STRERROR_R
531532

src/postgres/src/port/snprintf.c

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

350350
/*
351-
* If strchrnul exists (it's a glibc-ism), it's a good bit faster than the
352-
* equivalent manual loop. If it doesn't exist, provide a replacement.
351+
* If strchrnul exists (it's a glibc-ism, but since adopted by some other
352+
* platforms), it's a good bit faster than the equivalent manual loop.
353+
* Use it if possible, and if it doesn't exist, use this replacement.
353354
*
354355
* Note: glibc declares this as returning "char *", but that would require
355356
* casting away const internally, so we don't follow that detail.
357+
*
358+
* Note: macOS has this too as of Sequoia 15.4, but it's hidden behind
359+
* a deployment-target check that causes compile errors if the deployment
360+
* target isn't high enough. So !HAVE_DECL_STRCHRNUL may mean "yes it's
361+
* declared, but it doesn't compile". To avoid failing in that scenario,
362+
* use a macro to avoid matching <string.h>'s name.
356363
*/
357-
#ifndef HAVE_STRCHRNUL
364+
#if !HAVE_DECL_STRCHRNUL
365+
366+
#define strchrnul pg_strchrnul
358367

359368
static inline const char *
360369
strchrnul(const char *s, int c)
@@ -364,19 +373,7 @@ strchrnul(const char *s, int c)
364373
return s;
365374
}
366375

367-
#else
368-
369-
/*
370-
* glibc's <string.h> declares strchrnul only if _GNU_SOURCE is defined.
371-
* While we typically use that on glibc platforms, configure will set
372-
* HAVE_STRCHRNUL whether it's used or not. Fill in the missing declaration
373-
* so that this file will compile cleanly with or without _GNU_SOURCE.
374-
*/
375-
#ifndef _GNU_SOURCE
376-
extern char *strchrnul(const char *s, int c);
377-
#endif
378-
379-
#endif /* HAVE_STRCHRNUL */
376+
#endif /* !HAVE_DECL_STRCHRNUL */
380377

381378

382379
/*

src/postgres/src/tools/msvc/Solution.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ sub GenerateFiles
247247
HAVE_DECL_RTLD_GLOBAL => 0,
248248
HAVE_DECL_RTLD_NOW => 0,
249249
HAVE_DECL_SIGWAIT => 0,
250+
HAVE_DECL_STRCHRNUL => 0,
250251
HAVE_DECL_STRLCAT => 0,
251252
HAVE_DECL_STRLCPY => 0,
252253
HAVE_DECL_STRNLEN => 1,
@@ -367,7 +368,6 @@ sub GenerateFiles
367368
HAVE_STDBOOL_H => 1,
368369
HAVE_STDINT_H => 1,
369370
HAVE_STDLIB_H => 1,
370-
HAVE_STRCHRNUL => undef,
371371
HAVE_STRERROR_R => undef,
372372
HAVE_STRINGS_H => undef,
373373
HAVE_STRING_H => 1,

0 commit comments

Comments
 (0)