include/frx/frx_abi_impl.h

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