v7-0005-Support-using-list_make-macros-in-C.patch
text/x-patch
Filename: v7-0005-Support-using-list_make-macros-in-C.patch
Type: text/x-patch
Part: 4
Message:
Re: Make copyObject work in C++
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v7-0005
Subject: Support using list_make macros in C++
| File | + | − |
|---|---|---|
| src/include/nodes/pg_list.h | 38 | 5 |
| src/test/modules/test_cplusplusext/test_cplusplusext.cpp | 14 | 0 |
From dabaf5ef094b06a694f956f7b6749ade11c9b846 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Sat, 17 Jan 2026 14:55:28 +0100
Subject: [PATCH v7 5/5] Support using list_make macros in C++
The list_make_xxx_cell macros were using designated initializers and
these are only officially available in C++20. GCC and Clang allow them
in earlier C++ versions too, but MSVC is strict about it. Since we want
to support C++11 this changes these macros to use inline functions
instead, which work across both C and C++.
---
src/include/nodes/pg_list.h | 43 ++++++++++++++++---
.../test_cplusplusext/test_cplusplusext.cpp | 14 ++++++
2 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h
index ae80975548f..ba43d36bc89 100644
--- a/src/include/nodes/pg_list.h
+++ b/src/include/nodes/pg_list.h
@@ -202,12 +202,45 @@ list_length(const List *l)
#define llast_node(type,l) castNode(type, llast(l))
/*
- * Convenience macros for building fixed-length lists
+ * Convenience functions for building fixed-length lists. These cannot be
+ * macros with designated initializers, because we want these functions to be
+ * usable from C++ versions below C++20.
*/
-#define list_make_ptr_cell(v) ((ListCell) {.ptr_value = (v)})
-#define list_make_int_cell(v) ((ListCell) {.int_value = (v)})
-#define list_make_oid_cell(v) ((ListCell) {.oid_value = (v)})
-#define list_make_xid_cell(v) ((ListCell) {.xid_value = (v)})
+static inline ListCell
+list_make_ptr_cell(void *v)
+{
+ ListCell c;
+
+ c.ptr_value = v;
+ return c;
+}
+
+static inline ListCell
+list_make_int_cell(int v)
+{
+ ListCell c;
+
+ c.int_value = v;
+ return c;
+}
+
+static inline ListCell
+list_make_oid_cell(Oid v)
+{
+ ListCell c;
+
+ c.oid_value = v;
+ return c;
+}
+
+static inline ListCell
+list_make_xid_cell(TransactionId v)
+{
+ ListCell c;
+
+ c.xid_value = v;
+ return c;
+}
#define list_make1(x1) \
list_make1_impl(T_List, list_make_ptr_cell(x1))
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index bb9c310504e..2bdf2c3d057 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -17,6 +17,7 @@
extern "C" {
#include "postgres.h"
#include "fmgr.h"
+#include "nodes/pg_list.h"
#include "nodes/parsenodes.h"
PG_MODULE_MAGIC_EXT("test_cplusplusext", "1.2");
@@ -41,6 +42,19 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
(void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
+ List *list = list_make1(node);
+
+ foreach_ptr(RangeTblRef, rtr, list)
+ {
+ (void) rtr;
+ }
+
+ foreach_node(RangeTblRef, rtr, list)
+ {
+ (void) rtr;
+ }
+
+ list_free(list);
pfree(copy);
pfree(node);
--
2.52.0