v4-0001-Make-copyObject-work-in-C.patch
text/x-patch
Filename: v4-0001-Make-copyObject-work-in-C.patch
Type: text/x-patch
Part: 0
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 v4-0001
Subject: Make copyObject work in C++
| File | + | − |
|---|---|---|
| src/include/c.h | 13 | 0 |
| src/include/nodes/nodes.h | 2 | 2 |
From 290a1ab7788756adaed14dc2b483156d65bc3b95 Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio <postgres@jeltef.nl> Date: Fri, 5 Dec 2025 15:37:59 +0100 Subject: [PATCH v4 1/4] Make copyObject work in C++ Calling copyObject in C++ without GNU extensions fails with an error like this: error: use of undeclared identifier 'typeof'; did you mean 'typeid' This is due to the C compiler supporting used to compile postgres supporting typeof, but that function actually not being present in the C++ compiler. This fixes that by defining pg_exprtype which maps to typeof or decltype depending on the compiler. While pg_typeof would have been a more natural name, that name is already taken in our codebase as the implementation of the pg_typeof UDF. --- src/include/c.h | 13 +++++++++++++ src/include/nodes/nodes.h | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/include/c.h b/src/include/c.h index 77c754a904a..18bd50da510 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -418,6 +418,19 @@ #define unlikely(x) ((x) != 0) #endif +/* + * pg_exprtype + * Get the type of an expression at compile time. + * + * In C++ we use decltype since typeof is not standard C++, while in C we use + * typeof when available. + */ +#if defined(__cplusplus) +#define pg_exprtype(x) decltype(x) +#elif defined(HAVE_TYPEOF) +#define pg_exprtype(x) typeof(x) +#endif + /* * CppAsString * Convert the argument to a string, using the C preprocessor. diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h index b6ad28618ab..f5e17e670b7 100644 --- a/src/include/nodes/nodes.h +++ b/src/include/nodes/nodes.h @@ -226,8 +226,8 @@ extern int16 *readAttrNumberCols(int numCols); extern void *copyObjectImpl(const void *from); /* cast result back to argument type, if supported by compiler */ -#ifdef HAVE_TYPEOF -#define copyObject(obj) ((typeof(obj)) copyObjectImpl(obj)) +#ifdef pg_exprtype +#define copyObject(obj) ((pg_exprtype(obj)) copyObjectImpl(obj)) #else #define copyObject(obj) copyObjectImpl(obj) #endif base-commit: 094b61ce3ebbb1258675cb9b4eca9198628e2177 -- 2.52.0