Add COPY_ARRAY_FIELD and COMPARE_ARRAY_FIELD
authorPeter Eisentraut <[email protected]>
Tue, 14 Sep 2021 07:34:50 +0000 (09:34 +0200)
committerPeter Eisentraut <[email protected]>
Tue, 14 Sep 2021 08:27:34 +0000 (10:27 +0200)
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 <[email protected]>
Discussion: https://www.postgresql.org/message-id/c091e5cd-45f8-69ee-6a9b-de86912cc7e7@enterprisedb.com

src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c

index 83ec2a369e89548c1dc3c278a022d15fe08fed2d..228387eaeedfc893e0272b507c1321d957c6da9a 100644 (file)
 #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;
 }
index 4bad709f835a2b2b0993932513d562deb6975bd1..800f588b5cbdf7a6b52c0712b686d56832a8f64c 100644 (file)
 #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 { \