mongory 2.1.1-aarch64-linux → 2.2.0-aarch64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +45 -74
- data/docs/clang_bridge.md +2 -2
- data/docs/performance.md +28 -1
- data/lib/core/2.6/mongory_ext.so +0 -0
- data/lib/core/2.7/mongory_ext.so +0 -0
- data/lib/core/3.0/mongory_ext.so +0 -0
- data/lib/core/3.1/mongory_ext.so +0 -0
- data/lib/core/3.2/mongory_ext.so +0 -0
- data/lib/core/3.3/mongory_ext.so +0 -0
- data/lib/core/3.4/mongory_ext.so +0 -0
- data/lib/core/4.0/mongory_ext.so +0 -0
- data/lib/mongory/converters/abstract_converter.rb +5 -5
- data/lib/mongory/converters/converted.rb +0 -4
- data/lib/mongory/converters/key_converter.rb +13 -36
- data/lib/mongory/converters/value_converter.rb +4 -4
- data/lib/mongory/matchers.rb +8 -7
- data/lib/mongory/query_builder.rb +9 -0
- data/lib/mongory/utils/context.rb +0 -6
- data/lib/mongory/utils/singleton_builder.rb +1 -4
- data/lib/mongory/version.rb +1 -1
- data/lib/mongory.rb +0 -1
- data/mongory.gemspec +13 -12
- data/script/coverage.rb +84 -0
- metadata +9 -54
- data/ext/mongory_ext/extconf.rb +0 -115
- data/ext/mongory_ext/mongory-core/include/mongory-core/adapters/json.h +0 -62
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/array.h +0 -122
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +0 -217
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/error.h +0 -82
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/memory_pool.h +0 -115
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/table.h +0 -127
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/value.h +0 -175
- data/ext/mongory_ext/mongory-core/include/mongory-core/matchers/matcher.h +0 -103
- data/ext/mongory_ext/mongory-core/include/mongory-core.h +0 -12
- data/ext/mongory_ext/mongory-core/src/foundations/array.c +0 -336
- data/ext/mongory_ext/mongory-core/src/foundations/array_private.h +0 -20
- data/ext/mongory_ext/mongory-core/src/foundations/config.c +0 -335
- data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +0 -49
- data/ext/mongory_ext/mongory-core/src/foundations/error.c +0 -48
- data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +0 -406
- data/ext/mongory_ext/mongory-core/src/foundations/memory_pool_private.h +0 -45
- data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +0 -117
- data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.h +0 -43
- data/ext/mongory_ext/mongory-core/src/foundations/table.c +0 -502
- data/ext/mongory_ext/mongory-core/src/foundations/utils.c +0 -206
- data/ext/mongory_ext/mongory-core/src/foundations/utils.h +0 -77
- data/ext/mongory_ext/mongory-core/src/foundations/value.c +0 -548
- data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +0 -193
- data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +0 -117
- data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +0 -241
- data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.h +0 -83
- data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +0 -730
- data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h +0 -131
- data/ext/mongory_ext/mongory-core/src/matchers/existence_matcher.c +0 -158
- data/ext/mongory_ext/mongory-core/src/matchers/existence_matcher.h +0 -48
- data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +0 -199
- data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.h +0 -58
- data/ext/mongory_ext/mongory-core/src/matchers/implicit_array_matcher.c +0 -204
- data/ext/mongory_ext/mongory-core/src/matchers/implicit_array_matcher.h +0 -47
- data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c +0 -483
- data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.h +0 -46
- data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +0 -529
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c +0 -117
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h +0 -29
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c +0 -61
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h +0 -23
- data/ext/mongory_ext/mongory-core/src/matchers/value_matcher.c +0 -416
- data/ext/mongory_ext/mongory-core/src/matchers/value_matcher.h +0 -97
- data/ext/mongory_ext/mongory_ext.c +0 -66
- data/ext/mongory_ext/mongory_ext_internal.h +0 -74
- data/ext/mongory_ext/rb_mongory_adapters.c +0 -140
- data/ext/mongory_ext/rb_mongory_matcher.c +0 -440
- data/ext/mongory_ext/rb_mongory_value.c +0 -327
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file config.c
|
|
3
|
-
* @brief Implements global configuration and initialization for the Mongory
|
|
4
|
-
* library.
|
|
5
|
-
*
|
|
6
|
-
* This file manages the lifecycle of global resources such as the internal
|
|
7
|
-
* memory pool, regex adapter, matcher registration table, and value converters.
|
|
8
|
-
* It provides the `mongory_init` and `mongory_cleanup` functions, as well as
|
|
9
|
-
* setters for customizable components and a string copy utility.
|
|
10
|
-
*/
|
|
11
|
-
#include "mongory-core/foundations/config.h"
|
|
12
|
-
#include "../matchers/base_matcher.h" // For mongory_matcher_build_func
|
|
13
|
-
#include "../matchers/compare_matcher.h" // For specific matcher constructors
|
|
14
|
-
#include "../matchers/composite_matcher.h" // For specific matcher constructors
|
|
15
|
-
#include "../matchers/existence_matcher.h" // For specific matcher constructors
|
|
16
|
-
#include "../matchers/inclusion_matcher.h" // For specific matcher constructors
|
|
17
|
-
#include "../matchers/value_matcher.h" // For specific matcher constructors
|
|
18
|
-
#include "../matchers/external_matcher.h" // For specific matcher constructors
|
|
19
|
-
#include "config_private.h" // For mongory_regex_adapter, mongory_value_converter, etc.
|
|
20
|
-
#include "mongory-core/foundations/memory_pool.h"
|
|
21
|
-
#include "mongory-core/foundations/table.h"
|
|
22
|
-
#include "mongory-core/foundations/value.h"
|
|
23
|
-
|
|
24
|
-
#if defined(_WIN32)
|
|
25
|
-
# ifndef WIN32_LEAN_AND_MEAN
|
|
26
|
-
# define WIN32_LEAN_AND_MEAN
|
|
27
|
-
# endif
|
|
28
|
-
# include <windows.h>
|
|
29
|
-
static volatile LONG mongory_config_spinlock = 0;
|
|
30
|
-
static inline void mongory_config_lock(void) {
|
|
31
|
-
while (InterlockedExchange(&mongory_config_spinlock, 1) != 0) {
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
static inline void mongory_config_unlock(void) { InterlockedExchange(&mongory_config_spinlock, 0); }
|
|
35
|
-
#else
|
|
36
|
-
# include <pthread.h>
|
|
37
|
-
static pthread_mutex_t mongory_config_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
38
|
-
static inline void mongory_config_lock(void) { pthread_mutex_lock(&mongory_config_mutex); }
|
|
39
|
-
static inline void mongory_config_unlock(void) { pthread_mutex_unlock(&mongory_config_mutex); }
|
|
40
|
-
#endif
|
|
41
|
-
|
|
42
|
-
static bool mongory_regex_default_func(mongory_memory_pool *pool, mongory_value *pattern, mongory_value *value);
|
|
43
|
-
static char *mongory_regex_default_stringify_func(mongory_memory_pool *pool, mongory_value *pattern);
|
|
44
|
-
|
|
45
|
-
// Global internal memory pool for the library.
|
|
46
|
-
mongory_memory_pool *mongory_internal_pool = NULL;
|
|
47
|
-
// Global adapter for regex operations.
|
|
48
|
-
mongory_regex_adapter mongory_internal_regex_adapter = {
|
|
49
|
-
.match_func = mongory_regex_default_func,
|
|
50
|
-
.options_match_func = NULL,
|
|
51
|
-
.stringify_func = mongory_regex_default_stringify_func,
|
|
52
|
-
};
|
|
53
|
-
// Global table mapping matcher names (e.g., "$eq") to their build functions.
|
|
54
|
-
mongory_table *mongory_matcher_mapping = NULL;
|
|
55
|
-
// Global converter for handling external data types.
|
|
56
|
-
mongory_value_converter mongory_internal_value_converter = {
|
|
57
|
-
.deep_convert = NULL,
|
|
58
|
-
.shallow_convert = NULL,
|
|
59
|
-
.recover = NULL,
|
|
60
|
-
};
|
|
61
|
-
// Global adapter for custom matchers.
|
|
62
|
-
mongory_matcher_custom_adapter mongory_custom_matcher_adapter = {
|
|
63
|
-
.build = NULL,
|
|
64
|
-
.lookup = NULL,
|
|
65
|
-
.match = NULL,
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
bool mongory_matcher_trace_result_colorful = true;
|
|
69
|
-
static size_t mongory_compile_max_depth = MONGORY_DEFAULT_MAX_DEPTH;
|
|
70
|
-
static size_t mongory_compile_max_nodes = MONGORY_DEFAULT_MAX_NODES;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @brief Initializes the internal memory pool if it hasn't been already.
|
|
74
|
-
* This pool is used for allocations by various library components.
|
|
75
|
-
*/
|
|
76
|
-
static inline void mongory_internal_pool_init() {
|
|
77
|
-
if (mongory_internal_pool != NULL) {
|
|
78
|
-
return; // Already initialized.
|
|
79
|
-
}
|
|
80
|
-
mongory_internal_pool = mongory_memory_pool_new();
|
|
81
|
-
// TODO: Add error handling if mongory_memory_pool_new returns NULL.
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* @brief Default regex function that always returns false.
|
|
86
|
-
* Used if no custom regex function is set via mongory_regex_func_set.
|
|
87
|
-
* @param pool Unused.
|
|
88
|
-
* @param pattern Unused.
|
|
89
|
-
* @param value Unused.
|
|
90
|
-
* @return Always false.
|
|
91
|
-
*/
|
|
92
|
-
static bool mongory_regex_default_func(mongory_memory_pool *pool, mongory_value *pattern, mongory_value *value) {
|
|
93
|
-
(void)pool; // Mark as unused to prevent compiler warnings.
|
|
94
|
-
(void)pattern; // Mark as unused.
|
|
95
|
-
(void)value; // Mark as unused.
|
|
96
|
-
return false; // Default behavior is no match.
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
static char *mongory_regex_default_stringify_func(mongory_memory_pool *pool, mongory_value *pattern) {
|
|
100
|
-
(void)pool; // Mark as unused to prevent compiler warnings.
|
|
101
|
-
(void)pattern; // Mark as unused.
|
|
102
|
-
return "//"; // Default behavior is no stringification.
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* @brief Sets the global regex matching function.
|
|
107
|
-
* Initializes the regex adapter if it's not already.
|
|
108
|
-
* @param func The custom regex function to use.
|
|
109
|
-
*/
|
|
110
|
-
void mongory_regex_func_set(mongory_regex_func func) {
|
|
111
|
-
mongory_internal_regex_adapter.match_func = func;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* @brief Sets the global regex matching function used with `$options`.
|
|
116
|
-
* @param func The custom regex function to use.
|
|
117
|
-
*/
|
|
118
|
-
void mongory_regex_options_func_set(mongory_regex_options_func func) {
|
|
119
|
-
mongory_internal_regex_adapter.options_match_func = func;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @brief Sets the global regex stringify function.
|
|
124
|
-
* Initializes the regex adapter if it's not already.
|
|
125
|
-
* @param func The custom regex stringify function to use.
|
|
126
|
-
*/
|
|
127
|
-
void mongory_regex_stringify_func_set(mongory_regex_stringify_func func) {
|
|
128
|
-
mongory_internal_regex_adapter.stringify_func = func;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* @brief Initializes the matcher mapping table if it hasn't been already.
|
|
132
|
-
* This table stores registrations of matcher names to their constructor
|
|
133
|
-
* functions.
|
|
134
|
-
*/
|
|
135
|
-
static inline void mongory_matcher_mapping_init() {
|
|
136
|
-
if (mongory_matcher_mapping != NULL) {
|
|
137
|
-
return; // Already initialized.
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Ensure the internal pool is initialized first.
|
|
141
|
-
mongory_internal_pool_init();
|
|
142
|
-
if (mongory_internal_pool == NULL) {
|
|
143
|
-
return; // Cannot proceed if pool initialization failed.
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
mongory_matcher_mapping = mongory_table_new(mongory_internal_pool);
|
|
147
|
-
if (mongory_matcher_mapping == NULL) {
|
|
148
|
-
// TODO: Set error state.
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @brief Registers a matcher build function with a given name.
|
|
155
|
-
* The build function is stored in the global matcher mapping table.
|
|
156
|
-
* @param name The name of the matcher (e.g., "$eq", "$in").
|
|
157
|
-
* @param build_func A function pointer to the matcher's constructor.
|
|
158
|
-
*/
|
|
159
|
-
static void mongory_matcher_register_unlocked(char *name, mongory_matcher_build_func build_func) {
|
|
160
|
-
// Ensure mapping is initialized.
|
|
161
|
-
if (mongory_matcher_mapping == NULL) {
|
|
162
|
-
mongory_matcher_mapping_init();
|
|
163
|
-
if (mongory_matcher_mapping == NULL) {
|
|
164
|
-
// TODO: Set error: Cannot register if mapping init failed.
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Wrap the function pointer in a mongory_value to store in the table.
|
|
170
|
-
mongory_value *value = mongory_value_wrap_ptr(mongory_internal_pool, build_func);
|
|
171
|
-
if (value == NULL) {
|
|
172
|
-
// TODO: Set error: Failed to wrap pointer.
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
mongory_matcher_mapping->set(mongory_matcher_mapping, name, value);
|
|
177
|
-
// TODO: Check return value of set?
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
void mongory_matcher_register(char *name, mongory_matcher_build_func build_func) {
|
|
181
|
-
mongory_config_lock();
|
|
182
|
-
mongory_matcher_register_unlocked(name, build_func);
|
|
183
|
-
mongory_config_unlock();
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* @brief Retrieves a matcher build function by its name from the global
|
|
188
|
-
* mapping.
|
|
189
|
-
* @param name The name of the matcher to retrieve.
|
|
190
|
-
* @return mongory_matcher_build_func A function pointer to the matcher's
|
|
191
|
-
* constructor, or NULL if not found.
|
|
192
|
-
*/
|
|
193
|
-
mongory_matcher_build_func mongory_matcher_build_func_get(char *name) {
|
|
194
|
-
mongory_config_lock();
|
|
195
|
-
mongory_matcher_build_func result = NULL;
|
|
196
|
-
if (mongory_matcher_mapping != NULL) {
|
|
197
|
-
mongory_value *value = mongory_matcher_mapping->get(mongory_matcher_mapping, name);
|
|
198
|
-
if (value != NULL && value->type == MONGORY_TYPE_POINTER) {
|
|
199
|
-
result = (mongory_matcher_build_func)value->data.ptr;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
mongory_config_unlock();
|
|
203
|
-
return result;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* @brief Sets the function for deep conversion of external values.
|
|
208
|
-
* Initializes the value converter if necessary.
|
|
209
|
-
* @param deep_convert The deep conversion function.
|
|
210
|
-
*/
|
|
211
|
-
void mongory_value_converter_deep_convert_set(mongory_deep_convert_func deep_convert) {
|
|
212
|
-
mongory_internal_value_converter.deep_convert = deep_convert;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* @brief Sets the function for shallow conversion of external values.
|
|
217
|
-
* Initializes the value converter if necessary.
|
|
218
|
-
* @param shallow_convert The shallow conversion function.
|
|
219
|
-
*/
|
|
220
|
-
void mongory_value_converter_shallow_convert_set(mongory_shallow_convert_func shallow_convert) {
|
|
221
|
-
mongory_internal_value_converter.shallow_convert = shallow_convert;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* @brief Sets the function for recovering external values from mongory_value.
|
|
226
|
-
* Initializes the value converter if necessary.
|
|
227
|
-
* @param recover The recovery function.
|
|
228
|
-
*/
|
|
229
|
-
void mongory_value_converter_recover_set(mongory_recover_func recover) {
|
|
230
|
-
mongory_internal_value_converter.recover = recover;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
void mongory_custom_matcher_match_func_set(bool (*match)(void *external_matcher, mongory_value *value)) {
|
|
235
|
-
mongory_custom_matcher_adapter.match = match;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
void mongory_custom_matcher_build_func_set(mongory_matcher_custom_context *(*build)(char *key, mongory_value *condition, void *extern_ctx)) {
|
|
239
|
-
mongory_custom_matcher_adapter.build = build;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
void mongory_custom_matcher_lookup_func_set(bool (*lookup)(char *key)) {
|
|
243
|
-
mongory_custom_matcher_adapter.lookup = lookup;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
void mongory_matcher_trace_result_colorful_set(bool colorful) {
|
|
247
|
-
mongory_matcher_trace_result_colorful = colorful;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
void mongory_max_depth_set(size_t max_depth) {
|
|
251
|
-
mongory_config_lock();
|
|
252
|
-
mongory_compile_max_depth = max_depth;
|
|
253
|
-
mongory_config_unlock();
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
size_t mongory_max_depth_get(void) {
|
|
257
|
-
mongory_config_lock();
|
|
258
|
-
size_t val = mongory_compile_max_depth;
|
|
259
|
-
mongory_config_unlock();
|
|
260
|
-
return val;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
void mongory_max_nodes_set(size_t max_nodes) {
|
|
264
|
-
mongory_config_lock();
|
|
265
|
-
mongory_compile_max_nodes = max_nodes;
|
|
266
|
-
mongory_config_unlock();
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
size_t mongory_max_nodes_get(void) {
|
|
270
|
-
mongory_config_lock();
|
|
271
|
-
size_t val = mongory_compile_max_nodes;
|
|
272
|
-
mongory_config_unlock();
|
|
273
|
-
return val;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* @brief Initializes all core Mongory library components.
|
|
278
|
-
* This includes the internal memory pool, regex adapter, matcher mapping table,
|
|
279
|
-
* and value converter. It then registers all standard matcher types.
|
|
280
|
-
* This function MUST be called before using most other library features.
|
|
281
|
-
*/
|
|
282
|
-
void mongory_init() {
|
|
283
|
-
mongory_config_lock();
|
|
284
|
-
// Initialize all global components. Order can be important if one init
|
|
285
|
-
// depends on another (e.g., most depend on the pool).
|
|
286
|
-
mongory_internal_pool_init();
|
|
287
|
-
mongory_matcher_mapping_init();
|
|
288
|
-
|
|
289
|
-
// Register all standard matchers.
|
|
290
|
-
// Note: These registrations rely on mongory_internal_pool and
|
|
291
|
-
// mongory_matcher_mapping being successfully initialized.
|
|
292
|
-
// TODO: Add checks to ensure initializations were successful before
|
|
293
|
-
// proceeding.
|
|
294
|
-
mongory_matcher_register_unlocked("$in", mongory_matcher_in_new);
|
|
295
|
-
mongory_matcher_register_unlocked("$nin", mongory_matcher_not_in_new);
|
|
296
|
-
mongory_matcher_register_unlocked("$eq", mongory_matcher_equal_new);
|
|
297
|
-
mongory_matcher_register_unlocked("$ne", mongory_matcher_not_equal_new);
|
|
298
|
-
mongory_matcher_register_unlocked("$gt", mongory_matcher_greater_than_new);
|
|
299
|
-
mongory_matcher_register_unlocked("$gte", mongory_matcher_greater_than_or_equal_new);
|
|
300
|
-
mongory_matcher_register_unlocked("$lt", mongory_matcher_less_than_new);
|
|
301
|
-
mongory_matcher_register_unlocked("$lte", mongory_matcher_less_than_or_equal_new);
|
|
302
|
-
mongory_matcher_register_unlocked("$exists", mongory_matcher_exists_new);
|
|
303
|
-
mongory_matcher_register_unlocked("$present", mongory_matcher_present_new);
|
|
304
|
-
mongory_matcher_register_unlocked("$regex", mongory_matcher_regex_new);
|
|
305
|
-
mongory_matcher_register_unlocked("$and", mongory_matcher_and_new);
|
|
306
|
-
mongory_matcher_register_unlocked("$or", mongory_matcher_or_new);
|
|
307
|
-
mongory_matcher_register_unlocked("$elemMatch", mongory_matcher_elem_match_new);
|
|
308
|
-
mongory_matcher_register_unlocked("$every", mongory_matcher_every_new);
|
|
309
|
-
mongory_matcher_register_unlocked("$not", mongory_matcher_not_new);
|
|
310
|
-
mongory_matcher_register_unlocked("$size", mongory_matcher_size_new);
|
|
311
|
-
mongory_config_unlock();
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* @brief Cleans up all resources allocated by the Mongory library.
|
|
316
|
-
* This primarily involves freeing the internal memory pool, which should, in
|
|
317
|
-
* turn, release all memory allocated from it. It also resets global pointers
|
|
318
|
-
* to NULL. This should be called when the library is no longer needed to
|
|
319
|
-
* prevent memory leaks.
|
|
320
|
-
*/
|
|
321
|
-
void mongory_cleanup() {
|
|
322
|
-
mongory_config_lock();
|
|
323
|
-
if (mongory_internal_pool != NULL) {
|
|
324
|
-
// Freeing the pool should handle all allocations made from it,
|
|
325
|
-
// including the regex_adapter, matcher_mapping table (and its contents if
|
|
326
|
-
// they were allocated from this pool), and value_converter.
|
|
327
|
-
mongory_internal_pool->free(mongory_internal_pool);
|
|
328
|
-
mongory_internal_pool = NULL;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// Set other global pointers to NULL to indicate they are no longer valid.
|
|
332
|
-
// The memory they pointed to should have been managed by the internal pool.
|
|
333
|
-
mongory_matcher_mapping = NULL; // The table itself and its nodes.
|
|
334
|
-
mongory_config_unlock();
|
|
335
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
#ifndef MONGORY_FOUNDATIONS_CONFIG_PRIVATE_H
|
|
2
|
-
#define MONGORY_FOUNDATIONS_CONFIG_PRIVATE_H
|
|
3
|
-
#include "../matchers/base_matcher.h"
|
|
4
|
-
#include "mongory-core/foundations/config.h"
|
|
5
|
-
#include "mongory-core/foundations/table.h"
|
|
6
|
-
#include "mongory-core/matchers/matcher.h"
|
|
7
|
-
|
|
8
|
-
typedef struct mongory_regex_adapter {
|
|
9
|
-
mongory_regex_func match_func;
|
|
10
|
-
mongory_regex_options_func options_match_func;
|
|
11
|
-
mongory_regex_stringify_func stringify_func;
|
|
12
|
-
} mongory_regex_adapter;
|
|
13
|
-
|
|
14
|
-
typedef struct mongory_value_converter {
|
|
15
|
-
mongory_deep_convert_func deep_convert;
|
|
16
|
-
mongory_shallow_convert_func shallow_convert;
|
|
17
|
-
mongory_recover_func recover;
|
|
18
|
-
} mongory_value_converter;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @brief Function pointer type for matching a value against an external matcher.
|
|
22
|
-
*
|
|
23
|
-
* This function is called when a value needs to be matched against an external
|
|
24
|
-
* matcher.
|
|
25
|
-
*
|
|
26
|
-
* @param external_matcher The external reference to the matcher.
|
|
27
|
-
* @param value The value to match against.
|
|
28
|
-
* @return bool True if the value matches the matcher, false otherwise.
|
|
29
|
-
*/
|
|
30
|
-
typedef struct mongory_matcher_custom_adapter {
|
|
31
|
-
bool (*match)(void *external_matcher, mongory_value *value); // Match a value against an external matcher.
|
|
32
|
-
mongory_matcher_custom_context *(*build)(char *key, mongory_value *condition, void *extern_ctx); // Build an external matcher reference.
|
|
33
|
-
bool (*lookup)(char *key); // Lookup a matcher reference by key.
|
|
34
|
-
} mongory_matcher_custom_adapter;
|
|
35
|
-
|
|
36
|
-
extern mongory_memory_pool *mongory_internal_pool;
|
|
37
|
-
extern mongory_regex_adapter mongory_internal_regex_adapter;
|
|
38
|
-
extern mongory_table *mongory_matcher_mapping;
|
|
39
|
-
extern mongory_value_converter mongory_internal_value_converter;
|
|
40
|
-
extern mongory_matcher_custom_adapter mongory_custom_matcher_adapter;
|
|
41
|
-
extern bool mongory_matcher_trace_result_colorful;
|
|
42
|
-
|
|
43
|
-
typedef mongory_matcher *(*mongory_matcher_build_func)(mongory_memory_pool *pool,
|
|
44
|
-
mongory_value *condition,
|
|
45
|
-
void *extern_ctx); // build function
|
|
46
|
-
void mongory_matcher_register(char *name, mongory_matcher_build_func build_func);
|
|
47
|
-
mongory_matcher_build_func mongory_matcher_build_func_get(char *name);
|
|
48
|
-
|
|
49
|
-
#endif
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
#ifndef MONGORY_ERROR_C
|
|
2
|
-
#define MONGORY_ERROR_C
|
|
3
|
-
/**
|
|
4
|
-
* @file error.c
|
|
5
|
-
* @brief Implements error type to string conversion for the Mongory library.
|
|
6
|
-
*/
|
|
7
|
-
#include <mongory-core/foundations/error.h>
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @brief Converts a mongory_error_type enum to its human-readable string
|
|
11
|
-
* representation.
|
|
12
|
-
*
|
|
13
|
-
* This function uses the MONGORY_ERROR_TYPE_MACRO to generate a switch
|
|
14
|
-
* statement that maps each error enum to its corresponding string.
|
|
15
|
-
*
|
|
16
|
-
* @param type The mongory_error_type enum value to convert.
|
|
17
|
-
* @return const char* A string literal representing the error type. If the
|
|
18
|
-
* type is not recognized, it returns "Unknown Error Type".
|
|
19
|
-
*/
|
|
20
|
-
const char *mongory_error_type_to_string(enum mongory_error_type type) {
|
|
21
|
-
switch (type) {
|
|
22
|
-
// Use the X-Macro to generate case statements for each error type.
|
|
23
|
-
#define DEFINE_ERROR_STRING(name, num, str) \
|
|
24
|
-
case name: \
|
|
25
|
-
return str;
|
|
26
|
-
MONGORY_ERROR_TYPE_MACRO(DEFINE_ERROR_STRING)
|
|
27
|
-
#undef DEFINE_ERROR_STRING // Undefine the macro after use.
|
|
28
|
-
default:
|
|
29
|
-
// Fallback for any undefined or unknown error types.
|
|
30
|
-
return "Unknown Error Type";
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
mongory_error MONGORY_ALLOC_ERROR = {
|
|
35
|
-
.type = MONGORY_ERROR_MEMORY,
|
|
36
|
-
.message = "Memory Allocation Failed",
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
mongory_error MONGORY_DEPTH_LIMIT_ERROR = {
|
|
40
|
-
.type = MONGORY_ERROR_LIMIT_EXCEEDED,
|
|
41
|
-
.message = "Maximum condition nesting depth exceeded",
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
mongory_error MONGORY_NODE_LIMIT_ERROR = {
|
|
45
|
-
.type = MONGORY_ERROR_LIMIT_EXCEEDED,
|
|
46
|
-
.message = "Maximum matcher node count exceeded",
|
|
47
|
-
};
|
|
48
|
-
#endif
|