yeptris 0.6.64.0-riscv64-linux-gnu

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 (164) hide show
  1. checksums.yaml +7 -0
  2. data/README.adoc +150 -0
  3. data/ext/build_windows_native.rb +60 -0
  4. data/ext/libyeptris/extconf.rb +57 -0
  5. data/ext/yeptris_native/cbor_ruby.c +198 -0
  6. data/ext/yeptris_native/extconf.rb +99 -0
  7. data/ext/yeptris_native/json_ruby.c +414 -0
  8. data/ext/yeptris_native/version.h +29 -0
  9. data/ext/yeptris_native/yeptris_native.c +507 -0
  10. data/lib/yeptris/3.3/native.so +0 -0
  11. data/lib/yeptris/cbor.rb +169 -0
  12. data/lib/yeptris/document.rb +319 -0
  13. data/lib/yeptris/ffi.rb +572 -0
  14. data/lib/yeptris/json/descriptor.rb +266 -0
  15. data/lib/yeptris/json.rb +502 -0
  16. data/lib/yeptris/materializer.rb +389 -0
  17. data/lib/yeptris/node.rb +482 -0
  18. data/lib/yeptris/psych/class_loader.rb +24 -0
  19. data/lib/yeptris/psych/coder_shim.rb +55 -0
  20. data/lib/yeptris/psych/drop_in.rb +63 -0
  21. data/lib/yeptris/psych/encodable.rb +14 -0
  22. data/lib/yeptris/psych/handler.rb +95 -0
  23. data/lib/yeptris/psych/parser.rb +114 -0
  24. data/lib/yeptris/psych/scalar_scanner.rb +149 -0
  25. data/lib/yeptris/psych/tree_builder.rb +119 -0
  26. data/lib/yeptris/psych/visitors.rb +670 -0
  27. data/lib/yeptris/psych.rb +796 -0
  28. data/lib/yeptris/schema.rb +253 -0
  29. data/lib/yeptris/validation.rb +320 -0
  30. data/lib/yeptris/valueml.rb +477 -0
  31. data/lib/yeptris/yaml/descriptor.rb +56 -0
  32. data/lib/yeptris/yaml.rb +668 -0
  33. data/lib/yeptris.rb +130 -0
  34. data/libyeptris.so +0 -0
  35. data/vendor/libyeptris/CMakeLists.txt +280 -0
  36. data/vendor/libyeptris/cmake/yeptris-config.cmake.in +5 -0
  37. data/vendor/libyeptris/cmake/yeptris.pc.in +11 -0
  38. data/vendor/libyeptris/src/CMakeLists.txt +183 -0
  39. data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
  40. data/vendor/libyeptris/src/include/yeptris/cbor.h +174 -0
  41. data/vendor/libyeptris/src/include/yeptris/dom.h +196 -0
  42. data/vendor/libyeptris/src/include/yeptris/emit.h +128 -0
  43. data/vendor/libyeptris/src/include/yeptris/error.h +42 -0
  44. data/vendor/libyeptris/src/include/yeptris/events.h +171 -0
  45. data/vendor/libyeptris/src/include/yeptris/json.h +57 -0
  46. data/vendor/libyeptris/src/include/yeptris/json.hpp +258 -0
  47. data/vendor/libyeptris/src/include/yeptris/jsonc_compat.h +115 -0
  48. data/vendor/libyeptris/src/include/yeptris/marshal.h +75 -0
  49. data/vendor/libyeptris/src/include/yeptris/parse.h +121 -0
  50. data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
  51. data/vendor/libyeptris/src/include/yeptris/resolve.h +81 -0
  52. data/vendor/libyeptris/src/include/yeptris/schema.h +121 -0
  53. data/vendor/libyeptris/src/include/yeptris/tape.h +128 -0
  54. data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
  55. data/vendor/libyeptris/src/include/yeptris/validate.h +401 -0
  56. data/vendor/libyeptris/src/include/yeptris/values.h +108 -0
  57. data/vendor/libyeptris/src/include/yeptris/version.h.in +29 -0
  58. data/vendor/libyeptris/src/include/yeptris/visit.h +77 -0
  59. data/vendor/libyeptris/src/include/yeptris/yajl_compat.h +135 -0
  60. data/vendor/libyeptris/src/include/yeptris.h +24 -0
  61. data/vendor/libyeptris/src/yeptris/build.c +393 -0
  62. data/vendor/libyeptris/src/yeptris/cbor/cbor.h +35 -0
  63. data/vendor/libyeptris/src/yeptris/cbor/decode.c +1054 -0
  64. data/vendor/libyeptris/src/yeptris/cbor/encode.c +836 -0
  65. data/vendor/libyeptris/src/yeptris/cbor/encode_priv.h +32 -0
  66. data/vendor/libyeptris/src/yeptris/cbor/from_marshal.c +982 -0
  67. data/vendor/libyeptris/src/yeptris/cbor/sink.h +36 -0
  68. data/vendor/libyeptris/src/yeptris/common/chartype.c +41 -0
  69. data/vendor/libyeptris/src/yeptris/common/chartype.h +77 -0
  70. data/vendor/libyeptris/src/yeptris/common/cpu.c +81 -0
  71. data/vendor/libyeptris/src/yeptris/common/cpu.h +40 -0
  72. data/vendor/libyeptris/src/yeptris/common/error.c +65 -0
  73. data/vendor/libyeptris/src/yeptris/common/error.h +81 -0
  74. data/vendor/libyeptris/src/yeptris/common/mutex.h +45 -0
  75. data/vendor/libyeptris/src/yeptris/common/nametab.c +275 -0
  76. data/vendor/libyeptris/src/yeptris/common/nametab.h +68 -0
  77. data/vendor/libyeptris/src/yeptris/common/port.h +74 -0
  78. data/vendor/libyeptris/src/yeptris/common/simd_text.c +49 -0
  79. data/vendor/libyeptris/src/yeptris/common/simd_text.h +342 -0
  80. data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +672 -0
  81. data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +793 -0
  82. data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +324 -0
  83. data/vendor/libyeptris/src/yeptris/common/string_view.c +34 -0
  84. data/vendor/libyeptris/src/yeptris/common/string_view.h +93 -0
  85. data/vendor/libyeptris/src/yeptris/doc.h +86 -0
  86. data/vendor/libyeptris/src/yeptris/dom/dom.c +1312 -0
  87. data/vendor/libyeptris/src/yeptris/dom/dom.h +332 -0
  88. data/vendor/libyeptris/src/yeptris/dom/hpool.c +107 -0
  89. data/vendor/libyeptris/src/yeptris/dom/mapindex.c +173 -0
  90. data/vendor/libyeptris/src/yeptris/dom/mapindex.h +61 -0
  91. data/vendor/libyeptris/src/yeptris/dom/mutate.c +431 -0
  92. data/vendor/libyeptris/src/yeptris/dom/ytape.c +2323 -0
  93. data/vendor/libyeptris/src/yeptris/dom/ytape.h +96 -0
  94. data/vendor/libyeptris/src/yeptris/emit/emit.c +670 -0
  95. data/vendor/libyeptris/src/yeptris/emit/float/api.h +43 -0
  96. data/vendor/libyeptris/src/yeptris/emit/float/dragon.c +405 -0
  97. data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +231 -0
  98. data/vendor/libyeptris/src/yeptris/emit/float/fpconv.c +428 -0
  99. data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
  100. data/vendor/libyeptris/src/yeptris/emit/style.c +21 -0
  101. data/vendor/libyeptris/src/yeptris/emit/style.h +32 -0
  102. data/vendor/libyeptris/src/yeptris/emit/writer.c +1951 -0
  103. data/vendor/libyeptris/src/yeptris/emit/writer.h +111 -0
  104. data/vendor/libyeptris/src/yeptris/encoding/bom.c +31 -0
  105. data/vendor/libyeptris/src/yeptris/encoding/encoding.h +63 -0
  106. data/vendor/libyeptris/src/yeptris/encoding/transcode.c +157 -0
  107. data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
  108. data/vendor/libyeptris/src/yeptris/events/capture.c +166 -0
  109. data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
  110. data/vendor/libyeptris/src/yeptris/events/iterparse.c +298 -0
  111. data/vendor/libyeptris/src/yeptris/events/pull.c +117 -0
  112. data/vendor/libyeptris/src/yeptris/events/push.c +151 -0
  113. data/vendor/libyeptris/src/yeptris/events/recorder.c +144 -0
  114. data/vendor/libyeptris/src/yeptris/events/values.c +630 -0
  115. data/vendor/libyeptris/src/yeptris/events/values_priv.h +53 -0
  116. data/vendor/libyeptris/src/yeptris/events/yaml_compat.c +86 -0
  117. data/vendor/libyeptris/src/yeptris/events/yaml_compat.h +90 -0
  118. data/vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c +687 -0
  119. data/vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c +728 -0
  120. data/vendor/libyeptris/src/yeptris/marshal/to_json.c +650 -0
  121. data/vendor/libyeptris/src/yeptris/marshal.c +988 -0
  122. data/vendor/libyeptris/src/yeptris/memory/allocator.c +20 -0
  123. data/vendor/libyeptris/src/yeptris/memory/allocator.h +43 -0
  124. data/vendor/libyeptris/src/yeptris/memory/arena.c +150 -0
  125. data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
  126. data/vendor/libyeptris/src/yeptris/memory/pool.c +133 -0
  127. data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
  128. data/vendor/libyeptris/src/yeptris/parse/engine.c +6528 -0
  129. data/vendor/libyeptris/src/yeptris/parse/engine.h +96 -0
  130. data/vendor/libyeptris/src/yeptris/parse/events.h +137 -0
  131. data/vendor/libyeptris/src/yeptris/parse/numbers.c +374 -0
  132. data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
  133. data/vendor/libyeptris/src/yeptris/parse/scalars.c +435 -0
  134. data/vendor/libyeptris/src/yeptris/parse/scalars.h +87 -0
  135. data/vendor/libyeptris/src/yeptris/parse/stream_iter.c +358 -0
  136. data/vendor/libyeptris/src/yeptris/parse.c +1074 -0
  137. data/vendor/libyeptris/src/yeptris/plan.c +824 -0
  138. data/vendor/libyeptris/src/yeptris/resolve/compat11.c +339 -0
  139. data/vendor/libyeptris/src/yeptris/resolve/core12.c +153 -0
  140. data/vendor/libyeptris/src/yeptris/resolve/full12.c +201 -0
  141. data/vendor/libyeptris/src/yeptris/resolve/json12.c +109 -0
  142. data/vendor/libyeptris/src/yeptris/resolve/resolver.h +103 -0
  143. data/vendor/libyeptris/src/yeptris/resolve/tags.c +250 -0
  144. data/vendor/libyeptris/src/yeptris/scan/json.c +839 -0
  145. data/vendor/libyeptris/src/yeptris/scan/json.h +116 -0
  146. data/vendor/libyeptris/src/yeptris/scan/scan.c +862 -0
  147. data/vendor/libyeptris/src/yeptris/scan/scan.h +177 -0
  148. data/vendor/libyeptris/src/yeptris/schema.c +309 -0
  149. data/vendor/libyeptris/src/yeptris/tape.c +2375 -0
  150. data/vendor/libyeptris/src/yeptris/tape_in.h +39 -0
  151. data/vendor/libyeptris/src/yeptris/validate/compile.c +306 -0
  152. data/vendor/libyeptris/src/yeptris/validate/internal.h +347 -0
  153. data/vendor/libyeptris/src/yeptris/validate/jsonschema.c +1922 -0
  154. data/vendor/libyeptris/src/yeptris/validate/output.c +246 -0
  155. data/vendor/libyeptris/src/yeptris/validate/regexp.c +1600 -0
  156. data/vendor/libyeptris/src/yeptris/validate/registry.c +118 -0
  157. data/vendor/libyeptris/src/yeptris/validate/resources.c +601 -0
  158. data/vendor/libyeptris/src/yeptris/validate/stream.c +1155 -0
  159. data/vendor/libyeptris/src/yeptris/validate/validate.c +1043 -0
  160. data/vendor/libyeptris/src/yeptris/version.c +7 -0
  161. data/vendor/libyeptris/src/yeptris/visit/dom_visit.c +115 -0
  162. data/vendor/libyeptris/src/yeptris/visit/json_visit.c +293 -0
  163. data/vendor/libyeptris/src/yeptris/visit/yaml_visit.c +127 -0
  164. metadata +221 -0
