aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2021-09-14 09:34:50 +0200
committerPeter Eisentraut <peter@eisentraut.org>2021-09-14 10:27:34 +0200
commit308da179e7c2c41c146e23a1418f6419aee340af (patch)
treeffddbe17cfef331ced01c4e1a27d8d9e2fe63ecc /src
parent85399291977324d5c9f634a9a9d6d8591bfe7520 (diff)
downloadpostgresql-308da179e7c2c41c146e23a1418f6419aee340af.tar.gz
postgresql-308da179e7c2c41c146e23a1418f6419aee340af.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/backend/nodes/copyfuncs.c11
-rw-r--r--src/backend/nodes/equalfuncs.c7
2 files changed, 14 insertions, 4 deletions
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index 83ec2a369e8..228387eaeed 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -53,6 +53,10 @@
#define COPY_STRING_FIELD(fldname) \
(newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
+/* Copy a field that is an inline array */
+#define COPY_ARRAY_FIELD(fldname) \
+ memcpy(newnode->fldname, from->fldname, sizeof(newnode->fldname))
+
/* Copy a field that is a pointer to a simple palloc'd object of size sz */
#define COPY_POINTER_FIELD(fldname, sz) \
do { \
@@ -4947,10 +4951,9 @@ _copyForeignKeyCacheInfo(const ForeignKeyCacheInfo *from)
COPY_SCALAR_FIELD(conrelid);
COPY_SCALAR_FIELD(confrelid);
COPY_SCALAR_FIELD(nkeys);
- /* COPY_SCALAR_FIELD might work for these, but let's not assume that */
- memcpy(newnode->conkey, from->conkey, sizeof(newnode->conkey));
- memcpy(newnode->confkey, from->confkey, sizeof(newnode->confkey));
- memcpy(newnode->conpfeqop, from->conpfeqop, sizeof(newnode->conpfeqop));
+ COPY_ARRAY_FIELD(conkey);
+ COPY_ARRAY_FIELD(confkey);
+ COPY_ARRAY_FIELD(conpfeqop);
return newnode;
}
diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c
index 4bad709f835..800f588b5cb 100644
--- a/src/backend/nodes/equalfuncs.c
+++ b/src/backend/nodes/equalfuncs.c
@@ -74,6 +74,13 @@
#define equalstr(a, b) \
(((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
+/* Compare a field that is an inline array */
+#define COMPARE_ARRAY_FIELD(fldname) \
+ do { \
+ if (memcmp(a->fldname, b->fldname, sizeof(a->fldname)) != 0) \
+ return false; \
+ } while (0)
+
/* Compare a field that is a pointer to a simple palloc'd object of size sz */
#define COMPARE_POINTER_FIELD(fldname, sz) \
do { \