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

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




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, 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).

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.

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




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, 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).

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.

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..f7aa7cf3a3 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__)
+/*
+ * macOS 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




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

From
Michael Paquier
Date:
On Mon, Jun 24, 2024 at 02:58:47PM -0700, Stan Hu wrote:
> 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>

Ugh.  Which means that you are testing macOS Sequoia still in beta
phase?  Thanks for the report.

Perhaps we should wait for the actual release before seeing if this is
still an issue and see if this is still a problem?  Tom is a heavy
macOS user, I'm still under 14 myself for some time.
--
Michael

Attachment
Michael Paquier <michael@paquier.xyz> writes:
> Ugh.  Which means that you are testing macOS Sequoia still in beta
> phase?  Thanks for the report.

> Perhaps we should wait for the actual release before seeing if this is
> still an issue and see if this is still a problem?  Tom is a heavy
> macOS user, I'm still under 14 myself for some time.

Yeah, I'm not in a huge hurry to act on this.  The problem may
go away by the time SDK 15 gets out of beta --- in fact, I think
it'd be a good idea to file a bug with Apple complaining that this
pointless-looking change breaks third-party code.  If it doesn't
go away, we're going to have to back-patch all supported branches
(and, really, even out-of-support ones back to 9.2); which puts a
large premium on getting the patch right.  So we have both time to
think about it and good reason to be careful.

(I've not yet read any of Stan's proposed patches.)

            regards, tom lane



Thanks, Tom and Michael. I've submitted a bug report via Apple's
Feedback Assistant. It's filed under FB14047412.

If anyone happens to know the right person at Apple to look at this,
please direct them there.

On Mon, Jun 24, 2024 at 7:15 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Michael Paquier <michael@paquier.xyz> writes:
> > Ugh.  Which means that you are testing macOS Sequoia still in beta
> > phase?  Thanks for the report.
>
> > Perhaps we should wait for the actual release before seeing if this is
> > still an issue and see if this is still a problem?  Tom is a heavy
> > macOS user, I'm still under 14 myself for some time.
>
> Yeah, I'm not in a huge hurry to act on this.  The problem may
> go away by the time SDK 15 gets out of beta --- in fact, I think
> it'd be a good idea to file a bug with Apple complaining that this
> pointless-looking change breaks third-party code.  If it doesn't
> go away, we're going to have to back-patch all supported branches
> (and, really, even out-of-support ones back to 9.2); which puts a
> large premium on getting the patch right.  So we have both time to
> think about it and good reason to be careful.
>
> (I've not yet read any of Stan's proposed patches.)
>
>                         regards, tom lane