Fast.xs

filter: Statementstmt 95.1% 136 / 143 Branchbran 66.9% 87 / 130 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 81.6% 223 / 273 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/jsf_types.h ↑ Summary include/jsf_parse.h »
1 #define PERL_NO_GET_CONTEXT
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5  
6 #include "jsf.h"
7 #include "jsf_abi.h" /* the C ABI table consumers (e.g. OpenAPI::Fast) call */
8  
9 /* ---- Compiled object plumbing ------------------------------------------- */
10  
11 2351 static jsf_compiled_t *jsf_compiled_of(pTHX_ SV *self) {
12 2351 ▶ if (!SvROK(self)) croak("JSON::Schema::Fast: not a compiled schema");
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(self)) croak("JSON::Schema::Fast: not a compiled schema"); 0 2351 2351
13 2351 return (jsf_compiled_t *)INT2PTR(void *, SvIV(SvRV(self)));
14 }
15  
16 /* Decode JSON schema text via File::Raw::JSON's C ABI (jsf_frj.h; required by
17 * Fast.pm). Croaks (byte-offset message) on malformed JSON. */
18 3 static SV *jsf_json_decode(pTHX_ SV *text) {
19 3 SV *v = jsf_frj_decode(aTHX_ text);
20 3 ▶ if (!v)
Branch: 1 branch
BranchTrueFalseTotal
if (!v) 0 3 3
21 0 croak("JSON::Schema::Fast: File::Raw::JSON with a compatible C ABI "
22 "(FRJ_ABI_VERSION %d) is required to decode a JSON schema",
23 FRJ_ABI_VERSION);
24 3 return v;
25 }
26  
27 /* Compile a schema into a blessed JSON::Schema::Fast::Compiled SV. Shared by
28 * the XS compile() and the C ABI (jsf_abi.h): `schema` is a hashref/arrayref/
29 * boolean or JSON-text scalar; `resolver` is an optional coderef (NULL/undef
30 * => auto-fetch remote $ref via Fetch's ABI). Returns a +1-owned blessed SV. */
31 480 static SV *jsf_compile_api(pTHX_ SV *schema, SV *resolver, int coerce,
32 int apply_defaults) {
33 480 SV *actual = schema;
34 480 ▶ int auto_fetch = (resolver && SvOK(resolver)) ? 0 : 1;
Branch: 2 branches
BranchTrueFalseTotal
int auto_fetch = (resolver && SvOK(resolver)) ? 0 : 1; 387 93 480
int auto_fetch = (resolver && SvOK(resolver)) ? 0 : 1; 2 385 387
35 jsf_compiled_t *C;
36 480 ▶ if (SvOK(schema) && !SvROK(schema) && SvPOK(schema))
Branch: 3 branches
BranchTrueFalseTotal
if (SvOK(schema) && !SvROK(schema) && SvPOK(schema)) 480 0 480
if (SvOK(schema) && !SvROK(schema) && SvPOK(schema)) 3 477 480
if (SvOK(schema) && !SvROK(schema) && SvPOK(schema)) 3 0 3
37 3 actual = jsf_json_decode(aTHX_ schema);
38 480 ▶ C = jsf_compile_sv(aTHX_ actual, auto_fetch ? NULL : resolver, auto_fetch);
Branch: 1 branch
BranchTrueFalseTotal
C = jsf_compile_sv(aTHX_ actual, auto_fetch ? NULL : resolver, auto_fetch); 385 95 480
39 478 C->coerce = coerce ? 1 : 0;
40 478 C->apply_defaults = apply_defaults ? 1 : 0;
41 478 C->schema_sv = newSVsv(actual);
42 478 return sv_bless(newRV_noinc(newSViv(PTR2IV(C))),
43 gv_stashpv("JSON::Schema::Fast::Compiled", GV_ADD));
44 }
45  
46 /* ---- IR dump (debug shim for the phase-02 tests) ------------------------ */
47  
48 static const struct { uint64_t bit; const char *name; } jsf_bitnames[] = {
49 { JSF_HAS_TYPE,"type" },{ JSF_HAS_ENUM,"enum" },{ JSF_HAS_CONST,"const" },
50 { JSF_HAS_MIN,"minimum" },{ JSF_HAS_MAX,"maximum" },
51 { JSF_HAS_EXMIN,"exclusiveMinimum" },{ JSF_HAS_EXMAX,"exclusiveMaximum" },
52 { JSF_HAS_MULOF,"multipleOf" },{ JSF_HAS_MINLEN,"minLength" },
53 { JSF_HAS_MAXLEN,"maxLength" },{ JSF_HAS_PATTERN,"pattern" },
54 { JSF_HAS_FORMAT,"format" },{ JSF_HAS_ITEMS,"items" },
55 { JSF_HAS_PREFIX,"prefixItems" },{ JSF_HAS_MINITEMS,"minItems" },
56 { JSF_HAS_MAXITEMS,"maxItems" },{ JSF_HAS_UNIQUE,"uniqueItems" },
57 { JSF_HAS_CONTAINS,"contains" },{ JSF_HAS_MINCONT,"minContains" },
58 { JSF_HAS_MAXCONT,"maxContains" },{ JSF_HAS_PROPS,"properties" },
59 { JSF_HAS_PATPROPS,"patternProperties" },{ JSF_HAS_ADDPROPS,"additionalProperties" },
60 { JSF_HAS_REQUIRED,"required" },{ JSF_HAS_MINPROPS,"minProperties" },
61 { JSF_HAS_MAXPROPS,"maxProperties" },{ JSF_HAS_PROPNAMES,"propertyNames" },
62 { JSF_HAS_DEPREQ,"dependentRequired" },{ JSF_HAS_ALLOF,"allOf" },
63 { JSF_HAS_ANYOF,"anyOf" },{ JSF_HAS_ONEOF,"oneOf" },{ JSF_HAS_NOT,"not" },
64 { JSF_HAS_IF,"if" },{ JSF_HAS_REF,"$ref" },{ 0, NULL }
65 };
66  
67 /* brief view of a node: { tag, type_mask, present(UV) }, or undef for off 0 */
68 7 static SV *jsf_node_brief(pTHX_ jsf_compiled_t *C, uint32_t off) {
69 jsf_node_t *n; HV *h;
70 7 ▶ if (off == JSF_NULL_OFF) return &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
if (off == JSF_NULL_OFF) return &PL_sv_undef; 0 7 7
71 7 n = (jsf_node_t *)jsf_arena_ptr(C->arena, off);
72 7 h = newHV();
73 7 (void)hv_stores(h, "tag", newSViv(n->tag));
74 7 (void)hv_stores(h, "type_mask", newSVuv(n->type_mask));
75 7 (void)hv_stores(h, "present", newSVuv((UV)n->present));
76 7 return newRV_noinc((SV *)h);
77 }
78  
79 9 static SV *jsf_dump_node(pTHX_ jsf_compiled_t *C, uint32_t off) {
80 9 jsf_arena_t *a = C->arena;
81 9 jsf_node_t *n = (jsf_node_t *)jsf_arena_ptr(a, off);
82 9 HV *h = newHV();
83 9 HV *present = newHV();
84 int i;
85  
86 9 (void)hv_stores(h, "tag", newSViv(n->tag));
87 9 (void)hv_stores(h, "type_mask", newSVuv(n->type_mask));
88 9 (void)hv_stores(h, "enum_n", newSVuv(n->enum_n));
89 9 (void)hv_stores(h, "has_const", newSViv((n->present & JSF_HAS_CONST) ? 1 : 0));
90  
91 315 ▶ for (i = 0; jsf_bitnames[i].name; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; jsf_bitnames[i].name; i++) 306 9 315
92 306 ▶ if (n->present & jsf_bitnames[i].bit)
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & jsf_bitnames[i].bit) 30 276 306
93 30 (void)hv_store(present, jsf_bitnames[i].name,
94 (I32)strlen(jsf_bitnames[i].name), newSViv(1), 0);
95 9 (void)hv_stores(h, "present", newRV_noinc((SV *)present));
96  
97 9 ▶ if (n->present & JSF_HAS_PROPS) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_PROPS) { 3 6 9
98 3 jsf_proptab *pt = (jsf_proptab *)jsf_arena_ptr(a, n->props_off);
99 3 jsf_propent *en = (jsf_propent *)((char *)pt + sizeof(jsf_proptab));
100 3 AV *pa = newAV(); uint32_t p;
101 8 ▶ for (p = 0; p < pt->n; p++) {
Branch: 1 branch
BranchTrueFalseTotal
for (p = 0; p < pt->n; p++) { 5 3 8
102 5 uint32_t len; const char *nm = jsf_str_bytes(a, en[p].name_off, &len);
103 5 HV *pe = newHV();
104 5 (void)hv_stores(pe, "name", newSVpvn(nm, len));
105 5 (void)hv_stores(pe, "hash", newSVuv((UV)en[p].hash));
106 5 (void)hv_stores(pe, "child", jsf_node_brief(aTHX_ C, en[p].child_off));
107 5 av_push(pa, newRV_noinc((SV *)pe));
108 }
109 3 (void)hv_stores(h, "properties", newRV_noinc((SV *)pa));
110 }
111  
112 9 ▶ if (n->present & JSF_HAS_REQUIRED) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_REQUIRED) { 3 6 9
113 3 jsf_reqset *rs = (jsf_reqset *)jsf_arena_ptr(a, n->required_off);
114 3 jsf_reqent *re = (jsf_reqent *)((char *)rs + sizeof(jsf_reqset));
115 3 AV *ra = newAV(); uint32_t r;
116 7 ▶ for (r = 0; r < rs->n; r++) {
Branch: 1 branch
BranchTrueFalseTotal
for (r = 0; r < rs->n; r++) { 4 3 7
117 4 uint32_t len; const char *nm = jsf_str_bytes(a, re[r].name_off, &len);
118 4 HV *re2 = newHV();
119 4 (void)hv_stores(re2, "name", newSVpvn(nm, len));
120 4 ▶ (void)hv_stores(re2, "idx",
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(re2, "idx", 0 4 4
121 re[r].prop_idx == JSF_NO_IDX ? newSViv(-1) : newSVuv(re[r].prop_idx));
122 4 av_push(ra, newRV_noinc((SV *)re2));
123 }
124 3 (void)hv_stores(h, "required", newRV_noinc((SV *)ra));
125 }
126  
127 9 ▶ if (n->present & JSF_HAS_ITEMS)
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_ITEMS) 0 9 9
128 0 (void)hv_stores(h, "items", jsf_node_brief(aTHX_ C, n->items_off));
129 9 ▶ if (n->present & JSF_HAS_REF) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_REF) { 2 7 9
130 2 (void)hv_stores(h, "ref_resolved", newSViv(n->ref_off != JSF_NULL_OFF ? 1 : 0));
131 2 (void)hv_stores(h, "ref_target", jsf_node_brief(aTHX_ C, n->ref_off));
132 }
133 9 ▶ if (n->present & JSF_HAS_ADDPROPS)
Branch: 1 branch
BranchTrueFalseTotal
if (n->present & JSF_HAS_ADDPROPS) 2 7 9
134 2 (void)hv_stores(h, "addprops_false", newSViv(n->addprops_off == JSF_NULL_OFF ? 1 : 0));
135  
136 9 return newRV_noinc((SV *)h);
137 }
138  
139 /* ---- C ABI (jsf_abi.h) --------------------------------------------------- *
140 * The table consumers reach through JSON::Schema::Fast::_abi_ptr: compile once
141 * from C, then validate per call with no Perl method dispatch. compile is the
142 * shared jsf_compile_api above; is_valid/validate wrap the interpreter. */
143 0 static int jsf_abi_is_valid(pTHX_ SV *compiled, SV *data) {
144 0 return jsf_is_valid(aTHX_ jsf_compiled_of(aTHX_ compiled), data);
145 }
146 0 static int jsf_abi_validate(pTHX_ SV *compiled, SV *data, AV *errors) {
147 0 return jsf_run(aTHX_ jsf_compiled_of(aTHX_ compiled), data, errors);
148 }
149 static const jsf_abi JSF_ABI = {
150 JSF_ABI_VERSION,
151 jsf_compile_api,
152 jsf_abi_is_valid,
153 jsf_abi_validate,
154 };
155  
156 MODULE = JSON::Schema::Fast PACKAGE = JSON::Schema::Fast
157  
158 PROTOTYPES: DISABLE
159  
160 # Compile a schema (Perl hashref/boolean, or JSON text) into a compiled object.
161 # Options: coerce, apply_defaults, resolver. Remote references without a resolver
162 # are fetched via Fetch's C ABI (see include/jsf_fetch.h).
163 SV *
164 compile(class, schema, ...)
165 SV *class
166 SV *schema
167 CODE:
168 {
169 479 SV *resolver = NULL;
170 479 int i, coerce = 0, apply_defaults = 0;
171 877 ▶ for (i = 2; i + 1 < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 2; i + 1 < items; i += 2) { 398 479 877
172 398 STRLEN kl; const char *k = SvPV_const(ST(i), kl);
173 398 ▶ if (kl == 6 && memEQ(k, "coerce", 6)) coerce = SvTRUE(ST(i + 1)) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
if (kl == 6 && memEQ(k, "coerce", 6)) coerce = SvTRUE(ST(i + 1)) ? 1 : 0; 8 390 398
if (kl == 6 && memEQ(k, "coerce", 6)) coerce = SvTRUE(ST(i + 1)) ? 1 : 0; 8 0 8
174 390 ▶ else if (kl == 14 && memEQ(k, "apply_defaults", 14)) apply_defaults = SvTRUE(ST(i + 1)) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
else if (kl == 14 && memEQ(k, "apply_defaults", 14)) apply_defaults = SvTRUE(ST(i + 1)) ? 1 : 0; 3 387 390
else if (kl == 14 && memEQ(k, "apply_defaults", 14)) apply_defaults = SvTRUE(ST(i + 1)) ? 1 : 0; 3 0 3
175 387 ▶ else if (kl == 8 && memEQ(k, "resolver", 8)) resolver = ST(i + 1);
Branch: 2 branches
BranchTrueFalseTotal
else if (kl == 8 && memEQ(k, "resolver", 8)) resolver = ST(i + 1); 387 0 387
else if (kl == 8 && memEQ(k, "resolver", 8)) resolver = ST(i + 1); 387 0 387
176 }
177 479 RETVAL = jsf_compile_api(aTHX_ schema, resolver, coerce, apply_defaults);
178 PERL_UNUSED_VAR(class);
179 }
180 OUTPUT:
181 RETVAL
182  
183 # Address of the C ABI table (jsf_abi.h). A consumer XS module (OpenAPI::Fast)
184 # fetches this once at boot, INT2PTRs it to a `const jsf_abi *`, and checks
185 # ->abi_version before use. Not part of the public Perl API.
186 IV
187 _abi_ptr()
188 CODE:
189 0 ▶ RETVAL = PTR2IV(&JSF_ABI);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PTR2IV(&JSF_ABI); 0 0 0
190 OUTPUT:
191 RETVAL
192  
193 # ---- debug / self-test shims ------------------------------------------------
194  
195 UV
196 _classify(sv)
197 SV *sv
198 CODE:
199 9 ▶ RETVAL = (UV) jsf_classify_type(aTHX_ sv);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (UV) jsf_classify_type(aTHX_ sv); 8 1 9
200 OUTPUT:
201 RETVAL
202  
203 UV
204 _prehash(sv)
205 SV *sv
206 CODE:
207 {
208 3 STRLEN l; const char *p = SvPV_const(sv, l);
209 3 ▶ U32 hh; PERL_HASH(hh, p, l);
Branch: 1 branch
BranchTrueFalseTotal
U32 hh; PERL_HASH(hh, p, l); 3 0 3
210 3 ▶ RETVAL = (UV) hh;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (UV) hh; 2 1 3
211 }
212 OUTPUT:
213 RETVAL
214  
215 SV *
216 _arena_selftest()
217 CODE:
218 {
219 jsf_arena_t *a;
220 uint32_t o1, o2, o3, blk, len, na;
221 const char *b;
222 int dedup_ok, bytes_ok, align_ok;
223 1 a = jsf_arena_new(16);
224 1 ▶ if (!a) croak("oom");
Branch: 1 branch
BranchTrueFalseTotal
if (!a) croak("oom"); 0 1 1
225 1 o1 = jsf_arena_intern(a, "hello", 5);
226 1 o2 = jsf_arena_intern(a, "hello", 5);
227 1 o3 = jsf_arena_intern(a, "world", 5);
228 1 blk = jsf_arena_alloc(a, 1000, 8);
229 1 b = jsf_str_bytes(a, o1, &len);
230 1 ▶ dedup_ok = (o1 == o2) && (o1 != o3) && (o1 != JSF_NULL_OFF);
Branch: 3 branches
BranchTrueFalseTotal
dedup_ok = (o1 == o2) && (o1 != o3) && (o1 != JSF_NULL_OFF); 1 0 1
dedup_ok = (o1 == o2) && (o1 != o3) && (o1 != JSF_NULL_OFF); 1 0 1
dedup_ok = (o1 == o2) && (o1 != o3) && (o1 != JSF_NULL_OFF); 1 0 1
231 1 ▶ bytes_ok = (len == 5) && (memcmp(b, "hello", 5) == 0) && (blk != JSF_NULL_OFF);
Branch: 3 branches
BranchTrueFalseTotal
bytes_ok = (len == 5) && (memcmp(b, "hello", 5) == 0) && (blk != JSF_NULL_OFF); 1 0 1
bytes_ok = (len == 5) && (memcmp(b, "hello", 5) == 0) && (blk != JSF_NULL_OFF); 1 0 1
bytes_ok = (len == 5) && (memcmp(b, "hello", 5) == 0) && (blk != JSF_NULL_OFF); 1 0 1
232  
233 1 na = JSF_ALIGNOF(jsf_node_t);
234 1 ▶ align_ok = (na > 0) && ((na & (na - 1)) == 0)
Branch: 1 branch
BranchTrueFalseTotal
align_ok = (na > 0) && ((na & (na - 1)) == 0) 1 0 1
235 2 ▶ && (((uintptr_t)a->base % na) == 0);
Branch: 2 branches
BranchTrueFalseTotal
&& (((uintptr_t)a->base % na) == 0); 1 0 1
&& (((uintptr_t)a->base % na) == 0); 1 0 1
236 1 jsf_arena_free(a);
237 1 RETVAL = newSVpvf("%d:%d:%d:%u", dedup_ok, bytes_ok, align_ok,
238 (unsigned)na);
239 }
240 OUTPUT:
241 RETVAL
242  
243 # Alignment of the nodes the PARSER actually produced, which is the thing that
244 # broke in 0.05: jsf_parse.h asked the arena for alignment 8 while jsf_node_t
245 # holds NVs, and an NV is 16-byte aligned on a perl built -Duselongdouble or
246 # -Dusequadmath. Asserting against a freshly compiled schema (rather than
247 # against an allocation this function makes itself) is what makes this a real
248 # guard - it fails if the parser ever goes back to a hardcoded alignment.
249 # Returns "<all_aligned>:<alignof>:<nodes_checked>".
250 SV *
251 _node_align_selftest(schema)
252 SV *schema
253 CODE:
254 {
255 jsf_compiled_t *c;
256 SV *obj;
257 1 uint32_t na = JSF_ALIGNOF(jsf_node_t);
258 uint32_t off;
259 1 int ok = 1, seen = 0;
260  
261 1 obj = jsf_compile_api(aTHX_ schema, NULL, 0, 0);
262 1 ▶ if (!obj) croak("compile failed");
Branch: 1 branch
BranchTrueFalseTotal
if (!obj) croak("compile failed"); 0 1 1
263 1 c = jsf_compiled_of(aTHX_ obj);
264  
265 1 ▶ if (!c || !c->arena || ((uintptr_t)c->arena->base % na) != 0) ok = 0;
Branch: 3 branches
BranchTrueFalseTotal
if (!c || !c->arena || ((uintptr_t)c->arena->base % na) != 0) ok = 0; 1 0 1
if (!c || !c->arena || ((uintptr_t)c->arena->base % na) != 0) ok = 0; 1 0 1
if (!c || !c->arena || ((uintptr_t)c->arena->base % na) != 0) ok = 0; 0 1 1
266  
267 /* Walk every node-sized slot the parser laid down. Node offsets are
268 * not enumerable from outside, so scan the arena at the alignment the
269 * parser should have used: if it used a smaller one, the root offset
270 * itself will not be on this grid. */
271 1 ▶ if (c && c->arena && c->root != JSF_NULL_OFF) {
Branch: 3 branches
BranchTrueFalseTotal
if (c && c->arena && c->root != JSF_NULL_OFF) { 1 0 1
if (c && c->arena && c->root != JSF_NULL_OFF) { 1 0 1
if (c && c->arena && c->root != JSF_NULL_OFF) { 1 0 1
272 1 ▶ if ((c->root % na) != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if ((c->root % na) != 0) ok = 0; 0 1 1
273 1 ▶ if (((uintptr_t)jsf_arena_ptr(c->arena, c->root) % na) != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (((uintptr_t)jsf_arena_ptr(c->arena, c->root) % na) != 0) ok = 0; 0 1 1
274 1 seen++;
275 5 ▶ for (off = c->root; off + sizeof(jsf_node_t) <= c->arena->used;
Branch: 1 branch
BranchTrueFalseTotal
for (off = c->root; off + sizeof(jsf_node_t) <= c->arena->used; 4 1 5
276 4 off += (uint32_t)sizeof(jsf_node_t)) {
277 4 ▶ if (((uintptr_t)jsf_arena_ptr(c->arena, off) % na) != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (((uintptr_t)jsf_arena_ptr(c->arena, off) % na) != 0) ok = 0; 0 4 4
278 4 seen++;
279 }
280 }
281 1 SvREFCNT_dec(obj);
282 1 RETVAL = newSVpvf("%d:%u:%d", ok, (unsigned)na, seen);
283 }
284 OUTPUT:
285 RETVAL
286  
287 # Function-call fast path (importable). Hot callers - e.g. OpenAPI::Fast's
288 # compiled request handlers - call `is_valid($v, $data)` / `validate($v, $data)`
289 # as functions, bypassing method dispatch. Same semantics as the ::Compiled
290 # methods; parity is asserted in t/54.
291 int
292 is_valid(compiled, data)
293 SV *compiled
294 SV *data
295 CODE:
296 3 RETVAL = jsf_is_valid(aTHX_ jsf_compiled_of(aTHX_ compiled), data);
297 OUTPUT:
298 RETVAL
299  
300 void
301 validate(compiled, data)
302 SV *compiled
303 SV *data
304 PPCODE:
305 {
306 3 jsf_compiled_t *C = jsf_compiled_of(aTHX_ compiled);
307 3 AV *errs = (AV *)sv_2mortal((SV *)newAV());
308 3 int ok = jsf_run(aTHX_ C, data, errs);
309 3 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 2 1 3
310 2 ▶ if (ok) { mXPUSHs(newSViv(1)); }
Branch: 2 branches
BranchTrueFalseTotal
if (ok) { mXPUSHs(newSViv(1)); } 1 1 2
if (ok) { mXPUSHs(newSViv(1)); } 0 1 1
311 1 ▶ else { mXPUSHs(newSViv(0)); mXPUSHs(newRV_inc((SV *)errs)); }
Branch: 2 branches
BranchTrueFalseTotal
else { mXPUSHs(newSViv(0)); mXPUSHs(newRV_inc((SV *)errs)); } 0 1 1
else { mXPUSHs(newSViv(0)); mXPUSHs(newRV_inc((SV *)errs)); } 0 1 1
312 } else {
313 1 ▶ mXPUSHs(newSViv(ok ? 1 : 0));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSViv(ok ? 1 : 0)); 0 1 1
314 }
315 }
316  
317 MODULE = JSON::Schema::Fast PACKAGE = JSON::Schema::Fast::Compiled
318  
319 # Boolean validation (fail-fast). validate()/errors() with the JSON-Pointer
320 # vocabulary arrive in phase 04.
321 int
322 is_valid(self, data)
323 SV *self
324 SV *data
325 CODE:
326 1459 RETVAL = jsf_is_valid(aTHX_ jsf_compiled_of(aTHX_ self), data);
327 OUTPUT:
328 RETVAL
329  
330 # list context: (1) if valid, else (0, \@errors); scalar context: the boolean.
331 void
332 validate(self, data)
333 SV *self
334 SV *data
335 PPCODE:
336 {
337 4 jsf_compiled_t *C = jsf_compiled_of(aTHX_ self);
338 4 AV *errs = (AV *)sv_2mortal((SV *)newAV());
339 4 int ok = jsf_run(aTHX_ C, data, errs);
340 4 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 2 2 4
341 2 ▶ if (ok) { mXPUSHs(newSViv(1)); }
Branch: 2 branches
BranchTrueFalseTotal
if (ok) { mXPUSHs(newSViv(1)); } 1 1 2
if (ok) { mXPUSHs(newSViv(1)); } 0 1 1
342 1 ▶ else { mXPUSHs(newSViv(0)); mXPUSHs(newRV_inc((SV *)errs)); }
Branch: 2 branches
BranchTrueFalseTotal
else { mXPUSHs(newSViv(0)); mXPUSHs(newRV_inc((SV *)errs)); } 0 1 1
else { mXPUSHs(newSViv(0)); mXPUSHs(newRV_inc((SV *)errs)); } 0 1 1
343 } else {
344 2 ▶ mXPUSHs(newSViv(ok ? 1 : 0));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSViv(ok ? 1 : 0)); 0 2 2
345 }
346 }
347  
348 # always an arrayref (empty when valid)
349 SV *
350 errors(self, data)
351 SV *self
352 SV *data
353 CODE:
354 {
355 8 AV *errs = newAV();
356 8 (void)jsf_run(aTHX_ jsf_compiled_of(aTHX_ self), data, errs);
357 8 RETVAL = newRV_noinc((SV *)errs);
358 }
359 OUTPUT:
360 RETVAL
361  
362 SV *
363 engine(self)
364 SV *self
365 CODE:
366 PERL_UNUSED_VAR(self);
367 1 RETVAL = newSVpvs("interp");
368 OUTPUT:
369 RETVAL
370  
371 SV *
372 schema(self)
373 SV *self
374 CODE:
375 {
376 1 jsf_compiled_t *C = jsf_compiled_of(aTHX_ self);
377 1 ▶ RETVAL = C->schema_sv ? newSVsv(C->schema_sv) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = C->schema_sv ? newSVsv(C->schema_sv) : &PL_sv_undef; 1 0 1
378 }
379 OUTPUT:
380 RETVAL
381  
382 # dump the root node's IR as a nested Perl structure (tests only)
383 SV *
384 _dump_ir(self)
385 SV *self
386 CODE:
387 {
388 9 jsf_compiled_t *C = jsf_compiled_of(aTHX_ self);
389 9 RETVAL = jsf_dump_node(aTHX_ C, C->root);
390 }
391 OUTPUT:
392 RETVAL
393  
394 UV
395 _unsupported(self)
396 SV *self
397 CODE:
398 385 ▶ RETVAL = (UV) jsf_compiled_of(aTHX_ self)->unsupported;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (UV) jsf_compiled_of(aTHX_ self)->unsupported; 382 3 385
399 OUTPUT:
400 RETVAL
401  
402 void
403 DESTROY(self)
404 SV *self
405 CODE:
406 478 jsf_compiled_free(aTHX_ jsf_compiled_of(aTHX_ self));
« include/jsf_types.h ↑ Summary include/jsf_parse.h »