Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit440aedc

Browse files
committed
Cope with <regex.h> name clashes.
macOS 15's SDK pulls in headers related to <regex.h> when we include<xlocale.h>. This causes our own regex_t implementation to clash withthe OS's regex_t implementation. Luckily our function names already hadpg_ prefixes, but the macros and typenames did not.Include <regex.h> explicitly on all POSIX systems, and fix everythingthat breaks. Then we can prove that we are capable of fully hiding andreplacing the system regex API with our own.1. Deal with standard-clobbering macros by undefining them all first.POSIX says they are "symbolic constants". If they are macros, thisallows us to redefine them. If they are enums or variables, our macroswill hide them.2. Deal with standard-clobbering types by giving our types pg_prefixes, and then using macros to redirect xxx_t -> pg_xxx_t.After including our "regex/regex.h", the system <regex.h> is hidden,because we've replaced all the standard names. The PostgreSQL sourcetree and extensions can continue to use standard prefix-less type andmacro names, but reach our implementation, if they included our"regex/regex.h" header.Back-patch to all supported branches, so that macOS 15's tool chain canbuild them.Reported-by: Stan Hu <stanhu@gmail.com>Suggested-by: Tom Lane <tgl@sss.pgh.pa.us>Tested-by: Aleksander Alekseev <aleksander@timescale.com>Discussion:https://postgr.es/m/CAMBWrQnEwEJtgOv7EUNsXmFw2Ub4p5P%2B5QTBEgYwiyjy7rAsEQ%40mail.gmail.com
1 parentcfac450 commit440aedc

File tree

2 files changed

+95
-9
lines changed

2 files changed

+95
-9
lines changed

‎src/include/regex/regex.h

Lines changed: 92 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef_REGEX_H_
2-
#define_REGEX_H_/* never again */
1+
#ifndef_PG_REGEX_H_
2+
#define_PG_REGEX_H_/* never again */
33
/*
44
* regular expressions
55
*
@@ -32,6 +32,84 @@
3232
* src/include/regex/regex.h
3333
*/
3434

35+
/*
36+
* This is an implementation of POSIX regex_t, so it clashes with the
37+
* system-provided <regex.h> header. That header might be unintentionally
38+
* included already, so we force that to happen now on all systems to show that
39+
* we can cope and that we completely replace the system regex interfaces.
40+
*
41+
* Note that we avoided using _REGEX_H_ as an include guard, as that confuses
42+
* matters on BSD family systems including macOS that use the same include
43+
* guard.
44+
*/
45+
#ifndef_WIN32
46+
#include<regex.h>
47+
#endif
48+
49+
/* Avoid redefinition errors due to the system header. */
50+
#undef REG_UBACKREF
51+
#undef REG_ULOOKAROUND
52+
#undef REG_UBOUNDS
53+
#undef REG_UBRACES
54+
#undef REG_UBSALNUM
55+
#undef REG_UPBOTCH
56+
#undef REG_UBBS
57+
#undef REG_UNONPOSIX
58+
#undef REG_UUNSPEC
59+
#undef REG_UUNPORT
60+
#undef REG_ULOCALE
61+
#undef REG_UEMPTYMATCH
62+
#undef REG_UIMPOSSIBLE
63+
#undef REG_USHORTEST
64+
#undef REG_BASIC
65+
#undef REG_EXTENDED
66+
#undef REG_ADVF
67+
#undef REG_ADVANCED
68+
#undef REG_QUOTE
69+
#undef REG_NOSPEC
70+
#undef REG_ICASE
71+
#undef REG_NOSUB
72+
#undef REG_EXPANDED
73+
#undef REG_NLSTOP
74+
#undef REG_NLANCH
75+
#undef REG_NEWLINE
76+
#undef REG_PEND
77+
#undef REG_EXPECT
78+
#undef REG_BOSONLY
79+
#undef REG_DUMP
80+
#undef REG_FAKE
81+
#undef REG_PROGRESS
82+
#undef REG_NOTBOL
83+
#undef REG_NOTEOL
84+
#undef REG_STARTEND
85+
#undef REG_FTRACE
86+
#undef REG_MTRACE
87+
#undef REG_SMALL
88+
#undef REG_OKAY
89+
#undef REG_NOMATCH
90+
#undef REG_BADPAT
91+
#undef REG_ECOLLATE
92+
#undef REG_ECTYPE
93+
#undef REG_EESCAPE
94+
#undef REG_ESUBREG
95+
#undef REG_EBRACK
96+
#undef REG_EPAREN
97+
#undef REG_EBRACE
98+
#undef REG_BADBR
99+
#undef REG_ERANGE
100+
#undef REG_ESPACE
101+
#undef REG_BADRPT
102+
#undef REG_ASSERT
103+
#undef REG_INVARG
104+
#undef REG_MIXED
105+
#undef REG_BADOPT
106+
#undef REG_ETOOBIG
107+
#undef REG_ECOLORS
108+
#undef REG_ATOI
109+
#undef REG_ITOA
110+
#undef REG_PREFIX
111+
#undef REG_EXACT
112+
35113
/*
36114
* Add your own defines, if needed, here.
37115
*/
@@ -45,7 +123,7 @@
45123
* regoff_t has to be large enough to hold either off_t or ssize_t,
46124
* and must be signed; it's only a guess that long is suitable.
47125
*/
48-
typedeflongregoff_t;
126+
typedeflongpg_regoff_t;
49127

50128
/*
51129
* other interface types
@@ -77,19 +155,19 @@ typedef struct
77155
/* the rest is opaque pointers to hidden innards */
78156
char*re_guts;/* `char *' is more portable than `void *' */
79157
char*re_fns;
80-
}regex_t;
158+
}pg_regex_t;
81159

82160
/* result reporting (may acquire more fields later) */
83161
typedefstruct
84162
{
85-
regoff_trm_so;/* start of substring */
86-
regoff_trm_eo;/* end of substring */
87-
}regmatch_t;
163+
pg_regoff_trm_so;/* start of substring */
164+
pg_regoff_trm_eo;/* end of substring */
165+
}pg_regmatch_t;
88166

89167
/* supplementary control and reporting */
90168
typedefstruct
91169
{
92-
regmatch_trm_extend;/* see REG_EXPECT */
170+
pg_regmatch_trm_extend;/* see REG_EXPECT */
93171
}rm_detail_t;
94172

95173

@@ -163,6 +241,11 @@ typedef struct
163241
#defineREG_EXACT(-2)/* identified an exact match */
164242

165243

244+
/* Redirect the standard typenames to our typenames. */
245+
#defineregoff_t pg_regoff_t
246+
#defineregex_t pg_regex_t
247+
#defineregmatch_t pg_regmatch_t
248+
166249

167250
/*
168251
* the prototypes for exported functions
@@ -181,4 +264,4 @@ extern bool RE_compile_and_execute(text *text_re, char *dat, int dat_len,
181264
intcflags,Oidcollation,
182265
intnmatch,regmatch_t*pmatch);
183266

184-
#endif/*_REGEX_H_ */
267+
#endif/*_PG_REGEX_H_ */

‎src/tools/pgindent/typedefs.list

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3172,6 +3172,9 @@ pg_locale_t
31723172
pg_mb_radix_tree
31733173
pg_on_exit_callback
31743174
pg_re_flags
3175+
pg_regex_t
3176+
pg_regmatch_t
3177+
pg_regoff_t
31753178
pg_saslprep_rc
31763179
pg_sha224_ctx
31773180
pg_sha256_ctx

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp