mongory 0.8.1-aarch64-linux → 0.9.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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -0
  3. data/README.md +12 -0
  4. data/docs/advanced_usage.md +7 -0
  5. data/docs/clang_bridge.md +6 -0
  6. data/ext/mongory_ext/extconf.rb +6 -1
  7. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +25 -0
  8. data/ext/mongory_ext/mongory-core/src/foundations/array.c +22 -15
  9. data/ext/mongory_ext/mongory-core/src/foundations/array_private.h +1 -0
  10. data/ext/mongory_ext/mongory-core/src/foundations/config.c +64 -27
  11. data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +1 -0
  12. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +49 -0
  13. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool_private.h +45 -0
  14. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +0 -2
  15. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.h +0 -6
  16. data/ext/mongory_ext/mongory-core/src/foundations/table.c +9 -10
  17. data/ext/mongory_ext/mongory-core/src/foundations/utils.c +21 -14
  18. data/ext/mongory_ext/mongory-core/src/foundations/utils.h +2 -2
  19. data/ext/mongory_ext/mongory-core/src/foundations/value.c +54 -9
  20. data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.c +31 -10
  21. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +2 -0
  22. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +2 -0
  23. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +32 -13
  24. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +34 -13
  25. data/ext/mongory_ext/mongory-core/src/matchers/existance_matcher.c +16 -3
  26. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +76 -15
  27. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.h +12 -0
  28. data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.c +57 -15
  29. data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +43 -7
  30. data/ext/mongory_ext/mongory_ext.c +36 -687
  31. data/ext/mongory_ext/mongory_ext_internal.h +75 -0
  32. data/ext/mongory_ext/rb_mongory_adapters.c +140 -0
  33. data/ext/mongory_ext/rb_mongory_cmatcher.c +386 -0
  34. data/ext/mongory_ext/rb_mongory_value.c +260 -0
  35. data/lib/core/2.6/mongory_ext.so +0 -0
  36. data/lib/core/2.7/mongory_ext.so +0 -0
  37. data/lib/core/3.0/mongory_ext.so +0 -0
  38. data/lib/core/3.1/mongory_ext.so +0 -0
  39. data/lib/core/3.2/mongory_ext.so +0 -0
  40. data/lib/core/3.3/mongory_ext.so +0 -0
  41. data/lib/core/3.4/mongory_ext.so +0 -0
  42. data/lib/core/4.0/mongory_ext.so +0 -0
  43. data/lib/generators/mongory/install/templates/initializer.rb.erb +5 -0
  44. data/lib/mongory/converters/abstract_converter.rb +6 -5
  45. data/lib/mongory/converters/condition_converter.rb +2 -2
  46. data/lib/mongory/converters/key_converter.rb +1 -1
  47. data/lib/mongory/matchers/abstract_matcher.rb +1 -1
  48. data/lib/mongory/matchers/abstract_multi_matcher.rb +2 -2
  49. data/lib/mongory/matchers/array_record_matcher.rb +23 -11
  50. data/lib/mongory/matchers/elem_match_matcher.rb +2 -0
  51. data/lib/mongory/matchers/eq_matcher.rb +4 -2
  52. data/lib/mongory/matchers/field_matcher.rb +16 -3
  53. data/lib/mongory/matchers/hash_condition_matcher.rb +23 -6
  54. data/lib/mongory/matchers/in_matcher.rb +17 -1
  55. data/lib/mongory/matchers/ne_matcher.rb +7 -6
  56. data/lib/mongory/matchers/nin_matcher.rb +2 -6
  57. data/lib/mongory/matchers/regex_matcher.rb +29 -0
  58. data/lib/mongory/matchers.rb +7 -4
  59. data/lib/mongory/version.rb +1 -1
  60. data/lib/mongory.rb +57 -5
  61. metadata +8 -2
@@ -11,8 +11,9 @@
11
11
  * - $size checks the number of elements in an array against a condition.
12
12
  */
13
13
  #include "literal_matcher.h"
14
- #include "../foundations/config_private.h" // For mongory_internal_value_converter
15
- #include "../foundations/utils.h" // For mongory_try_parse_int, mongory_string_cpy
14
+ #include "../foundations/config_private.h" // For mongory_internal_value_converter
15
+ #include "../foundations/memory_pool_private.h" // For atomic & lock helpers
16
+ #include "../foundations/utils.h" // For mongory_try_parse_int, mongory_string_cpy
16
17
  #include "../foundations/string_buffer.h" // For mongory_string_buffer_appendf
17
18
  #include "array_record_matcher.h" // For handling array-specific matching logic
18
19
  #include "base_matcher.h" // For mongory_matcher_base_new
@@ -49,22 +50,56 @@
49
50
  * @param value The `mongory_value` to evaluate against the matcher's condition.
50
51
  * @return True if the value matches, false otherwise.
51
52
  */