@@ -0,0 +1,414 @@
1
+
2
+ /* json_ruby.c — fused RFC 8259 → Ruby VALUE (TODO.restructure/22). */
3
+ #include <ruby.h>
4
+ /* rb_hash_new_capa is Ruby 3.2+; older Rubies grow dynamically (the
5
+ * FFI fallback stays correct on every minor either way). */
6
+ #if RUBY_API_VERSION_MAJOR > 3 || (RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 2)
7
+ #define HASH_NEW_CAPA(n) rb_hash_new_capa(n)
8
+ #else
9
+ #define HASH_NEW_CAPA(n) rb_hash_new()
10
+ #endif
11
+
12
+ #include <ruby/encoding.h>
13
+ #include <ruby/intern.h>
14
+ #include <stdlib.h>
15
+ #include <string.h>
16
+ #include "parse/scalars.h"
17
+ #include <yeptris/visit.h>
18
+ #include "scan/json.h"
19
+
20
+ #define YEP_JR_MAX 1000
21
+ #define YEP_KC 1024
22
+
23
+ typedef struct {
24
+ uint64_t h;
25
+ uint32_t len;
26
+ VALUE v;
27
+ } kcent;
28
+
29
+ typedef struct {
30
+ const char* p;
31
+ size_t len;
32
+ size_t i;
33
+ char* scratch;
34
+ size_t scratch_cap;
35
+ int depth;
36
+ int err;
37
+ rb_encoding* enc;
38
+ int strict_dup; /* json gem >= 3: duplicate keys raise (issue #37) */
39
+ VALUE dup_key;
40
+ kcent kc[YEP_KC];
41
+ } jr;
42
+
43
+ static VALUE jr_value(jr* j);
44
+ static VALUE jr_object_body(jr* j, VALUE h_pre);
45
+
46
+ static void jr_ws(jr* j) {
47
+ while (j->i < j->len) {
48
+ unsigned char c = (unsigned char)j->p[j->i];
49
+ if (c == ' ' || c == '\t' || c == '\n' || c == '\r') j->i++;
50
+ else break;
51
+ }
52
+ }
53
+
54
+ /* Token-cache knob (TODO.restructure/37): off = fresh strings
55
+ * everywhere (JSON.parse's shape: every key pays its own aset
56
+ * hashing); on = interned keys/tokens (shared frozen VALUEs
57
+ * memoize their hash). The CI referee A/Bs the net sign per arch. */
58
+ enum { YEP_CACHE_ON = 0, YEP_CACHE_OFF = 1 };
59
+ static int yep_cache_mode = YEP_CACHE_ON;
60
+
61
+ /* Allocation-shape knob (TODO.restructure/39): pre = capa(8) up
62
+ * front (forces heap buffers even for tiny arrays); natural =
63
+ * rb_ary_new() so 3-element arrays stay EMBEDDED in the RVALUE, and
64
+ * bulk-path hashes get exact capacity from the counted pairs. */
65
+ enum { YEP_SHAPE_PRE = 0, YEP_SHAPE_NATURAL = 1 };
66
+ /* Default per arch (the #310 arm64 referee matrix, 24 cells over the
67
+ * json-users-shaped corpus): NATURAL — rb_ary_new() keeps 3-element
68
+ * arrays embedded in the RVALUE instead of forcing heap buffers, and
69
+ * it won EVERY cell (1.00-1.04x vs pre's 1.10-1.22x vs JSON.parse).
70
+ * x86 keeps PRE until its referee says otherwise (the GATE judges the
71
+ * per-arch default on CI). */
72
+ #if defined(__aarch64__) || defined(__arm__) || defined(__ARMEL__) || defined(_M_ARM64)
73
+ #define YEP_SHAPE_DEFAULT YEP_SHAPE_NATURAL
74
+ #else
75
+ #define YEP_SHAPE_DEFAULT YEP_SHAPE_PRE
76
+ #endif
77
+ static int yep_shape_mode = YEP_SHAPE_DEFAULT;
78
+
79
+ static uint64_t jr_hash(const char* sp, long sl) {
80
+ /* 8-byte-prefix key (the leptris nametab trick): one safe load
81
+ * of min(8, len) bytes + a multiply mix. Replaced byte-wise FNV
82
+ * (~15-20ns per token on the cached path, ~15k tokens per
83
+ * reference-corpus parse - the x86 materialization cost the
84
+ * decomposition isolated, TODO.restructure/37/38). */
85
+ uint64_t k = 0;
86
+ uint64_t take = (uint64_t)sl < 8 ? (uint64_t)sl : 8;
87
+ memcpy(&k, sp, (size_t)take);
88
+ k ^= (uint64_t)sl * 0x9E3779B97F4A7C15ull;
89
+ k *= 0xC2B2AE3D27D4EB4Full;
90
+ k ^= k >> 29;
91
+ return k;
92
+ }
93
+
94
+ static VALUE jr_cached(jr* j, const char* sp, long sl) {
95
+ uint64_t h = jr_hash(sp, sl);
96
+ uint32_t slot = (uint32_t)(h & (YEP_KC - 1));
97
+ kcent* e = &j->kc[slot];
98
+ if (e->v != 0 && e->h == h && e->len == (uint32_t)sl &&
99
+ (long)RSTRING_LEN(e->v) == sl &&
100
+ memcmp(RSTRING_PTR(e->v), sp, (size_t)sl) == 0) {
101
+ return e->v;
102
+ }
103
+ VALUE s = rb_enc_str_new(sp, sl, j->enc);
104
+ rb_str_freeze(s);
105
+ e->h = h;
106
+ e->len = (uint32_t)sl;
107
+ e->v = s;
108
+ return s;
109
+ }
110
+
111
+ static VALUE jr_str(jr* j, int as_key) {
112
+ size_t start = j->i, close = 0;
113
+ int has_esc = 0;
114
+ if (!yep_json_string(j->p, j->len, &j->i, &close, &has_esc)) { j->err = -2; return Qnil; }
115
+ const char* sp; long sl;
116
+ if (has_esc) {
117
+ uint32_t span = (uint32_t)(close - start - 1);
118
+ if (span + 1 > j->scratch_cap) {
119
+ size_t cap = j->scratch_cap ? j->scratch_cap : 64;
120
+ while (cap < span + 1) cap *= 2;
121
+ char* ns = realloc(j->scratch, cap);
122
+ if (!ns) { j->err = -1; return Qnil; }
123
+ j->scratch = ns; j->scratch_cap = cap;
124
+ }
125
+ sl = (long)yep_finish_double_into(j->p, (uint32_t)(start + 1), (uint32_t)close, j->scratch, span);
126
+ sp = j->scratch;
127
+ } else {
128
+ sp = j->p + start + 1;
129
+ sl = (long)(close - start - 1);
130
+ }
131
+ if (yep_cache_mode == YEP_CACHE_ON && (as_key || sl <= 24)) return jr_cached(j, sp, sl);
132
+ return rb_enc_str_new(sp, sl, j->enc);
133
+ }
134
+
135
+ static VALUE jr_num(jr* j) {
136
+ size_t start = j->i;
137
+ int shape = 0;
138
+ int64_t iv = 0;
139
+ double dv = 0.0;
140
+ /* the fused kernel (scan/json.h): ONE grammar walk, values out */
141
+ if (!yep_json_number_scan(j->p, j->len, &j->i, &shape, &iv, &dv)) {
142
+ j->err = -2;
143
+ return Qnil;
144
+ }
145
+ if (shape == 0) {
146
+ return LL2NUM(iv);
147
+ }
148
+ if (shape == 1) {
149
+ return DBL2NUM(dv);
150
+ }
151
+ /* integer text beyond int64: exact Bignum from the validated
152
+ * span (JSON.parse's behavior). Absurd lengths degrade to the
153
+ * approximate double. */
154
+ size_t n = j->i - start;
155
+ if (n < 512) {
156
+ char buf[512];
157
+ memcpy(buf, j->p + start, n);
158
+ buf[n] = '\0';
159
+ return rb_cstr_to_inum(buf, 10, TRUE);
160
+ }
161
+ return DBL2NUM(dv);
162
+ }
163
+
164
+ /* Insert strategy (TODO.restructure/34): bulk lands all pairs in one
165
+ * rb_hash_bulk_insert (skips per-pair dispatch) but costs +1.4k
166
+ * intermediate allocations on the reference corpus — the CI referee
167
+ * rules per platform. aset = the per-pair rb_hash_aset loop. */
168
+ enum { YEP_INS_BULK = 0, YEP_INS_ASET = 1 };
169
+ static int yep_ins_mode = YEP_INS_BULK;
170
+
171
+ static VALUE jr_object(jr* j) {
172
+ j->i++; j->depth++;
173
+ if (yep_shape_mode == YEP_SHAPE_PRE) {
174
+ VALUE h = HASH_NEW_CAPA(8);
175
+ jr_ws(j);
176
+ if (j->i < j->len && j->p[j->i] == '}') { j->i++; j->depth--; return h; }
177
+ return jr_object_body(j, h);
178
+ }
179
+ jr_ws(j);
180
+ if (j->i < j->len && j->p[j->i] == '}') { j->i++; j->depth--; return rb_hash_new(); }
181
+ return jr_object_body(j, Qundef); /* created post-loop with exact capa */
182
+
183
+ /* NOTREACHED */
184
+ }
185
+
186
+ static VALUE jr_object_body(jr* j, VALUE h_pre) {
187
+ /* The pairs staging buffer MUST live in GC-scanned memory: pairs
188
+ * beyond the current one exist only there once the key/val locals
189
+ * are reused, so a malloc'd buffer makes them invisible to the
190
+ * collector — it can free them mid-parse and recycle their slots,
191
+ * and rb_hash_bulk_insert then inserts garbage (yeptris-ruby#279:
192
+ * the arm64-darwin SIGSEGV whose fault address was document text).
193
+ * The stack array IS scanned, so the bulk fast path is bounded at
194
+ * 31 pairs; beyond that the buffered pairs flush with one
195
+ * bulk_insert and the rest of the object rides rb_hash_aset. */
196
+ VALUE pairs[64];
197
+ VALUE* pv = pairs;
198
+ size_t pcap = 64, pn = 0, heap_cap = 0;
199
+ int aset_rest = 0;
200
+ for (;;) {
201
+ jr_ws(j);
202
+ if (j->i >= j->len || j->p[j->i] != '"') { j->err = -2; goto out; }
203
+ VALUE key = jr_str(j, 1);
204
+ if (j->err) goto out;
205
+ jr_ws(j);
206
+ if (j->i >= j->len || j->p[j->i] != ':') { j->err = -2; goto out; }
207
+ j->i++;
208
+ VALUE val = jr_value(j);
209
+ if (j->err) goto out;
210
+ if (yep_ins_mode == YEP_INS_ASET || j->strict_dup || aset_rest) {
211
+ VALUE h = h_pre == Qundef ? (h_pre = HASH_NEW_CAPA(8)) : h_pre;
212
+ if (j->strict_dup && !NIL_P(rb_hash_aref(h, key))) {
213
+ j->err = -3;
214
+ j->dup_key = key;
215
+ goto out;
216
+ }
217
+ rb_hash_aset(h, key, val);
218
+ } else {
219
+ if (pn + 2 > pcap) {
220
+ /* buffer full: flush what is staged (no heap staging —
221
+ * see the #279 note above); THIS pair and the rest of
222
+ * the object ride aset — no continue here, the
223
+ * delimiter scan below must still run */
224
+ VALUE h = (h_pre == Qundef) ? (h_pre = HASH_NEW_CAPA((long)(pn / 2) + 8)) : h_pre;
225
+ rb_hash_bulk_insert((long)pn, (const VALUE*)pv, h);
226
+ pn = 0;
227
+ aset_rest = 1;
228
+ }
229
+ if (aset_rest) {
230
+ rb_hash_aset(h_pre, key, val);
231
+ } else {
232
+ pv[pn++] = key;
233
+ pv[pn++] = val;
234
+ }
235
+ }
236
+ jr_ws(j);
237
+ if (j->i >= j->len) { j->err = -2; goto out; }
238
+ if (j->p[j->i] == ',') { j->i++; continue; }
239
+ if (j->p[j->i] == '}') { j->i++; break; }
240
+ j->err = -2; goto out;
241
+ }
242
+ if (yep_ins_mode == YEP_INS_BULK) {
243
+ VALUE h = (h_pre == Qundef) ? HASH_NEW_CAPA((long)(pn / 2)) : h_pre;
244
+ rb_hash_bulk_insert((long)pn, (const VALUE*)pv, h);
245
+ if (pv != pairs) { free(pv); }
246
+ j->depth--;
247
+ return h;
248
+ }
249
+ if (h_pre == Qundef) { h_pre = HASH_NEW_CAPA(8); }
250
+ out:
251
+ if (pv != pairs) { free(pv); (void)heap_cap; }
252
+ if (j->err) return Qnil;
253
+ j->depth--;
254
+ return h_pre;
255
+ }
256
+
257
+ static VALUE jr_array(jr* j) {
258
+ j->i++; j->depth++;
259
+ VALUE a = (yep_shape_mode == YEP_SHAPE_NATURAL) ? rb_ary_new() : rb_ary_new_capa(8);
260
+ jr_ws(j);
261
+ if (j->i < j->len && j->p[j->i] == ']') { j->i++; j->depth--; return a; }
262
+ for (;;) {
263
+ VALUE v = jr_value(j);
264
+ if (j->err) return Qnil;
265
+ rb_ary_push(a, v);
266
+ jr_ws(j);
267
+ if (j->i >= j->len) { j->err = -2; return Qnil; }
268
+ if (j->p[j->i] == ',') { j->i++; continue; }
269
+ if (j->p[j->i] == ']') { j->i++; j->depth--; return a; }
270
+ j->err = -2; return Qnil;
271
+ }
272
+ }
273
+
274
+ static VALUE jr_value(jr* j) {
275
+ if (j->depth >= YEP_JR_MAX) { j->err = -2; return Qnil; }
276
+ jr_ws(j);
277
+ if (j->i >= j->len) { j->err = -2; return Qnil; }
278
+ char c = j->p[j->i];
279
+ if (c == '{') return jr_object(j);
280
+ if (c == '[') return jr_array(j);
281
+ if (c == '"') return jr_str(j, 0);
282
+ if (c == 't') {
283
+ if (!yep_json_literal(j->p, j->len, &j->i, "true")) { j->err = -2; return Qnil; }
284
+ return Qtrue;
285
+ }
286
+ if (c == 'f') {
287
+ if (!yep_json_literal(j->p, j->len, &j->i, "false")) { j->err = -2; return Qnil; }
288
+ return Qfalse;
289
+ }
290
+ if (c == 'n') {
291
+ if (!yep_json_literal(j->p, j->len, &j->i, "null")) { j->err = -2; return Qnil; }
292
+ return Qnil;
293
+ }
294
+ if (c == '-' || (c >= '0' && c <= '9')) return jr_num(j);
295
+ j->err = -2; return Qnil;
296
+ }
297
+
298
+ /* GC strategy for the parse window (TODO.restructure/34): JSON.parse
299
+ * pays minor GCs mid-parse and recycles slots continuously; a blanket
300
+ * disable defers every collection — fresh pages each iteration, which
301
+ * is cheap idle and expensive exactly under memory contention (the
302
+ * loaded-box regression). The strategy is a runtime choice so the CI
303
+ * referee can A/B without rebuilds:
304
+ * disable (default) — pause GC for the window
305
+ * none — never pause
306
+ * start — pause, then one gc_start before returning
307
+ * (pay the minor GC in-window, like JSON.parse)
308
+ */
309
+ enum { YEP_GC_DISABLE = 0, YEP_GC_NONE = 1, YEP_GC_START = 2 };
310
+ /* Default per arch (TODO.restructure/35, two CI rounds of evidence):
311
+ * - aarch64/darwin: NONE — +0 heap pages, the stdlib's own GC cadence
312
+ * (0.745x mean, h2h 91% on mac runners; disable was 0.899x/48%).
313
+ * - x86_64: DISABLE — fresh CI VMs have free pages and cheaper
314
+ * page faults than minor GCs (0.911-0.922x vs none's 1.06-1.20x).
315
+ * The mechanism cuts both ways under load: disable's +478 pages/50
316
+ * iters is exactly what a LOADED x86 box punishes — set
317
+ * YEPTRIS_NATIVE_GC=none there (documented in README). */
318
+ #if defined(__aarch64__) || defined(__arm__) || defined(__ARMEL__) || defined(_M_ARM64)
319
+ #define YEP_GC_DEFAULT YEP_GC_NONE
320
+ #else
321
+ #define YEP_GC_DEFAULT YEP_GC_DISABLE
322
+ #endif
323
+ static int yep_gc_mode = YEP_GC_DEFAULT;
324
+
325
+ int yep_rb_gc_mode(void) { return yep_gc_mode; }
326
+ int yep_rb_ins_mode(void) { return yep_ins_mode; }
327
+ int yep_rb_cache_mode(void) { return yep_cache_mode; }
328
+ int yep_rb_shape_mode(void) { return yep_shape_mode; }
329
+ void yep_rb_set_shape_mode(int mode) {
330
+ if (mode == YEP_SHAPE_PRE || mode == YEP_SHAPE_NATURAL) yep_shape_mode = mode;
331
+ }
332
+ void yep_rb_set_cache_mode(int mode) {
333
+ if (mode == YEP_CACHE_ON || mode == YEP_CACHE_OFF) yep_cache_mode = mode;
334
+ }
335
+ void yep_rb_set_ins_mode(int mode) {
336
+ if (mode == YEP_INS_BULK || mode == YEP_INS_ASET) yep_ins_mode = mode;
337
+ }
338
+ void yep_rb_set_gc_mode(int mode) {
339
+ if (mode >= YEP_GC_DISABLE && mode <= YEP_GC_START) {
340
+ yep_gc_mode = mode;
341
+ }
342
+ }
343
+
344
+ /* Pure grammar walk, no materialization (TODO.restructure/37): the
345
+ * same scan kernels through the null vtable. Decomposes scan vs
346
+ * materialize cost. Returns seconds for n iterations. */
347
+ #include <time.h>
348
+
349
+
350
+ /* portable monotonic seconds: clock_gettime macro-expands to Ruby's
351
+ * rb_w32_clock_gettime on mingw toolchains, which the windows-11-arm
352
+ * Ruby does not export (undefined symbol at link) */
353
+ #ifdef _WIN32
354
+ #include <windows.h>
355
+ static double yep_now_s(void) {
356
+ LARGE_INTEGER c, f;
357
+ QueryPerformanceCounter(&c);
358
+ QueryPerformanceFrequency(&f);
359
+ return (double)c.QuadPart / (double)f.QuadPart;
360
+ }
361
+ #else
362
+ static double yep_now_s(void) {
363
+ struct timespec t;
364
+ clock_gettime(CLOCK_MONOTONIC, &t);
365
+ return (double)t.tv_sec + (double)t.tv_nsec / 1e9;
366
+ }
367
+ #endif
368
+
369
+ double yep_rb_scan_time(const char* p, size_t len, int n) {
370
+ static const YeptrisVisitVTable none = {0};
371
+ double s0 = yep_now_s();
372
+ for (int i = 0; i < n; i++) {
373
+ (void)yeptris_visit_json(p, len, &none, NULL);
374
+ }
375
+ return yep_now_s() - s0;
376
+ }
377
+
378
+ VALUE yep_rb_parse_json(const char* p, size_t len, int strict_dup) {
379
+ jr j;
380
+ memset(&j, 0, sizeof(j));
381
+ /* The parse holds j.p across unbounded allocations, and the GC
382
+ * strategy knobs leave collection ENABLED during the window
383
+ * (arm64's default is none). A compaction moving the source
384
+ * string would dangle every j->p read after the move
385
+ * (yeptris-ruby#279's heap-layout-dependent SIGSEGV class), so
386
+ * the parse runs on a private copy: one memcpy of the input,
387
+ * then no Ruby object backs the cursor. */
388
+ char* own = malloc(len ? len : 1);
389
+ if (own == NULL) rb_raise(rb_eNoMemError, "yeptris native json");
390
+ memcpy(own, p, len);
391
+ j.p = own; j.len = len; j.enc = rb_utf8_encoding();
392
+ j.strict_dup = strict_dup;
393
+ VALUE already = Qtrue;
394
+ if (yep_gc_mode != YEP_GC_NONE) already = rb_gc_disable();
395
+ VALUE v = jr_value(&j);
396
+ jr_ws(&j);
397
+ if (j.i != len && j.err == 0) j.err = -2;
398
+ free(j.scratch);
399
+ free(own);
400
+ if (already == Qfalse) rb_gc_enable();
401
+ if (yep_gc_mode == YEP_GC_START && j.err == 0) rb_gc_start();
402
+ if (j.err == -1) rb_raise(rb_eNoMemError, "yeptris native json");
403
+ if (j.err == -3) {
404
+ rb_raise(rb_path2class("Yeptris::ParseError"), "duplicate key \"%s\" in JSON object",
405
+ RSTRING_PTR(j.dup_key));
406
+ }
407
+ if (j.err != 0) {
408
+ /* the tape engine's wording ("not strict JSON at byte N") so
409
+ * consumers can pin one error shape across both routes
410
+ * (yeptris-ruby#279's adjacent note) */
411
+ rb_raise(rb_path2class("Yeptris::ParseError"), "not strict JSON at byte %zu", j.i);
412
+ }
413
+ return v;
414
+ }
@@ -0,0 +1,29 @@
1
+ /* version.h — generated from the CMake project VERSION.
2
+ *
3
+ * CMakeLists.txt project(yeptris VERSION ...) is the single source of truth;
4
+ * scripts/bump-version.sh syncs vcpkg.json and CHANGELOG.md from it. Never
5
+ * hand-edit the generated file (it lives in the build tree).
6
+ */
7
+ #ifndef YEPTRIS_VERSION_H
8
+ #define YEPTRIS_VERSION_H
9
+
10
+ #include <yeptris/api.h>
11
+
12
+ #define YEPTRIS_VERSION_MAJOR 0
13
+ #define YEPTRIS_VERSION_MINOR 6
14
+ #define YEPTRIS_VERSION_PATCH 64
15
+ #define YEPTRIS_VERSION_STRING "0.6.64"
16
+
17
+ #ifdef __cplusplus
18
+ extern "C" {
19
+ #endif
20
+
21
+ /* Returns the library version string ("major.minor.patch").
22
+ * Memory: static storage; valid for the lifetime of the process. */
23
+ YEPTRIS_API const char* yeptris_version(void);
24
+
25
+ #ifdef __cplusplus
26
+ }
27
+ #endif
28
+
29
+ #endif /* YEPTRIS_VERSION_H */