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

From: Stan Hu <stanhu(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: Stan Hu <stanhu(at)gmail(dot)com>
Subject: [PATCH v3] Fix type redefinition build errors with macOS SDK 15.0
Date: 2024-06-24 22:20:25
Message-ID: 5329c60d4c9d1b6d17719f90594f36a6d470c8f8.1719266466.git.stanhu@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2024-06-24 22:53:46 Re: improve predefined roles documentation
Previous Message Joel Jacobson 2024-06-24 22:20:20 Re: [PATCH] Add ACL (Access Control List) acronym