include/frx/frx_abi_impl.h

filter: Statementstmt 93.5% 479 / 512 Branchbran 51.4% 284 / 552 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 71.7% 763 / 1064 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/abi.xs ↑ Summary xs/reader.xs »
1 #ifndef FRX_ABI_IMPL_H
2 #define FRX_ABI_IMPL_H
3  
4 /* The table behind File::Raw::XML::_abi_ptr.
5 *
6 * Every entry points at a core function, wrapped only where the ABI's
7 * signature differs from the core's: parse turns an frx_err into NULL
8 * plus a mortal message SV; text and c14n turn an frx_buf into a +1 SV;
9 * the accessors read a field. Nothing is implemented here (rule 5):
10 * logic written in this file has found a core function with the wrong
11 * shape.
12 *
13 * The table is a static const; _abi_ptr returns its address as an IV and
14 * a consumer INT2PTRs it once at BOOT and compares abi_version with >=,
15 * never ==. Append only after 0.01.
16 *
17 * `parse` points at the strict form and always will; `parse_ex` is the
18 * full profile's entry, and everything after it in the table is the rest
19 * of what the full profile built. Nothing has been released, so the whole
20 * table is version 1; the append-only rule begins the day it ships.
21 *
22 * Needs frx_abi.h and every core header the entries name. */
23  
24 static void
25 1 frx_abi_opts_init(frx_opts *o)
26 {
27 1 o->max_bytes = 0;
28 1 o->max_depth = 0;
29 1 o->id_attrs = NULL;
30 1 o->n_id_attrs = 0;
31 1 }
32  
33 static frx_doc *
34 2 frx_abi_parse(pTHX_ const char *bytes, STRLEN len, const frx_opts *o, SV **err)
35 {
36 frx_err e;
37 2 frx_doc *d = frx_parse_doc(bytes, (size_t)len, o, &e);
38 2 ▶ if (!d && err) {
Branch: 2 branches
BranchTrueFalseTotal
if (!d && err) { 1 1 2
if (!d && err) { 1 0 1
39 char msg[512];
40 1 size_t n = frx_err_format(&e, bytes, (size_t)len, msg, sizeof msg);
41 1 *err = sv_2mortal(newSVpvn(msg, n));
42 }
43 2 return d;
44 }
45  
46 static void
47 5 frx_abi_doc_free(pTHX_ frx_doc *d)
48 {
49 PERL_UNUSED_CONTEXT;
50 5 frx_doc_free(d);
51 5 }
52  
53 6 static const frx_node *frx_abi_root(const frx_doc *d) { return d->root; }
54 9 static const frx_node *frx_abi_document(const frx_doc *d) { return d->document; }
55 8 static int frx_abi_kind(const frx_node *n) { return n->kind; }
56 3 static const frx_node *frx_abi_parent(const frx_node *n) { return n->parent; }
57 3 static const frx_node *frx_abi_first_child(const frx_node *n) { return n->first_child; }
58 7 static const frx_node *frx_abi_next(const frx_node *n) { return n->next; }
59 1 static int frx_abi_attr_count(const frx_node *n) { return n->n_attrs; }
60  
61 static const char *
62 31 frx_abi_str(const frx_str *s, STRLEN *len)
63 {
64 31 ▶ if (len) *len = (STRLEN)s->len;
Branch: 1 branch
BranchTrueFalseTotal
if (len) *len = (STRLEN)s->len; 31 0 31
65 31 ▶ return s->p ? s->p : "";
Branch: 1 branch
BranchTrueFalseTotal
return s->p ? s->p : ""; 31 0 31
66 }
67  
68 2 static const char *frx_abi_ns(const frx_node *n, STRLEN *len) { return frx_abi_str(&n->ns, len); }
69 4 static const char *frx_abi_local(const frx_node *n, STRLEN *len) { return frx_abi_str(&n->local, len); }
70 1 static const char *frx_abi_prefix(const frx_node *n, STRLEN *len) { return frx_abi_str(&n->prefix, len); }
71  
72 static void
73 3 frx_abi_attr(const frx_node *n, int i,
74 const char **ns, STRLEN *nslen,
75 const char **local, STRLEN *loclen,
76 const char **value, STRLEN *vlen)
77 {
78 const frx_attr *a;
79 3 ▶ if (i < 0 || i >= n->n_attrs) {
Branch: 2 branches
BranchTrueFalseTotal
if (i < 0 || i >= n->n_attrs) { 3 0 3
if (i < 0 || i >= n->n_attrs) { 1 2 3
80 1 ▶ if (ns) *ns = NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (ns) *ns = NULL; 1 0 1
81 1 ▶ if (local) *local = NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (local) *local = NULL; 1 0 1
82 1 ▶ if (value) *value = NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (value) *value = NULL; 1 0 1
83 1 ▶ if (nslen) *nslen = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (nslen) *nslen = 0; 1 0 1
84 1 ▶ if (loclen) *loclen = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (loclen) *loclen = 0; 1 0 1
85 1 ▶ if (vlen) *vlen = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (vlen) *vlen = 0; 1 0 1
86 1 return;
87 }
88 2 a = &n->attrs[i];
89 2 ▶ if (ns) *ns = frx_abi_str(&a->ns, nslen);
Branch: 1 branch
BranchTrueFalseTotal
if (ns) *ns = frx_abi_str(&a->ns, nslen); 1 1 2
90 2 ▶ if (local) *local = frx_abi_str(&a->local, loclen);
Branch: 1 branch
BranchTrueFalseTotal
if (local) *local = frx_abi_str(&a->local, loclen); 2 0 2
91 2 ▶ if (value) *value = frx_abi_str(&a->value, vlen);
Branch: 1 branch
BranchTrueFalseTotal
if (value) *value = frx_abi_str(&a->value, vlen); 1 1 2
92 }
93  
94 static const char *
95 6 frx_abi_attr_value(const frx_node *n, const char *ns, const char *local, STRLEN *len)
96 {
97 6 const frx_str *v = frx_attr_value(n, ns, local);
98 6 ▶ if (!v) { if (len) *len = 0; return NULL; }
Branch: 2 branches
BranchTrueFalseTotal
if (!v) { if (len) *len = 0; return NULL; } 2 4 6
if (!v) { if (len) *len = 0; return NULL; } 2 0 2
99 4 return frx_abi_str(v, len);
100 }
101  
102 static const frx_node *
103 4 frx_abi_by_id(const frx_doc *d, const char *attr, const char *value, STRLEN vlen)
104 {
105 4 return frx_by_id(d, attr, value, (size_t)vlen);
106 }
107  
108 static SV *
109 1 frx_abi_text(pTHX_ const frx_node *n)
110 {
111 frx_buf b;
112 SV *out;
113 1 frx_buf_init(&b);
114 1 frx_text(n, &b);
115 1 ▶ out = b.failed ? NULL : newSVpvn(b.p ? b.p : "", b.len);
Branch: 2 branches
BranchTrueFalseTotal
out = b.failed ? NULL : newSVpvn(b.p ? b.p : "", b.len); 1 0 1
out = b.failed ? NULL : newSVpvn(b.p ? b.p : "", b.len); 1 0 1
116 1 ▶ if (out) SvUTF8_on(out);
Branch: 1 branch
BranchTrueFalseTotal
if (out) SvUTF8_on(out); 1 0 1
117 1 frx_buf_free(&b);
118 1 return out;
119 }
120  
121 static SV *
122 3 frx_abi_c14n(pTHX_ const frx_node *n, const frx_c14n *c)
123 {
124 frx_buf b;
125 SV *out;
126 3 frx_buf_init(&b);
127 3 ▶ out = frx_c14n_render(n, c, &b) ? newSVpvn(b.p ? b.p : "", b.len) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
out = frx_c14n_render(n, c, &b) ? newSVpvn(b.p ? b.p : "", b.len) : NULL; 3 0 3
out = frx_c14n_render(n, c, &b) ? newSVpvn(b.p ? b.p : "", b.len) : NULL; 3 0 3
128 3 frx_buf_free(&b);
129 3 return out;
130 }
131  
132  
133 /* ---- the full profile ---------------------------------------------------
134 *
135 * Almost every entry below is a direct pointer to a core function, which
136 * is what taking an frx_err * rather than an SV bought. What is here is
137 * field reads, in the shape the v1 accessors already use, and the three
138 * places the ABI's types differ from the core's: STRLEN for size_t, and
139 * the two selectors that keep the reader from needing an entry per
140 * accessor. */
141  
142 static STRLEN
143 1 frx_abi_err_format(const frx_err *e, const char *in, STRLEN len, char *out, STRLEN cap)
144 {
145 1 return (STRLEN)frx_err_format(e, in, (size_t)len, out, (size_t)cap);
146 }
147  
148 1 static int frx_abi_version(const frx_doc *d)
149 {
150 1 ▶ return frx_str_eq(&d->version, "1.1", 3) ? 11 : 10;
Branch: 1 branch
BranchTrueFalseTotal
return frx_str_eq(&d->version, "1.1", 3) ? 11 : 10; 0 1 1
151 }
152 1 static int frx_abi_standalone(const frx_doc *d) { return d->standalone ? 1 : 0; }
153  
154 static const char *
155 4 frx_abi_dt(const frx_doc *d, int which, STRLEN *len)
156 {
157 4 const frx_doctype *dt = d->doctype;
158 4 ▶ if (!dt) { if (len) *len = 0; return NULL; }
Branch: 2 branches
BranchTrueFalseTotal
if (!dt) { if (len) *len = 0; return NULL; } 0 4 4
if (!dt) { if (len) *len = 0; return NULL; } 0 0 0
159 4 switch (which) {
160 1 case 1: return frx_abi_str(&dt->public_id, len);
161 1 case 2: return frx_abi_str(&dt->system_id, len);
162 1 case 3: return frx_abi_str(&dt->subset, len);
163 1 default: return frx_abi_str(&dt->name, len);
164 }
165 }
166  
167 1 static const char *frx_abi_dt_name(const frx_doc *d, STRLEN *l) { return frx_abi_dt(d, 0, l); }
168 1 static const char *frx_abi_dt_public(const frx_doc *d, STRLEN *l) { return frx_abi_dt(d, 1, l); }
169 1 static const char *frx_abi_dt_system(const frx_doc *d, STRLEN *l) { return frx_abi_dt(d, 2, l); }
170 1 static const char *frx_abi_dt_subset(const frx_doc *d, STRLEN *l) { return frx_abi_dt(d, 3, l); }
171  
172 1 static int frx_abi_span_count(const frx_node *n) { return n->n_cdata_spans; }
173  
174 static void
175 2 frx_abi_span(const frx_node *n, int i, STRLEN *off, STRLEN *len)
176 {
177 2 ▶ if (i < 0 || i >= n->n_cdata_spans) {
Branch: 2 branches
BranchTrueFalseTotal
if (i < 0 || i >= n->n_cdata_spans) { 2 0 2
if (i < 0 || i >= n->n_cdata_spans) { 1 1 2
178 1 ▶ if (off) *off = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (off) *off = 0; 1 0 1
179 1 ▶ if (len) *len = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (len) *len = 0; 1 0 1
180 1 return;
181 }
182 1 ▶ if (off) *off = (STRLEN)n->cdata_spans[i].offset;
Branch: 1 branch
BranchTrueFalseTotal
if (off) *off = (STRLEN)n->cdata_spans[i].offset; 1 0 1
183 1 ▶ if (len) *len = (STRLEN)n->cdata_spans[i].len;
Branch: 1 branch
BranchTrueFalseTotal
if (len) *len = (STRLEN)n->cdata_spans[i].len; 1 0 1
184 }
185  
186 2 static int frx_abi_error_count(const frx_doc *d) { return d->n_errors; }
187  
188 static const char *
189 2 frx_abi_error_at(const frx_doc *d, int i, STRLEN *offset)
190 {
191 2 const frx_verr *e = d->errors;
192 2 ▶ if (offset) *offset = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (offset) *offset = 0; 1 1 2
193 2 ▶ if (i < 0) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (i < 0) return NULL; 0 2 2
194 3 ▶ while (e && i--) e = e->next;
Branch: 2 branches
BranchTrueFalseTotal
while (e && i--) e = e->next; 2 1 3
while (e && i--) e = e->next; 1 1 2
195 2 ▶ if (!e) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!e) return NULL; 1 1 2
196 1 ▶ if (offset) *offset = (STRLEN)e->offset;
Branch: 1 branch
BranchTrueFalseTotal
if (offset) *offset = (STRLEN)e->offset; 1 0 1
197 1 return e->what;
198 }
199  
200 static SV *
201 1 frx_abi_write(pTHX_ const frx_node *apex, const frx_doc *d,
202 const frx_write_opts *o, frx_err *err)
203 {
204 frx_buf b;
205 SV *out;
206 1 frx_buf_init(&b);
207 1 ▶ out = frx_write(apex, d, o, &b, err) ? newSVpvn(b.p ? b.p : "", b.len) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
out = frx_write(apex, d, o, &b, err) ? newSVpvn(b.p ? b.p : "", b.len) : NULL; 1 0 1
out = frx_write(apex, d, o, &b, err) ? newSVpvn(b.p ? b.p : "", b.len) : NULL; 1 0 1
208 1 frx_buf_free(&b);
209 1 return out;
210 }
211  
212 /* ---- the reader's two selectors ---------------------------------------- */
213  
214 static const char *
215 9 frx_abi_reader_str(const frx_reader *r, int which, STRLEN *len)
216 {
217 9 const frx_event *e = &r->cur;
218 9 ▶ if (!r->have_cur) { if (len) *len = 0; return ""; }
Branch: 2 branches
BranchTrueFalseTotal
if (!r->have_cur) { if (len) *len = 0; return ""; } 0 9 9
if (!r->have_cur) { if (len) *len = 0; return ""; } 0 0 0
219 9 switch (which) {
220 5 case FRX_R_LOCAL: return frx_abi_str(&e->local, len);
221 0 case FRX_R_NS: return frx_abi_str(&e->ns, len);
222 0 case FRX_R_PREFIX: return frx_abi_str(&e->prefix, len);
223 4 case FRX_R_VALUE: return frx_abi_str(&e->value, len);
224 0 case FRX_R_ENTITY: return frx_abi_str(&e->entity, len);
225 0 default: return frx_abi_str(&e->qname, len);
226 }
227 }
228  
229 static int
230 4 frx_abi_reader_int(const frx_reader *r, int which)
231 {
232 4 switch (which) {
233 1 case FRX_R_DEPTH:
234 1 ▶ if (!r->have_cur) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!r->have_cur) return 0; 0 1 1
235 1 ▶ return r->cur.kind == FRX_START ? r->cur.depth + 1 : r->cur.depth;
Branch: 1 branch
BranchTrueFalseTotal
return r->cur.kind == FRX_START ? r->cur.depth + 1 : r->cur.depth; 1 0 1
236 1 ▶ case FRX_R_EMPTY: return r->have_cur ? (r->cur.empty ? 1 : 0) : 0;
Branch: 2 branches
BranchTrueFalseTotal
case FRX_R_EMPTY: return r->have_cur ? (r->cur.empty ? 1 : 0) : 0; 1 0 1
case FRX_R_EMPTY: return r->have_cur ? (r->cur.empty ? 1 : 0) : 0; 0 1 1
237 1 case FRX_R_DONE: return r->done ? 1 : 0;
238 0 case FRX_R_CAPTURING: return r->capturing ? 1 : 0;
239 1 ▶ default: return r->have_cur ? r->cur.kind : 0;
Branch: 1 branch
BranchTrueFalseTotal
default: return r->have_cur ? r->cur.kind : 0; 1 0 1
240 }
241 }
242  
243 1 static STRLEN frx_abi_reader_offset(const frx_reader *r)
244 {
245 1 ▶ return r->have_cur ? (STRLEN)r->cur.offset : 0;
Branch: 1 branch
BranchTrueFalseTotal
return r->have_cur ? (STRLEN)r->cur.offset : 0; 1 0 1
246 }
247  
248 1 static int frx_abi_reader_attr_count(const frx_reader *r)
249 {
250 1 ▶ return r->have_cur ? r->cur.n_attrs : 0;
Branch: 1 branch
BranchTrueFalseTotal
return r->have_cur ? r->cur.n_attrs : 0; 1 0 1
251 }
252  
253 static void
254 1 frx_abi_reader_attr(const frx_reader *r, int i,
255 const char **ns, STRLEN *nslen,
256 const char **local, STRLEN *loclen,
257 const char **value, STRLEN *vlen)
258 {
259 const frx_attr *a;
260 1 ▶ if (!r->have_cur || i < 0 || i >= r->cur.n_attrs) {
Branch: 3 branches
BranchTrueFalseTotal
if (!r->have_cur || i < 0 || i >= r->cur.n_attrs) { 1 0 1
if (!r->have_cur || i < 0 || i >= r->cur.n_attrs) { 1 0 1
if (!r->have_cur || i < 0 || i >= r->cur.n_attrs) { 0 1 1
261 0 ▶ if (ns) *ns = NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (ns) *ns = NULL; 0 0 0
262 0 ▶ if (local) *local = NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (local) *local = NULL; 0 0 0
263 0 ▶ if (value) *value = NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (value) *value = NULL; 0 0 0
264 0 ▶ if (nslen) *nslen = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (nslen) *nslen = 0; 0 0 0
265 0 ▶ if (loclen) *loclen = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (loclen) *loclen = 0; 0 0 0
266 0 ▶ if (vlen) *vlen = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (vlen) *vlen = 0; 0 0 0
267 0 return;
268 }
269 1 a = &r->cur.attrs[i];
270 1 ▶ if (ns) *ns = frx_abi_str(&a->ns, nslen);
Branch: 1 branch
BranchTrueFalseTotal
if (ns) *ns = frx_abi_str(&a->ns, nslen); 1 0 1
271 1 ▶ if (local) *local = frx_abi_str(&a->local, loclen);
Branch: 1 branch
BranchTrueFalseTotal
if (local) *local = frx_abi_str(&a->local, loclen); 1 0 1
272 1 ▶ if (value) *value = frx_abi_str(&a->value, vlen);
Branch: 1 branch
BranchTrueFalseTotal
if (value) *value = frx_abi_str(&a->value, vlen); 1 0 1
273 }
274  
275 static int
276 2 frx_abi_reader_feed(frx_reader *r, const char *bytes, STRLEN len, int eof)
277 {
278 2 return frx_reader_feed(r, bytes, (size_t)len, eof);
279 }
280  
281 static int
282 15 frx_abi_reader_next(frx_reader *r)
283 {
284 frx_event ev;
285 15 int rc = frx_reader_next(r, &ev);
286 15 ▶ return rc > 0 ? ev.kind : rc; /* 0 wants bytes, -1 is the end */
Branch: 1 branch
BranchTrueFalseTotal
return rc > 0 ? ev.kind : rc; /* 0 wants bytes, -1 is the end */ 14 1 15
287 }
288  
289 static frx_doc *
290 1 frx_abi_reader_subtree(frx_reader *r)
291 {
292 1 frx_doc *d = NULL;
293 1 ▶ return frx_reader_subtree(r, &d) > 0 ? d : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return frx_reader_subtree(r, &d) > 0 ? d : NULL; 1 0 1
294 }
295  
296 1 static const frx_err *frx_abi_reader_error(const frx_reader *r) { return &r->err; }
297  
298 /* ---- the edits, with STRLEN where the core takes size_t ---------------- */
299  
300 static frx_node *
301 2 frx_abi_new_element(frx_doc *d, const char *ns, STRLEN nslen,
302 const char *prefix, STRLEN plen,
303 const char *local, STRLEN llen, frx_err *e)
304 {
305 2 return frx_new_element(d, ns, (size_t)nslen, prefix, (size_t)plen,
306 local, (size_t)llen, e);
307 }
308 1 static frx_node *frx_abi_new_text(frx_doc *d, const char *s, STRLEN n, frx_err *e)
309 1 { return frx_new_text(d, s, (size_t)n, e); }
310 1 static frx_node *frx_abi_new_comment(frx_doc *d, const char *s, STRLEN n, frx_err *e)
311 1 { return frx_new_comment(d, s, (size_t)n, e); }
312 1 static frx_node *frx_abi_new_pi(frx_doc *d, const char *t, STRLEN tl,
313 const char *v, STRLEN vl, frx_err *e)
314 1 { return frx_new_pi(d, t, (size_t)tl, v, (size_t)vl, e); }
315  
316 static int
317 1 frx_abi_set_attr(frx_doc *d, frx_node *el, const char *ns, STRLEN nslen,
318 const char *prefix, STRLEN plen, const char *local, STRLEN llen,
319 const char *value, STRLEN vlen, frx_err *e)
320 {
321 1 return frx_set_attr(d, el, ns, (size_t)nslen, prefix, (size_t)plen,
322 local, (size_t)llen, value, (size_t)vlen, e);
323 }
324 1 static int frx_abi_remove_attr(frx_doc *d, frx_node *el, const char *ns, STRLEN nslen,
325 const char *local, STRLEN llen, frx_err *e)
326 1 { return frx_remove_attr(d, el, ns, (size_t)nslen, local, (size_t)llen, e); }
327 1 static int frx_abi_set_text(frx_doc *d, frx_node *n, const char *s, STRLEN len, frx_err *e)
328 1 { return frx_set_text(d, n, s, (size_t)len, e); }
329 1 static int frx_abi_declare_ns(frx_doc *d, frx_node *el, const char *p, STRLEN pl,
330 const char *u, STRLEN ul, frx_err *e)
331 1 { return frx_declare_ns(d, el, p, (size_t)pl, u, (size_t)ul, e); }
332 1 static int frx_abi_set_name(frx_doc *d, frx_node *el, const char *ns, STRLEN nslen,
333 const char *prefix, STRLEN plen, const char *local, STRLEN llen,
334 frx_err *e)
335 1 { return frx_set_name(d, el, ns, (size_t)nslen, prefix, (size_t)plen, local, (size_t)llen, e); }
336  
337 /* ---- XPath ------------------------------------------------------------- */
338  
339 static frx_doc *
340 3 frx_abi_parse_ex(const char *bytes, STRLEN len, const frx_opts_ex *o, frx_err *err)
341 {
342 frx_opts_ex oe;
343 3 ▶ if (o) return frx_parse_doc_ex(bytes, (size_t)len, o, err);
Branch: 1 branch
BranchTrueFalseTotal
if (o) return frx_parse_doc_ex(bytes, (size_t)len, o, err); 3 0 3
344 0 memset(&oe, 0, sizeof oe);
345 0 oe.size = sizeof oe;
346 0 oe.profile = FRX_PROFILE_STRICT;
347 0 return frx_parse_doc_ex(bytes, (size_t)len, &oe, err);
348 }
349  
350 static frx_xpath *
351 5 frx_abi_xpath_compile(const char *expr, STRLEN len, const frx_ns_map *ns,
352 int max_depth, const char **err, STRLEN *err_at)
353 {
354 5 size_t at = 0;
355 5 frx_xpath *x = frx_xpath_compile(expr, (size_t)len, ns, max_depth, err, &at);
356 5 ▶ if (err_at) *err_at = (STRLEN)at;
Branch: 1 branch
BranchTrueFalseTotal
if (err_at) *err_at = (STRLEN)at; 5 0 5
357 5 return x;
358 }
359  
360 static int
361 1 frx_abi_xpath_bind_str(frx_xpath *x, int i, const char *p, STRLEN n)
362 {
363 1 return frx_xpath_bind_str(x, i, p, (size_t)n);
364 }
365  
366 3 static int frx_abi_xpath_kind(const frx_xp_result *r) { return r->kind; }
367 1 static double frx_abi_xpath_number(const frx_xp_result *r) { return r->num; }
368  
369 static const char *
370 1 frx_abi_xpath_string(const frx_xp_result *r, STRLEN *len)
371 {
372 1 ▶ if (len) *len = (STRLEN)r->str.len;
Branch: 1 branch
BranchTrueFalseTotal
if (len) *len = (STRLEN)r->str.len; 1 0 1
373 1 ▶ return r->str.p ? r->str.p : "";
Branch: 1 branch
BranchTrueFalseTotal
return r->str.p ? r->str.p : ""; 1 0 1
374 }
375  
376 1 static int frx_abi_xpath_count(const frx_xp_result *r)
377 {
378 1 ▶ return r->kind == FRX_XV_NODESET ? r->set.n : 0;
Branch: 1 branch
BranchTrueFalseTotal
return r->kind == FRX_XV_NODESET ? r->set.n : 0; 1 0 1
379 }
380  
381 static const frx_node *
382 2 frx_abi_xpath_node(const frx_xp_result *r, int i, int *kind, int *index)
383 {
384 2 ▶ if (kind) *kind = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (kind) *kind = 0; 1 1 2
385 2 ▶ if (index) *index = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (index) *index = 0; 1 1 2
386 2 ▶ if (r->kind != FRX_XV_NODESET || i < 0 || i >= r->set.n) return NULL;
Branch: 3 branches
BranchTrueFalseTotal
if (r->kind != FRX_XV_NODESET || i < 0 || i >= r->set.n) return NULL; 2 0 2
if (r->kind != FRX_XV_NODESET || i < 0 || i >= r->set.n) return NULL; 2 0 2
if (r->kind != FRX_XV_NODESET || i < 0 || i >= r->set.n) return NULL; 1 1 2
387 1 ▶ if (kind) *kind = r->set.v[i].kind;
Branch: 1 branch
BranchTrueFalseTotal
if (kind) *kind = r->set.v[i].kind; 1 0 1
388 1 ▶ if (index) *index = r->set.v[i].index;
Branch: 1 branch
BranchTrueFalseTotal
if (index) *index = r->set.v[i].index; 1 0 1
389 1 return r->set.v[i].node;
390 }
391  
392 static const frx_abi FRX_ABI = {
393 FRX_ABI_VERSION,
394 frx_abi_opts_init,
395 frx_abi_parse,
396 frx_abi_doc_free,
397 frx_abi_root,
398 frx_abi_document,
399 frx_abi_kind,
400 frx_abi_ns,
401 frx_abi_local,
402 frx_abi_prefix,
403 frx_abi_parent,
404 frx_abi_first_child,
405 frx_abi_next,
406 frx_abi_attr_count,
407 frx_abi_attr,
408 frx_abi_attr_value,
409 frx_find,
410 frx_abi_by_id,
411 frx_abi_text,
412 frx_abi_c14n,
413  
414 /* the full profile */
415 frx_abi_parse_ex,
416 frx_abi_err_format,
417 frx_abi_version,
418 frx_abi_standalone,
419 frx_abi_dt_name,
420 frx_abi_dt_public,
421 frx_abi_dt_system,
422 frx_abi_dt_subset,
423 frx_abi_span_count,
424 frx_abi_span,
425 frx_abi_error_count,
426 frx_abi_error_at,
427 frx_write_opts_init,
428 frx_abi_write,
429 frx_tree_equal,
430  
431 frx_reader_new,
432 frx_reader_destroy,
433 frx_abi_reader_feed,
434 frx_abi_reader_next,
435 frx_abi_reader_str,
436 frx_abi_reader_int,
437 frx_abi_reader_offset,
438 frx_abi_reader_attr_count,
439 frx_abi_reader_attr,
440 frx_abi_reader_subtree,
441 frx_abi_reader_error,
442  
443 frx_doc_new_empty,
444 frx_abi_new_element,
445 frx_abi_new_text,
446 frx_abi_new_comment,
447 frx_abi_new_pi,
448 frx_append_child,
449 frx_insert_before,
450 frx_remove,
451 frx_abi_set_attr,
452 frx_abi_remove_attr,
453 frx_abi_set_text,
454 frx_abi_declare_ns,
455 frx_abi_set_name,
456 frx_import,
457  
458 frx_abi_xpath_compile,
459 frx_xpath_free,
460 frx_xpath_var_count,
461 frx_xpath_var_name,
462 frx_abi_xpath_bind_str,
463 frx_xpath_bind_num,
464 frx_xpath_bind_bool,
465 frx_xpath_result_new,
466 frx_xpath_result_destroy,
467 frx_xpath_eval_at,
468 frx_abi_xpath_kind,
469 frx_abi_xpath_number,
470 frx_abi_xpath_string,
471 frx_abi_xpath_count,
472 frx_abi_xpath_node
473 };
474  
475 /* The selftest: a fixed document through every entry, in C, with every
476 * answer checked. Returns the exclusive canonical bytes of the root as a
477 * +1 SV, or NULL on the first mismatch; the test compares those bytes
478 * with the Perl surface's for the same literal. */
479 #define FRX_SELFTEST_INPUT \
480 "<?pi data?><!-- c --><r xmlns=\"urn:d\" xmlns:p=\"urn:p\" ID=\"r1\" a=\"1\" p:b=\"2\">" \
481 "<p:e ID=\"e1\">text<![CDATA[!]]></p:e><f/><!-- x --><?q?></r>"
482  
483 static SV *
484 1 frx_abi_selftest(pTHX)
485 {
486 1 const frx_abi *A = &FRX_ABI;
487 static const char *const ids[] = { "ID" };
488 frx_opts o;
489 1 SV *err = NULL;
490 frx_doc *d;
491 const frx_node *doc, *root, *n, *e, *f;
492 const char *s;
493 STRLEN len;
494 1 SV *text = NULL, *out = NULL, *tmp;
495 frx_c14n c;
496 int i;
497  
498 1 ▶ if (A->abi_version < 1) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (A->abi_version < 1) return NULL; 0 1 1
499 1 A->opts_init(&o);
500 1 o.id_attrs = ids;
501 1 o.n_id_attrs = 1;
502 1 d = A->parse(aTHX_ FRX_SELFTEST_INPUT, sizeof FRX_SELFTEST_INPUT - 1, &o, &err);
503 1 ▶ if (!d) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!d) return NULL; 0 1 1
504  
505 1 doc = A->document(d);
506 1 root = A->root(d);
507 1 ▶ if (A->kind(doc) != FRX_DOCUMENT || A->kind(root) != FRX_ELEMENT) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (A->kind(doc) != FRX_DOCUMENT || A->kind(root) != FRX_ELEMENT) goto fail; 1 0 1
if (A->kind(doc) != FRX_DOCUMENT || A->kind(root) != FRX_ELEMENT) goto fail; 0 1 1
508 1 ▶ if (A->parent(root) != doc || A->parent(doc) != NULL) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (A->parent(root) != doc || A->parent(doc) != NULL) goto fail; 1 0 1
if (A->parent(root) != doc || A->parent(doc) != NULL) goto fail; 0 1 1
509  
510 /* the document's children: PI, comment, root, end */
511 1 n = A->first_child(doc);
512 1 ▶ if (!n || A->kind(n) != FRX_PI) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (!n || A->kind(n) != FRX_PI) goto fail; 1 0 1
if (!n || A->kind(n) != FRX_PI) goto fail; 0 1 1
513 1 s = A->local(n, &len);
514 1 ▶ if (len != 2 || memcmp(s, "pi", 2)) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (len != 2 || memcmp(s, "pi", 2)) goto fail; 1 0 1
if (len != 2 || memcmp(s, "pi", 2)) goto fail; 0 1 1
515 1 n = A->next(n);
516 1 ▶ if (!n || A->kind(n) != FRX_COMMENT) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (!n || A->kind(n) != FRX_COMMENT) goto fail; 1 0 1
if (!n || A->kind(n) != FRX_COMMENT) goto fail; 0 1 1
517 1 n = A->next(n);
518 1 ▶ if (n != root || A->next(n) != NULL) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (n != root || A->next(n) != NULL) goto fail; 1 0 1
if (n != root || A->next(n) != NULL) goto fail; 0 1 1
519  
520 /* names */
521 1 ▶ s = A->ns(root, &len); if (len != 5 || memcmp(s, "urn:d", 5)) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
s = A->ns(root, &len); if (len != 5 || memcmp(s, "urn:d", 5)) goto fail; 1 0 1
s = A->ns(root, &len); if (len != 5 || memcmp(s, "urn:d", 5)) goto fail; 0 1 1
522 1 ▶ s = A->local(root, &len); if (len != 1 || s[0] != 'r') goto fail;
Branch: 2 branches
BranchTrueFalseTotal
s = A->local(root, &len); if (len != 1 || s[0] != 'r') goto fail; 1 0 1
s = A->local(root, &len); if (len != 1 || s[0] != 'r') goto fail; 0 1 1
523 1 ▶ s = A->prefix(root, &len); if (len != 0 || s[0] != '\0') goto fail;
Branch: 2 branches
BranchTrueFalseTotal
s = A->prefix(root, &len); if (len != 0 || s[0] != '\0') goto fail; 1 0 1
s = A->prefix(root, &len); if (len != 0 || s[0] != '\0') goto fail; 0 1 1
524  
525 /* attributes: ID, a, p:b in order; xmlns never counted */
526 1 ▶ if (A->attr_count(root) != 3) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (A->attr_count(root) != 3) goto fail; 0 1 1
527 {
528 const char *ns, *local, *value;
529 STRLEN nsl, ll, vl;
530 1 A->attr(root, 2, &ns, &nsl, &local, &ll, &value, &vl);
531 1 ▶ if (nsl != 5 || memcmp(ns, "urn:p", 5) || ll != 1 || local[0] != 'b' || vl != 1 || value[0] != '2') goto fail;
Branch: 6 branches
BranchTrueFalseTotal
if (nsl != 5 || memcmp(ns, "urn:p", 5) || ll != 1 || local[0] != 'b' || vl != 1 || value[0] != '2') goto fail; 1 0 1
if (nsl != 5 || memcmp(ns, "urn:p", 5) || ll != 1 || local[0] != 'b' || vl != 1 || value[0] != '2') goto fail; 1 0 1
if (nsl != 5 || memcmp(ns, "urn:p", 5) || ll != 1 || local[0] != 'b' || vl != 1 || value[0] != '2') goto fail; 1 0 1
if (nsl != 5 || memcmp(ns, "urn:p", 5) || ll != 1 || local[0] != 'b' || vl != 1 || value[0] != '2') goto fail; 1 0 1
if (nsl != 5 || memcmp(ns, "urn:p", 5) || ll != 1 || local[0] != 'b' || vl != 1 || value[0] != '2') goto fail; 1 0 1
if (nsl != 5 || memcmp(ns, "urn:p", 5) || ll != 1 || local[0] != 'b' || vl != 1 || value[0] != '2') goto fail; 0 1 1
532 1 A->attr(root, 3, &ns, &nsl, &local, &ll, &value, &vl);
533 1 ▶ if (ns || local || value) goto fail;
Branch: 3 branches
BranchTrueFalseTotal
if (ns || local || value) goto fail; 1 0 1
if (ns || local || value) goto fail; 1 0 1
if (ns || local || value) goto fail; 0 1 1
534 }
535 1 ▶ s = A->attr_value(root, NULL, "b", &len); if (!s || len != 1 || s[0] != '2') goto fail;
Branch: 3 branches
BranchTrueFalseTotal
s = A->attr_value(root, NULL, "b", &len); if (!s || len != 1 || s[0] != '2') goto fail; 1 0 1
s = A->attr_value(root, NULL, "b", &len); if (!s || len != 1 || s[0] != '2') goto fail; 1 0 1
s = A->attr_value(root, NULL, "b", &len); if (!s || len != 1 || s[0] != '2') goto fail; 0 1 1
536 1 ▶ s = A->attr_value(root, "", "b", &len); if (s) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
s = A->attr_value(root, "", "b", &len); if (s) goto fail; 0 1 1
537 1 ▶ s = A->attr_value(root, "urn:p", "b", &len); if (!s || len != 1 || s[0] != '2') goto fail;
Branch: 3 branches
BranchTrueFalseTotal
s = A->attr_value(root, "urn:p", "b", &len); if (!s || len != 1 || s[0] != '2') goto fail; 1 0 1
s = A->attr_value(root, "urn:p", "b", &len); if (!s || len != 1 || s[0] != '2') goto fail; 1 0 1
s = A->attr_value(root, "urn:p", "b", &len); if (!s || len != 1 || s[0] != '2') goto fail; 0 1 1
538 1 ▶ s = A->attr_value(root, "", "a", &len); if (!s || len != 1 || s[0] != '1') goto fail;
Branch: 3 branches
BranchTrueFalseTotal
s = A->attr_value(root, "", "a", &len); if (!s || len != 1 || s[0] != '1') goto fail; 1 0 1
s = A->attr_value(root, "", "a", &len); if (!s || len != 1 || s[0] != '1') goto fail; 1 0 1
s = A->attr_value(root, "", "a", &len); if (!s || len != 1 || s[0] != '1') goto fail; 0 1 1
539  
540 /* find with the cursor, to exhaustion */
541 1 e = A->find(root, NULL, "e", NULL);
542 1 ▶ if (!e || A->kind(e) != FRX_ELEMENT) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (!e || A->kind(e) != FRX_ELEMENT) goto fail; 1 0 1
if (!e || A->kind(e) != FRX_ELEMENT) goto fail; 0 1 1
543 1 ▶ s = A->ns(e, &len); if (len != 5 || memcmp(s, "urn:p", 5)) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
s = A->ns(e, &len); if (len != 5 || memcmp(s, "urn:p", 5)) goto fail; 1 0 1
s = A->ns(e, &len); if (len != 5 || memcmp(s, "urn:p", 5)) goto fail; 0 1 1
544 1 ▶ if (A->find(root, NULL, "e", e) != NULL) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (A->find(root, NULL, "e", e) != NULL) goto fail; 0 1 1
545 1 f = A->find(root, "urn:d", "f", NULL);
546 1 ▶ if (!f) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!f) goto fail; 0 1 1
547 1 ▶ if (A->find(root, "", "f", NULL) != NULL) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (A->find(root, "", "f", NULL) != NULL) goto fail; 0 1 1
548 1 ▶ if (A->parent(e) != root || A->first_child(f) != NULL) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (A->parent(e) != root || A->first_child(f) != NULL) goto fail; 1 0 1
if (A->parent(e) != root || A->first_child(f) != NULL) goto fail; 0 1 1
549 1 ▶ n = A->next(e); if (n != f) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
n = A->next(e); if (n != f) goto fail; 0 1 1
550 1 ▶ n = A->next(f); if (!n || A->kind(n) != FRX_COMMENT) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
n = A->next(f); if (!n || A->kind(n) != FRX_COMMENT) goto fail; 1 0 1
n = A->next(f); if (!n || A->kind(n) != FRX_COMMENT) goto fail; 0 1 1
551 1 ▶ n = A->next(n); if (!n || A->kind(n) != FRX_PI) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
n = A->next(n); if (!n || A->kind(n) != FRX_PI) goto fail; 1 0 1
n = A->next(n); if (!n || A->kind(n) != FRX_PI) goto fail; 0 1 1
552 1 ▶ if (A->next(n) != NULL) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (A->next(n) != NULL) goto fail; 0 1 1
553  
554 /* by_id */
555 1 ▶ if (A->by_id(d, "ID", "e1", 2) != e) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (A->by_id(d, "ID", "e1", 2) != e) goto fail; 0 1 1
556 1 ▶ if (A->by_id(d, "ID", "r1", 2) != root) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (A->by_id(d, "ID", "r1", 2) != root) goto fail; 0 1 1
557 1 ▶ if (A->by_id(d, "ID", "zz", 2) != NULL) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (A->by_id(d, "ID", "zz", 2) != NULL) goto fail; 0 1 1
558 1 ▶ if (A->by_id(d, "Id", "e1", 2) != NULL) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (A->by_id(d, "Id", "e1", 2) != NULL) goto fail; 0 1 1
559  
560 /* text */
561 1 text = A->text(aTHX_ root);
562 1 ▶ if (!text) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!text) goto fail; 0 1 1
563 1 s = SvPV(text, len);
564 1 ▶ if (len != 5 || memcmp(s, "text!", 5)) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (len != 5 || memcmp(s, "text!", 5)) goto fail; 1 0 1
if (len != 5 || memcmp(s, "text!", 5)) goto fail; 0 1 1
565  
566 /* c14n in every mode; the exclusive bytes are the answer */
567 1 c.comments = 0; c.prefix_list = NULL; c.n_prefix = 0; c.without = NULL; c.n_without = 0;
568 4 ▶ for (i = FRX_C14N_INC11; i >= FRX_C14N_EXC; i--) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = FRX_C14N_INC11; i >= FRX_C14N_EXC; i--) { 3 1 4
569 3 c.mode = i;
570 3 tmp = A->c14n(aTHX_ root, &c);
571 3 ▶ if (!tmp || !SvCUR(tmp)) { if (tmp) SvREFCNT_dec(tmp); goto fail; }
Branch: 3 branches
BranchTrueFalseTotal
if (!tmp || !SvCUR(tmp)) { if (tmp) SvREFCNT_dec(tmp); goto fail; } 3 0 3
if (!tmp || !SvCUR(tmp)) { if (tmp) SvREFCNT_dec(tmp); goto fail; } 0 3 3
if (!tmp || !SvCUR(tmp)) { if (tmp) SvREFCNT_dec(tmp); goto fail; } 0 0 0
572 3 ▶ if (i == FRX_C14N_EXC) out = tmp; else SvREFCNT_dec(tmp);
Branch: 1 branch
BranchTrueFalseTotal
if (i == FRX_C14N_EXC) out = tmp; else SvREFCNT_dec(tmp); 1 2 3
573 }
574  
575 /* a refusal is NULL and a message, never a croak */
576 {
577 1 SV *e2 = NULL;
578 1 frx_doc *bad = A->parse(aTHX_ "<!DOCTYPE x><x/>", 16, NULL, &e2);
579 1 ▶ if (bad) { A->doc_free(aTHX_ bad); goto fail; }
Branch: 1 branch
BranchTrueFalseTotal
if (bad) { A->doc_free(aTHX_ bad); goto fail; } 0 1 1
580 2 ▶ if (!e2 || !SvPOK(e2) || !strstr(SvPV_nolen(e2), "DOCTYPE")) goto fail;
Branch: 3 branches
BranchTrueFalseTotal
if (!e2 || !SvPOK(e2) || !strstr(SvPV_nolen(e2), "DOCTYPE")) goto fail; 1 0 1
if (!e2 || !SvPOK(e2) || !strstr(SvPV_nolen(e2), "DOCTYPE")) goto fail; 1 0 1
if (!e2 || !SvPOK(e2) || !strstr(SvPV_nolen(e2), "DOCTYPE")) goto fail; 0 1 1
581 }
582  
583 1 A->doc_free(aTHX_ d);
584 1 SvREFCNT_dec(text);
585 1 return out;
586  
587 0 fail:
588 0 A->doc_free(aTHX_ d);
589 0 ▶ if (text) SvREFCNT_dec(text);
Branch: 1 branch
BranchTrueFalseTotal
if (text) SvREFCNT_dec(text); 0 0 0
590 0 ▶ if (out) SvREFCNT_dec(out);
Branch: 1 branch
BranchTrueFalseTotal
if (out) SvREFCNT_dec(out); 0 0 0
591 0 return NULL;
592 }
593  
594  
595 /* The full profile's selftest: a document with a DOCTYPE, a CDATA
596 * section and a validity error through every entry the strict selftest
597 * does not reach. Returns 0 when all of it held and the number of the
598 * check that did not otherwise, so a failure names itself.
599 *
600 * The document is invalid on purpose - `b` is declared EMPTY and holds
601 * text - so that `validate => collect` has something to collect and the
602 * error entries have something to report. */
603 #define FRX_SELFTEST_FULL \
604 "<?xml version=\"1.0\" standalone=\"yes\"?>" \
605 "<!DOCTYPE r PUBLIC \"-//p//DTD//EN\" \"r.dtd\" [" \
606 "<!ELEMENT r (a,b)><!ELEMENT a (#PCDATA)><!ELEMENT b EMPTY>" \
607 "<!ATTLIST a id ID #IMPLIED>" \
608 "<!ENTITY e \"E\">" \
609 "]>" \
610 "<r><a id=\"a1\">x&e;<![CDATA[<&]]></a><b>no</b></r>"
611  
612 #define FRX_STEP(n) do { step = (n); } while (0)
613  
614 /* the selftest's resolver: the DOCTYPE names an external subset, so
615 * something has to hand the bytes over, and this is also the one place
616 * the resolver seam is walked from C */
617 static const char *
618 4 frx_abi_selftest_resolve(void *ud, const char *pub, const char *sys,
619 const char *base, int kind, frx_fetched *out)
620 {
621 static const char subset[] = "<!ENTITY x \"X\">";
622 (void)ud; (void)pub; (void)sys; (void)base;
623 4 ▶ if (kind != FRX_REF_SUBSET) return "the selftest resolves only the external subset";
Branch: 1 branch
BranchTrueFalseTotal
if (kind != FRX_REF_SUBSET) return "the selftest resolves only the external subset"; 0 4 4
624 4 out->bytes = subset;
625 4 out->len = sizeof subset - 1;
626 4 out->release = NULL;
627 4 out->ud = NULL;
628 4 return NULL;
629 }
630  
631 static int
632 1 frx_abi_selftest_full(pTHX)
633 {
634 1 const frx_abi *A = &FRX_ABI;
635 frx_opts_ex oe;
636 frx_err err;
637 1 frx_doc *d = NULL, *d2 = NULL, *built = NULL;
638 frx_node *el, *tx;
639 const frx_node *n, *a;
640 const char *s;
641 STRLEN len, off;
642 1 int step = 0;
643 1 SV *out = NULL;
644  
645 1 memset(&err, 0, sizeof err);
646  
647 /* parse_ex, and the whole prolog it read */
648 1 memset(&oe, 0, sizeof oe);
649 1 oe.size = sizeof oe;
650 1 oe.profile = FRX_PROFILE_FULL;
651 1 oe.validate = 2; /* collect */
652 1 oe.resolve = frx_abi_selftest_resolve;
653 1 FRX_STEP(1);
654 1 d = A->parse_ex(FRX_SELFTEST_FULL, sizeof FRX_SELFTEST_FULL - 1, &oe, &err);
655 1 ▶ if (!d) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!d) goto fail; 0 1 1
656  
657 1 ▶ FRX_STEP(2); if (A->version(d) != 10) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
FRX_STEP(2); if (A->version(d) != 10) goto fail; 0 1 1
658 1 ▶ FRX_STEP(3); if (!A->standalone(d)) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
FRX_STEP(3); if (!A->standalone(d)) goto fail; 0 1 1
659 1 FRX_STEP(4);
660 1 ▶ s = A->doctype_name(d, &len); if (!s || len != 1 || s[0] != 'r') goto fail;
Branch: 3 branches
BranchTrueFalseTotal
s = A->doctype_name(d, &len); if (!s || len != 1 || s[0] != 'r') goto fail; 1 0 1
s = A->doctype_name(d, &len); if (!s || len != 1 || s[0] != 'r') goto fail; 1 0 1
s = A->doctype_name(d, &len); if (!s || len != 1 || s[0] != 'r') goto fail; 0 1 1
661 1 FRX_STEP(5);
662 1 ▶ s = A->doctype_public(d, &len); if (!s || len != 13) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
s = A->doctype_public(d, &len); if (!s || len != 13) goto fail; 1 0 1
s = A->doctype_public(d, &len); if (!s || len != 13) goto fail; 0 1 1
663 1 FRX_STEP(6);
664 1 ▶ s = A->doctype_system(d, &len); if (!s || len != 5 || memcmp(s, "r.dtd", 5)) goto fail;
Branch: 3 branches
BranchTrueFalseTotal
s = A->doctype_system(d, &len); if (!s || len != 5 || memcmp(s, "r.dtd", 5)) goto fail; 1 0 1
s = A->doctype_system(d, &len); if (!s || len != 5 || memcmp(s, "r.dtd", 5)) goto fail; 1 0 1
s = A->doctype_system(d, &len); if (!s || len != 5 || memcmp(s, "r.dtd", 5)) goto fail; 0 1 1
665 1 FRX_STEP(7);
666 1 ▶ s = A->doctype_subset(d, &len); if (!s || !len) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
s = A->doctype_subset(d, &len); if (!s || !len) goto fail; 1 0 1
s = A->doctype_subset(d, &len); if (!s || !len) goto fail; 0 1 1
667  
668 /* the CDATA section inside a's merged text: "xE<&", the section at 2 */
669 1 FRX_STEP(8);
670 1 a = A->find(A->root(d), NULL, "a", NULL);
671 1 ▶ if (!a) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!a) goto fail; 0 1 1
672 1 n = A->first_child(a);
673 1 ▶ if (!n || A->kind(n) != FRX_TEXT) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (!n || A->kind(n) != FRX_TEXT) goto fail; 1 0 1
if (!n || A->kind(n) != FRX_TEXT) goto fail; 0 1 1
674 1 ▶ FRX_STEP(9); if (A->cdata_span_count(n) != 1) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
FRX_STEP(9); if (A->cdata_span_count(n) != 1) goto fail; 0 1 1
675 1 FRX_STEP(10);
676 1 A->cdata_span(n, 0, &off, &len);
677 1 ▶ if (off != 2 || len != 2) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (off != 2 || len != 2) goto fail; 1 0 1
if (off != 2 || len != 2) goto fail; 0 1 1
678 1 FRX_STEP(11);
679 1 A->cdata_span(n, 1, &off, &len);
680 1 ▶ if (off != 0 || len != 0) goto fail; /* out of range is zeroed */
Branch: 2 branches
BranchTrueFalseTotal
if (off != 0 || len != 0) goto fail; /* out of range is zeroed */ 1 0 1
if (off != 0 || len != 0) goto fail; /* out of range is zeroed */ 0 1 1
681  
682 /* the validity error collect gathered */
683 1 ▶ FRX_STEP(12); if (A->error_count(d) < 1) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
FRX_STEP(12); if (A->error_count(d) < 1) goto fail; 0 1 1
684 1 FRX_STEP(13);
685 1 s = A->error_at(d, 0, &off);
686 1 ▶ if (!s || !strstr(s, "VC:")) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (!s || !strstr(s, "VC:")) goto fail; 1 0 1
if (!s || !strstr(s, "VC:")) goto fail; 0 1 1
687 1 ▶ FRX_STEP(14); if (A->error_at(d, A->error_count(d), NULL) != NULL) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
FRX_STEP(14); if (A->error_at(d, A->error_count(d), NULL) != NULL) goto fail; 0 1 1
688  
689 /* write, then read what was written back and compare as data */
690 {
691 frx_write_opts w;
692 1 A->write_opts_init(&w);
693 1 FRX_STEP(15);
694 /* (A->write), never A->write(: under PERL_IMPLICIT_SYS iperlsys.h
695 * makes `write` a function-like macro (PerlLIO_write), and a
696 * member call written the usual way expands it and fails to
697 * compile. The parentheses leave `write` followed by `)` so the
698 * macro cannot fire. Every consumer of the table has to do the
699 * same; frx_abi.h says so beside the entry. */
700 1 out = (A->write)(aTHX_ A->document(d), d, &w, &err);
701 1 ▶ if (!out || !SvCUR(out)) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (!out || !SvCUR(out)) goto fail; 1 0 1
if (!out || !SvCUR(out)) goto fail; 0 1 1
702 1 FRX_STEP(16);
703 1 d2 = A->parse_ex(SvPVX(out), SvCUR(out), &oe, &err);
704 1 ▶ if (!d2) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!d2) goto fail; 0 1 1
705 1 FRX_STEP(17);
706 1 ▶ if (!A->tree_equal(A->document(d), A->document(d2))) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->tree_equal(A->document(d), A->document(d2))) goto fail; 0 1 1
707 1 FRX_STEP(18);
708 1 ▶ if (A->tree_equal(A->root(d), A->find(A->root(d), NULL, "a", NULL))) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (A->tree_equal(A->root(d), A->find(A->root(d), NULL, "a", NULL))) goto fail; 0 1 1
709 1 A->doc_free(aTHX_ d2);
710 1 d2 = NULL;
711 1 SvREFCNT_dec(out);
712 1 out = NULL;
713 }
714  
715 /* err_format renders a refusal, and parse_ex refuses without croaking */
716 {
717 char msg[512];
718 frx_doc *bad;
719 1 FRX_STEP(19);
720 1 bad = A->parse_ex("<r><</r>", 8, &oe, &err);
721 1 ▶ if (bad) { A->doc_free(aTHX_ bad); goto fail; }
Branch: 1 branch
BranchTrueFalseTotal
if (bad) { A->doc_free(aTHX_ bad); goto fail; } 0 1 1
722 1 FRX_STEP(20);
723 1 len = A->err_format(&err, "<r><</r>", 8, msg, sizeof msg);
724 1 ▶ if (!len || !strstr(msg, "File::Raw::XML: ")) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (!len || !strstr(msg, "File::Raw::XML: ")) goto fail; 1 0 1
if (!len || !strstr(msg, "File::Raw::XML: ")) goto fail; 0 1 1
725 }
726  
727 /* the reader over the same bytes */
728 {
729 frx_reader *r;
730 1 int kind, saw_start = 0, saw_cdata = 0;
731 1 FRX_STEP(21);
732 1 r = A->reader_new(&oe);
733 1 ▶ if (!r) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) goto fail; 0 1 1
734 1 FRX_STEP(22);
735 1 ▶ if (!A->reader_feed(r, FRX_SELFTEST_FULL, sizeof FRX_SELFTEST_FULL - 1, 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!A->reader_feed(r, FRX_SELFTEST_FULL, sizeof FRX_SELFTEST_FULL - 1, 1)) { 0 1 1
736 0 A->reader_free(r);
737 0 goto fail;
738 }
739 12 ▶ while ((kind = A->reader_next(r)) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
while ((kind = A->reader_next(r)) >= 0) { 11 1 12
740 11 ▶ if (kind == 0) break; /* wants bytes it will not get */
Branch: 1 branch
BranchTrueFalseTotal
if (kind == 0) break; /* wants bytes it will not get */ 0 11 11
741 11 ▶ if (kind == FRX_START) {
Branch: 1 branch
BranchTrueFalseTotal
if (kind == FRX_START) { 3 8 11
742 3 s = A->reader_str(r, FRX_R_LOCAL, &len);
743 3 ▶ if (len == 1 && s[0] == 'a') {
Branch: 2 branches
BranchTrueFalseTotal
if (len == 1 && s[0] == 'a') { 3 0 3
if (len == 1 && s[0] == 'a') { 1 2 3
744 1 saw_start = 1;
745 1 ▶ if (A->reader_int(r, FRX_R_KIND) != FRX_START) break;
Branch: 1 branch
BranchTrueFalseTotal
if (A->reader_int(r, FRX_R_KIND) != FRX_START) break; 0 1 1
746 1 ▶ if (A->reader_int(r, FRX_R_DEPTH) != 2) break;
Branch: 1 branch
BranchTrueFalseTotal
if (A->reader_int(r, FRX_R_DEPTH) != 2) break; 0 1 1
747 1 ▶ if (A->reader_int(r, FRX_R_EMPTY)) break;
Branch: 1 branch
BranchTrueFalseTotal
if (A->reader_int(r, FRX_R_EMPTY)) break; 0 1 1
748 1 ▶ if (A->reader_attr_count(r) != 1) break;
Branch: 1 branch
BranchTrueFalseTotal
if (A->reader_attr_count(r) != 1) break; 0 1 1
749 {
750 const char *ans, *al, *av;
751 STRLEN anl, all, avl;
752 1 A->reader_attr(r, 0, &ans, &anl, &al, &all, &av, &avl);
753 1 ▶ if (all != 2 || memcmp(al, "id", 2) || avl != 2 || memcmp(av, "a1", 2)) break;
Branch: 4 branches
BranchTrueFalseTotal
if (all != 2 || memcmp(al, "id", 2) || avl != 2 || memcmp(av, "a1", 2)) break; 1 0 1
if (all != 2 || memcmp(al, "id", 2) || avl != 2 || memcmp(av, "a1", 2)) break; 1 0 1
if (all != 2 || memcmp(al, "id", 2) || avl != 2 || memcmp(av, "a1", 2)) break; 1 0 1
if (all != 2 || memcmp(al, "id", 2) || avl != 2 || memcmp(av, "a1", 2)) break; 1 0 1
754 }
755 1 ▶ if (!A->reader_offset(r)) break;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->reader_offset(r)) break; 0 1 1
756 1 saw_start = 2;
757 }
758 8 ▶ } else if (kind == FRX_TEXT) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (kind == FRX_TEXT) { 4 4 8
759 4 s = A->reader_str(r, FRX_R_VALUE, &len);
760 4 ▶ if (len == 2 && memcmp(s, "<&", 2) == 0) saw_cdata = 1;
Branch: 2 branches
BranchTrueFalseTotal
if (len == 2 && memcmp(s, "<&", 2) == 0) saw_cdata = 1; 2 2 4
if (len == 2 && memcmp(s, "<&", 2) == 0) saw_cdata = 1; 1 1 2
761 }
762 }
763 1 FRX_STEP(23);
764 1 ▶ if (saw_start != 2) { A->reader_free(r); goto fail; }
Branch: 1 branch
BranchTrueFalseTotal
if (saw_start != 2) { A->reader_free(r); goto fail; } 0 1 1
765 1 FRX_STEP(24);
766 1 ▶ if (!saw_cdata) { A->reader_free(r); goto fail; }
Branch: 1 branch
BranchTrueFalseTotal
if (!saw_cdata) { A->reader_free(r); goto fail; } 0 1 1
767 1 FRX_STEP(25);
768 1 ▶ if (!A->reader_int(r, FRX_R_DONE)) { A->reader_free(r); goto fail; }
Branch: 1 branch
BranchTrueFalseTotal
if (!A->reader_int(r, FRX_R_DONE)) { A->reader_free(r); goto fail; } 0 1 1
769 1 FRX_STEP(26);
770 1 ▶ if (A->reader_error(r) == NULL) { A->reader_free(r); goto fail; }
Branch: 1 branch
BranchTrueFalseTotal
if (A->reader_error(r) == NULL) { A->reader_free(r); goto fail; } 0 1 1
771 1 A->reader_free(r);
772 }
773  
774 /* the reader again, this time cutting one element out as a document */
775 {
776 1 frx_reader *r = A->reader_new(&oe);
777 1 frx_doc *sub = NULL;
778 int kind;
779 1 FRX_STEP(27);
780 1 ▶ if (!r) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) goto fail; 0 1 1
781 1 (void)A->reader_feed(r, FRX_SELFTEST_FULL, sizeof FRX_SELFTEST_FULL - 1, 1);
782 3 ▶ while ((kind = A->reader_next(r)) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
while ((kind = A->reader_next(r)) > 0) { 3 0 3
783 3 ▶ if (kind != FRX_START) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (kind != FRX_START) continue; 1 2 3
784 2 s = A->reader_str(r, FRX_R_LOCAL, &len);
785 2 ▶ if (len == 1 && s[0] == 'a') { sub = A->reader_subtree(r); break; }
Branch: 2 branches
BranchTrueFalseTotal
if (len == 1 && s[0] == 'a') { sub = A->reader_subtree(r); break; } 2 0 2
if (len == 1 && s[0] == 'a') { sub = A->reader_subtree(r); break; } 1 1 2
786 }
787 1 FRX_STEP(28);
788 1 ▶ if (!sub) { A->reader_free(r); goto fail; }
Branch: 1 branch
BranchTrueFalseTotal
if (!sub) { A->reader_free(r); goto fail; } 0 1 1
789 1 FRX_STEP(29);
790 1 s = A->local(A->root(sub), &len);
791 1 ▶ if (len != 1 || s[0] != 'a') { A->doc_free(aTHX_ sub); A->reader_free(r); goto fail; }
Branch: 2 branches
BranchTrueFalseTotal
if (len != 1 || s[0] != 'a') { A->doc_free(aTHX_ sub); A->reader_free(r); goto fail; } 1 0 1
if (len != 1 || s[0] != 'a') { A->doc_free(aTHX_ sub); A->reader_free(r); goto fail; } 0 1 1
792 1 A->doc_free(aTHX_ sub);
793 1 A->reader_free(r);
794 }
795  
796 /* the mutable tree, built from nothing and then taken apart */
797 1 FRX_STEP(30);
798 1 built = A->new_document(0);
799 1 ▶ if (!built) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!built) goto fail; 0 1 1
800 1 FRX_STEP(31);
801 1 el = A->new_element(built, "urn:x", 5, "p", 1, "top", 3, &err);
802 1 ▶ if (!el) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!el) goto fail; 0 1 1
803 1 FRX_STEP(32);
804 1 ▶ if (!A->append_child(built, (frx_node *)A->document(built), el, &err)) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->append_child(built, (frx_node *)A->document(built), el, &err)) goto fail; 0 1 1
805 1 FRX_STEP(33);
806 1 ▶ if (!A->set_attr(built, el, "", 0, "", 0, "k", 1, "v", 1, &err)) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->set_attr(built, el, "", 0, "", 0, "k", 1, "v", 1, &err)) goto fail; 0 1 1
807 1 FRX_STEP(34);
808 1 s = A->attr_value(el, "", "k", &len);
809 1 ▶ if (!s || len != 1 || s[0] != 'v') goto fail;
Branch: 3 branches
BranchTrueFalseTotal
if (!s || len != 1 || s[0] != 'v') goto fail; 1 0 1
if (!s || len != 1 || s[0] != 'v') goto fail; 1 0 1
if (!s || len != 1 || s[0] != 'v') goto fail; 0 1 1
810 1 FRX_STEP(35);
811 1 tx = A->new_text(built, "hi", 2, &err);
812 1 ▶ if (!tx || !A->append_child(built, el, tx, &err)) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (!tx || !A->append_child(built, el, tx, &err)) goto fail; 1 0 1
if (!tx || !A->append_child(built, el, tx, &err)) goto fail; 0 1 1
813 1 FRX_STEP(36);
814 {
815 1 frx_node *c = A->new_comment(built, " c ", 3, &err);
816 1 frx_node *pi = A->new_pi(built, "t", 1, "d", 1, &err);
817 1 ▶ if (!c || !pi) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (!c || !pi) goto fail; 1 0 1
if (!c || !pi) goto fail; 0 1 1
818 1 ▶ if (!A->insert_before(built, tx, c, &err)) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->insert_before(built, tx, c, &err)) goto fail; 0 1 1
819 1 ▶ if (!A->append_child(built, el, pi, &err)) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->append_child(built, el, pi, &err)) goto fail; 0 1 1
820 }
821 1 FRX_STEP(37);
822 1 ▶ if (!A->declare_ns(built, el, "q", 1, "urn:q", 5, &err)) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->declare_ns(built, el, "q", 1, "urn:q", 5, &err)) goto fail; 0 1 1
823 1 FRX_STEP(38);
824 1 ▶ if (!A->set_name(built, el, "urn:x", 5, "p", 1, "renamed", 7, &err)) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->set_name(built, el, "urn:x", 5, "p", 1, "renamed", 7, &err)) goto fail; 0 1 1
825 1 FRX_STEP(39);
826 1 s = A->local(el, &len);
827 1 ▶ if (len != 7 || memcmp(s, "renamed", 7)) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (len != 7 || memcmp(s, "renamed", 7)) goto fail; 1 0 1
if (len != 7 || memcmp(s, "renamed", 7)) goto fail; 0 1 1
828 1 FRX_STEP(40);
829 1 ▶ if (!A->set_text(built, tx, "bye", 3, &err)) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->set_text(built, tx, "bye", 3, &err)) goto fail; 0 1 1
830 1 FRX_STEP(41);
831 1 ▶ if (!A->remove_attr(built, el, "", 0, "k", 1, &err)) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->remove_attr(built, el, "", 0, "k", 1, &err)) goto fail; 0 1 1
832 1 FRX_STEP(42);
833 1 ▶ if (A->attr_value(el, "", "k", &len) != NULL) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (A->attr_value(el, "", "k", &len) != NULL) goto fail; 0 1 1
834 1 FRX_STEP(43);
835 {
836 1 frx_node *copy = A->import_node(built, A->find(A->root(d), NULL, "a", NULL), &err);
837 1 ▶ if (!copy) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!copy) goto fail; 0 1 1
838 1 ▶ if (!A->append_child(built, el, copy, &err)) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->append_child(built, el, copy, &err)) goto fail; 0 1 1
839 1 ▶ if (!A->remove_node(built, copy, &err)) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->remove_node(built, copy, &err)) goto fail; 0 1 1
840 }
841 1 FRX_STEP(44);
842 /* a refusal leaves the tree alone and fills err */
843 1 ▶ if (A->new_element(built, NULL, 0, "", 0, "1bad", 4, &err) != NULL) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (A->new_element(built, NULL, 0, "", 0, "1bad", 4, &err) != NULL) goto fail; 0 1 1
844 1 FRX_STEP(45);
845 1 ▶ if (err.code == FRX_OK || !err.what) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (err.code == FRX_OK || !err.what) goto fail; 1 0 1
if (err.code == FRX_OK || !err.what) goto fail; 0 1 1
846  
847 /* XPath, compiled once and evaluated against two documents */
848 {
849 frx_ns_binding b;
850 frx_ns_map map;
851 frx_xpath *x;
852 frx_xp_result *res;
853 1 const char *xerr = NULL;
854 1 STRLEN xat = 0;
855  
856 1 b.prefix = "p"; b.uri = "urn:x";
857 1 map.v = &b; map.n = 1;
858  
859 1 FRX_STEP(46);
860 1 x = A->xpath_compile("count(//p:renamed)", 18, &map, 0, &xerr, &xat);
861 1 ▶ if (!x) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!x) goto fail; 0 1 1
862 1 FRX_STEP(47);
863 1 res = A->xpath_result_new();
864 1 ▶ if (!res) { A->xpath_free(x); goto fail; }
Branch: 1 branch
BranchTrueFalseTotal
if (!res) { A->xpath_free(x); goto fail; } 0 1 1
865 1 FRX_STEP(48);
866 1 ▶ if (!A->xpath_eval(x, built, A->document(built), res, &xerr)) goto fail_x;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->xpath_eval(x, built, A->document(built), res, &xerr)) goto fail_x; 0 1 1
867 1 FRX_STEP(49);
868 1 ▶ if (A->xpath_result_kind(res) != FRX_XP_NUMBER) goto fail_x;
Branch: 1 branch
BranchTrueFalseTotal
if (A->xpath_result_kind(res) != FRX_XP_NUMBER) goto fail_x; 0 1 1
869 1 FRX_STEP(50);
870 1 ▶ if (A->xpath_result_number(res) != 1.0) goto fail_x;
Branch: 1 branch
BranchTrueFalseTotal
if (A->xpath_result_number(res) != 1.0) goto fail_x; 0 1 1
871 1 A->xpath_result_free(res);
872 1 A->xpath_free(x);
873  
874 1 FRX_STEP(51);
875 1 x = A->xpath_compile("//a/@id", 7, NULL, 0, &xerr, &xat);
876 1 ▶ if (!x) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!x) goto fail; 0 1 1
877 1 res = A->xpath_result_new();
878 1 FRX_STEP(52);
879 1 ▶ if (!res || !A->xpath_eval(x, d, A->document(d), res, &xerr)) goto fail_x;
Branch: 2 branches
BranchTrueFalseTotal
if (!res || !A->xpath_eval(x, d, A->document(d), res, &xerr)) goto fail_x; 1 0 1
if (!res || !A->xpath_eval(x, d, A->document(d), res, &xerr)) goto fail_x; 0 1 1
880 1 FRX_STEP(53);
881 1 ▶ if (A->xpath_result_kind(res) != FRX_XP_NODESET) goto fail_x;
Branch: 1 branch
BranchTrueFalseTotal
if (A->xpath_result_kind(res) != FRX_XP_NODESET) goto fail_x; 0 1 1
882 1 FRX_STEP(54);
883 1 ▶ if (A->xpath_result_count(res) != 1) goto fail_x;
Branch: 1 branch
BranchTrueFalseTotal
if (A->xpath_result_count(res) != 1) goto fail_x; 0 1 1
884 1 FRX_STEP(55);
885 {
886 1 int kind = -1, index = -1;
887 1 n = A->xpath_result_node(res, 0, &kind, &index);
888 1 ▶ if (!n || kind != FRX_XP_KATTR || index != 0) goto fail_x;
Branch: 3 branches
BranchTrueFalseTotal
if (!n || kind != FRX_XP_KATTR || index != 0) goto fail_x; 1 0 1
if (!n || kind != FRX_XP_KATTR || index != 0) goto fail_x; 1 0 1
if (!n || kind != FRX_XP_KATTR || index != 0) goto fail_x; 0 1 1
889 1 A->attr(n, index, NULL, NULL, &s, &len, NULL, NULL);
890 1 ▶ if (len != 2 || memcmp(s, "id", 2)) goto fail_x;
Branch: 2 branches
BranchTrueFalseTotal
if (len != 2 || memcmp(s, "id", 2)) goto fail_x; 1 0 1
if (len != 2 || memcmp(s, "id", 2)) goto fail_x; 0 1 1
891 }
892 1 FRX_STEP(56);
893 1 ▶ if (A->xpath_result_node(res, 1, NULL, NULL) != NULL) goto fail_x;
Branch: 1 branch
BranchTrueFalseTotal
if (A->xpath_result_node(res, 1, NULL, NULL) != NULL) goto fail_x; 0 1 1
894 1 A->xpath_result_free(res);
895 1 A->xpath_free(x);
896  
897 /* a variable, and an unmapped prefix as a compile refusal */
898 1 FRX_STEP(57);
899 1 x = A->xpath_compile("string($v)", 10, NULL, 0, &xerr, &xat);
900 1 ▶ if (!x) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!x) goto fail; 0 1 1
901 1 FRX_STEP(58);
902 1 ▶ if (A->xpath_var_count(x) != 1) { A->xpath_free(x); goto fail; }
Branch: 1 branch
BranchTrueFalseTotal
if (A->xpath_var_count(x) != 1) { A->xpath_free(x); goto fail; } 0 1 1
903 1 FRX_STEP(59);
904 1 s = A->xpath_var_name(x, 0, &len);
905 1 ▶ if (len != 1 || s[0] != 'v') { A->xpath_free(x); goto fail; }
Branch: 2 branches
BranchTrueFalseTotal
if (len != 1 || s[0] != 'v') { A->xpath_free(x); goto fail; } 1 0 1
if (len != 1 || s[0] != 'v') { A->xpath_free(x); goto fail; } 0 1 1
906 1 FRX_STEP(60);
907 1 ▶ if (!A->xpath_bind_str(x, 0, "bound", 5)) { A->xpath_free(x); goto fail; }
Branch: 1 branch
BranchTrueFalseTotal
if (!A->xpath_bind_str(x, 0, "bound", 5)) { A->xpath_free(x); goto fail; } 0 1 1
908 1 res = A->xpath_result_new();
909 1 FRX_STEP(61);
910 1 ▶ if (!res || !A->xpath_eval(x, d, A->document(d), res, &xerr)) goto fail_x;
Branch: 2 branches
BranchTrueFalseTotal
if (!res || !A->xpath_eval(x, d, A->document(d), res, &xerr)) goto fail_x; 1 0 1
if (!res || !A->xpath_eval(x, d, A->document(d), res, &xerr)) goto fail_x; 0 1 1
911 1 FRX_STEP(62);
912 1 s = A->xpath_result_string(res, &len);
913 1 ▶ if (len != 5 || memcmp(s, "bound", 5)) goto fail_x;
Branch: 2 branches
BranchTrueFalseTotal
if (len != 5 || memcmp(s, "bound", 5)) goto fail_x; 1 0 1
if (len != 5 || memcmp(s, "bound", 5)) goto fail_x; 0 1 1
914 1 A->xpath_result_free(res);
915 1 A->xpath_free(x);
916  
917 /* the other two bindings, over one expression that reads both */
918 1 FRX_STEP(63);
919 1 x = A->xpath_compile("$n + 1 = 2 and $b", 17, NULL, 0, &xerr, &xat);
920 1 ▶ if (!x) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (!x) goto fail; 0 1 1
921 1 FRX_STEP(64);
922 1 ▶ if (A->xpath_var_count(x) != 2) { A->xpath_free(x); goto fail; }
Branch: 1 branch
BranchTrueFalseTotal
if (A->xpath_var_count(x) != 2) { A->xpath_free(x); goto fail; } 0 1 1
923 1 A->xpath_bind_num(x, 0, 1.0);
924 1 A->xpath_bind_bool(x, 1, 1);
925 1 res = A->xpath_result_new();
926 1 FRX_STEP(65);
927 1 ▶ if (!res || !A->xpath_eval(x, d, A->document(d), res, &xerr)) goto fail_x;
Branch: 2 branches
BranchTrueFalseTotal
if (!res || !A->xpath_eval(x, d, A->document(d), res, &xerr)) goto fail_x; 1 0 1
if (!res || !A->xpath_eval(x, d, A->document(d), res, &xerr)) goto fail_x; 0 1 1
928 1 FRX_STEP(66);
929 1 ▶ if (A->xpath_result_kind(res) != FRX_XP_BOOLEAN) goto fail_x;
Branch: 1 branch
BranchTrueFalseTotal
if (A->xpath_result_kind(res) != FRX_XP_BOOLEAN) goto fail_x; 0 1 1
930 1 A->xpath_result_free(res);
931 1 A->xpath_free(x);
932 1 goto compiled;
933 0 fail_x:
934 0 ▶ if (res) A->xpath_result_free(res);
Branch: 1 branch
BranchTrueFalseTotal
if (res) A->xpath_result_free(res); 0 0 0
935 0 A->xpath_free(x);
936 0 goto fail;
937 1 compiled:
938 /* an unmapped prefix is a compile refusal with an offset */
939 1 FRX_STEP(67);
940 1 ▶ if (A->xpath_compile("//q:e", 5, NULL, 0, &xerr, &xat) != NULL) goto fail;
Branch: 1 branch
BranchTrueFalseTotal
if (A->xpath_compile("//q:e", 5, NULL, 0, &xerr, &xat) != NULL) goto fail; 0 1 1
941 1 FRX_STEP(68);
942 1 ▶ if (!xerr || !xat) goto fail;
Branch: 2 branches
BranchTrueFalseTotal
if (!xerr || !xat) goto fail; 1 0 1
if (!xerr || !xat) goto fail; 0 1 1
943 }
944  
945 1 A->doc_free(aTHX_ built);
946 1 A->doc_free(aTHX_ d);
947 1 return 0;
948  
949 0 fail:
950 0 ▶ if (out) SvREFCNT_dec(out);
Branch: 1 branch
BranchTrueFalseTotal
if (out) SvREFCNT_dec(out); 0 0 0
951 0 ▶ if (d2) A->doc_free(aTHX_ d2);
Branch: 1 branch
BranchTrueFalseTotal
if (d2) A->doc_free(aTHX_ d2); 0 0 0
952 0 ▶ if (built) A->doc_free(aTHX_ built);
Branch: 1 branch
BranchTrueFalseTotal
if (built) A->doc_free(aTHX_ built); 0 0 0
953 0 ▶ if (d) A->doc_free(aTHX_ d);
Branch: 1 branch
BranchTrueFalseTotal
if (d) A->doc_free(aTHX_ d); 0 0 0
954 0 return step;
955 }
956  
957 #endif /* FRX_ABI_IMPL_H */
« xs/abi.xs ↑ Summary xs/reader.xs »