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,39 @@
1
+ /* tape_in.h — the tape module's internal seams (not public ABI).
2
+ *
3
+ * parse.c's #342 slice-2 lazy route drives the fused lenient walk
4
+ * directly: the gate and opener checks it already ran must not be
5
+ * repeated (the lenient public entry re-gates). The walk's contract
6
+ * is the public entry's: gate-clean buffer, p[open] is '[' or '{',
7
+ * tail must be whitespace-only. */
8
+ #ifndef YEP_TAPE_IN_H
9
+ #define YEP_TAPE_IN_H
10
+
11
+ #include <stddef.h>
12
+
13
+ #include <yeptris/parse.h>
14
+ #include <yeptris/tape.h>
15
+
16
+ /* tape.c (was tape_walk_lnt_fused) */
17
+ int yep_tape_long_simple_key(const yeptris_json_tape* t);
18
+
19
+ YeptrisStatus yep_tape_walk_lenient_fused(const char* p, size_t len, size_t open,
20
+ yeptris_json_tape* t, int strict_nums, int clean_only,
21
+ int reuse_block);
22
+
23
+ /* parse.c (#378 slice 1): the YAML parse carrying the packed record
24
+ * tape — the tree materializes on first access (yep_doc_dom). */
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+ YeptrisDocument yeptris_parse_ytape_ex(const char* buf, size_t len, const YeptrisParseOptions* opts,
29
+ YeptrisStatus* status);
30
+
31
+ /* the eager form (the A/B reference lane): the engine builds nodes at
32
+ * parse, no tape */
33
+ YeptrisDocument yeptris_parse_eager_ex(const char* buf, size_t len, const YeptrisParseOptions* opts,
34
+ YeptrisStatus* status);
35
+ #ifdef __cplusplus
36
+ }
37
+ #endif
38
+
39
+ #endif
@@ -0,0 +1,306 @@
1
+ /* compile.c — the compiled-schema economy (#885 item 3).
2
+ *
3
+ * The leptris-XSD shape (~/src/leptris/leptris/src/leptris/xsd/):
4
+ * parse the schema ONCE, retain the DOM and the derived state, validate
5
+ * many instance streams against the retained model. The handle owns
6
+ * everything it reads — the schema bytes (copied: the DOM's scalar
7
+ * views borrow them), the parsed document (its DOM, pools and finish
8
+ * pool die with yeptris_document_free), and the compiled pattern
9
+ * programs (the XSD content-model analog: `(a+)+$` compiles once at
10
+ * compile time, not once per validated string). One free call releases
11
+ * it all — no refcounting, the document-ownership law.
12
+ *
13
+ * The pattern programs are populated EAGERLY by a DFS over the schema
14
+ * tree (`pattern` values and `patternProperties` keys — the kernel's
15
+ * only two consumers), so the handle is immutable after compile and
16
+ * `yeptris_schema_validate` is a pure reader: one schema handle per
17
+ * thread like documents; read-only sharing across threads is safe.
18
+ * An invalid pattern is simply not retained — every use then recompiles
19
+ * to the one-shot's -1 (ignored keyword), never a guess.
20
+ *
21
+ * The one-shot face (yeptris_json_schema_validate) routes through the
22
+ * same compile+validate machinery internally: identical parse, walk
23
+ * and report code paths, so its observable statuses and byte-for-byte
24
+ * verdicts are preserved (the 1298-case suite port is the referee).
25
+ */
26
+
27
+ #include <string.h>
28
+
29
+ #include <yeptris/dom.h>
30
+ #include <yeptris/validate.h>
31
+
32
+ #include "../common/error.h"
33
+ #include "../doc.h"
34
+ #include "../memory/allocator.h"
35
+ #include "../tape_in.h"
36
+ #include "internal.h"
37
+
38
+ /* The compiled schema. Opaque at the face (validate.h); everything it
39
+ * reads dies with it. */
40
+ struct yeptris_schema {
41
+ char* bytes; /* owned: the schema bytes (the DOM's input views borrow them) */
42
+ yeptris_document* doc; /* owned: the parsed schema document */
43
+ const yep_dom* dom; /* borrowed from doc (yep_doc_dom) */
44
+ uint32_t sroot; /* the schema document's root (docs[0]) */
45
+ yep_re_cache* cache; /* owned: pattern source -> compiled NFA; immutable after compile */
46
+ js_resources* res; /* owned: $id/$anchor/$dynamicAnchor map + ref-site bases */
47
+ };
48
+
49
+ /* ---- the pattern collection (compile-time, eager) ----------------------- */
50
+
51
+ static int collect_patterns(yep_re_cache* t, const yep_dom* d, uint32_t id, int depth);
52
+
53
+ /* Collects every pattern source of one mapping pair set. 0 ok, -1 OOM. */
54
+ static int collect_map(yep_re_cache* t, const yep_dom* d, uint32_t map_id, int depth) {
55
+ const yep_dnode* m = yep_dom_node(d, map_id);
56
+ uint32_t k = m->first_child;
57
+ while (k != UINT32_MAX) {
58
+ uint32_t v = yep_dom_node(d, k) ? yep_dom_node(d, k)->next_sibling : UINT32_MAX;
59
+ const yep_dnode* kn = yep_dom_node(d, k);
60
+ const yep_dnode* vn = v != UINT32_MAX ? yep_dom_node(d, v) : NULL;
61
+ if (kn != NULL && kn->kind == YEP_DOM_SCALAR) {
62
+ yep_view kv = yep_dom_view(d, kn->value);
63
+ /* the keyword names, matched by bytes like the walk's kw_get */
64
+ if (kv.len == 7 && memcmp(kv.p, "pattern", 7) == 0) {
65
+ /* "pattern": the value is the pattern source (a string
66
+ * scalar, schema_word's exact read) */
67
+ if (vn != NULL && vn->kind == YEP_DOM_SCALAR &&
68
+ yep_validate_scalar_tag(vn) == YEPTRIS_TAG_STR) {
69
+ yep_view vv = yep_dom_view(d, vn->value);
70
+ if (vv.p != NULL && yep_re_cache_add(t, vv.p, vv.len) < 0) {
71
+ return -1;
72
+ }
73
+ }
74
+ } else if (kv.len == 17 && memcmp(kv.p, "patternProperties", 17) == 0) {
75
+ /* "patternProperties": its KEYS are the pattern sources */
76
+ if (vn != NULL && vn->kind == YEP_DOM_MAPPING) {
77
+ uint32_t pk = vn->first_child;
78
+ while (pk != UINT32_MAX) {
79
+ uint32_t pv =
80
+ yep_dom_node(d, pk) ? yep_dom_node(d, pk)->next_sibling : UINT32_MAX;
81
+ const yep_dnode* pkn = yep_dom_node(d, pk);
82
+ if (pkn != NULL && pkn->kind == YEP_DOM_SCALAR &&
83
+ yep_validate_scalar_tag(pkn) == YEPTRIS_TAG_STR) {
84
+ yep_view pw = yep_dom_view(d, pkn->value);
85
+ if (pw.p != NULL && yep_re_cache_add(t, pw.p, pw.len) < 0) {
86
+ return -1;
87
+ }
88
+ }
89
+ pk = pv;
90
+ }
91
+ }
92
+ }
93
+ }
94
+ /* the rest of the schema rides the values (keys are scalars —
95
+ * nothing under them; the walk reaches nodes the same way) */
96
+ if (v != UINT32_MAX && collect_patterns(t, d, v, depth + 1) != 0) {
97
+ return -1;
98
+ }
99
+ k = v != UINT32_MAX && yep_dom_node(d, v) ? yep_dom_node(d, v)->next_sibling : UINT32_MAX;
100
+ }
101
+ return 0;
102
+ }
103
+
104
+ /* Depth-bounded DFS gathering every pattern the walk can reach. 0 ok,
105
+ * -1 OOM. Aliases are skipped: the walk sees an alias node as opaque
106
+ * (never a mapping), so no reachable pattern hides behind one. */
107
+ static int collect_patterns(yep_re_cache* t, const yep_dom* d, uint32_t id, int depth) {
108
+ if (depth > YEP_DOM_MAX_DEPTH) {
109
+ return 0; /* the walk's own guard: deeper nodes are unreachable to it too */
110
+ }
111
+ const yep_dnode* n = yep_dom_node(d, id);
112
+ if (n == NULL) {
113
+ return 0;
114
+ }
115
+ if (n->kind == YEP_DOM_MAPPING) {
116
+ return collect_map(t, d, id, depth);
117
+ }
118
+ if (n->kind == YEP_DOM_SEQUENCE) {
119
+ uint32_t ch = n->first_child;
120
+ while (ch != UINT32_MAX) {
121
+ uint32_t next = yep_dom_node(d, ch) ? yep_dom_node(d, ch)->next_sibling : UINT32_MAX;
122
+ if (collect_patterns(t, d, ch, depth + 1) != 0) {
123
+ return -1;
124
+ }
125
+ ch = next;
126
+ }
127
+ }
128
+ return 0;
129
+ }
130
+
131
+ /* ---- the seam with the explicit status (internal.h) --------------------- */
132
+
133
+ yeptris_schema* yep_schema_compile_st(const char* bytes, size_t n, YeptrisStatus* st) {
134
+ *st = YEPTRIS_OK;
135
+ if (bytes == NULL && n != 0) {
136
+ *st = YEPTRIS_ERROR_ARG;
137
+ return NULL;
138
+ }
139
+ const yep_allocator* sys = yep_system_allocator();
140
+
141
+ /* the schema bytes are COPIED: the DOM's scalar views borrow its
142
+ * input, and the handle outlives this call */
143
+ char* copy = NULL;
144
+ if (n > 0) {
145
+ copy = yep_alloc(sys, n);
146
+ if (copy == NULL) {
147
+ *st = YEPTRIS_ERROR_MEMORY;
148
+ return NULL;
149
+ }
150
+ memcpy(copy, bytes, n);
151
+ }
152
+
153
+ /* document 0 of the stream is the schema (the one-shot's exact rule) */
154
+ YeptrisParseOptions opts;
155
+ memset(&opts, 0, sizeof(opts)); /* core12: the YAML->JSON data model */
156
+ YeptrisStatus ps = YEPTRIS_OK;
157
+ yeptris_document* doc = (yeptris_document*)yeptris_parse_eager_ex(copy, n, &opts, &ps);
158
+ if (doc == NULL) {
159
+ yep_free(sys, copy);
160
+ if (ps == YEPTRIS_OK) { /* empty bytes: the stream holds no document */
161
+ yep_error_set(yep_error_tls(), YEP_ERR_UNEXPECTED, 0, 0, 0,
162
+ "the schema bytes hold no document");
163
+ *st = YEPTRIS_ERROR_ARG;
164
+ } else {
165
+ *st = ps; /* the schema did not parse — the engine's own status */
166
+ }
167
+ return NULL;
168
+ }
169
+ const yep_dom* dom = yep_doc_dom(doc);
170
+ if (dom == NULL || dom->dcount == 0) {
171
+ yeptris_document_free(doc);
172
+ yep_free(sys, copy);
173
+ yep_error_set(yep_error_tls(), YEP_ERR_UNEXPECTED, 0, 0, 0,
174
+ "the schema bytes hold no document");
175
+ *st = YEPTRIS_ERROR_ARG;
176
+ return NULL;
177
+ }
178
+
179
+ /* the pattern programs: compiled once, here (a failure to retain is
180
+ * an allocation failure — loud, like every constructor's OOM) */
181
+ yep_re_cache* cache = yep_re_cache_new();
182
+ if (cache == NULL || collect_patterns(cache, dom, dom->docs[0], 0) != 0) {
183
+ yep_re_cache_free(cache);
184
+ yeptris_document_free(doc);
185
+ yep_free(sys, copy);
186
+ yep_error_set(yep_error_tls(), YEP_ERR_MEMORY, 0, 0, 0,
187
+ "the schema's pattern programs failed to compile");
188
+ *st = YEPTRIS_ERROR_MEMORY;
189
+ return NULL;
190
+ }
191
+
192
+ /* the identifier map: $id resources, anchors, ref-site bases —
193
+ * built once by the crawl, read-only afterwards (OOM is loud) */
194
+ js_resources* res = yep_js_resources_crawl(dom, dom->docs[0]);
195
+ if (res == NULL) {
196
+ yep_re_cache_free(cache);
197
+ yeptris_document_free(doc);
198
+ yep_free(sys, copy);
199
+ yep_error_set(yep_error_tls(), YEP_ERR_MEMORY, 0, 0, 0,
200
+ "the schema's identifier map failed to build");
201
+ *st = YEPTRIS_ERROR_MEMORY;
202
+ return NULL;
203
+ }
204
+
205
+ yeptris_schema* s = yep_alloc(sys, sizeof(*s));
206
+ if (s == NULL) {
207
+ yep_js_resources_free(res);
208
+ yep_re_cache_free(cache);
209
+ yeptris_document_free(doc);
210
+ yep_free(sys, copy);
211
+ *st = YEPTRIS_ERROR_MEMORY;
212
+ return NULL;
213
+ }
214
+ s->bytes = copy;
215
+ s->doc = doc;
216
+ s->dom = dom;
217
+ s->sroot = dom->docs[0];
218
+ s->cache = cache;
219
+ s->res = res;
220
+ return s;
221
+ }
222
+
223
+ /* ---- the public face (validate.h) --------------------------------------- */
224
+
225
+ YEPTRIS_API yeptris_schema* yeptris_schema_compile(const char* bytes, size_t n) {
226
+ YeptrisStatus st = YEPTRIS_OK;
227
+ return yep_schema_compile_st(bytes, n, &st); /* the error channel carries the why */
228
+ }
229
+
230
+ /* The tag-driven hook's read-only view (internal.h, #906 slice 4):
231
+ * everything the subtree walk reads, borrowed from the handle — the
232
+ * REGISTRY LAW keeps the handle alive underneath it. */
233
+ void yep_schema_view_of(const yeptris_schema* s, yep_schema_view* out) {
234
+ if (out == NULL) {
235
+ return;
236
+ }
237
+ if (s == NULL) {
238
+ memset(out, 0, sizeof(*out));
239
+ return;
240
+ }
241
+ out->dom = s->dom;
242
+ out->sroot = s->sroot;
243
+ out->cache = s->cache;
244
+ out->res = s->res;
245
+ }
246
+
247
+ YEPTRIS_API void yeptris_schema_free(yeptris_schema* s) {
248
+ if (s == NULL) {
249
+ return;
250
+ }
251
+ const yep_allocator* sys = yep_system_allocator();
252
+ yep_js_resources_free(s->res);
253
+ yep_re_cache_free(s->cache);
254
+ yeptris_document_free(s->doc); /* the DOM and every pool under it */
255
+ yep_free(sys, s->bytes); /* the views' home: freed after its readers */
256
+ yep_free(sys, s);
257
+ }
258
+
259
+ YEPTRIS_API YeptrisStatus yeptris_schema_validate(yeptris_schema* s, const char* buf, size_t len,
260
+ yeptris_validate_report** out) {
261
+ if (out == NULL || s == NULL || (buf == NULL && len != 0)) {
262
+ return YEPTRIS_ERROR_ARG;
263
+ }
264
+ *out = NULL;
265
+
266
+ /* the instance stream (core12, the one-shot's exact parse) */
267
+ YeptrisParseOptions opts;
268
+ memset(&opts, 0, sizeof(opts));
269
+ YeptrisStatus st = YEPTRIS_OK;
270
+ YeptrisDocument idoc = yeptris_parse_eager_ex(buf, len, &opts, &st);
271
+ if (idoc == NULL) {
272
+ if (st == YEPTRIS_OK) {
273
+ /* an empty instance stream: nothing to invalidate */
274
+ yeptris_validate_report* r = yep_validate_report_new();
275
+ if (r == NULL) {
276
+ return YEPTRIS_ERROR_MEMORY;
277
+ }
278
+ *out = r;
279
+ return YEPTRIS_OK;
280
+ }
281
+ return st; /* the parse's own error */
282
+ }
283
+ yep_dom* idom = yep_doc_dom((yeptris_document*)idoc);
284
+ if (idom == NULL) {
285
+ yeptris_document_free(idoc);
286
+ return YEPTRIS_ERROR_MEMORY;
287
+ }
288
+
289
+ yeptris_validate_report* r = yep_validate_report_new();
290
+ if (r == NULL) {
291
+ yeptris_document_free(idoc);
292
+ return YEPTRIS_ERROR_MEMORY;
293
+ }
294
+ /* the handle is a pure reader here (its cache and identifier map
295
+ * are immutable): the same walk, the same report shape, the
296
+ * one-shot's verdicts */
297
+ int rc =
298
+ yep_jsonschema_run(s->dom, s->sroot, idom, idom->docs, idom->dcount, r, s->cache, s->res);
299
+ yeptris_document_free(idoc);
300
+ if (rc != 0) {
301
+ yeptris_validate_report_free(r);
302
+ return YEPTRIS_ERROR_MEMORY;
303
+ }
304
+ *out = r;
305
+ return r->count > 0 ? YEPTRIS_ERROR_SCHEMA : YEPTRIS_OK;
306
+ }