Skip to content

Commit 308da17

Browse files
committed
Add COPY_ARRAY_FIELD and COMPARE_ARRAY_FIELD
These handle node fields that are inline arrays (as opposed to dynamically allocated arrays handled by COPY_POINTER_FIELD and COMPARE_POINTER_FIELD). These cases were hand-coded until now. Reviewed-by: Jacob Champion <pchampion@vmware.com> Discussion: https://www.postgresql.org/message-id/c091e5cd-45f8-69ee-6a9b-de86912cc7e7@enterprisedb.com
1 parent 8539929 commit 308da17

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/backend/nodes/copyfuncs.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
#define COPY_STRING_FIELD(fldname) \
5454
(newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
5555

56+
/* Copy a field that is an inline array */
57+
#define COPY_ARRAY_FIELD(fldname) \
58+
memcpy(newnode->fldname, from->fldname, sizeof(newnode->fldname))
59+
5660
/* Copy a field that is a pointer to a simple palloc'd object of size sz */
5761
#define COPY_POINTER_FIELD(fldname, sz) \
5862
do { \
@@ -4947,10 +4951,9 @@ _copyForeignKeyCacheInfo(const ForeignKeyCacheInfo *from)
49474951
COPY_SCALAR_FIELD(conrelid);
49484952
COPY_SCALAR_FIELD(confrelid);
49494953
COPY_SCALAR_FIELD(nkeys);
4950-
/* COPY_SCALAR_FIELD might work for these, but let's not assume that */
4951-
memcpy(newnode->conkey, from->conkey, sizeof(newnode->conkey));
4952-
memcpy(newnode->confkey, from->confkey, sizeof(newnode->confkey));
4953-
memcpy(newnode->conpfeqop, from->conpfeqop, sizeof(newnode->conpfeqop));
4954+
COPY_ARRAY_FIELD(conkey);
4955+
COPY_ARRAY_FIELD(confkey);
4956+
COPY_ARRAY_FIELD(conpfeqop);
49544957

49554958
return newnode;
49564959
}

src/backend/nodes/equalfuncs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@
7474
#define equalstr(a, b) \
7575
(((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
7676

77+
/* Compare a field that is an inline array */
78+
#define COMPARE_ARRAY_FIELD(fldname) \
79+
do { \
80+
if (memcmp(a->fldname, b->fldname, sizeof(a->fldname)) != 0) \
81+
return false; \
82+
} while (0)
83+
7784
/* Compare a field that is a pointer to a simple palloc'd object of size sz */
7885
#define COMPARE_POINTER_FIELD(fldname, sz) \
7986
do { \

0 commit comments

Comments
 (0)