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 List *list = list_make1(node);
41
43 {
44 (void) rtr;
45 }
46
48 {
49 (void) rtr;
50 }
51
52 StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
53 (void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
54
55 list_free(list);
56 pfree(node);
57
58 switch (a)
59 {
60 case 1:
61 elog(DEBUG1, "1");
63 case 2:
64 elog(DEBUG1, "2");
65 break;
66 }
67
69}
#define StaticAssertExpr(condition, errmessage)
Definition c.h:972
int64_t int64
Definition c.h:555
int32_t int32
Definition c.h:554
#define pg_fallthrough
Definition c.h:144
#define StaticAssertDecl(condition, errmessage)
Definition c.h:950
#define StaticAssertStmt(condition, errmessage)
Definition c.h:957
#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 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)