PostgreSQL Source Code git master
Loading...
Searching...
No Matches
test_cplusplusext.cpp
Go to the documentation of this file.
1/*--------------------------------------------------------------------------
2 *
3 * test_cplusplusext.cpp
4 * Test that PostgreSQL headers compile with a C++ compiler.
5 *
6 * This file is compiled with a C++ compiler to verify that PostgreSQL
7 * headers remain compatible with C++ extensions.
8 *
9 * Copyright (c) 2025-2026, PostgreSQL Global Development Group
10 *
11 * IDENTIFICATION
12 * src/test/modules/test_cplusplusext/test_cplusplusext.cpp
13 *
14 * -------------------------------------------------------------------------
15 */
16
17extern "C" {
18#include "postgres.h"
19#include "fmgr.h"
20#include "nodes/pg_list.h"
21#include "nodes/primnodes.h"
22
24
26}
27
28StaticAssertDecl(sizeof(int32) == 4, "int32 should be 4 bytes");
29
30/*
31 * Simple function that returns the sum of two integers. This verifies that
32 * C++ extension modules can be loaded and called correctly at runtime.
33 */
34extern "C" Datum
36{
40 const RangeTblRef *nodec = node;
42 List *list = list_make1(node);
43
45 {
46 (void) rtr;
47 }
48
50 {
51 (void) rtr;
52 }
53
54 StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
55 (void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
56
57 list_free(list);
58 pfree(node);
59 pfree(copy);
60
61 switch (a)
62 {
63 case 1:
64 elog(DEBUG1, "1");
66 case 2:
67 elog(DEBUG1, "2");
68 break;
69 }
70
72}
#define StaticAssertExpr(condition, errmessage)
Definition c.h:1035
int64_t int64
Definition c.h:615
int32_t int32
Definition c.h:614
#define pg_fallthrough
Definition c.h:152
#define StaticAssertDecl(condition, errmessage)
Definition c.h:1010
#define StaticAssertStmt(condition, errmessage)
Definition c.h:1017
#define DEBUG1
Definition elog.h:30
#define elog(elevel,...)
Definition elog.h:226
#define PG_FUNCTION_INFO_V1(funcname)
Definition fmgr.h:417
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
int b
Definition isn.c:74
int a
Definition isn.c:73
void list_free(List *list)
Definition list.c:1546
void pfree(void *pointer)
Definition mcxt.c:1616
#define copyObject(obj)
Definition nodes.h:232
#define makeNode(_type_)
Definition nodes.h:161
#define list_make1(x1)
Definition pg_list.h:212
#define foreach_ptr(type, var, lst)
Definition pg_list.h:469
#define foreach_node(type, var, lst)
Definition pg_list.h:496
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
Definition pg_list.h:54
PG_MODULE_MAGIC
Datum test_cplusplus_add(PG_FUNCTION_ARGS)