53
+ static inline void mongory_propagate_build_error(mongory_memory_pool *build_pool, mongory_value *value) {
54
+ if (!build_pool || !build_pool->error) {
55
+ return;
56
+ }
57
+ if (value && value->pool && value->pool != build_pool) {
58
+ if (build_pool->error == &MONGORY_ALLOC_ERROR) {
59
+ value->pool->error = &MONGORY_ALLOC_ERROR;
60
+ } else {
61
+ mongory_error *copied = MG_ALLOC_PTR(value->pool, mongory_error);
62
+ if (copied) {
63
+ copied->type = build_pool->error->type;
64
+ copied->message = build_pool->error->message
65
+ ? mongory_string_cpy(value->pool, (char *)build_pool->error->message)
66
+ : NULL;
67
+ value->pool->error = copied;
68
+ } else {
69
+ value->pool->error = &MONGORY_ALLOC_ERROR;
70
+ }
71
+ }
72
+ build_pool->error = NULL;
73
+ }
74
+ }
75
+
52
76
  static inline bool mongory_matcher_literal_match(mongory_matcher *matcher, mongory_value *value) {
53
77
  mongory_literal_matcher *literal = (mongory_literal_matcher *)matcher;
54
78
  if (!literal || !literal->base.pool)
55
79
  return false; // Basic safety check
56
80
 
57
81
  if (value != NULL && value->type == MONGORY_TYPE_ARRAY) {
58
- // If the value being matched is an array, there's special handling.
59
- // The `right` child of the composite matcher is used for array record matching.
60
- // It's created on-demand if not already present.
61
- if (literal->array_record_matcher == NULL) {
62
- // Lazily create the array_record_matcher if needed.
63
- // The condition for array_record_new is the original condition of the literal matcher.
64
- literal->array_record_matcher = mongory_matcher_array_record_new(literal->base.pool, literal->base.condition, literal->base.extern_ctx);
82
+ // Double-checked locking: lazy build runs only on the first array value seen,
83
+ // keeping non-array matching and subsequent array matches lock-free.
84
+ mongory_matcher *arm = mongory_atomic_load_ptr_acquire(&literal->array_record_matcher);
85
+ if (arm == NULL) {
86
+ mongory_memory_pool *build_pool = literal->base.pool;
87
+ mongory_memory_pool_lock(build_pool);
88
+ arm = mongory_atomic_load_ptr_relaxed(&literal->array_record_matcher);
89
+ if (arm == NULL) {
90
+ arm = mongory_matcher_array_record_new(build_pool, literal->base.condition, literal->base.extern_ctx);
91
+ if (arm && literal->base.trace_stack) {
92
+ mongory_matcher_enable_trace_at(arm, literal->base.trace_stack, literal->base.trace_level + 1);
93
+ }
94
+ if (arm != NULL) {
95
+ mongory_atomic_store_ptr_release(&literal->array_record_matcher, arm);
96
+ } else {
97
+ mongory_propagate_build_error(build_pool, value);
98
+ }
99
+ }
100
+ mongory_memory_pool_unlock(build_pool);
65
101
  }
66
- // If right child exists (or was successfully created), use it.
67
- return literal->array_record_matcher ? literal->array_record_matcher->match(literal->array_record_matcher, value) : false;
102
+ return arm ? arm->match(arm, value) : false;
68
103
  } else {
69
104
  // For non-array values, or if array-specific path wasn't taken.
70
105
  // The `left` child handles the general literal condition.
@@ -173,10 +208,16 @@ static inline bool mongory_matcher_field_match(mongory_matcher *matcher, mongory
173
208
  // If the extracted field value is a pointer type that needs conversion
174
209
  // (e.g., from a language binding), convert it.
175
210
  if (field_value && field_value->type == MONGORY_TYPE_POINTER && mongory_internal_value_converter.shallow_convert) {
176
- // The pool for the converted value should ideally be the field_value's pool
177
- // or the matcher's pool.
178
- mongory_memory_pool *conversion_pool = field_value->pool ? field_value->pool : matcher->pool;
179
- field_value = mongory_internal_value_converter.shallow_convert(conversion_pool, field_value->data.ptr);
211
+ // Prefer the caller/record's thread-local pool over the shared matcher->pool.
212
+ mongory_memory_pool *conversion_pool =
213
+ field_value->pool ? field_value->pool : (value->pool ? value->pool : matcher->pool);
214
+ if (conversion_pool == matcher->pool) {
215
+ mongory_memory_pool_lock(matcher->pool);
216
+ field_value = mongory_internal_value_converter.shallow_convert(conversion_pool, field_value->data.ptr);
217
+ mongory_memory_pool_unlock(matcher->pool);
218
+ } else {
219
+ field_value = mongory_internal_value_converter.shallow_convert(conversion_pool, field_value->data.ptr);
220
+ }
180
221
  }
181
222
  // Now, use the literal_match logic (which uses composite.left primarily)
182
223
  // to match the extracted field_value.
@@ -207,6 +248,7 @@ mongory_matcher *mongory_matcher_field_new(mongory_memory_pool *pool, char *fiel
207
248
  field_m->literal.base.name = mongory_string_cpy(pool, "Field");
208
249
  field_m->literal.base.explain = mongory_matcher_field_explain;
209
250
  field_m->literal.base.traverse = mongory_matcher_literal_traverse;
251
+ field_m->literal.base.extern_ctx = extern_ctx;
210
252
  // The 'left' child of the composite is the actual matcher for the field's value,
211
253
  // determined by the type of 'condition_for_field'.
212
254
  field_m->literal.delegate_matcher = mongory_matcher_literal_delegate(pool, condition_for_field, extern_ctx);
@@ -147,13 +147,38 @@ static bool mongory_matcher_enable_trace_cb(mongory_matcher *matcher, mongory_ma
147
147
  matcher->trace_stack = (mongory_array *)ctx->acc;
148
148
  matcher->trace_level = ctx->level;
149
149
  matcher->match = mongory_matcher_traced_match;
150
+ if (matcher->traverse == mongory_matcher_literal_traverse) {
151
+ mongory_literal_matcher *literal = (mongory_literal_matcher *)matcher;
152
+ if (literal->array_record_matcher && literal->delegate_matcher) {
153
+ mongory_matcher_traverse_context delegate_ctx = {
154
+ .pool = ctx->pool,
155
+ .level = ctx->level + 1,
156
+ .count = 0,
157
+ .total = 1,
158
+ .acc = ctx->acc,
159
+ .callback = ctx->callback,
160
+ };
161
+ literal->delegate_matcher->traverse(literal->delegate_matcher, &delegate_ctx);
162
+ }
163
+ }
150
164
  return true;
151
165
  }
152
166
 
153
167
  static bool mongory_matcher_disable_trace_cb(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
154
- (void)ctx;
155
168
  matcher->match = matcher->original_match;
156
169
  matcher->trace_stack = NULL;
170
+ if (matcher->traverse == mongory_matcher_literal_traverse) {
171
+ mongory_literal_matcher *literal = (mongory_literal_matcher *)matcher;
172
+ if (literal->array_record_matcher && literal->delegate_matcher) {
173
+ mongory_matcher_traverse_context delegate_ctx = {
174
+ .level = ctx->level + 1,
175
+ .count = 0,
176
+ .total = 1,
177
+ .callback = ctx->callback,
178
+ };
179
+ literal->delegate_matcher->traverse(literal->delegate_matcher, &delegate_ctx);
180
+ }
181
+ }
157
182
  return true;
158
183
  }
159
184
 
@@ -192,15 +217,17 @@ static mongory_array *mongory_matcher_traces_sort(mongory_array *self, int level
192
217
  return sorted_array;
193
218
  }
194
219
 
195
- void mongory_matcher_enable_trace(mongory_matcher *matcher, mongory_memory_pool *temp_pool) {
196
- MONGORY_VALIDATE_PTR(temp_pool, matcher) && MONGORY_VALIDATE_PTR(temp_pool, matcher->traverse);
197
- if (temp_pool->error != NULL) {
220
+ void mongory_matcher_enable_trace_at(mongory_matcher *matcher, mongory_array *trace_stack, int level) {
221
+ if (!matcher || !trace_stack) {
222
+ return;
223
+ }
224
+ MONGORY_VALIDATE_PTR(trace_stack->pool, matcher->traverse);
225
+ if (trace_stack->pool->error != NULL) {
198
226
  return;
199
227
  }
200
- mongory_array *trace_stack = mongory_array_new(temp_pool);
201
228
  mongory_matcher_traverse_context ctx = {
202
- .pool = temp_pool,
203
- .level = 0,
229
+ .pool = trace_stack->pool,
230
+ .level = level,
204
231
  .count = 0,
205
232
  .total = 0,
206
233
  .acc = (void *)trace_stack,
@@ -209,6 +236,15 @@ void mongory_matcher_enable_trace(mongory_matcher *matcher, mongory_memory_pool
209
236
  matcher->traverse(matcher, &ctx);
210
237
  }
211
238
 
239
+ void mongory_matcher_enable_trace(mongory_matcher *matcher, mongory_memory_pool *temp_pool) {
240
+ MONGORY_VALIDATE_PTR(temp_pool, matcher) && MONGORY_VALIDATE_PTR(temp_pool, matcher->traverse);
241
+ if (temp_pool->error != NULL) {
242
+ return;
243
+ }
244
+ mongory_array *trace_stack = mongory_array_new(temp_pool);
245
+ mongory_matcher_enable_trace_at(matcher, trace_stack, 0);
246
+ }
247
+
212
248
  void mongory_matcher_disable_trace(mongory_matcher *matcher) {
213
249
  MONGORY_VALIDATE_PTR(matcher->pool, matcher) && MONGORY_VALIDATE_PTR(matcher->pool, matcher->traverse);
214
250
  if (matcher->pool->error != NULL) {