leptris 1.9.412.0-aarch64-linux → 1.9.412.1-aarch64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/leptris/version.rb +1 -1
- data/lib/libleptris.so +0 -0
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +12 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/TODO.max-perf/15-c-face-vs-pugixml.md +57 -23
- data/vendor-src/libleptris/src/leptris/leptris_internal.h +7 -0
- data/vendor-src/libleptris/src/leptris/xpath/bytecode.h +3 -0
- data/vendor-src/libleptris/src/leptris/xpath/compiler.c +83 -0
- data/vendor-src/libleptris/src/leptris/xpath/evaluator_internal.h +5 -0
- data/vendor-src/libleptris/src/leptris/xpath/evaluator_path.c +18 -3
- data/vendor-src/libleptris/src/leptris/xpath/parser.c +12 -0
- data/vendor-src/libleptris/src/leptris/xpath/vm.c +210 -0
- data/vendor-src/libleptris/test/xpath/test_bytecode_vm.cpp +147 -0
- data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +72 -0
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 26683648ba0323846c47d44da9ab84c298b00a93bacc029769a2b08986c3706d
|
|
4
|
+
data.tar.gz: 76687021d38e547fcc5851839ce9cec7d4c132e096ffe5e0968e7e5d34cd56c9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 75b6460f8bfd1d4cdedb40ec12a2ff4c3063662d59bf7acf53cb754cba88269d32b18651f32b0c2c9a40f62766059460441acdabf79a2e0928e8d513c7474f39
|
|
7
|
+
data.tar.gz: 51bca24d151d29b11a759cf32b6ffccd885db3fb1f71bb10a481a6819bd9805d497a5567f2d2b96cdcd931d76c4b4249076a91d023fd0d1def60bab722abe507
|
data/Rakefile
CHANGED
|
@@ -8,7 +8,7 @@ RSpec::Core::RakeTask.new(:spec)
|
|
|
8
8
|
# Pin for `rake compile` and the platform-gem builds. Keep in lockstep
|
|
9
9
|
# with .github/workflows/build.yml (which calls `rake compile`) and the
|
|
10
10
|
# CHANGELOG when libleptris releases.
|
|
11
|
-
LIBLEPTRIS_VERSION = "1.9.
|
|
11
|
+
LIBLEPTRIS_VERSION = "1.9.412"
|
|
12
12
|
# Vendored alongside libleptris for fn:normalize-unicode (TODO
|
|
13
13
|
# .restructure/20): built per platform with a RELOCATABLE @rpath
|
|
14
14
|
# install name, loaded by ffi.rb before libleptris so the
|
data/lib/leptris/version.rb
CHANGED
data/lib/libleptris.so
CHANGED
|
Binary file
|
data/vendor-src/README.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## Changed
|
|
4
|
+
|
|
5
|
+
- **XPath: `//a | //b` fuses to one doc-ordered pass** (#1842 Track C lever 2). The scoreboard's first XPath query shape (serialbench-c bench.c:104) compiled to two fused descendant walks plus the generic union operator — per-eval concatenation then an O(n log n) doc-order sort. Both bare plain-name descendant branches now compile to one `XPATH_BC_ABSOLUTE_UNION_NAMES` opcode: one combined pre-order walk when the element index is not yet built, an O(n+m) two-pointer merge over the parse-offset keys once it is, and a single bucket copy for same-name unions. Wildcards, prefixed names, predicates, and deep branches stay on the generic path. Measured (ABBA x6, fresh RelWithDebInfo+LTO builds, serialbench medium.xml): union-only shape +8.5%, full scoreboard row (parse + 3 canonical queries) **888 → 945 ops/s (+6.4%)**, all pairs positive. Seven new `XPathUnionFusion` pins, including the interleaved-layout document-order trap a branch-concatenation would get wrong.
|
|
6
|
+
|
|
7
|
+
- **XPath: node-test hash pre-filter shipped write-once** (#1842 Track C lever 1, #1986). `matches_node_test` rejects candidates on the element's stored `name_hash` before the strcmp; the AST node's hash is computed at parser construction (compiled ASTs are thread-shared across concurrent evals — the lazy cache was a TSan data race and `ast_node_new` initializes every field explicitly after gcc read garbage where clang zeroed). 1.011x on the parse+query mix.
|
|
8
|
+
|
|
9
|
+
## Tests
|
|
10
|
+
|
|
11
|
+
- schG2 through every three-unit `compile_set` order (#1979 coverage): the lutaml-xsd hints lane delivers the resolved units in any order — all six permutations pinned to the W3C oracle (valid). #1979 itself was answered by v1.9.410's resolved-lane spec; this closes the ordering gap so merged-table order can never flip the verdict again.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
3
15
|
## [1.9.411] - 2026-11-06
|
|
4
16
|
|
|
5
17
|
### Performance
|
|
@@ -20,11 +20,17 @@ validation 2.8% | elem_pos journal ~2.5%.
|
|
|
20
20
|
- [ ] **A2** fold the UTF-8 validation into the count3 pass
|
|
21
21
|
(`count3_high`: ASCII => valid; high bytes => the existing
|
|
22
22
|
DFA). Saves one full memory pass (~2.8%).
|
|
23
|
-
- [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
- [x] **A3** FALSIFIED (2026-11-06, reverted). The audit passed
|
|
24
|
+
(only `dp_nul` writes the input — 8 sites; CR/entity paths
|
|
25
|
+
write the pool) and the implementation (drop the pristine
|
|
26
|
+
carve, xml_buffer = scratch for const inputs) passed the full
|
|
27
|
+
suite, but the A/B measured 0.985-1.001 (neutral to slightly
|
|
28
|
+
negative against the predicted +2-3%): the pristine memcpy was
|
|
29
|
+
arena-bump and overlapped the caller-side copy on the cache
|
|
30
|
+
pipeline — lane-18 round 8 had already banked the win. The
|
|
31
|
+
write inventory stands; xml_buffer's only readers are the
|
|
32
|
+
lazy line table (newline offsets — NUL placements never move
|
|
33
|
+
a newline) and the free path.
|
|
28
34
|
- [ ] **A4** (sprint 2, the actual gap) scanner-loop surgery in
|
|
29
35
|
`direct_parse_internal`: per-tag branch layout, edge-encode
|
|
30
36
|
elimination on the hot path, NUL-write discipline audit.
|
|
@@ -53,24 +59,52 @@ whole tree to assign ranks (#485 table).
|
|
|
53
59
|
- [x] **C1** exact-ops profile (scratch_sb_repro vs serialbench-c
|
|
54
60
|
bench.c BENCH bodies; fixture = serialbench/fixtures
|
|
55
61
|
medium.xml).
|
|
56
|
-
- [
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
the
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
- [x] **C2** offset fast path LANDED (evaluator_path.c:
|
|
63
|
+
doc_order_offset_key + the mutation_version==0 gate with the
|
|
64
|
+
LEPTRIS_SORT_SLOW escape) — the historical failures predated
|
|
65
|
+
the adjacent-dedup the fast path now carries ("Same contract
|
|
66
|
+
here"). VERIFIED 2026-11-06: the historical repro (kSubtree,
|
|
67
|
+
//item then //section//item) is clean on the current tree; the
|
|
68
|
+
full xpath suite 104/104; suite 2241/2241. MEASURED: perf
|
|
69
|
+
NEUTRAL on both the 80 KB driver fixture and the canonical
|
|
70
|
+
serialbench medium.xml (306 KB) — fast 188 vs slow 187 median
|
|
71
|
+
ops/s. C0's sample attribution over-weighted the rank-table
|
|
72
|
+
build; the build is not a bottleneck the offsets can remove.
|
|
73
|
+
The xpath 3.48x gap therefore lives in the eval/axis layer,
|
|
74
|
+
not the sort.
|
|
75
|
+
**Track C lever 1 SHIPPED** (perf/1842-node-test-hash): the
|
|
76
|
+
line-level profile of the eval layer named node-test strcmp
|
|
77
|
+
(~65 samples) — matches_node_test now pre-filters candidates
|
|
78
|
+
on elem->name_hash (the AST node caches the test's local-name
|
|
79
|
+
hash lazily; the strcmp remains as the collision guard).
|
|
80
|
+
ABBA x6 median 1.011x on parse+3-query mix, all pairs
|
|
81
|
+
positive, suite 2241/2241.
|
|
82
|
+
**RE-SCOPED 2026-11-07**: the sample inventory above was
|
|
83
|
+
measured on a synthetic `[@stock > '50']` shape that
|
|
84
|
+
classify_predicate does NOT cover — the SCOREBOARD set
|
|
85
|
+
(serialbench-c bench.c:104: `//user | //record`,
|
|
86
|
+
`//user[@id='101']`, `//preferences/theme`) is fully VM-fused
|
|
87
|
+
already; the interpreter is absent from the row. Measured
|
|
88
|
+
shares (RelWithDebInfo+LTO, fresh-doc driver): parse 56.9%,
|
|
89
|
+
union 20.1%, theme 12.4%, attreq 10.7%. The apply_axis/
|
|
90
|
+
step-dispatch levers are de-prioritized (they only pay on
|
|
91
|
+
non-fused shapes).
|
|
92
|
+
**Track C lever 2 SHIPPED** (perf/1842-union-fusion, PR
|
|
93
|
+
#1987): `//a | //b` fuses to ONE doc-ordered pass —
|
|
94
|
+
XPATH_BC_ABSOLUTE_UNION_NAMES. Compiler gate = both branches
|
|
95
|
+
bare plain-name descendant shapes (second step arrives
|
|
96
|
+
RELATIVE_PATH-wrapped — same duality compile_absolute_path
|
|
97
|
+
unwraps). VM: index up = O(n+m) two-pointer merge on the
|
|
98
|
+
parse-offset keys (xpath_doc_order_offset_key exported);
|
|
99
|
+
index not yet built (first query per doc) = one combined
|
|
100
|
+
pre-order walk matching either name; same-name unions =
|
|
101
|
+
one bucket copy. ABBA x6, serialbench medium.xml: union-only
|
|
102
|
+
1255 vs 1156 ops/s (+8.5%), full scoreboard row 945 vs 888
|
|
103
|
+
(+6.4%), all pairs positive, suite 2248/2248 (7 new
|
|
104
|
+
XPathUnionFusion pins incl. the interleaved doc-order trap).
|
|
105
|
+
Next: A4 (parse, 56.9% of the row) remains the other live
|
|
106
|
+
arc; the attr-num-cmp predicate family ([@a > '50']) is a
|
|
107
|
+
real-world fallback shape but NOT on the scoreboard row.
|
|
74
108
|
- [ ] **C3** mingw/Windows parity investigation: we are AT parity
|
|
75
109
|
there — diff the codegen assumptions (branch-heavy loops?
|
|
76
110
|
LTO behavior on gcc-win vs clang-mac?) and port whatever
|
|
@@ -649,6 +649,13 @@ typedef struct xpath_ast_node {
|
|
|
649
649
|
* to skip the strcmp dispatch chain in apply_axis. Defaults to
|
|
650
650
|
* XPATH_AXIS_CHILD (the default axis per XPath spec). */
|
|
651
651
|
XPathAxisType axis_id;
|
|
652
|
+
|
|
653
|
+
/* #1842 Track C: lazily cached 16-bit FNV-1a of local_name
|
|
654
|
+
* (leptris_name_hash_compute) — matches_node_test pre-filters
|
|
655
|
+
* candidates on elem->name_hash before the strcmp. local_hash_set
|
|
656
|
+
* guards the lazy init (0 until first use). */
|
|
657
|
+
uint16_t local_hash;
|
|
658
|
+
uint8_t local_hash_set;
|
|
652
659
|
} XPathASTNode;
|
|
653
660
|
|
|
654
661
|
/* XPath parser - Matches ext/leptris/xpath.h _xpath_parser */
|
|
@@ -129,6 +129,9 @@ typedef enum {
|
|
|
129
129
|
XPATH_BC_ABSOLUTE_DESCENDANT_TYPE, /* u16 u16: type name (node/text/
|
|
130
130
|
comment/processing-instruction),
|
|
131
131
|
PI target (0xFFFF = any) */
|
|
132
|
+
XPATH_BC_ABSOLUTE_UNION_NAMES, /* u16 u16: two plain names — one
|
|
133
|
+
merged doc-ordered match of
|
|
134
|
+
`//a | //b` (#1842 Track C) */
|
|
132
135
|
|
|
133
136
|
/* Inline function opcodes (TODO 130). The compiler emits
|
|
134
137
|
* <arg bytecode> + BC_FUNC_<NAME> for the common XPath functions
|
|
@@ -331,6 +331,67 @@ static int op_is_comparison(XPathOperatorType op) {
|
|
|
331
331
|
op == XPATH_OP_GREATER || op == XPATH_OP_GREATER_EQUAL;
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
+
/* #1842 Track C lever 2: is this union branch a bare `//name`?
|
|
335
|
+
* ABSOLUTE_PATH whose whole body is descendant-or-self::node() (or
|
|
336
|
+
* ::*) followed by ONE unprefixed child-name step, no predicates,
|
|
337
|
+
* no further steps. On match, *out is the branch name. Mirrors the
|
|
338
|
+
* first-step unwrapping in compile_absolute_path. */
|
|
339
|
+
static int union_branch_plain_name(XPathASTNode* ast, const char** out) {
|
|
340
|
+
*out = NULL;
|
|
341
|
+
if (!ast || ast->type != XPATH_AST_ABSOLUTE_PATH) return 0;
|
|
342
|
+
|
|
343
|
+
XPathASTNode* steps[2] = {NULL, NULL};
|
|
344
|
+
size_t step_count = 0;
|
|
345
|
+
if (ast->child_count >= 1 &&
|
|
346
|
+
ast->children[0]->type == XPATH_AST_RELATIVE_PATH) {
|
|
347
|
+
const XPathASTNode* rp = ast->children[0];
|
|
348
|
+
if (rp->child_count >= 1) steps[0] = rp->children[0];
|
|
349
|
+
if (rp->child_count >= 2) steps[1] = rp->children[1];
|
|
350
|
+
step_count = rp->child_count;
|
|
351
|
+
} else {
|
|
352
|
+
if (ast->child_count >= 1) steps[0] = ast->children[0];
|
|
353
|
+
if (ast->child_count >= 2) {
|
|
354
|
+
/* The second child may be a STEP directly or a
|
|
355
|
+
* RELATIVE_PATH wrapping the remaining steps (the same
|
|
356
|
+
* duality compile_absolute_path unwraps). */
|
|
357
|
+
if (ast->children[1]->type == XPATH_AST_RELATIVE_PATH) {
|
|
358
|
+
if (ast->children[1]->child_count >= 1)
|
|
359
|
+
steps[1] = ast->children[1]->children[0];
|
|
360
|
+
step_count = 1 + ast->children[1]->child_count;
|
|
361
|
+
} else {
|
|
362
|
+
steps[1] = ast->children[1];
|
|
363
|
+
step_count = ast->child_count;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
step_count = ast->child_count >= 2 ? step_count : ast->child_count;
|
|
367
|
+
}
|
|
368
|
+
if (step_count != 2 || !steps[0] || !steps[1]) return 0;
|
|
369
|
+
if (steps[0]->type != XPATH_AST_STEP || steps[1]->type != XPATH_AST_STEP)
|
|
370
|
+
return 0;
|
|
371
|
+
|
|
372
|
+
/* descendant-or-self::node() or descendant-or-self::* */
|
|
373
|
+
if (steps[0]->axis_id != XPATH_AXIS_DESCENDANT_OR_SELF ||
|
|
374
|
+
steps[0]->child_count != 1)
|
|
375
|
+
return 0;
|
|
376
|
+
const XPathASTNode* ds = steps[0]->children[0];
|
|
377
|
+
int ds_node = (ds && ds->type == XPATH_AST_NODE_TEST_TYPE && ds->value &&
|
|
378
|
+
strcmp(ds->value, "node") == 0);
|
|
379
|
+
int ds_wild = (ds && ds->type == XPATH_AST_NODE_TEST_ALL && !ds->prefix);
|
|
380
|
+
if (!ds_node && !ds_wild) return 0;
|
|
381
|
+
|
|
382
|
+
/* child::name — unprefixed, no predicates */
|
|
383
|
+
if (steps[1]->axis_id != XPATH_AXIS_CHILD ||
|
|
384
|
+
steps[1]->child_count != 1)
|
|
385
|
+
return 0;
|
|
386
|
+
const XPathASTNode* ct = steps[1]->children[0];
|
|
387
|
+
if (!ct || ct->type != XPATH_AST_NODE_TEST_NAME || !ct->value ||
|
|
388
|
+
strchr(ct->value, ':'))
|
|
389
|
+
return 0;
|
|
390
|
+
|
|
391
|
+
*out = ct->value;
|
|
392
|
+
return 1;
|
|
393
|
+
}
|
|
394
|
+
|
|
334
395
|
/* Try to lower a STEP AST to a specialized axis opcode (TODO 126).
|
|
335
396
|
* Returns 1 if emitted, 0 if the shape doesn't match a fast path
|
|
336
397
|
* and the caller should fall back to BC_AXIS_STEP.
|
|
@@ -1393,6 +1454,28 @@ static void compile_node(CompilerState* st, XPathASTNode* node) {
|
|
|
1393
1454
|
break;
|
|
1394
1455
|
}
|
|
1395
1456
|
|
|
1457
|
+
/* #1842 Track C lever 2: `//a | //b` with both branches
|
|
1458
|
+
* bare plain-name descendant shapes lowers to ONE opcode
|
|
1459
|
+
* whose handler merges the doc-ordered runs directly —
|
|
1460
|
+
* the generic path concatenates then doc-order-sorts per
|
|
1461
|
+
* eval. Wildcards, prefixed names, predicates, and deep
|
|
1462
|
+
* branches stay generic. */
|
|
1463
|
+
if (op == XPATH_OP_UNION && node->child_count == 2) {
|
|
1464
|
+
const char* ua = NULL;
|
|
1465
|
+
const char* ub = NULL;
|
|
1466
|
+
if (union_branch_plain_name(node->children[0], &ua) &&
|
|
1467
|
+
union_branch_plain_name(node->children[1], &ub)) {
|
|
1468
|
+
emit_op_u16(st, XPATH_BC_ABSOLUTE_UNION_NAMES,
|
|
1469
|
+
add_const_string(st, ua));
|
|
1470
|
+
if (reserve_code(st, 2) == 0) {
|
|
1471
|
+
uint16_t v = add_const_string(st, ub);
|
|
1472
|
+
st->bc->code[st->bc->code_len++] = (v >> 8) & 0xFF;
|
|
1473
|
+
st->bc->code[st->bc->code_len++] = v & 0xFF;
|
|
1474
|
+
}
|
|
1475
|
+
break;
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1396
1479
|
/* Comparison operators with a nodeset operand require
|
|
1397
1480
|
* XPath's any-pair semantics, which the inline VM handler
|
|
1398
1481
|
* does not implement. Fall back to evaluate_expr so the
|
|
@@ -64,6 +64,11 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
|
|
|
64
64
|
* Issue #485. Defined in evaluator_path.c. */
|
|
65
65
|
int xpath_nodeset_sort_doc_order(XPathContext* ctx, XPathNodeSet* ns,
|
|
66
66
|
int reverse);
|
|
67
|
+
/* #1842 Track C: parse-time byte-offset doc-order key — valid ONLY
|
|
68
|
+
* while the document is unmutated (mutation_version == 0). The
|
|
69
|
+
* fused union merge (vm.c) merges its two doc-ordered runs with it,
|
|
70
|
+
* no sort. Defined in evaluator_path.c. */
|
|
71
|
+
int xpath_doc_order_offset_key(void* node, uint64_t* out);
|
|
67
72
|
|
|
68
73
|
/* From evaluator_path.c */
|
|
69
74
|
struct leptris_xpath_result* evaluate_location_path(XPathContext* ctx,
|
|
@@ -149,6 +149,20 @@ int matches_node_test(XPathContext* ctx, LeptrisNode* node, XPathASTNode* test)
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
/* #1842 Track C: hash pre-filter — elem->name_hash is
|
|
153
|
+
* the 16-bit FNV-1a of the stored LOCAL name (parse-side
|
|
154
|
+
* dp_scan_name_fused / mutation-side
|
|
155
|
+
* leptris_name_hash_compute agree), and node_name IS the
|
|
156
|
+
* stored local name, so a hash mismatch rejects exactly.
|
|
157
|
+
* The hash is computed WRITE-ONCE at parser construction
|
|
158
|
+
* (the AST is thread-shared across concurrent evals —
|
|
159
|
+
* TSan caught the lazy-cache write). Tests constructed
|
|
160
|
+
* without a hash (PI targets, legacy paths) skip the
|
|
161
|
+
* filter; the strcmps below remain as the collision
|
|
162
|
+
* guard. */
|
|
163
|
+
if (test->local_hash_set &&
|
|
164
|
+
elem->name_hash != test->local_hash) return 0;
|
|
165
|
+
|
|
152
166
|
if (!test_prefix) {
|
|
153
167
|
/* Simple name match - no prefix in test */
|
|
154
168
|
/* Issue #525 (XPath 1.0 §2.3): an unprefixed test
|
|
@@ -605,8 +619,9 @@ void leptris_doc_order_index_free(void* table) {
|
|
|
605
619
|
* (issue #485: a per-call walk made union-heavy benchmark loops
|
|
606
620
|
* quadratic). */
|
|
607
621
|
/* Offset fast path (#1842 Track C2, EXPERIMENT): unmutated
|
|
608
|
-
* parse-created documents rank by parse-time byte offset.
|
|
609
|
-
|
|
622
|
+
* parse-created documents rank by parse-time byte offset.
|
|
623
|
+
* Exported for the fused union merge (vm.c — Track C lever 2). */
|
|
624
|
+
int xpath_doc_order_offset_key(void* node, uint64_t* out) {
|
|
610
625
|
int tag = (int)XPATH_NODE_TYPE(node);
|
|
611
626
|
if (tag == (int)LEPTRIS_NODE_TYPE_DOCUMENT) {
|
|
612
627
|
*out = (uint64_t)INT64_MAX -
|
|
@@ -649,7 +664,7 @@ int xpath_nodeset_sort_doc_order(XPathContext* ctx, XPathNodeSet* ns,
|
|
|
649
664
|
if (keys) {
|
|
650
665
|
int ok = 1;
|
|
651
666
|
for (size_t i = 0; i < n; i++) {
|
|
652
|
-
if (!
|
|
667
|
+
if (!xpath_doc_order_offset_key(ns->nodes[i], &keys[i])) {
|
|
653
668
|
ok = 0;
|
|
654
669
|
break;
|
|
655
670
|
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
#include "lexer.h"
|
|
10
10
|
#include "evaluator_internal.h" /* xpath_axis_from_name (TODO 113) */
|
|
11
11
|
#include "../leptris_internal.h"
|
|
12
|
+
#include "../dom/element.h" /* leptris_name_hash_compute (#1842 Track C) */
|
|
12
13
|
#include <string.h>
|
|
13
14
|
#include <stdlib.h>
|
|
14
15
|
#include <stdio.h>
|
|
@@ -164,6 +165,13 @@ static XPathASTNode* ast_node_new(XPathASTType type) {
|
|
|
164
165
|
node->prefix = NULL;
|
|
165
166
|
node->local_name = NULL;
|
|
166
167
|
|
|
168
|
+
/* #1842 Track C: the lazy node-test hash starts unset — the
|
|
169
|
+
* explicit init is load-bearing (this constructor sets fields
|
|
170
|
+
* individually, no memset; garbage local_hash_set rejected
|
|
171
|
+
* every name test on gcc/Linux CI). */
|
|
172
|
+
node->local_hash = 0;
|
|
173
|
+
node->local_hash_set = 0;
|
|
174
|
+
|
|
167
175
|
return node;
|
|
168
176
|
}
|
|
169
177
|
|
|
@@ -3715,6 +3723,8 @@ static XPathASTNode* parse_node_test(XPathParser* parser) {
|
|
|
3715
3723
|
node->prefix = NULL;
|
|
3716
3724
|
node->local_name = leptris_strdup(full_name);
|
|
3717
3725
|
}
|
|
3726
|
+
node->local_hash = leptris_name_hash_compute(node->local_name);
|
|
3727
|
+
node->local_hash_set = 1;
|
|
3718
3728
|
|
|
3719
3729
|
node->value = full_name; /* Keep full name for backward compat */
|
|
3720
3730
|
advance_token(parser);
|
|
@@ -3738,6 +3748,8 @@ static XPathASTNode* parse_node_test(XPathParser* parser) {
|
|
|
3738
3748
|
|
|
3739
3749
|
node->prefix = NULL;
|
|
3740
3750
|
node->local_name = leptris_strdup(name);
|
|
3751
|
+
node->local_hash = leptris_name_hash_compute(node->local_name);
|
|
3752
|
+
node->local_hash_set = 1;
|
|
3741
3753
|
node->value = name;
|
|
3742
3754
|
advance_token(parser);
|
|
3743
3755
|
|
|
@@ -492,6 +492,160 @@ static struct leptris_xpath_result* vm_apply_absolute(XPathContext* ctx,
|
|
|
492
492
|
return r;
|
|
493
493
|
}
|
|
494
494
|
|
|
495
|
+
static void descendant_walk_two_names(XPathContext* ctx, XPathNodeSet* out,
|
|
496
|
+
LeptrisElement elem,
|
|
497
|
+
const char* name_a, const char* name_b);
|
|
498
|
+
|
|
499
|
+
/* #1842 Track C lever 2: `//a | //b` fused union (compile gate: both
|
|
500
|
+
* branches are bare unprefixed descendant-name shapes). Each side is
|
|
501
|
+
* a doc-ordered run of elements — bucket memcpy when the element
|
|
502
|
+
* index is up, preorder walk otherwise — and the runs are DISJOINT
|
|
503
|
+
* (an element has one local name, no prefixes involved). The merge
|
|
504
|
+
* is an O(n+m) two-pointer over the parse-offset keys; the generic
|
|
505
|
+
* path concatenates then doc-order-sorts per eval. Same-name unions
|
|
506
|
+
* collapse to one run's copy when the index is up; mutated or
|
|
507
|
+
* synthetic-node documents fall back to concat + the generic sort
|
|
508
|
+
* (which also dedups, covering the same-name-no-index case). */
|
|
509
|
+
static struct leptris_xpath_result* vm_apply_absolute_union_names(
|
|
510
|
+
XPathContext* ctx, const char* name_a, const char* name_b) {
|
|
511
|
+
if (!ctx || !ctx->document) return NULL;
|
|
512
|
+
if (!name_a || !name_b) return NULL;
|
|
513
|
+
struct leptris_document* ctx_doc = xpath_context_document(ctx);
|
|
514
|
+
LeptrisElement root = (LeptrisElement)ctx_doc->new_dom_root;
|
|
515
|
+
if (!root) return NULL;
|
|
516
|
+
|
|
517
|
+
int same = strcmp(name_a, name_b) == 0;
|
|
518
|
+
struct leptris_element_index* idx = ctx_doc->element_index;
|
|
519
|
+
/* TODO 190 law: build on the SECOND axis query — the union
|
|
520
|
+
* participates in the same count as single-name queries. */
|
|
521
|
+
if (!idx &&
|
|
522
|
+
++ctx_doc->axis_query_count >= LEPTRIS_ELEMENT_INDEX_MIN_QUERIES) {
|
|
523
|
+
idx = leptris_element_index_build(ctx_doc);
|
|
524
|
+
ctx_doc->element_index = idx;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (!idx && !same) {
|
|
528
|
+
/* First axis query on this document: ONE combined pre-order
|
|
529
|
+
* walk matching either name. Two separate walks double the
|
|
530
|
+
* traversal; the generic path would additionally sort the
|
|
531
|
+
* concatenation. Emission order is document order by
|
|
532
|
+
* construction. */
|
|
533
|
+
XPathNodeSet* out = xpath_nodeset_new();
|
|
534
|
+
if (!out) return NULL;
|
|
535
|
+
if (vm_unprefixed_name_matches(ctx, root, name_a) ||
|
|
536
|
+
vm_unprefixed_name_matches(ctx, root, name_b))
|
|
537
|
+
xpath_nodeset_add_fast(out, root);
|
|
538
|
+
descendant_walk_two_names(ctx, out, root, name_a, name_b);
|
|
539
|
+
struct leptris_xpath_result* r =
|
|
540
|
+
xpath_result_new(XPATH_RESULT_NODESET);
|
|
541
|
+
if (!r) { xpath_nodeset_free(out); return NULL; }
|
|
542
|
+
r->value.nodeset_value = out;
|
|
543
|
+
return r;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
if (same && idx && !(ctx->document && ctx->document->has_namespaces)) {
|
|
547
|
+
/* One bucket copy IS the union. */
|
|
548
|
+
const LeptrisElementIndexBucket* b =
|
|
549
|
+
leptris_element_index_lookup(idx, name_a);
|
|
550
|
+
XPathNodeSet* out = xpath_nodeset_new();
|
|
551
|
+
if (!out) return NULL;
|
|
552
|
+
if (b && b->count > 0) {
|
|
553
|
+
void** arr = (void**)malloc(b->count * sizeof(void*));
|
|
554
|
+
if (arr) {
|
|
555
|
+
memcpy(arr, b->matches, b->count * sizeof(void*));
|
|
556
|
+
out->nodes = arr;
|
|
557
|
+
out->count = b->count;
|
|
558
|
+
out->capacity = b->count;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
struct leptris_xpath_result* r =
|
|
562
|
+
xpath_result_new(XPATH_RESULT_NODESET);
|
|
563
|
+
if (!r) { xpath_nodeset_free(out); return NULL; }
|
|
564
|
+
r->value.nodeset_value = out;
|
|
565
|
+
return r;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
struct leptris_xpath_result* ra = vm_apply_absolute(ctx, name_a, 0, 2);
|
|
569
|
+
struct leptris_xpath_result* rb = vm_apply_absolute(ctx, name_b, 0, 2);
|
|
570
|
+
if (!ra || !rb) {
|
|
571
|
+
if (ra) xpath_result_free(ra);
|
|
572
|
+
if (rb) xpath_result_free(rb);
|
|
573
|
+
return NULL;
|
|
574
|
+
}
|
|
575
|
+
XPathNodeSet* la = ra->value.nodeset_value;
|
|
576
|
+
XPathNodeSet* lb = rb->value.nodeset_value;
|
|
577
|
+
|
|
578
|
+
size_t n = la->count + lb->count;
|
|
579
|
+
XPathNodeSet* out = xpath_nodeset_new();
|
|
580
|
+
struct leptris_xpath_result* r = xpath_result_new(XPATH_RESULT_NODESET);
|
|
581
|
+
void** arr = out ? (void**)malloc((n ? n : 1) * sizeof(void*)) : NULL;
|
|
582
|
+
if (!out || !r || !arr) {
|
|
583
|
+
free(arr);
|
|
584
|
+
if (out) xpath_nodeset_free(out);
|
|
585
|
+
if (r) xpath_result_free(r);
|
|
586
|
+
xpath_nodeset_free(la);
|
|
587
|
+
xpath_nodeset_free(lb);
|
|
588
|
+
ra->value.nodeset_value = NULL;
|
|
589
|
+
rb->value.nodeset_value = NULL;
|
|
590
|
+
xpath_result_free(ra);
|
|
591
|
+
xpath_result_free(rb);
|
|
592
|
+
return NULL;
|
|
593
|
+
}
|
|
594
|
+
out->nodes = arr;
|
|
595
|
+
out->capacity = n ? n : 1;
|
|
596
|
+
|
|
597
|
+
int merged = 0;
|
|
598
|
+
if (!same && ctx->document->mutation_version == 0) {
|
|
599
|
+
uint64_t* ka =
|
|
600
|
+
la->count ? (uint64_t*)malloc(la->count * sizeof(uint64_t))
|
|
601
|
+
: (uint64_t*)malloc(sizeof(uint64_t));
|
|
602
|
+
uint64_t* kb =
|
|
603
|
+
lb->count ? (uint64_t*)malloc(lb->count * sizeof(uint64_t))
|
|
604
|
+
: (uint64_t*)malloc(sizeof(uint64_t));
|
|
605
|
+
if (ka && kb) {
|
|
606
|
+
int ok = 1;
|
|
607
|
+
for (size_t i = 0; i < la->count && ok; i++)
|
|
608
|
+
if (!xpath_doc_order_offset_key(la->nodes[i], &ka[i]))
|
|
609
|
+
ok = 0;
|
|
610
|
+
for (size_t j = 0; j < lb->count && ok; j++)
|
|
611
|
+
if (!xpath_doc_order_offset_key(lb->nodes[j], &kb[j]))
|
|
612
|
+
ok = 0;
|
|
613
|
+
if (ok) {
|
|
614
|
+
size_t i = 0, j = 0, k = 0;
|
|
615
|
+
while (i < la->count && j < lb->count)
|
|
616
|
+
out->nodes[k++] = (ka[i] <= kb[j]) ? la->nodes[i++]
|
|
617
|
+
: lb->nodes[j++];
|
|
618
|
+
while (i < la->count) out->nodes[k++] = la->nodes[i++];
|
|
619
|
+
while (j < lb->count) out->nodes[k++] = lb->nodes[j++];
|
|
620
|
+
out->count = k;
|
|
621
|
+
merged = 1;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
free(ka);
|
|
625
|
+
free(kb);
|
|
626
|
+
}
|
|
627
|
+
if (!merged) {
|
|
628
|
+
if (la->count)
|
|
629
|
+
memcpy(out->nodes, la->nodes, la->count * sizeof(void*));
|
|
630
|
+
if (lb->count)
|
|
631
|
+
memcpy(out->nodes + la->count, lb->nodes,
|
|
632
|
+
lb->count * sizeof(void*));
|
|
633
|
+
out->count = n;
|
|
634
|
+
/* Sort dedups adjacent equal pointers — covers the
|
|
635
|
+
* same-name-no-index case (two identical runs). */
|
|
636
|
+
xpath_nodeset_sort_doc_order(ctx, out, 0);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
xpath_nodeset_free(la);
|
|
640
|
+
xpath_nodeset_free(lb);
|
|
641
|
+
ra->value.nodeset_value = NULL;
|
|
642
|
+
rb->value.nodeset_value = NULL;
|
|
643
|
+
xpath_result_free(ra);
|
|
644
|
+
xpath_result_free(rb);
|
|
645
|
+
r->value.nodeset_value = out;
|
|
646
|
+
return r;
|
|
647
|
+
}
|
|
648
|
+
|
|
495
649
|
struct leptris_xpath_result* vm_apply_axis_child(XPathContext* ctx, XPathVM* vm,
|
|
496
650
|
const char* name, int wild) {
|
|
497
651
|
XPathNodeSet* input = vm_detach_input_nodeset(vm);
|
|
@@ -878,6 +1032,46 @@ static void descendant_walk(XPathContext* ctx, XPathNodeSet* out, LeptrisElement
|
|
|
878
1032
|
}
|
|
879
1033
|
}
|
|
880
1034
|
|
|
1035
|
+
/* #1842 Track C lever 2: descendant_walk matching EITHER of two
|
|
1036
|
+
* plain names in one pre-order pass. Both tests are unprefixed
|
|
1037
|
+
* (compile gate) and disjoint — an element can match at most one —
|
|
1038
|
+
* so the emission is doc-ordered without any merge or sort. */
|
|
1039
|
+
static void descendant_walk_two_names(XPathContext* ctx, XPathNodeSet* out,
|
|
1040
|
+
LeptrisElement elem,
|
|
1041
|
+
const char* name_a, const char* name_b) {
|
|
1042
|
+
if (!elem) return;
|
|
1043
|
+
if (out->capacity < 32) {
|
|
1044
|
+
void** new_nodes = (void**)malloc(32 * sizeof(void*));
|
|
1045
|
+
if (new_nodes) {
|
|
1046
|
+
if (out->count > 0) {
|
|
1047
|
+
memcpy(new_nodes, out->nodes, out->count * sizeof(void*));
|
|
1048
|
+
}
|
|
1049
|
+
out->nodes = new_nodes;
|
|
1050
|
+
out->capacity = 32;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
LeptrisElement cur = leptris_element_get_first_child(elem);
|
|
1054
|
+
while (cur) {
|
|
1055
|
+
if (vm_unprefixed_name_matches(ctx, cur, name_a) ||
|
|
1056
|
+
vm_unprefixed_name_matches(ctx, cur, name_b))
|
|
1057
|
+
xpath_nodeset_add_fast(out, cur);
|
|
1058
|
+
LeptrisElement next = leptris_element_get_first_child(cur);
|
|
1059
|
+
if (next) {
|
|
1060
|
+
cur = next;
|
|
1061
|
+
continue;
|
|
1062
|
+
}
|
|
1063
|
+
while (cur && cur != elem) {
|
|
1064
|
+
LeptrisElement sib = leptris_element_get_next_sibling(cur);
|
|
1065
|
+
if (sib) {
|
|
1066
|
+
cur = sib;
|
|
1067
|
+
break;
|
|
1068
|
+
}
|
|
1069
|
+
cur = leptris_element_get_parent(cur);
|
|
1070
|
+
}
|
|
1071
|
+
if (cur == elem) break;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
|
|
881
1075
|
/* Pre-order all-nodes walk: n itself, then (for elements) each
|
|
882
1076
|
* subtree. Matches descendant_walk's recursion risk profile. */
|
|
883
1077
|
static void all_nodes_preorder(XPathNodeSet* out, LeptrisNode* n) {
|
|
@@ -2108,6 +2302,22 @@ static struct leptris_xpath_result* vm_run(LeptrisXPathBytecode* bc,
|
|
|
2108
2302
|
break;
|
|
2109
2303
|
}
|
|
2110
2304
|
|
|
2305
|
+
case XPATH_BC_ABSOLUTE_UNION_NAMES: {
|
|
2306
|
+
uint16_t ia = read_u16(&pc);
|
|
2307
|
+
uint16_t ib = read_u16(&pc);
|
|
2308
|
+
const char* na = (ia < bc->const_count &&
|
|
2309
|
+
bc->constants[ia].type == XPATH_CONST_STRING)
|
|
2310
|
+
? bc->constants[ia].v.string : NULL;
|
|
2311
|
+
const char* nb = (ib < bc->const_count &&
|
|
2312
|
+
bc->constants[ib].type == XPATH_CONST_STRING)
|
|
2313
|
+
? bc->constants[ib].v.string : NULL;
|
|
2314
|
+
struct leptris_xpath_result* r =
|
|
2315
|
+
vm_apply_absolute_union_names(ctx, na, nb);
|
|
2316
|
+
if (!r) { vm.error = 1; break; }
|
|
2317
|
+
vm_push(&vm, r);
|
|
2318
|
+
break;
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2111
2321
|
case XPATH_BC_ABSOLUTE_DESCENDANT_WILD: {
|
|
2112
2322
|
/* Same document-context semantics as the NAME variant:
|
|
2113
2323
|
* /descendant::* includes the root element. */
|
|
@@ -788,4 +788,151 @@ TEST(XPathBytecodeFusedAxisPredicate, DescendantWildWithAttrExists) {
|
|
|
788
788
|
leptris_document_free(doc);
|
|
789
789
|
}
|
|
790
790
|
|
|
791
|
+
// ---- #1842 Track C lever 2: descendant-name union fusion ----
|
|
792
|
+
// `//a | //b` compiles to ONE pre-order walk matching either name
|
|
793
|
+
// (the generic path walks the tree once per branch and unions the
|
|
794
|
+
// results). The fused form must be results-identical: same members,
|
|
795
|
+
// document order, dedup. Coverage gate: only plain-name branches
|
|
796
|
+
// fuse — prefixed, wildcard-mixed, deep, and variable branches stay
|
|
797
|
+
// generic and must keep working.
|
|
798
|
+
|
|
799
|
+
static void expect_names_in_order(LeptrisDocument doc, const char* expr,
|
|
800
|
+
const char* const* names, size_t n) {
|
|
801
|
+
LeptrisXPathResult r = leptris_xpath_eval(doc, nullptr, expr);
|
|
802
|
+
ASSERT_NE(r, nullptr) << expr;
|
|
803
|
+
ASSERT_EQ(leptris_xpath_result_count(r), n) << expr;
|
|
804
|
+
for (size_t i = 0; i < n; i++) {
|
|
805
|
+
LeptrisElement e = leptris_xpath_result_get(r, i);
|
|
806
|
+
ASSERT_NE(e, (LeptrisElement)nullptr) << expr << " [" << i << "]";
|
|
807
|
+
const char* nm = leptris_element_name(e);
|
|
808
|
+
ASSERT_NE(nm, nullptr);
|
|
809
|
+
EXPECT_STREQ(nm, names[i]) << expr << " [" << i << "]";
|
|
810
|
+
}
|
|
811
|
+
leptris_xpath_result_free(r);
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
TEST(XPathUnionFusion, DocumentOrderCompleteness) {
|
|
815
|
+
const char xml[] =
|
|
816
|
+
"<lib><b><c>X</c></b><b><c>Y</c></b><d><b><c>Z</c></b></d></lib>";
|
|
817
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
818
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
819
|
+
ASSERT_NE(doc, nullptr);
|
|
820
|
+
|
|
821
|
+
/* Doc order: b, b, d (then its child b), i.e. the nested b
|
|
822
|
+
* comes AFTER d — a branch-ordered concatenation (b b then d b)
|
|
823
|
+
* would still match here, but the count must be 4. */
|
|
824
|
+
LeptrisXPathResult r = leptris_xpath_eval(doc, nullptr, "count(//b | //d)");
|
|
825
|
+
ASSERT_NE(r, nullptr);
|
|
826
|
+
EXPECT_DOUBLE_EQ(leptris_xpath_result_number(r), 4.0);
|
|
827
|
+
leptris_xpath_result_free(r);
|
|
828
|
+
|
|
829
|
+
/* Full order pin: the nested b must follow its d parent. */
|
|
830
|
+
static const char* const names[] = {"b", "b", "d", "b"};
|
|
831
|
+
expect_names_in_order(doc, "//b | //d", names, 4);
|
|
832
|
+
|
|
833
|
+
leptris_document_free(doc);
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
TEST(XPathUnionFusion, SelfUnionDedups) {
|
|
837
|
+
const char xml[] = "<r><b/><b/><b/></r>";
|
|
838
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
839
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
840
|
+
ASSERT_NE(doc, nullptr);
|
|
841
|
+
|
|
842
|
+
LeptrisXPathResult r = leptris_xpath_eval(doc, nullptr, "count(//b | //b)");
|
|
843
|
+
ASSERT_NE(r, nullptr);
|
|
844
|
+
EXPECT_DOUBLE_EQ(leptris_xpath_result_number(r), 3.0);
|
|
845
|
+
leptris_xpath_result_free(r);
|
|
846
|
+
|
|
847
|
+
leptris_document_free(doc);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
TEST(XPathUnionFusion, InterleavedBranchesDocOrder) {
|
|
851
|
+
/* The merge trap: branch-concatenation ([b b] ++ [d]) violates
|
|
852
|
+
* document order when the names interleave. The fused union
|
|
853
|
+
* must interleave the runs — [b, d, b], not [b, b, d]. */
|
|
854
|
+
const char xml[] = "<r><b/><d/><b/></r>";
|
|
855
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
856
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
857
|
+
ASSERT_NE(doc, nullptr);
|
|
858
|
+
|
|
859
|
+
static const char* const names[] = {"b", "d", "b"};
|
|
860
|
+
expect_names_in_order(doc, "//b | //d", names, 3);
|
|
861
|
+
|
|
862
|
+
leptris_document_free(doc);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
TEST(XPathUnionFusion, NestedContainerOverlap) {
|
|
866
|
+
const char xml[] =
|
|
867
|
+
"<lib><b><c>X</c></b><b><c>Y</c></b><d><b><c>Z</c></b></d></lib>";
|
|
868
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
869
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
870
|
+
ASSERT_NE(doc, nullptr);
|
|
871
|
+
|
|
872
|
+
/* lib contains all three c's — the union must dedup across the
|
|
873
|
+
* ancestor/descendant overlap. */
|
|
874
|
+
LeptrisXPathResult r = leptris_xpath_eval(doc, nullptr, "count(//lib | //c)");
|
|
875
|
+
ASSERT_NE(r, nullptr);
|
|
876
|
+
EXPECT_DOUBLE_EQ(leptris_xpath_result_number(r), 4.0);
|
|
877
|
+
leptris_xpath_result_free(r);
|
|
878
|
+
|
|
879
|
+
leptris_document_free(doc);
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
TEST(XPathUnionFusion, DisjointBranch) {
|
|
883
|
+
const char xml[] = "<users><user/><user/><user/></users>";
|
|
884
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
885
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
886
|
+
ASSERT_NE(doc, nullptr);
|
|
887
|
+
|
|
888
|
+
/* The scoreboard shape: one branch matches nothing. */
|
|
889
|
+
LeptrisXPathResult r = leptris_xpath_eval(doc, nullptr, "count(//user | //record)");
|
|
890
|
+
ASSERT_NE(r, nullptr);
|
|
891
|
+
EXPECT_DOUBLE_EQ(leptris_xpath_result_number(r), 3.0);
|
|
892
|
+
leptris_xpath_result_free(r);
|
|
893
|
+
|
|
894
|
+
leptris_document_free(doc);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
TEST(XPathUnionFusion, ThreeBranches) {
|
|
898
|
+
const char xml[] =
|
|
899
|
+
"<lib><b><c>X</c></b><b><c>Y</c></b><d><b><c>Z</c></b></d></lib>";
|
|
900
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
901
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
902
|
+
ASSERT_NE(doc, nullptr);
|
|
903
|
+
|
|
904
|
+
static const char* const names[] = {"b", "c", "b", "c", "d", "b", "c"};
|
|
905
|
+
expect_names_in_order(doc, "//b | //c | //d", names, 7);
|
|
906
|
+
|
|
907
|
+
leptris_document_free(doc);
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
TEST(XPathUnionFusion, NonFusableShapesStayCorrect) {
|
|
911
|
+
const char xml[] =
|
|
912
|
+
"<lib><b><c>X</c></b><b><c>Y</c></b><d><b><c>Z</c></b></d></lib>";
|
|
913
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
914
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
915
|
+
ASSERT_NE(doc, nullptr);
|
|
916
|
+
|
|
917
|
+
/* Wildcard branch — outside the plain-name coverage gate. */
|
|
918
|
+
LeptrisXPathResult r = leptris_xpath_eval(doc, nullptr, "count(//* | //c)");
|
|
919
|
+
ASSERT_NE(r, nullptr);
|
|
920
|
+
EXPECT_DOUBLE_EQ(leptris_xpath_result_number(r), 8.0);
|
|
921
|
+
leptris_xpath_result_free(r);
|
|
922
|
+
|
|
923
|
+
/* Deep branch — child::c under //b, not a bare //name. */
|
|
924
|
+
LeptrisXPathResult r2 = leptris_xpath_eval(doc, nullptr, "count(//b/c | //d)");
|
|
925
|
+
ASSERT_NE(r2, nullptr);
|
|
926
|
+
EXPECT_DOUBLE_EQ(leptris_xpath_result_number(r2), 4.0);
|
|
927
|
+
leptris_xpath_result_free(r2);
|
|
928
|
+
|
|
929
|
+
/* Prefixed name branch — unbound prefix selects nothing. */
|
|
930
|
+
LeptrisXPathResult r3 = leptris_xpath_eval(doc, nullptr, "count(//lib | //x:c)");
|
|
931
|
+
ASSERT_NE(r3, nullptr);
|
|
932
|
+
EXPECT_DOUBLE_EQ(leptris_xpath_result_number(r3), 1.0);
|
|
933
|
+
leptris_xpath_result_free(r3);
|
|
934
|
+
|
|
935
|
+
leptris_document_free(doc);
|
|
936
|
+
}
|
|
937
|
+
|
|
791
938
|
} // namespace
|
|
@@ -5011,3 +5011,75 @@ TEST(XsdCrossNs, RedefineExtensionKeepsTheExtensionModel) {
|
|
|
5011
5011
|
std::remove(redef_p.c_str());
|
|
5012
5012
|
leptris_xsd_free(s);
|
|
5013
5013
|
}
|
|
5014
|
+
|
|
5015
|
+
/* leptris#1979: the schG2 corpus shape through an import-RESOLVED
|
|
5016
|
+
* compile (compile_file, so the import's schemaLocation loads).
|
|
5017
|
+
* Both units define same-named components with SWAPPED member
|
|
5018
|
+
* types — ns-a's ct-A (a1 int, a2 bool) vs the no-targetNamespace
|
|
5019
|
+
* unit's ct-A (a1 bool, a2 int). The instance's no-ns <e1> must
|
|
5020
|
+
* bind ITS OWN unit's ct-A; resolving the unprefixed type="
|
|
5021
|
+
* ct-A" reference against the importing namespace's same-name
|
|
5022
|
+
* type (which sits ahead in the merged table) types a1 as
|
|
5023
|
+
* xsd:int and manufactures a false lexical row on a1=true. */
|
|
5024
|
+
/* leptris#1979: the schG2 corpus shape through an import-RESOLVED
|
|
5025
|
+
* compile (compile_file on the vendored corpus case, so the
|
|
5026
|
+
* import's schemaLocation chain loads: a imports b, b imports c).
|
|
5027
|
+
* THREE units define same-named ct-A/e1 with different member
|
|
5028
|
+
* types — ns-a (a1 int, a2 bool), the no-targetNamespace unit
|
|
5029
|
+
* (a1 bool, a2 int), ns-c (a1 int, a2 int). The instance's no-ns
|
|
5030
|
+
* <e1> must bind ITS OWN unit's ct-A; the no-ns unit's unprefixed
|
|
5031
|
+
* type="ct-A" reference resolving against an earlier same-name
|
|
5032
|
+
* entry in the merged table types a1 as xsd:int and manufactures
|
|
5033
|
+
* a false lexical row on a1=true. The 1.9.410 fix (#1976) covered
|
|
5034
|
+
* the roundtrip (location-less) lane; this is the resolved lane. */
|
|
5035
|
+
/* #1979 variant: the lutaml-xsd EngineContext passes ALL resolved
|
|
5036
|
+
* units to compile_set (hints) — the three-unit orders. The merged
|
|
5037
|
+
* table order differs from the import-chase order; every permutation
|
|
5038
|
+
* must keep the W3C oracle (valid). */
|
|
5039
|
+
TEST(XsdCrossNs, SchG2CompileSetThreeUnitOrdersValid) {
|
|
5040
|
+
const char* units[] = {
|
|
5041
|
+
LEPTRIS_XSD_CASES_DIR "/schG2-import-compose/schG2_a.xsd",
|
|
5042
|
+
LEPTRIS_XSD_CASES_DIR "/schG2-import-compose/schG2_b.xsd",
|
|
5043
|
+
LEPTRIS_XSD_CASES_DIR "/schG2-import-compose/schG1_c.xsd",
|
|
5044
|
+
};
|
|
5045
|
+
const int perms[6][3] = {{0,1,2},{0,2,1},{1,0,2},{1,2,0},{2,0,1},{2,1,0}};
|
|
5046
|
+
for (int pi = 0; pi < 6; pi++) {
|
|
5047
|
+
const char* paths[3];
|
|
5048
|
+
for (int u = 0; u < 3; u++) paths[u] = units[perms[pi][u]];
|
|
5049
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
5050
|
+
LeptrisXsdSchema s = leptris_xsd_compile_set(paths, 3, &st);
|
|
5051
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0) << "perm " << pi;
|
|
5052
|
+
LeptrisDocument d = leptris_parse_file(
|
|
5053
|
+
LEPTRIS_XSD_CASES_DIR "/schG2-import-compose/schG2.xml", &st);
|
|
5054
|
+
ASSERT_NE(d, nullptr) << "perm " << pi;
|
|
5055
|
+
EXPECT_EQ(leptris_xsd_validate(s, d), 1) << "perm " << pi;
|
|
5056
|
+
for (size_t i = 0; i < leptris_xsd_error_count(s); i++)
|
|
5057
|
+
ADD_FAILURE() << "perm " << pi << ": "
|
|
5058
|
+
<< leptris_xsd_error_at(s, i);
|
|
5059
|
+
leptris_document_free(d);
|
|
5060
|
+
leptris_xsd_free(s);
|
|
5061
|
+
}
|
|
5062
|
+
}
|
|
5063
|
+
|
|
5064
|
+
TEST(XsdCrossNs, SchG2ImportResolvedNoNsUnitBindsOwnTypes) {
|
|
5065
|
+
std::string dir = LEPTRIS_XSD_CASES_DIR;
|
|
5066
|
+
std::string main_path = dir + "/schG2-import-compose/schG2_a.xsd";
|
|
5067
|
+
std::string inst;
|
|
5068
|
+
{
|
|
5069
|
+
std::ifstream f(dir + "/schG2-import-compose/schG2.xml");
|
|
5070
|
+
ASSERT_TRUE(f.is_open()) << "corpus instance missing";
|
|
5071
|
+
std::stringstream ss;
|
|
5072
|
+
ss << f.rdbuf();
|
|
5073
|
+
inst = ss.str();
|
|
5074
|
+
}
|
|
5075
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
5076
|
+
LeptrisXsdSchema s = leptris_xsd_compile_file(main_path.c_str(), &st);
|
|
5077
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
5078
|
+
ASSERT_EQ(st, LEPTRIS_OK) << leptris_xsd_error(s);
|
|
5079
|
+
|
|
5080
|
+
/* W3C oracle: the whole instance is VALID. */
|
|
5081
|
+
EXPECT_EQ(validate_compiled(s, inst.c_str()), 1)
|
|
5082
|
+
<< "schG2 import-resolved lane: "
|
|
5083
|
+
<< leptris_xsd_error(s);
|
|
5084
|
+
leptris_xsd_free(s);
|
|
5085
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
|
|
3
3
|
"name": "leptris",
|
|
4
|
-
"version": "1.9.
|
|
4
|
+
"version": "1.9.412",
|
|
5
5
|
"description": "High-performance XML parser and XPath 1.0 engine in C (libleptris)",
|
|
6
6
|
"homepage": "https://github.com/leptris/leptris",
|
|
7
7
|
"license": "MIT",
|