2026-01-20 10:24:57 -05:00
|
|
|
/*--------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* test_cplusplusext.cpp
|
|
|
|
|
* Test that PostgreSQL headers compile with a C++ compiler.
|
|
|
|
|
*
|
|
|
|
|
* This file is compiled with a C++ compiler to verify that PostgreSQL
|
|
|
|
|
* headers remain compatible with C++ extensions.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2025-2026, PostgreSQL Global Development Group
|
|
|
|
|
*
|
|
|
|
|
* IDENTIFICATION
|
|
|
|
|
* src/test/modules/test_cplusplusext/test_cplusplusext.cpp
|
|
|
|
|
*
|
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
#include "fmgr.h"
|
2026-02-17 04:06:32 -05:00
|
|
|
#include "nodes/pg_list.h"
|
|
|
|
|
#include "nodes/primnodes.h"
|
2026-01-20 10:24:57 -05:00
|
|
|
|
|
|
|
|
PG_MODULE_MAGIC;
|
|
|
|
|
|
|
|
|
|
PG_FUNCTION_INFO_V1(test_cplusplus_add);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-17 04:06:39 -05:00
|
|
|
StaticAssertDecl(sizeof(int32) == 4, "int32 should be 4 bytes");
|
|
|
|
|
|
2026-01-20 10:24:57 -05:00
|
|
|
/*
|
|
|
|
|
* Simple function that returns the sum of two integers. This verifies that
|
|
|
|
|
* C++ extension modules can be loaded and called correctly at runtime.
|
|
|
|
|
*/
|
|
|
|
|
extern "C" Datum
|
|
|
|
|
test_cplusplus_add(PG_FUNCTION_ARGS)
|
|
|
|
|
{
|
|
|
|
|
int32 a = PG_GETARG_INT32(0);
|
|
|
|
|
int32 b = PG_GETARG_INT32(1);
|
2026-02-17 04:06:32 -05:00
|
|
|
RangeTblRef *node = makeNode(RangeTblRef);
|
2026-03-02 05:46:02 -05:00
|
|
|
RangeTblRef *copy = copyObject(node);
|
2026-02-17 04:06:32 -05:00
|
|
|
List *list = list_make1(node);
|
|
|
|
|
|
|
|
|
|
foreach_ptr(RangeTblRef, rtr, list)
|
|
|
|
|
{
|
|
|
|
|
(void) rtr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach_node(RangeTblRef, rtr, list)
|
|
|
|
|
{
|
|
|
|
|
(void) rtr;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-17 04:06:39 -05:00
|
|
|
StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
|
|
|
|
|
(void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
|
|
|
|
|
|
2026-02-17 04:06:32 -05:00
|
|
|
list_free(list);
|
|
|
|
|
pfree(node);
|
2026-03-02 05:46:02 -05:00
|
|
|
pfree(copy);
|
2026-01-20 10:24:57 -05:00
|
|
|
|
2026-02-23 01:37:50 -05:00
|
|
|
switch (a)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
elog(DEBUG1, "1");
|
|
|
|
|
pg_fallthrough;
|
|
|
|
|
case 2:
|
|
|
|
|
elog(DEBUG1, "2");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-20 10:24:57 -05:00
|
|
|
PG_RETURN_INT32(a + b);
|
|
|
|
|
}
|