Skip to content

Commit

Permalink
Update Postgres to 13.8 and backport bc7a40b4 to fix new Xcode build
Browse files Browse the repository at this point in the history
See https://postgr.es/m/[email protected] for discussion
of the Xcode build issue. Fixed in bc7a40b4, which is on REL_13_STABLE but
not yet in an official Postgres release.

In passing this also fixes a extract source issue with newer clang
versions.
  • Loading branch information
lfittl committed Nov 2, 2022
1 parent da177d0 commit 662539d
Show file tree
Hide file tree
Showing 132 changed files with 2,063 additions and 522 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARLIB = lib$(TARGET).a
PGDIR = $(root_dir)/tmp/postgres
PGDIRBZ2 = $(root_dir)/tmp/postgres.tar.bz2

PG_VERSION = 13.3
PG_VERSION = 13.8
PG_VERSION_MAJOR = $(call word-dot,$(PG_VERSION),1)
PROTOC_VERSION = 3.14.0

Expand Down Expand Up @@ -120,6 +120,7 @@ $(PGDIR):
cd $(PGDIR); patch -p1 < $(root_dir)/patches/06_alloc_set_delete_free_list.patch
cd $(PGDIR); patch -p1 < $(root_dir)/patches/07_plpgsql_start_finish_datums.patch
cd $(PGDIR); patch -p1 < $(root_dir)/patches/08_avoid_zero_length_delimiter_in_regression_tests.patch
cd $(PGDIR); patch -p1 < $(root_dir)/patches/09_backport_gram_ref_p_fix.patch
cd $(PGDIR); ./configure $(PG_CONFIGURE_FLAGS)
cd $(PGDIR); rm src/pl/plpgsql/src/pl_gram.h
cd $(PGDIR); make -C src/pl/plpgsql/src pl_gram.h
Expand All @@ -133,6 +134,7 @@ extract_source: $(PGDIR)
mkdir ./src/postgres/include
LIBCLANG=/Library/Developer/CommandLineTools/usr/lib/libclang.dylib ruby ./scripts/extract_source.rb $(PGDIR)/ ./src/postgres/
cp $(PGDIR)/src/include/storage/dsm_impl.h ./src/postgres/include/storage
cp $(PGDIR)/src/include/port/atomics/arch-x86.h ./src/postgres/include/port/atomics
cp $(PGDIR)/src/include/port/atomics/arch-arm.h ./src/postgres/include/port/atomics
cp $(PGDIR)/src/include/port/atomics/arch-ppc.h ./src/postgres/include/port/atomics
touch ./src/postgres/guc-file.c
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ This will output the parse tree (whitespace adjusted here for better readability

```json
{
"version": 130003,
"version": 130008,
"stmts": [
{
"stmt": {
Expand Down Expand Up @@ -124,7 +124,7 @@ int main() {
This will output the following:

```
version: 130003, tokens: 7, size: 77
version: 130008, tokens: 7, size: 77
"SELECT" = [ 0, 6, SELECT, RESERVED_KEYWORD ]
"update" = [ 7, 13, UPDATE, UNRESERVED_KEYWORD ]
"AS" = [ 14, 16, AS, RESERVED_KEYWORD ]
Expand Down
4 changes: 2 additions & 2 deletions patches/01_parser_additional_param_ref_support.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commit 2be7057a595bdf4794dd4f9397de19a0fcd0dc23
commit 708fe3468d0f373c2208ae927d0de52247f2fda8
Author: Lukas Fittl <[email protected]>
Date: Sun Jan 3 15:06:25 2021 -0800

Expand All @@ -23,7 +23,7 @@ Date: Sun Jan 3 15:06:25 2021 -0800
SELECT INTERVAL (6) $1;

diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 3adc087e3f..cf2b521c23 100644
index 74339aa4db..4529fea74e 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -162,6 +162,8 @@ static Node *makeBitStringConst(char *str, int location);
Expand Down
6 changes: 3 additions & 3 deletions patches/02_parser_support_question_mark_as_param_ref.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commit 911e2c633fc9f75ea587f9763470ee6140cea0f1
commit c813b6930bd68577f7db381ff9178a807c989942
Author: Lukas Fittl <[email protected]>
Date: Sun Jan 3 15:56:21 2021 -0800

Expand All @@ -14,7 +14,7 @@ Date: Sun Jan 3 15:56:21 2021 -0800
should be considered deprecated.

diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index cf2b521c23..ad796b87e1 100644
index 4529fea74e..8beb6fef5e 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -164,6 +164,7 @@ static Node *makeAConst(Value *v, int location);
Expand Down Expand Up @@ -250,7 +250,7 @@ index cf2b521c23..ad796b87e1 100644
* Create a RoleSpec with the given type
*/
diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index b1ea0cb538..9ba31f418c 100644
index b1ea0cb538..a0dfcf3b99 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -277,6 +277,9 @@ xehexesc [\\]x[0-9A-Fa-f]{1,2}
Expand Down
6 changes: 3 additions & 3 deletions patches/03_lexer_track_yyllocend.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commit 70279ba982378d70ba19e312bf5acd627109acce
commit 386cf95ca17d28ae4bc7db92a784ab8f6dde9f8b
Author: Lukas Fittl <[email protected]>
Date: Sun Jan 3 15:59:40 2021 -0800

Expand All @@ -8,7 +8,7 @@ Date: Sun Jan 3 15:59:40 2021 -0800
as this is made available by pg_query for uses such as syntax highlighting.

diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index 9ba31f418c..5caa03e395 100644
index a0dfcf3b99..768170bb30 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -517,6 +517,7 @@ other .
Expand Down Expand Up @@ -75,7 +75,7 @@ index 9ba31f418c..5caa03e395 100644
return IDENT;
}

