Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2026-04-30 9f2ef60949ced4fab4d077a7e1c6d913f3620c9b
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * PL/.NET (pldotnet) - PostgreSQL support for .NET C# and F# as
 *             procedural languages (PL)
 *
 *
 * Copyright (c) 2023 Brick Abode
 *
 * This code is subject to the terms of the PostgreSQL License.
 * The full text of the license can be found in the LICENSE file
 * at the top level of the pldotnet repository.
 *
 * pldotnet_hostfxr.h
 *
 */
 
#ifndef PLDOTNET_HOSTFXR_H_
#define PLDOTNET_HOSTFXR_H_
 
#include <stddef.h>
#include <coreclr_delegates.h>
#include <nethost.h>
#include <stdbool.h>
#include <stdint.h>
 
#if defined(_WIN32)
#define CORECLR_DELEGATE_CALLTYPE __stdcall
#define HOSTFXR_CALLTYPE __cdecl
#ifdef _WCHAR_T_DEFINED
typedef wchar_t char_t;
#else
typedef unsigned int16_t char_t;
#endif
#else
#define CORECLR_DELEGATE_CALLTYPE
#define HOSTFXR_CALLTYPE
typedef char char_t;
#endif
 
enum hostfxr_delegate_type {
    hdt_com_activation,
    hdt_load_in_memory_assembly,
    hdt_winrt_activation,
    hdt_com_register,
    hdt_com_unregister,
    hdt_load_assembly_and_get_function_pointer
};
 
typedef void *hostfxr_handle;
 
typedef struct hostfxr_initialize_parameters {
    size_t size;
    const char_t *host_path;
    const char_t *dotnet_root;
} hostfxr_initialize_parameters;
 
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_initialize_for_runtime_config_fn)(
    const char_t *runtime_config_path,
    const hostfxr_initialize_parameters *parameters,
    hostfxr_handle *host_context_handle);
 
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_set_runtime_property_value_fn)(
    const hostfxr_handle host_context_handle, const char_t *name,
    const char_t *value);
 
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_get_runtime_delegate_fn)(
    const hostfxr_handle host_context_handle, enum hostfxr_delegate_type type,
    void **delegate);
 
typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_close_fn)(
    const hostfxr_handle host_context_handle);
 
typedef load_assembly_and_get_function_pointer_fn dotnet_loader;
 
/**
 * @brief A function pointer that references Engine.CompileUserFunction().
 *
 */
typedef int(CORECLR_DELEGATE_CALLTYPE *compile_user_fn)(
    uint32_t functionId, char *func_name, uint32_t func_ret_type, bool retset,
    bool is_trigger, char *func_param_names, uint32_t *func_param_types,
    char *param_modes, int num_output_values, char *func_body,
    bool support_null_input, char *dotnet_language);
 
/**
 * @brief A function pointer that references Engine.RunUserFunction().
 *
 */
typedef int(CORECLR_DELEGATE_CALLTYPE *run_user_fn)(
    uint32_t functionId, uint64_t call_id, int call_mode, void *arguments,
    int num_arguments, bool *nullmap, void *output);
 
/**
 * @brief A function pointer that references Engine.RunUserTFunction().
 *
 */
typedef int(CORECLR_DELEGATE_CALLTYPE *run_user_tg_fn)(
    uint32_t functionId, int call_mode, void *old_row, void *new_row,
    char *triggerName, char *triggerWhen, char *triggerLevel,
    char *triggerOperation, int relationId, char *tableName, char *tableSchema,
    char **arguments, int nargs);
 
/**
 * @brief A function pointer that references Engine.BuildDatumList().
 *
 */
typedef void *(CORECLR_DELEGATE_CALLTYPE *build_datum_list_fn)(void);
 
/**
 * @brief A function pointer that references Engine.AddDatumToList().
 *
 */
typedef void(CORECLR_DELEGATE_CALLTYPE *add_datum_to_list_fn)(void *list,
                                                              void *datum);
 
/**
 * @brief A function pointer that references Engine.FreeGenericGCHandle().
 *
 */
typedef void(CORECLR_DELEGATE_CALLTYPE *free_generic_gchandle_fn)(
    void *gchandle);
 
/**
 * @brief A function pointer that references Engine.UnloadAssemblies().
 *
 */
typedef void(CORECLR_DELEGATE_CALLTYPE *unload_assemblies_fn)(
    uint32_t functionId);
 
/** @brief Loads dotnet using the HostFXR.  HostFXR "finds and resolves
 * the runtime and all the frameworks the app needs", which in our
 * case is via `nethost`, "which is used by native apps (any app
 * which is not .NET Core) to load .NET Core code dynamically"
 *
 * See these URLs for more background:
 * https://github.com/dotnet/runtime/blob/main/docs/design/features/host-components.md
 * https://github.com/dotnet/runtime/blob/main/docs/design/features/sharedfx-lookup.md
 *
 * @return 1 on success, 0 on failure
 */
int pldotnet_LoadHostfxr(void);
 
/**
 * @brief Load and initialize .NET Core and get desired function pointer for
 * scenario.
 *
 * @param config_path the config path.
 * @param host_base_path the host base path.
 *
 * @return pointer to .NET's function to load an assembly and get the function
 * pointer, or NULL on error.
 */
load_assembly_and_get_function_pointer_fn GetNetLoadAssemblySetup(
    const char_t *config_path, const char_t *host_base_path);
 
/**
 * @brief Using the nethost library, this function discovers the location of
 * hostfxr and get exports IF the hostfxr was not loaded yet.
 *
 * @return Returns whether the hostfxr was loaded.
 */
bool pldotnet_LoadHostFxrIfNeeded(void);
 
#endif  // PLDOTNET_HOSTFXR_H_