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.
- checksums.yaml +7 -0
- data/README.adoc +150 -0
- data/ext/build_windows_native.rb +60 -0
- data/ext/libyeptris/extconf.rb +57 -0
- data/ext/yeptris_native/cbor_ruby.c +198 -0
- data/ext/yeptris_native/extconf.rb +99 -0
- data/ext/yeptris_native/json_ruby.c +414 -0
- data/ext/yeptris_native/version.h +29 -0
- data/ext/yeptris_native/yeptris_native.c +507 -0
- data/lib/yeptris/3.3/native.so +0 -0
- data/lib/yeptris/cbor.rb +169 -0
- data/lib/yeptris/document.rb +319 -0
- data/lib/yeptris/ffi.rb +572 -0
- data/lib/yeptris/json/descriptor.rb +266 -0
- data/lib/yeptris/json.rb +502 -0
- data/lib/yeptris/materializer.rb +389 -0
- data/lib/yeptris/node.rb +482 -0
- data/lib/yeptris/psych/class_loader.rb +24 -0
- data/lib/yeptris/psych/coder_shim.rb +55 -0
- data/lib/yeptris/psych/drop_in.rb +63 -0
- data/lib/yeptris/psych/encodable.rb +14 -0
- data/lib/yeptris/psych/handler.rb +95 -0
- data/lib/yeptris/psych/parser.rb +114 -0
- data/lib/yeptris/psych/scalar_scanner.rb +149 -0
- data/lib/yeptris/psych/tree_builder.rb +119 -0
- data/lib/yeptris/psych/visitors.rb +670 -0
- data/lib/yeptris/psych.rb +796 -0
- data/lib/yeptris/schema.rb +253 -0
- data/lib/yeptris/validation.rb +320 -0
- data/lib/yeptris/valueml.rb +477 -0
- data/lib/yeptris/yaml/descriptor.rb +56 -0
- data/lib/yeptris/yaml.rb +668 -0
- data/lib/yeptris.rb +130 -0
- data/libyeptris.so +0 -0
- data/vendor/libyeptris/CMakeLists.txt +280 -0
- data/vendor/libyeptris/cmake/yeptris-config.cmake.in +5 -0
- data/vendor/libyeptris/cmake/yeptris.pc.in +11 -0
- data/vendor/libyeptris/src/CMakeLists.txt +183 -0
- data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
- data/vendor/libyeptris/src/include/yeptris/cbor.h +174 -0
- data/vendor/libyeptris/src/include/yeptris/dom.h +196 -0
- data/vendor/libyeptris/src/include/yeptris/emit.h +128 -0
- data/vendor/libyeptris/src/include/yeptris/error.h +42 -0
- data/vendor/libyeptris/src/include/yeptris/events.h +171 -0
- data/vendor/libyeptris/src/include/yeptris/json.h +57 -0
- data/vendor/libyeptris/src/include/yeptris/json.hpp +258 -0
- data/vendor/libyeptris/src/include/yeptris/jsonc_compat.h +115 -0
- data/vendor/libyeptris/src/include/yeptris/marshal.h +75 -0
- data/vendor/libyeptris/src/include/yeptris/parse.h +121 -0
- data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
- data/vendor/libyeptris/src/include/yeptris/resolve.h +81 -0
- data/vendor/libyeptris/src/include/yeptris/schema.h +121 -0
- data/vendor/libyeptris/src/include/yeptris/tape.h +128 -0
- data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
- data/vendor/libyeptris/src/include/yeptris/validate.h +401 -0
- data/vendor/libyeptris/src/include/yeptris/values.h +108 -0
- data/vendor/libyeptris/src/include/yeptris/version.h.in +29 -0
- data/vendor/libyeptris/src/include/yeptris/visit.h +77 -0
- data/vendor/libyeptris/src/include/yeptris/yajl_compat.h +135 -0
- data/vendor/libyeptris/src/include/yeptris.h +24 -0
- data/vendor/libyeptris/src/yeptris/build.c +393 -0
- data/vendor/libyeptris/src/yeptris/cbor/cbor.h +35 -0
- data/vendor/libyeptris/src/yeptris/cbor/decode.c +1054 -0
- data/vendor/libyeptris/src/yeptris/cbor/encode.c +836 -0
- data/vendor/libyeptris/src/yeptris/cbor/encode_priv.h +32 -0
- data/vendor/libyeptris/src/yeptris/cbor/from_marshal.c +982 -0
- data/vendor/libyeptris/src/yeptris/cbor/sink.h +36 -0
- data/vendor/libyeptris/src/yeptris/common/chartype.c +41 -0
- data/vendor/libyeptris/src/yeptris/common/chartype.h +77 -0
- data/vendor/libyeptris/src/yeptris/common/cpu.c +81 -0
- data/vendor/libyeptris/src/yeptris/common/cpu.h +40 -0
- data/vendor/libyeptris/src/yeptris/common/error.c +65 -0
- data/vendor/libyeptris/src/yeptris/common/error.h +81 -0
- data/vendor/libyeptris/src/yeptris/common/mutex.h +45 -0
- data/vendor/libyeptris/src/yeptris/common/nametab.c +275 -0
- data/vendor/libyeptris/src/yeptris/common/nametab.h +68 -0
- data/vendor/libyeptris/src/yeptris/common/port.h +74 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text.c +49 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text.h +342 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +672 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +793 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +324 -0
- data/vendor/libyeptris/src/yeptris/common/string_view.c +34 -0
- data/vendor/libyeptris/src/yeptris/common/string_view.h +93 -0
- data/vendor/libyeptris/src/yeptris/doc.h +86 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.c +1312 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.h +332 -0
- data/vendor/libyeptris/src/yeptris/dom/hpool.c +107 -0
- data/vendor/libyeptris/src/yeptris/dom/mapindex.c +173 -0
- data/vendor/libyeptris/src/yeptris/dom/mapindex.h +61 -0
- data/vendor/libyeptris/src/yeptris/dom/mutate.c +431 -0
- data/vendor/libyeptris/src/yeptris/dom/ytape.c +2323 -0
- data/vendor/libyeptris/src/yeptris/dom/ytape.h +96 -0
- data/vendor/libyeptris/src/yeptris/emit/emit.c +670 -0
- data/vendor/libyeptris/src/yeptris/emit/float/api.h +43 -0
- data/vendor/libyeptris/src/yeptris/emit/float/dragon.c +405 -0
- data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +231 -0
- data/vendor/libyeptris/src/yeptris/emit/float/fpconv.c +428 -0
- data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
- data/vendor/libyeptris/src/yeptris/emit/style.c +21 -0
- data/vendor/libyeptris/src/yeptris/emit/style.h +32 -0
- data/vendor/libyeptris/src/yeptris/emit/writer.c +1951 -0
- data/vendor/libyeptris/src/yeptris/emit/writer.h +111 -0
- data/vendor/libyeptris/src/yeptris/encoding/bom.c +31 -0
- data/vendor/libyeptris/src/yeptris/encoding/encoding.h +63 -0
- data/vendor/libyeptris/src/yeptris/encoding/transcode.c +157 -0
- data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
- data/vendor/libyeptris/src/yeptris/events/capture.c +166 -0
- data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
- data/vendor/libyeptris/src/yeptris/events/iterparse.c +298 -0
- data/vendor/libyeptris/src/yeptris/events/pull.c +117 -0
- data/vendor/libyeptris/src/yeptris/events/push.c +151 -0
- data/vendor/libyeptris/src/yeptris/events/recorder.c +144 -0
- data/vendor/libyeptris/src/yeptris/events/values.c +630 -0
- data/vendor/libyeptris/src/yeptris/events/values_priv.h +53 -0
- data/vendor/libyeptris/src/yeptris/events/yaml_compat.c +86 -0
- data/vendor/libyeptris/src/yeptris/events/yaml_compat.h +90 -0
- data/vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c +687 -0
- data/vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c +728 -0
- data/vendor/libyeptris/src/yeptris/marshal/to_json.c +650 -0
- data/vendor/libyeptris/src/yeptris/marshal.c +988 -0
- data/vendor/libyeptris/src/yeptris/memory/allocator.c +20 -0
- data/vendor/libyeptris/src/yeptris/memory/allocator.h +43 -0
- data/vendor/libyeptris/src/yeptris/memory/arena.c +150 -0
- data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
- data/vendor/libyeptris/src/yeptris/memory/pool.c +133 -0
- data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.c +6528 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.h +96 -0
- data/vendor/libyeptris/src/yeptris/parse/events.h +137 -0
- data/vendor/libyeptris/src/yeptris/parse/numbers.c +374 -0
- data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
- data/vendor/libyeptris/src/yeptris/parse/scalars.c +435 -0
- data/vendor/libyeptris/src/yeptris/parse/scalars.h +87 -0
- data/vendor/libyeptris/src/yeptris/parse/stream_iter.c +358 -0
- data/vendor/libyeptris/src/yeptris/parse.c +1074 -0
- data/vendor/libyeptris/src/yeptris/plan.c +824 -0
- data/vendor/libyeptris/src/yeptris/resolve/compat11.c +339 -0
- data/vendor/libyeptris/src/yeptris/resolve/core12.c +153 -0
- data/vendor/libyeptris/src/yeptris/resolve/full12.c +201 -0
- data/vendor/libyeptris/src/yeptris/resolve/json12.c +109 -0
- data/vendor/libyeptris/src/yeptris/resolve/resolver.h +103 -0
- data/vendor/libyeptris/src/yeptris/resolve/tags.c +250 -0
- data/vendor/libyeptris/src/yeptris/scan/json.c +839 -0
- data/vendor/libyeptris/src/yeptris/scan/json.h +116 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.c +862 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.h +177 -0
- data/vendor/libyeptris/src/yeptris/schema.c +309 -0
- data/vendor/libyeptris/src/yeptris/tape.c +2375 -0
- data/vendor/libyeptris/src/yeptris/tape_in.h +39 -0
- data/vendor/libyeptris/src/yeptris/validate/compile.c +306 -0
- data/vendor/libyeptris/src/yeptris/validate/internal.h +347 -0
- data/vendor/libyeptris/src/yeptris/validate/jsonschema.c +1922 -0
- data/vendor/libyeptris/src/yeptris/validate/output.c +246 -0
- data/vendor/libyeptris/src/yeptris/validate/regexp.c +1600 -0
- data/vendor/libyeptris/src/yeptris/validate/registry.c +118 -0
- data/vendor/libyeptris/src/yeptris/validate/resources.c +601 -0
- data/vendor/libyeptris/src/yeptris/validate/stream.c +1155 -0
- data/vendor/libyeptris/src/yeptris/validate/validate.c +1043 -0
- data/vendor/libyeptris/src/yeptris/version.c +7 -0
- data/vendor/libyeptris/src/yeptris/visit/dom_visit.c +115 -0
- data/vendor/libyeptris/src/yeptris/visit/json_visit.c +293 -0
- data/vendor/libyeptris/src/yeptris/visit/yaml_visit.c +127 -0
- metadata +221 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
/* values.c — the typed value stream (TODO.impl/15 phase F).
|
|
2
|
+
*
|
|
3
|
+
* One engine run through the shared capture sink, then one C pass
|
|
4
|
+
* converting every scalar by its resolver tag through the number
|
|
5
|
+
* kernels (parse/numbers.c — the same converters the node typed
|
|
6
|
+
* accessors ride). The host walks a flat typed array: no per-scalar
|
|
7
|
+
* parsing, no pending-key bookkeeping (is_key), anchor names arrive
|
|
8
|
+
* as uniform YEP_V_ANCHOR entries decorating the value they bind.
|
|
9
|
+
*
|
|
10
|
+
* TODO.restructure/21: the record machinery is shared (values_priv.h)
|
|
11
|
+
* with the Marshal emitter, a DOM linearizer produces the same records
|
|
12
|
+
* from a built tree, and the input entry sniffs strict JSON to build
|
|
13
|
+
* through the JSON scanner — any grammar surprise defers to the engine
|
|
14
|
+
* so records stay byte-identical across routes. */
|
|
15
|
+
|
|
16
|
+
#include <stdlib.h>
|
|
17
|
+
#include <string.h>
|
|
18
|
+
|
|
19
|
+
#include "../../include/yeptris/values.h"
|
|
20
|
+
#include "../common/simd_text.h"
|
|
21
|
+
#include "../dom/dom.h"
|
|
22
|
+
#include "../encoding/encoding.h"
|
|
23
|
+
#include "../memory/allocator.h"
|
|
24
|
+
#include "../parse/engine.h"
|
|
25
|
+
#include "../parse/numbers.h"
|
|
26
|
+
#include "../resolve/resolver.h"
|
|
27
|
+
#include "../scan/json.h"
|
|
28
|
+
#include "capture.h"
|
|
29
|
+
#include "values_priv.h"
|
|
30
|
+
|
|
31
|
+
uint32_t yep_val_arena_put(yep_value_ctx* c, const char* p, uint32_t len) {
|
|
32
|
+
if (c->arena_len + len + 1 > c->arena_cap) {
|
|
33
|
+
size_t cap = c->arena_cap ? c->arena_cap : 256;
|
|
34
|
+
while (cap < c->arena_len + len + 1) {
|
|
35
|
+
cap *= 2;
|
|
36
|
+
}
|
|
37
|
+
char* na = realloc(c->arena, cap);
|
|
38
|
+
if (na == NULL) {
|
|
39
|
+
c->oom = 1;
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
c->arena = na;
|
|
43
|
+
c->arena_cap = cap;
|
|
44
|
+
}
|
|
45
|
+
if (len != 0) {
|
|
46
|
+
memcpy(c->arena + c->arena_len, p, len);
|
|
47
|
+
}
|
|
48
|
+
uint32_t off = (uint32_t)c->arena_len;
|
|
49
|
+
c->arena_len += len;
|
|
50
|
+
c->arena[c->arena_len++] = '\0'; /* names read as C strings */
|
|
51
|
+
return off;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
void yep_val_put(yep_value_ctx* c, const YeptrisValue* v) {
|
|
55
|
+
if (c->n == c->cap) {
|
|
56
|
+
size_t cap = c->cap ? c->cap * 2 : 256;
|
|
57
|
+
YeptrisValue* nv = realloc(c->vals, cap * sizeof(*nv));
|
|
58
|
+
if (nv == NULL) {
|
|
59
|
+
c->oom = 1;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
c->vals = nv;
|
|
63
|
+
c->cap = cap;
|
|
64
|
+
}
|
|
65
|
+
c->vals[c->n++] = *v;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* The map slot rule: in a mapping, entries alternate key/value — the
|
|
69
|
+
* entry landing in an empty key slot is the key (is_key set), the
|
|
70
|
+
* next completes the pair. Applies to scalars, aliases, and
|
|
71
|
+
* collection opens (complex keys) alike. */
|
|
72
|
+
void yep_val_slot(yep_value_ctx* c, YeptrisValue* v) {
|
|
73
|
+
if (c->depth > 0 && c->depth <= YEP_V_MAX_DEPTH) {
|
|
74
|
+
int di = c->depth - 1;
|
|
75
|
+
if (c->is_seq[di]) {
|
|
76
|
+
/* a sequence entry never takes a key slot — the toggle
|
|
77
|
+
* flagged every ODD-position entry is_key=1, and the
|
|
78
|
+
* marshal strict-dup scan then false-flagged arrays with a
|
|
79
|
+
* repeated value at two odd positions ("[\"a\",\"b\",\"a\"]"
|
|
80
|
+
* = "duplicate key in object"; yeptris-ruby#333, the
|
|
81
|
+
* yeptris#680 class resurfacing through the value
|
|
82
|
+
* stream's own parity) */
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (c->key_pend[di] == 0) {
|
|
86
|
+
v->is_key = 1;
|
|
87
|
+
c->key_pend[di] = 1;
|
|
88
|
+
} else {
|
|
89
|
+
c->key_pend[di] = 0;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static void anchor_entry(yep_value_ctx* c, const char* name, uint32_t len) {
|
|
95
|
+
YeptrisValue a = {YEP_V_ANCHOR, 0, 0, 0, 0, len, 0};
|
|
96
|
+
a.off = yep_val_arena_put(c, name, len);
|
|
97
|
+
yep_val_put(c, &a);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* The scalar conversion SSOT: tag verdict + raw bytes → typed record.
|
|
101
|
+
* The engine transform and the DOM linearizer both land here, so the
|
|
102
|
+
* routes cannot drift. */
|
|
103
|
+
static void val_scalar(yep_value_ctx* c, uint8_t tag_id, int implicit_plain, const char* text,
|
|
104
|
+
uint32_t len) {
|
|
105
|
+
YeptrisValue v = {0, 0, 0, 0, 0, 0, 0};
|
|
106
|
+
int64_t vi = 0;
|
|
107
|
+
double vd = 0.0;
|
|
108
|
+
v.tag_id = tag_id;
|
|
109
|
+
/* EVERY scalar carries its raw bytes: hosts with schema quirks
|
|
110
|
+
* (Psych's single-char y/n, PyYAML's dot-required floats)
|
|
111
|
+
* re-decide from tag_id + text without re-running a conversion
|
|
112
|
+
* grammar */
|
|
113
|
+
v.off = yep_val_arena_put(c, text, len);
|
|
114
|
+
v.len = len;
|
|
115
|
+
if (tag_id != YEPTRIS_TAG_BOOL) {
|
|
116
|
+
/* b doubles as the implicit-plain flag for the other kinds
|
|
117
|
+
* (host symbol scans and friends key on it) */
|
|
118
|
+
v.b = implicit_plain ? 1 : 0;
|
|
119
|
+
}
|
|
120
|
+
switch (tag_id) {
|
|
121
|
+
case YEPTRIS_TAG_NULL:
|
|
122
|
+
v.kind = YEP_V_NULL;
|
|
123
|
+
break;
|
|
124
|
+
case YEPTRIS_TAG_BOOL:
|
|
125
|
+
v.kind = YEP_V_BOOL;
|
|
126
|
+
v.b = (uint8_t)yep_num_bool_ci(text, len);
|
|
127
|
+
break;
|
|
128
|
+
case YEPTRIS_TAG_INT:
|
|
129
|
+
v.kind = YEP_V_INT;
|
|
130
|
+
if (yep_num_i64(text, len, &vi) != 0) {
|
|
131
|
+
/* the resolver tagged it but the kernel rejects:
|
|
132
|
+
* degrade to STR — host policy decides */
|
|
133
|
+
v.kind = YEP_V_STR;
|
|
134
|
+
v.p = 0;
|
|
135
|
+
} else {
|
|
136
|
+
v.p = (uint64_t)vi;
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
case YEPTRIS_TAG_FLOAT:
|
|
140
|
+
v.kind = YEP_V_FLOAT;
|
|
141
|
+
if (yep_num_f64(text, len, &vd) != 0) {
|
|
142
|
+
v.kind = YEP_V_STR;
|
|
143
|
+
} else {
|
|
144
|
+
memcpy(&v.p, &vd, sizeof(v.p));
|
|
145
|
+
}
|
|
146
|
+
break;
|
|
147
|
+
case YEPTRIS_TAG_TIMESTAMP:
|
|
148
|
+
v.kind = YEP_V_TIMESTAMP;
|
|
149
|
+
break;
|
|
150
|
+
default:
|
|
151
|
+
v.kind = YEP_V_STR;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
yep_val_slot(c, &v);
|
|
155
|
+
yep_val_put(c, &v);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static int transform(yep_value_ctx* c, const yep_rec_store* store) {
|
|
159
|
+
const YeptrisEventRecord* rs = store->recs;
|
|
160
|
+
const char* ra = store->arena ? store->arena : "";
|
|
161
|
+
for (size_t i = 0; i < store->n; i++) {
|
|
162
|
+
const YeptrisEventRecord* r = &rs[i];
|
|
163
|
+
if (r->anchor_len != 0 && r->type != YEPTRIS_EV_ALIAS) {
|
|
164
|
+
anchor_entry(c, ra + r->anchor_off, r->anchor_len);
|
|
165
|
+
}
|
|
166
|
+
YeptrisValue v = {0, 0, 0, 0, 0, 0, 0};
|
|
167
|
+
switch (r->type) {
|
|
168
|
+
case YEPTRIS_EV_STREAM_START:
|
|
169
|
+
case YEPTRIS_EV_STREAM_END:
|
|
170
|
+
continue;
|
|
171
|
+
case YEPTRIS_EV_DOCUMENT_START:
|
|
172
|
+
v.kind = YEP_V_DOC;
|
|
173
|
+
yep_val_put(c, &v);
|
|
174
|
+
continue;
|
|
175
|
+
case YEPTRIS_EV_SEQUENCE_START:
|
|
176
|
+
v.kind = YEP_V_SEQ_OPEN;
|
|
177
|
+
v.tag_id = r->tag_id;
|
|
178
|
+
if (r->tag_len != 0) {
|
|
179
|
+
/* the collection's explicit tag text rides the opens'
|
|
180
|
+
* span fields (untagged containers keep off/len 0 —
|
|
181
|
+
* the arena is not touched on the hot path): a host
|
|
182
|
+
* constructor re-tags containers (!!set -> Python set,
|
|
183
|
+
* !!omap -> pairs) without a second drain */
|
|
184
|
+
v.off = yep_val_arena_put(c, ra + r->tag_off, r->tag_len);
|
|
185
|
+
v.len = r->tag_len;
|
|
186
|
+
}
|
|
187
|
+
yep_val_slot(c, &v);
|
|
188
|
+
yep_val_put(c, &v);
|
|
189
|
+
if (c->depth < YEP_V_MAX_DEPTH) {
|
|
190
|
+
c->key_pend[c->depth] = 0;
|
|
191
|
+
c->is_seq[c->depth] = 1;
|
|
192
|
+
}
|
|
193
|
+
c->depth++;
|
|
194
|
+
continue;
|
|
195
|
+
case YEPTRIS_EV_MAPPING_START:
|
|
196
|
+
v.kind = YEP_V_MAP_OPEN;
|
|
197
|
+
v.tag_id = r->tag_id;
|
|
198
|
+
if (r->tag_len != 0) {
|
|
199
|
+
/* the set/omap tag text, exactly as the SEQ arm above */
|
|
200
|
+
v.off = yep_val_arena_put(c, ra + r->tag_off, r->tag_len);
|
|
201
|
+
v.len = r->tag_len;
|
|
202
|
+
}
|
|
203
|
+
yep_val_slot(c, &v);
|
|
204
|
+
yep_val_put(c, &v);
|
|
205
|
+
if (c->depth < YEP_V_MAX_DEPTH) {
|
|
206
|
+
c->key_pend[c->depth] = 0;
|
|
207
|
+
c->is_seq[c->depth] = 0;
|
|
208
|
+
}
|
|
209
|
+
c->depth++;
|
|
210
|
+
continue;
|
|
211
|
+
case YEPTRIS_EV_SEQUENCE_END:
|
|
212
|
+
case YEPTRIS_EV_MAPPING_END:
|
|
213
|
+
v.kind = YEP_V_CLOSE;
|
|
214
|
+
yep_val_put(c, &v);
|
|
215
|
+
c->depth--;
|
|
216
|
+
continue;
|
|
217
|
+
case YEPTRIS_EV_ALIAS:
|
|
218
|
+
v.kind = YEP_V_ALIAS;
|
|
219
|
+
v.off = yep_val_arena_put(c, ra + r->value_off, r->value_len);
|
|
220
|
+
v.len = r->value_len;
|
|
221
|
+
yep_val_slot(c, &v);
|
|
222
|
+
yep_val_put(c, &v);
|
|
223
|
+
continue;
|
|
224
|
+
case YEPTRIS_EV_SCALAR: {
|
|
225
|
+
const char* text = ra + r->value_off;
|
|
226
|
+
uint32_t len = r->value_len;
|
|
227
|
+
int plain = (r->flags & YEPTRIS_EF_IMPLICIT) != 0;
|
|
228
|
+
val_scalar(c, r->tag_id, plain, text, len);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
default:
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return c->oom ? -1 : 0;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static yep_value_ctx* ctx_create(void) {
|
|
239
|
+
return calloc(1, sizeof(yep_value_ctx));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
void yep_value_ctx_free(yep_value_ctx* c) {
|
|
243
|
+
if (c == NULL) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
free(c->vals);
|
|
247
|
+
free(c->arena);
|
|
248
|
+
free(c);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
static int ctx_finalize(yep_value_ctx* c, yep_value_ctx** out) {
|
|
252
|
+
if (c->oom) {
|
|
253
|
+
yep_value_ctx_free(c);
|
|
254
|
+
return -1;
|
|
255
|
+
}
|
|
256
|
+
if (c->arena == NULL) {
|
|
257
|
+
c->arena = malloc(1); /* non-NULL so hosts can free blindly */
|
|
258
|
+
if (c->arena == NULL) {
|
|
259
|
+
yep_value_ctx_free(c);
|
|
260
|
+
return -1;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
*out = c;
|
|
264
|
+
return 0;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/* ---- the DOM linearizer (21): preorder walk, same records ---- */
|
|
268
|
+
|
|
269
|
+
static int lin_node(yep_value_ctx* c, const yep_dom* d, uint32_t id);
|
|
270
|
+
|
|
271
|
+
static int lin_children(yep_value_ctx* c, const yep_dom* d, const yep_dnode* n) {
|
|
272
|
+
for (uint32_t cid = n->first_child; cid != UINT32_MAX; cid = d->nodes[cid].next_sibling) {
|
|
273
|
+
if (lin_node(c, d, cid) != 0) {
|
|
274
|
+
return -1;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return 0;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
static int lin_node(yep_value_ctx* c, const yep_dom* d, uint32_t id) {
|
|
281
|
+
const yep_dnode* n = yep_dom_node(d, id);
|
|
282
|
+
if (n == NULL) {
|
|
283
|
+
return -1;
|
|
284
|
+
}
|
|
285
|
+
if (n->anchor.len != 0 && n->kind != YEP_DOM_ALIAS) {
|
|
286
|
+
yep_view a = yep_dom_view(d, n->anchor);
|
|
287
|
+
anchor_entry(c, a.p, (uint32_t)a.len);
|
|
288
|
+
}
|
|
289
|
+
YeptrisValue v = {0, 0, 0, 0, 0, 0, 0};
|
|
290
|
+
switch (n->kind) {
|
|
291
|
+
case YEP_DOM_SCALAR: {
|
|
292
|
+
yep_view s = yep_dom_view(d, n->value);
|
|
293
|
+
val_scalar(c, n->tag_id, n->implicit, s.p, (uint32_t)s.len);
|
|
294
|
+
return 0;
|
|
295
|
+
}
|
|
296
|
+
case YEP_DOM_ALIAS: {
|
|
297
|
+
yep_view s = yep_dom_view(d, n->value);
|
|
298
|
+
v.kind = YEP_V_ALIAS;
|
|
299
|
+
v.off = yep_val_arena_put(c, s.p, (uint32_t)s.len);
|
|
300
|
+
v.len = (uint32_t)s.len;
|
|
301
|
+
yep_val_slot(c, &v);
|
|
302
|
+
yep_val_put(c, &v);
|
|
303
|
+
return 0;
|
|
304
|
+
}
|
|
305
|
+
default:
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
v.kind = n->kind == YEP_DOM_SEQUENCE ? YEP_V_SEQ_OPEN : YEP_V_MAP_OPEN;
|
|
309
|
+
v.tag_id = n->tag_id;
|
|
310
|
+
if (n->tag.len != 0) {
|
|
311
|
+
/* route parity with the engine transform: the opens' span
|
|
312
|
+
* fields carry the explicit tag text there, so the linearizer
|
|
313
|
+
* must too (the routes stay byte-identical — values_priv.h's
|
|
314
|
+
* law). Marshal bails on tagged subtrees before this matters
|
|
315
|
+
* (#178); strict JSON carries no tags. */
|
|
316
|
+
yep_view tv = yep_dom_view(d, n->tag);
|
|
317
|
+
v.off = yep_val_arena_put(c, tv.p, (uint32_t)tv.len);
|
|
318
|
+
v.len = (uint32_t)tv.len;
|
|
319
|
+
}
|
|
320
|
+
yep_val_slot(c, &v);
|
|
321
|
+
yep_val_put(c, &v);
|
|
322
|
+
if (c->depth < YEP_V_MAX_DEPTH) {
|
|
323
|
+
c->key_pend[c->depth] = 0;
|
|
324
|
+
c->is_seq[c->depth] = (n->kind == YEP_DOM_SEQUENCE);
|
|
325
|
+
}
|
|
326
|
+
c->depth++;
|
|
327
|
+
if (lin_children(c, d, n) != 0) {
|
|
328
|
+
return -1;
|
|
329
|
+
}
|
|
330
|
+
v.kind = YEP_V_CLOSE;
|
|
331
|
+
v.tag_id = 0;
|
|
332
|
+
v.is_key = 0;
|
|
333
|
+
yep_val_put(c, &v);
|
|
334
|
+
c->depth--;
|
|
335
|
+
return 0;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
int yep_values_from_dom(const yep_dom* d, uint32_t root_id, int with_doc, yep_value_ctx** out) {
|
|
339
|
+
*out = NULL;
|
|
340
|
+
if (d == NULL) {
|
|
341
|
+
return -1;
|
|
342
|
+
}
|
|
343
|
+
yep_value_ctx* c = ctx_create();
|
|
344
|
+
if (c == NULL) {
|
|
345
|
+
return -1;
|
|
346
|
+
}
|
|
347
|
+
if (with_doc) {
|
|
348
|
+
YeptrisValue dv = {YEP_V_DOC, 0, 0, 0, 0, 0, 0};
|
|
349
|
+
yep_val_put(c, &dv);
|
|
350
|
+
}
|
|
351
|
+
if (root_id != UINT32_MAX && lin_node(c, d, root_id) != 0) {
|
|
352
|
+
yep_value_ctx_free(c);
|
|
353
|
+
return -1;
|
|
354
|
+
}
|
|
355
|
+
return ctx_finalize(c, out);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/* ---- the input entry: strict-JSON sniff, else the engine ---- */
|
|
359
|
+
|
|
360
|
+
static int looks_strict_json(const char* p, size_t len) {
|
|
361
|
+
for (size_t i = 0; i < len; i++) {
|
|
362
|
+
char ch = p[i];
|
|
363
|
+
if (ch == '{' || ch == '[') {
|
|
364
|
+
return 1;
|
|
365
|
+
}
|
|
366
|
+
if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r') {
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
return 0;
|
|
370
|
+
}
|
|
371
|
+
return 0;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/* JSON route: validate + direct build + linearize. Returns 0 taken,
|
|
375
|
+
* 1 not applicable (grammar surprise — engine decides), -1 fatal. */
|
|
376
|
+
static int drain_json_route(const char* yaml, size_t len, yep_value_ctx** out) {
|
|
377
|
+
size_t verr = 0;
|
|
378
|
+
if (!yep_json_document(yaml, len, &verr)) {
|
|
379
|
+
return 1; /* not strict JSON: YAML flow, tags, or junk — engine */
|
|
380
|
+
}
|
|
381
|
+
const yep_allocator* sys = yep_system_allocator();
|
|
382
|
+
yep_dom* dom = yep_dom_create(sys);
|
|
383
|
+
if (dom == NULL) {
|
|
384
|
+
return -1;
|
|
385
|
+
}
|
|
386
|
+
dom->input_base = yaml; /* strict JSON is UTF-8 by definition */
|
|
387
|
+
dom->input_len = len;
|
|
388
|
+
yep_dom_prepare_len(dom, len);
|
|
389
|
+
int rc = yep_dom_build_json(dom, yaml, len);
|
|
390
|
+
if (rc != 0) {
|
|
391
|
+
/* builder/validator disagreement: belt and braces, engine wins */
|
|
392
|
+
yep_dom_destroy(dom);
|
|
393
|
+
return rc == -1 ? -1 : 1;
|
|
394
|
+
}
|
|
395
|
+
yep_value_ctx* c = ctx_create();
|
|
396
|
+
if (c == NULL) {
|
|
397
|
+
yep_dom_destroy(dom);
|
|
398
|
+
return -1;
|
|
399
|
+
}
|
|
400
|
+
int bad = 0;
|
|
401
|
+
for (uint32_t i = 0; i < dom->dcount && !bad; i++) {
|
|
402
|
+
YeptrisValue dv = {YEP_V_DOC, 0, 0, 0, 0, 0, 0};
|
|
403
|
+
yep_val_put(c, &dv);
|
|
404
|
+
bad = lin_node(c, dom, dom->docs[i]) != 0;
|
|
405
|
+
}
|
|
406
|
+
yep_dom_destroy(dom);
|
|
407
|
+
if (bad) {
|
|
408
|
+
yep_value_ctx_free(c);
|
|
409
|
+
return -1;
|
|
410
|
+
}
|
|
411
|
+
return ctx_finalize(c, out) == 0 ? 0 : -1;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/* Shared core of both drain flavors and the Marshal input path: one
|
|
415
|
+
* record array + arena, ownership moves to the caller. */
|
|
416
|
+
int yep_values_from_input(const char* yaml, size_t len, int schema_compat, yep_value_ctx** out) {
|
|
417
|
+
*out = NULL;
|
|
418
|
+
/* The encoding gate the parse entry owns (parse.c): the marshal/
|
|
419
|
+
* visit / value drains must not feed raw UTF-16/32 bytes to the
|
|
420
|
+
* engine while yeptris_parse accepts them — the nightly's marshal
|
|
421
|
+
* crasher (a UTF-16BE doc whose raw bytes contain "-s"). */
|
|
422
|
+
yep_encoding enc = YEP_ENC_UNKNOWN;
|
|
423
|
+
size_t bom = yep_bom_sniff((const unsigned char*)yaml, len, &enc);
|
|
424
|
+
const char* data = yaml + bom;
|
|
425
|
+
size_t data_len = len - bom;
|
|
426
|
+
unsigned char* transcoded = NULL;
|
|
427
|
+
const yep_allocator* sys = yep_system_allocator();
|
|
428
|
+
if (enc == YEP_ENC_UTF16LE || enc == YEP_ENC_UTF16BE || enc == YEP_ENC_UTF32LE ||
|
|
429
|
+
enc == YEP_ENC_UTF32BE) {
|
|
430
|
+
size_t tlen = 0;
|
|
431
|
+
size_t terr = 0;
|
|
432
|
+
int rc = yep_transcode_to_utf8(sys, enc, (const unsigned char*)data, data_len, &transcoded,
|
|
433
|
+
&tlen, &terr);
|
|
434
|
+
if (rc != 0) {
|
|
435
|
+
return -2;
|
|
436
|
+
}
|
|
437
|
+
size_t pverr = 0;
|
|
438
|
+
if (!yep_printable_validate(transcoded, tlen, &pverr)) {
|
|
439
|
+
yep_free(sys, transcoded);
|
|
440
|
+
return -2;
|
|
441
|
+
}
|
|
442
|
+
data = (const char*)transcoded;
|
|
443
|
+
data_len = tlen;
|
|
444
|
+
}
|
|
445
|
+
int prc_final = -2;
|
|
446
|
+
do {
|
|
447
|
+
if (looks_strict_json(data, data_len)) {
|
|
448
|
+
int jrc = drain_json_route(data, data_len, out);
|
|
449
|
+
if (jrc <= 0) {
|
|
450
|
+
prc_final = (jrc == 0) ? 0 : -1;
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
/* fall through: engine */
|
|
454
|
+
}
|
|
455
|
+
/* Unicode breaks (NEL/LS/PS) normalize to '\n' BEFORE the
|
|
456
|
+
* engine, exactly as the parse entry's front-end does
|
|
457
|
+
* (parse_frontend): this drain feeds the SAME compat-grammar
|
|
458
|
+
* engine, and a raw NEL it never normalized errors where
|
|
459
|
+
* parse accepts -- the nightly's round 239 roundtrip catch
|
|
460
|
+
* ("<NEL>...<NEL> >\n <NEL>...<NEL>\nt": marshal returned
|
|
461
|
+
* ERROR_PARSE on a document yeptris_parse_ex accepted and
|
|
462
|
+
* serialized cleanly). JSON stays above this: the JSON reader
|
|
463
|
+
* keeps U+0085 raw inside strings, only the YAML reader
|
|
464
|
+
* normalizes (the parse_frontend law). Ownership rides the
|
|
465
|
+
* same `transcoded` plumbing the transcode above installed. */
|
|
466
|
+
{
|
|
467
|
+
size_t nlen = 0;
|
|
468
|
+
int kept_raw = 0;
|
|
469
|
+
char* norm = yep_engine_normalize_breaks(sys, data, data_len, &nlen, &kept_raw);
|
|
470
|
+
if (norm != NULL) {
|
|
471
|
+
yep_free(sys, transcoded);
|
|
472
|
+
transcoded = (unsigned char*)norm;
|
|
473
|
+
data = (const char*)norm;
|
|
474
|
+
data_len = nlen;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
yep_engine* eng = yep_engine_create(yep_system_allocator());
|
|
478
|
+
if (eng == NULL) {
|
|
479
|
+
return -1;
|
|
480
|
+
}
|
|
481
|
+
yep_engine_set_resolver(eng,
|
|
482
|
+
schema_compat ? yep_resolver_compat11() : yep_resolver_core12());
|
|
483
|
+
if (schema_compat) {
|
|
484
|
+
yep_engine_set_compat_grammar(eng, 1); /* libyaml grammar parity
|
|
485
|
+
* (the value drains ride the
|
|
486
|
+
* same compat contract) */
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
yep_value_ctx* c = ctx_create();
|
|
490
|
+
if (c == NULL) {
|
|
491
|
+
yep_engine_destroy(eng);
|
|
492
|
+
return -1;
|
|
493
|
+
}
|
|
494
|
+
yep_rec_store store;
|
|
495
|
+
yep_rec_init(&store);
|
|
496
|
+
|
|
497
|
+
int prc = -2;
|
|
498
|
+
yep_sink sink = {.on_event = yep_rec_on_event,
|
|
499
|
+
.ctx = &store,
|
|
500
|
+
.on_flow_build = NULL,
|
|
501
|
+
.on_flow_commit = NULL,
|
|
502
|
+
.on_flow_rollback = NULL,
|
|
503
|
+
.on_block_pair = NULL,
|
|
504
|
+
.on_block_open = NULL,
|
|
505
|
+
.on_block_item = NULL};
|
|
506
|
+
/* strict JSON carries no anchors: no nametab reserve needed */
|
|
507
|
+
yep_engine_front_done(eng);
|
|
508
|
+
if (yep_engine_run(eng, data, data_len, &sink) == 0 && transform(c, &store) == 0) {
|
|
509
|
+
prc = 0;
|
|
510
|
+
} else if (c->oom) {
|
|
511
|
+
prc = -1;
|
|
512
|
+
}
|
|
513
|
+
yep_engine_destroy(eng);
|
|
514
|
+
yep_rec_free(&store);
|
|
515
|
+
if (prc != 0) {
|
|
516
|
+
yep_value_ctx_free(c);
|
|
517
|
+
break;
|
|
518
|
+
}
|
|
519
|
+
prc_final = ctx_finalize(c, out) == 0 ? 0 : -1;
|
|
520
|
+
} while (0);
|
|
521
|
+
yep_free(sys, transcoded);
|
|
522
|
+
if (prc_final != 0 && prc_final != -1) {
|
|
523
|
+
return -2;
|
|
524
|
+
}
|
|
525
|
+
return prc_final;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
static YeptrisStatus map_status(int rc) {
|
|
529
|
+
return rc == 0 ? YEPTRIS_OK : (rc == -1 ? YEPTRIS_ERROR_MEMORY : YEPTRIS_ERROR_PARSE);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
YEPTRIS_API YeptrisStatus yeptris_value_drain(const char* yaml, size_t len, YeptrisSchema schema,
|
|
533
|
+
YeptrisValue** vals, size_t* count, char** arena,
|
|
534
|
+
size_t* arena_len) {
|
|
535
|
+
if (vals == NULL || count == NULL || arena == NULL || arena_len == NULL ||
|
|
536
|
+
(yaml == NULL && len != 0)) {
|
|
537
|
+
return YEPTRIS_ERROR_ARG;
|
|
538
|
+
}
|
|
539
|
+
*vals = NULL;
|
|
540
|
+
*count = 0;
|
|
541
|
+
*arena = NULL;
|
|
542
|
+
*arena_len = 0;
|
|
543
|
+
yep_value_ctx* c = NULL;
|
|
544
|
+
int rc = yep_values_from_input(yaml, len, schema == YEPTRIS_SCHEMA_11_COMPAT, &c);
|
|
545
|
+
if (rc != 0) {
|
|
546
|
+
return map_status(rc);
|
|
547
|
+
}
|
|
548
|
+
*vals = c->vals;
|
|
549
|
+
*count = c->n;
|
|
550
|
+
*arena = c->arena;
|
|
551
|
+
*arena_len = c->arena_len;
|
|
552
|
+
free(c);
|
|
553
|
+
return YEPTRIS_OK;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
YEPTRIS_API void yeptris_value_free(YeptrisValue* vals, char* arena) {
|
|
557
|
+
free(vals);
|
|
558
|
+
free(arena);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
YEPTRIS_API YeptrisStatus yeptris_value_drain_columns(const char* yaml, size_t len,
|
|
562
|
+
YeptrisSchema schema,
|
|
563
|
+
YeptrisValueColumns* cols) {
|
|
564
|
+
if (cols == NULL || (yaml == NULL && len != 0)) {
|
|
565
|
+
return YEPTRIS_ERROR_ARG;
|
|
566
|
+
}
|
|
567
|
+
memset(cols, 0, sizeof(*cols));
|
|
568
|
+
yep_value_ctx* c = NULL;
|
|
569
|
+
int rc = yep_values_from_input(yaml, len, schema == YEPTRIS_SCHEMA_11_COMPAT, &c);
|
|
570
|
+
if (rc != 0) {
|
|
571
|
+
return map_status(rc);
|
|
572
|
+
}
|
|
573
|
+
size_t n = c->n;
|
|
574
|
+
/* one carved block, widest-first so every column is naturally
|
|
575
|
+
* aligned: payloads(8n) offs(4n) lens(4n) kinds tags is_keys bools */
|
|
576
|
+
size_t total = n * (8 + 4 + 4 + 1 + 1 + 1 + 1);
|
|
577
|
+
int64_t* block = NULL;
|
|
578
|
+
if (n > 0) {
|
|
579
|
+
block = malloc(total);
|
|
580
|
+
if (block == NULL) {
|
|
581
|
+
yep_value_ctx_free(c);
|
|
582
|
+
return YEPTRIS_ERROR_MEMORY;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
cols->count = n;
|
|
586
|
+
cols->arena_len = c->arena_len;
|
|
587
|
+
cols->arena = c->arena;
|
|
588
|
+
/* a zero-entry drain keeps every column NULL (pointer arithmetic
|
|
589
|
+
* on a null block is UB — caught by UBSan on the empty stream) */
|
|
590
|
+
if (block != NULL) {
|
|
591
|
+
cols->payloads = block;
|
|
592
|
+
cols->offs = (uint32_t*)(block + n);
|
|
593
|
+
cols->lens = cols->offs + n;
|
|
594
|
+
cols->kinds = (uint8_t*)(cols->lens + n);
|
|
595
|
+
cols->tags = cols->kinds + n;
|
|
596
|
+
cols->is_keys = cols->tags + n;
|
|
597
|
+
cols->bools = cols->is_keys + n;
|
|
598
|
+
}
|
|
599
|
+
for (size_t i = 0; i < n; i++) {
|
|
600
|
+
const YeptrisValue* v = &c->vals[i];
|
|
601
|
+
cols->payloads[i] = (int64_t)v->p;
|
|
602
|
+
cols->offs[i] = v->off;
|
|
603
|
+
cols->lens[i] = v->len;
|
|
604
|
+
cols->kinds[i] = v->kind;
|
|
605
|
+
cols->tags[i] = v->tag_id;
|
|
606
|
+
cols->is_keys[i] = v->is_key;
|
|
607
|
+
cols->bools[i] = v->b;
|
|
608
|
+
}
|
|
609
|
+
free(c->vals);
|
|
610
|
+
free(c);
|
|
611
|
+
return YEPTRIS_OK;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
YEPTRIS_API void yeptris_value_free_columns(YeptrisValueColumns* cols) {
|
|
615
|
+
if (cols == NULL) {
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
free(cols->payloads); /* the carved block base */
|
|
619
|
+
free(cols->arena);
|
|
620
|
+
cols->payloads = NULL;
|
|
621
|
+
cols->offs = NULL;
|
|
622
|
+
cols->lens = NULL;
|
|
623
|
+
cols->kinds = NULL;
|
|
624
|
+
cols->tags = NULL;
|
|
625
|
+
cols->is_keys = NULL;
|
|
626
|
+
cols->bools = NULL;
|
|
627
|
+
cols->arena = NULL;
|
|
628
|
+
cols->count = 0;
|
|
629
|
+
cols->arena_len = 0;
|
|
630
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* values_priv.h — the record-building machinery, shared with the
|
|
2
|
+
* Marshal emitter (TODO.restructure/21).
|
|
3
|
+
*
|
|
4
|
+
* The value stream's SSOT lives in values.c; marshal.c consumes the
|
|
5
|
+
* SAME ctx (records + arena) the drains produce, and the DOM
|
|
6
|
+
* linearizer produces the same records the engine transform does, so
|
|
7
|
+
* every route through the value format is byte-identical.
|
|
8
|
+
*/
|
|
9
|
+
#ifndef YEP_EVENTS_VALUES_PRIV_H
|
|
10
|
+
#define YEP_EVENTS_VALUES_PRIV_H
|
|
11
|
+
|
|
12
|
+
#include "../../include/yeptris/values.h"
|
|
13
|
+
|
|
14
|
+
struct yep_dom;
|
|
15
|
+
|
|
16
|
+
#define YEP_V_MAX_DEPTH 1024
|
|
17
|
+
|
|
18
|
+
typedef struct yep_value_ctx {
|
|
19
|
+
/* records + arena as handed to hosts by the public drains */
|
|
20
|
+
YeptrisValue* vals;
|
|
21
|
+
size_t n, cap;
|
|
22
|
+
char* arena;
|
|
23
|
+
size_t arena_len, arena_cap;
|
|
24
|
+
int oom;
|
|
25
|
+
int unsupported; /* linearize: construct the emitter cannot express */
|
|
26
|
+
uint8_t key_pend[YEP_V_MAX_DEPTH]; /* per open map: key slot taken */
|
|
27
|
+
uint8_t is_seq[YEP_V_MAX_DEPTH]; /* per open frame: 1 = sequence —
|
|
28
|
+
* entries never take key slots */
|
|
29
|
+
int depth;
|
|
30
|
+
} yep_value_ctx;
|
|
31
|
+
|
|
32
|
+
/* values.c owns these; declared here for marshal.c and the linearizer. */
|
|
33
|
+
void yep_val_put(yep_value_ctx* c, const YeptrisValue* v);
|
|
34
|
+
uint32_t yep_val_arena_put(yep_value_ctx* c, const char* p, uint32_t len);
|
|
35
|
+
void yep_val_slot(yep_value_ctx* c, YeptrisValue* v);
|
|
36
|
+
|
|
37
|
+
/* engine route — now with the strict-JSON sniff: first non-space
|
|
38
|
+
* byte '{'/'[' builds through the JSON scanner and the linearizer,
|
|
39
|
+
* falling back to the engine on any grammar failure. Both routes
|
|
40
|
+
* produce identical records (the differential gate). Returns 0 ok,
|
|
41
|
+
* -1 oom, -2 parse (detail via the TLS error channel). */
|
|
42
|
+
int yep_values_from_input(const char* yaml, size_t len, int schema_compat, yep_value_ctx** out);
|
|
43
|
+
|
|
44
|
+
/* DOM route: preorder walk of a subtree producing the same records
|
|
45
|
+
* the engine transform produces (21's linearizer). root_id may be
|
|
46
|
+
* UINT32_MAX for an empty document; with_doc emits YEP_V_DOC records
|
|
47
|
+
* around the root (the input path always documents). */
|
|
48
|
+
int yep_values_from_dom(const struct yep_dom* d, uint32_t root_id, int with_doc,
|
|
49
|
+
yep_value_ctx** out);
|
|
50
|
+
|
|
51
|
+
void yep_value_ctx_free(yep_value_ctx* c); /* frees records, arena, ctx */
|
|
52
|
+
|
|
53
|
+
#endif /* YEP_EVENTS_VALUES_PRIV_H */
|