Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*--------------------------------------------------------------------------
 *
 * 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"
#include "nodes/pg_list.h"
#include "nodes/primnodes.h"
 
PG_MODULE_MAGIC;
 
PG_FUNCTION_INFO_V1(test_cplusplus_add);
}
 
StaticAssertDecl(sizeof(int32) == 4, "int32 should be 4 bytes");
 
/*
 * 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);
    RangeTblRef *node = makeNode(RangeTblRef);
    const RangeTblRef *nodec = node;
    RangeTblRef *copy = copyObject(nodec);
    List       *list = list_make1(node);
 
    foreach_ptr(RangeTblRef, rtr, list)
    {
        (void) rtr;
    }
 
    foreach_node(RangeTblRef, rtr, list)
    {
        (void) rtr;
    }
 
    StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
    (void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
 
    list_free(list);
    pfree(node);
    pfree(copy);
 
    switch (a)
    {
        case 1:
            elog(DEBUG1, "1");
            pg_fallthrough;
        case 2:
            elog(DEBUG1, "2");
            break;
    }
 
    PG_RETURN_INT32(a + b);
}