Subject: [PATCH] Fix type redefinition build errors with macOS SDK 15.0

From: Stan Hu <[email-masked]>
Date: Mon, 24 Jun 2024 14:51:07 -0700

Prior to macOS SDK 15, there were include guards in
$SDK_ROOT/usr/include/xlocale/_regex.h:

  #ifndef _REGEX_H_
  #include <_regex.h>
  #endif // _REGEX_H_
  #include <_xlocale.h>

In macOS SDK 15.5, these include guards are gone:

  #include <_regex.h>
  #include <_xlocale.h>

Because _REGEX_H_ was defined locally in PostgreSQL's version of
src/include/regex/regex.h, these include guards prevented duplicate
definitions from $SDK_ROOT/usr/include/_regex.h (not to be confused
with $SDK_ROOT/usr/include/xlocale/_regex.h).

To fix this build issue, define __REGEX_H_ to prevent macOS from
including the header that contain redefinitions of the local regex
structures.

Discussion: https://www.postgresql.org/message-id/CAMBWrQ%3DF9SSPfsFtCv%3DJT51WGK2VcgLA%2BiiJJOmjN0zbbufOEA%40mail.gmail.com
---
 src/include/regex/regex.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/include/regex/regex.h b/src/include/regex/regex.h
index d08113724f..045ac626cc 100644
--- a/src/include/regex/regex.h
+++ b/src/include/regex/regex.h
@@ -32,6 +32,20 @@
  * src/include/regex/regex.h
  */
 
+#if defined(__darwin__)
+/*
+ * mmacOS SDK 15.0 removed the _REGEX_H_ include guards in
+ * $SDK_ROOT/usr/include/xlocale/_regex.h, so now
+ * $SDK_ROOT/usr/include/_regex.h is always included. That file defines
+ * the same types as below. To guard against type redefinition errors,
+ * define __REGEX_H_.
+ */
+#ifndef __REGEX_H_
+#define __REGEX_H_
+
+#endif							/* __REGEX_H_ */
+#endif
+
 /*
  * Add your own defines, if needed, here.
  */
-- 
2.45.0

---

From: Stan Hu <[email-masked]>
Date: Mon, 24 Jun 2024 14:58:47 -0700

#ifndef _REGEX_H_
  #include <_regex.h>
  #endif // _REGEX_H_
  #include <_xlocale.h>

In macOS SDK 15, these include guards are gone:

  #include <_regex.h>
  #include <_xlocale.h>

As a result, attempting to compile PostgreSQL with macOS SDK 15 fails
with "previous definition is here" errors for regoff_t, regex_t, and
regmatch_t structures.

 
+#if defined(__darwin__)
+/*