@@ -1065,6 +1074,7 @@ other .
@@ -1068,6 +1077,7 @@ other .
*/
ident = downcase_truncate_identifier(yytext, yyleng, true);
yylval->str = ident;
Expand Down
8 changes: 4 additions & 4 deletions patches/04_lexer_comments_as_tokens.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commit 2e6aded5d64f6825e8e4e100d2234b3e89b62cd6
commit 17aa7e51f4a3bf12d4662720ef39f6f60336dc83
Author: Lukas Fittl <[email protected]>
Date: Sun Jan 3 16:01:44 2021 -0800

Expand All @@ -12,7 +12,7 @@ Date: Sun Jan 3 16:01:44 2021 -0800
this change, the lexer returns them as SQL_COMMENT/C_COMMENT tokens.

diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index bcdda00a3a..9a581cbde6 100644
index 8beb6fef5e..f2c963e801 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -620,6 +620,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
Expand All @@ -38,7 +38,7 @@ index be86eb37fe..07b8fd486f 100644
return cur_token;
}
diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index 5caa03e395..6d7e2f0f12 100644
index 768170bb30..24fd149497 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -223,7 +223,7 @@ non_newline [^\n\r]
Expand Down Expand Up @@ -100,7 +100,7 @@ index a2eeeba217..cbfb92384a 100644
return cur_token;
}
diff --git a/src/pl/plpgsql/src/pl_gram.y b/src/pl/plpgsql/src/pl_gram.y
index 3e84162487..d1e6e714ab 100644
index fc6cedb7a4..1cf9405d81 100644
--- a/src/pl/plpgsql/src/pl_gram.y
+++ b/src/pl/plpgsql/src/pl_gram.y
@@ -236,6 +236,7 @@ static void check_raise_parameters(PLpgSQL_stmt_raise *stmt);
Expand Down
2 changes: 1 addition & 1 deletion patches/05_limit_option_enum_value_default.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commit d72ada28933f0e04fe2b4481f7886997050ec403
commit e855d8c81a0cd73aa1913825e7b4395961e6f2c9
Author: Lukas Fittl <[email protected]>
Date: Sun Jan 3 15:57:25 2021 -0800

Expand Down
2 changes: 1 addition & 1 deletion patches/06_alloc_set_delete_free_list.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commit bac06c62ccb4d4d5bfa7ae30e3ebef64f37d2254
commit f716536100e86bb410341daf3f84cf23f4e3adc2
Author: Lukas Fittl <[email protected]>
Date: Sat Jan 9 23:42:42 2021 -0800

Expand Down
10 changes: 5 additions & 5 deletions patches/07_plpgsql_start_finish_datums.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commit 80cb7dcdd721b21fd1e56e915482fd4345a80b17
commit 4850baf8039f2714d01c45a64af7ccbd12bbbd64
Author: Lukas Fittl <[email protected]>
Date: Sun Jan 10 00:28:33 2021 -0800

Expand All @@ -8,7 +8,7 @@ Date: Sun Jan 10 00:28:33 2021 -0800
the already exported plpgsql_adddatum.

diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c
index 828ff5a288..4670fcafa2 100644
index cb0ce3900b..fbd0ad8bd0 100644
--- a/src/pl/plpgsql/src/pl_comp.c
+++ b/src/pl/plpgsql/src/pl_comp.c
@@ -105,8 +105,6 @@ static Node *make_datum_param(PLpgSQL_expr *expr, int dno, int location);
Expand All @@ -20,7 +20,7 @@ index 828ff5a288..4670fcafa2 100644
static void compute_function_hashkey(FunctionCallInfo fcinfo,
Form_pg_proc procStruct,
PLpgSQL_func_hashkey *hashkey,
@@ -2270,7 +2268,7 @@ plpgsql_parse_err_condition(char *condname)
@@ -2272,7 +2270,7 @@ plpgsql_parse_err_condition(char *condname)
* plpgsql_start_datums Initialize datum list at compile startup.
* ----------
*/
Expand All @@ -29,7 +29,7 @@ index 828ff5a288..4670fcafa2 100644
plpgsql_start_datums(void)
{
datums_alloc = 128;
@@ -2304,7 +2302,7 @@ plpgsql_adddatum(PLpgSQL_datum *newdatum)
@@ -2306,7 +2304,7 @@ plpgsql_adddatum(PLpgSQL_datum *newdatum)
* plpgsql_finish_datums Copy completed datum info into function struct.
* ----------
*/
Expand All @@ -39,7 +39,7 @@ index 828ff5a288..4670fcafa2 100644
{
Size copiable_size = 0;
diff --git a/src/pl/plpgsql/src/plpgsql.h b/src/pl/plpgsql/src/plpgsql.h
index 0c3d30fb13..25fdd20bbf 100644
index bc6eefb60b..53864ca881 100644
--- a/src/pl/plpgsql/src/plpgsql.h
+++ b/src/pl/plpgsql/src/plpgsql.h
@@ -1263,6 +1263,8 @@ extern PLpgSQL_recfield *plpgsql_build_recfield(PLpgSQL_rec *rec,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commit da83e9064fad6128f1968df975b3ad56377a4476
commit 48cc023e889e02f8f172c5130a6f958c92da3ddf
Author: Lukas Fittl <[email protected]>
Date: Sat Feb 20 04:38:04 2021 -0800

Expand Down
71 changes: 71 additions & 0 deletions patches/09_backport_gram_ref_p_fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
commit c3506d3dd7ca1fd2ad88a038bce507f104b1e53f
Author: Tom Lane <[email protected]>
Date: Sun Oct 16 15:27:04 2022 -0400

Rename parser token REF to REF_P to avoid a symbol conflict.

In the latest version of Apple's macOS SDK, <sys/socket.h>
fails to compile if "REF" is #define'd as something.
Apple may or may not agree that this is a bug, and even if
they do accept the bug report I filed, they probably won't
fix it very quickly. In the meantime, our back branches will all
fail to compile gram.y. v15 and HEAD currently escape the problem
thanks to the refactoring done in 98e93a1fc, but that's purely
accidental. Moreover, since that patch removed a widely-visible
inclusion of <netdb.h>, back-patching it seems too likely to break
third-party code.

Instead, change the token's code name to REF_P, following our usual
convention for naming parser tokens that are likely to have symbol
conflicts. The effects of that should be localized to the grammar
and immediately surrounding files, so it seems like a safer answer.

Per project policy that we want to keep recently-out-of-support
branches buildable on modern systems, back-patch all the way to 9.2.

Discussion: https://postgr.es/m/[email protected]

diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index f2c963e801..fc1de59430 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -692,7 +692,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);

QUOTE

- RANGE READ REAL REASSIGN RECHECK RECURSIVE REF REFERENCES REFERENCING
+ RANGE READ REAL REASSIGN RECHECK RECURSIVE REF_P REFERENCES REFERENCING
REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
RESET RESTART RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
ROUTINE ROUTINES ROW ROWS RULE
@@ -14369,7 +14369,7 @@ xmlexists_argument:
;

xml_passing_mech:
- BY REF
+ BY REF_P
| BY VALUE_P
;

@@ -15660,7 +15660,7 @@ unreserved_keyword:
| REASSIGN
| RECHECK
| RECURSIVE
- | REF
+ | REF_P
| REFERENCING
| REFRESH
| REINDEX
diff --git a/src/include/parser/kwlist.h b/src/include/parser/kwlist.h
index 08f22ce211..4121a53ba0 100644
--- a/src/include/parser/kwlist.h
+++ b/src/include/parser/kwlist.h
@@ -330,7 +330,7 @@ PG_KEYWORD("real", REAL, COL_NAME_KEYWORD)
PG_KEYWORD("reassign", REASSIGN, UNRESERVED_KEYWORD)
PG_KEYWORD("recheck", RECHECK, UNRESERVED_KEYWORD)
PG_KEYWORD("recursive", RECURSIVE, UNRESERVED_KEYWORD)
-PG_KEYWORD("ref", REF, UNRESERVED_KEYWORD)
+PG_KEYWORD("ref", REF_P, UNRESERVED_KEYWORD)
PG_KEYWORD("references", REFERENCES, RESERVED_KEYWORD)
PG_KEYWORD("referencing", REFERENCING, UNRESERVED_KEYWORD)
PG_KEYWORD("refresh", REFRESH, UNRESERVED_KEYWORD)
4 changes: 2 additions & 2 deletions pg_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ void pg_query_free_fingerprint_result(PgQueryFingerprintResult result);
void pg_query_exit(void);

// Postgres version information
#define PG_VERSION "13.3"
#define PG_VERSION "13.8"
#define PG_MAJORVERSION "13"
#define PG_VERSION_NUM 130003
#define PG_VERSION_NUM 130008

// Deprecated APIs below

Expand Down
23 changes: 18 additions & 5 deletions protobuf/pg_query.pb-c.c
Original file line number Diff line number Diff line change
Expand Up @@ -20686,7 +20686,7 @@ const ProtobufCMessageDescriptor pg_query__alter_table_stmt__descriptor =
(ProtobufCMessageInit) pg_query__alter_table_stmt__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor pg_query__alter_table_cmd__field_descriptors[7] =
static const ProtobufCFieldDescriptor pg_query__alter_table_cmd__field_descriptors[8] =
{
{
"subtype",
Expand Down Expand Up @@ -20772,6 +20772,18 @@ static const ProtobufCFieldDescriptor pg_query__alter_table_cmd__field_descripto
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"recurse",
8,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_BOOL,
0, /* quantifier_offset */
offsetof(PgQuery__AlterTableCmd, recurse),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
};
static const unsigned pg_query__alter_table_cmd__field_indices_by_name[] = {
5, /* field[5] = behavior */
Expand All @@ -20780,12 +20792,13 @@ static const unsigned pg_query__alter_table_cmd__field_indices_by_name[] = {
1, /* field[1] = name */
3, /* field[3] = newowner */
2, /* field[2] = num */
7, /* field[7] = recurse */
0, /* field[0] = subtype */
};
static const ProtobufCIntRange pg_query__alter_table_cmd__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 7 }
{ 0, 8 }
};
const ProtobufCMessageDescriptor pg_query__alter_table_cmd__descriptor =
{
Expand All @@ -20795,7 +20808,7 @@ const ProtobufCMessageDescriptor pg_query__alter_table_cmd__descriptor =
"PgQuery__AlterTableCmd",
"pg_query",
sizeof(PgQuery__AlterTableCmd),
7,
8,
pg_query__alter_table_cmd__field_descriptors,
pg_query__alter_table_cmd__field_indices_by_name,
1, pg_query__alter_table_cmd__number_ranges,
Expand Down Expand Up @@ -36975,7 +36988,7 @@ static const ProtobufCEnumValue pg_query__token__enum_values_by_number[494] =
{ "REASSIGN", "PG_QUERY__TOKEN__REASSIGN", 579 },
{ "RECHECK", "PG_QUERY__TOKEN__RECHECK", 580 },
{ "RECURSIVE", "PG_QUERY__TOKEN__RECURSIVE", 581 },
{ "REF", "PG_QUERY__TOKEN__REF", 582 },
{ "REF_P", "PG_QUERY__TOKEN__REF_P", 582 },
{ "REFERENCES", "PG_QUERY__TOKEN__REFERENCES", 583 },
{ "REFERENCING", "PG_QUERY__TOKEN__REFERENCING", 584 },
{ "REFRESH", "PG_QUERY__TOKEN__REFRESH", 585 },
Expand Down Expand Up @@ -37472,10 +37485,10 @@ static const ProtobufCEnumValueIndex pg_query__token__enum_values_by_name[494] =
{ "REASSIGN", 341 },
{ "RECHECK", 342 },
{ "RECURSIVE", 343 },
{ "REF", 344 },
{ "REFERENCES", 345 },
{ "REFERENCING", 346 },
{ "REFRESH", 347 },
{ "REF_P", 344 },
{ "REINDEX", 348 },
{ "RELATIVE_P", 349 },
{ "RELEASE", 350 },
Expand Down
7 changes: 4 additions & 3 deletions protobuf/pg_query.pb-c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 662539d

Please sign in to comment.