leptris 1.9.352.0-arm-linux → 1.9.354.0-arm-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.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/Rakefile +1 -1
  4. data/lib/leptris/version.rb +1 -1
  5. data/lib/leptris/xml/element.rb +56 -0
  6. data/lib/leptris/xml/ffi.rb +9 -0
  7. data/lib/libleptris.so +0 -0
  8. data/vendor-src/README.md +1 -1
  9. data/vendor-src/libleptris/CHANGELOG.md +71 -0
  10. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  11. data/vendor-src/libleptris/scripts/gen_xsd_manifest.py +88 -0
  12. data/vendor-src/libleptris/src/include/leptris.h +44 -0
  13. data/vendor-src/libleptris/src/leptris/common/string_view.c +8 -5
  14. data/vendor-src/libleptris/src/leptris/dom/element_index.c +6 -2
  15. data/vendor-src/libleptris/src/leptris/dom/element_query.c +100 -0
  16. data/vendor-src/libleptris/src/leptris/leptris.c +3 -3
  17. data/vendor-src/libleptris/src/leptris/rng/validate.c +5 -5
  18. data/vendor-src/libleptris/src/leptris/sch/schematron.c +2 -1
  19. data/vendor-src/libleptris/src/leptris/xpath/evaluator_path.c +2 -2
  20. data/vendor-src/libleptris/src/leptris/xpath/vm.c +1 -1
  21. data/vendor-src/libleptris/src/leptris/xpath/xpath_public.c +3 -2
  22. data/vendor-src/libleptris/src/leptris/xsd/compile.c +147 -56
  23. data/vendor-src/libleptris/src/leptris/xslt/xslt_exec.c +4 -2
  24. data/vendor-src/libleptris/src/leptris/xslt/xslt_functions.c +5 -2
  25. data/vendor-src/libleptris/src/leptris/xslt/xslt_parse.c +4 -2
  26. data/vendor-src/libleptris/test/dom/test_dom.cpp +140 -0
  27. data/vendor-src/libleptris/test/xsd/libxml2-cases/MANIFEST.tsv +1058 -0
  28. data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +91 -4
  29. data/vendor-src/libleptris/vcpkg.json +1 -1
  30. metadata +3 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21a3eba4767538ae554e7594dba12ce4f67e7185766e38132ab148db3ac46200
4
- data.tar.gz: 002de7934da94e8558ec6690d66db91664da58a928cb63ce45337d1841587d97
3
+ metadata.gz: 4934e78f0b0c6b08aca5f8574d6cc262453a67f3238705c951d7c0e79c5a8f9f
4
+ data.tar.gz: eb97994c93bb47b928cba5f92057469962a901445345801e55af5c9e804718c7
5
5
  SHA512:
6
- metadata.gz: 21f4aaaef7acfed9aa45f37ba5ec2c68b7c2a53ab2cad4d89d89a63f8850c5c5cbaaf98c936ee5e51197aad6c10422b33bd63fb906dc8b409ba7c1ddb3ad0854
7
- data.tar.gz: 455a8e311be82b234210ddece6d221eeef3e9d2e8818c2bad7b47a43c5b7d7a223605a916638b1e7ef3d0f3af15f5bdb56e95d6c6c1054dfcb8efa4a0f33860d
6
+ metadata.gz: 3f8b44470d831bfe5c988a3175d58371308194eb734520d2765e26126112c9fec2ed8bb5c9c516c9b77dcfaf66e9efa0e1e6d3f07cbf3558e950c69f4627dc15
7
+ data.tar.gz: 94cf2b038a54dd48a43fe3657d191b3f970052bb749de82cc10a1880fda75632163cb51d633a8ca6630ebd70e92f9272f93802de3dde91090b171c9263c6851b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.9.353.0] - 2026-10-14
2
+
3
+ ### Added — engine sync (libleptris 1.9.353)
4
+
5
+ - **Element#attributes_snapshot — ALL attribute names/values in
6
+ ONE FFI crossing (libleptris 1.9.353, leptris/leptris#1689/
7
+ #1690)**: the element sibling of PlanValue#attributes_snapshot
8
+ (#447). Two-phase capacity/retry (sizing pass returns the exact
9
+ blob capacity; SIZE_MAX retries double the guess for
10
+ between-call mutations), UTF-8 encoded like the per-name reader,
11
+ prefixed attributes carried by their spelled names (ns lanes
12
+ stay NULL on this surface). The count half
13
+ (leptris_element_attribute_count) was already attached.
14
+
1
15
  ## [1.9.352.0] - 2026-10-14
2
16
 
3
17
  ### Fixed — engine sync (libleptris 1.9.352)
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.352"
11
+ LIBLEPTRIS_VERSION = "1.9.354"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.9.352.0"
4
+ VERSION = "1.9.354.0"
5
5
  end
@@ -284,6 +284,62 @@ class Leptris::XML::Element < Leptris::XML::Node
284
284
  result
285
285
  end
286
286
 
287
+ # ALL bound attributes as { name => value } in ONE FFI crossing
288
+ # (libleptris 1.9.353, leptris#1689) — the element sibling of
289
+ # PlanValue#attributes_snapshot: two-phase capacity/retry, names
290
+ # + values lanes; the ns lanes stay NULL and prefixed attributes
291
+ # ride the names lane spelled as the element spells them. UTF-8
292
+ # encoded like the per-name reader.
293
+ def attributes_snapshot
294
+ ensure_alive!
295
+ ptr = c_ptr
296
+ n = Leptris::XML::FFI.leptris_element_attribute_count(ptr)
297
+ return {}.freeze if n.zero?
298
+
299
+ need = Leptris::XML::FFI.leptris_element_attributes_snapshot(
300
+ ptr, nil, 0, nil, nil, 0, nil, nil, 0, nil, nil, 0, nil
301
+ )
302
+ return {}.freeze if need.zero?
303
+
304
+ size_t = ::FFI::MemoryPointer.new(:size_t, 2).total / 2
305
+ cap = need
306
+ loop do
307
+ names = ::FFI::MemoryPointer.new(:char, cap)
308
+ values = ::FFI::MemoryPointer.new(:char, cap)
309
+ name_offsets = ::FFI::MemoryPointer.new(:size_t, n + 1)
310
+ value_offsets = ::FFI::MemoryPointer.new(:size_t, n + 1)
311
+ rc = Leptris::XML::FFI.leptris_element_attributes_snapshot(
312
+ ptr, names, cap, name_offsets, values, cap,
313
+ value_offsets, nil, 0, nil, nil, 0, nil
314
+ )
315
+ break build_attributes_snapshot(
316
+ names, name_offsets, values, value_offsets, n, size_t
317
+ ) if rc.zero?
318
+
319
+ # The sizing call reports the exact capacity, so (size_t)-1
320
+ # here means the element mutated between calls — retry at the
321
+ # doubled guess.
322
+ raise "attributes snapshot failed" if rc != SIZE_MAX
323
+
324
+ cap *= 2
325
+ end
326
+ end
327
+
328
+ def build_attributes_snapshot(names, name_offsets, values,
329
+ value_offsets, n, size_t)
330
+ result = {}
331
+ n.times do |i|
332
+ noff = name_offsets.get_uint64(i * size_t)
333
+ voff = value_offsets.get_uint64(i * size_t)
334
+ # Raw pointer reads come back ASCII-8BIT; match the per-name
335
+ # reader's UTF8_STRING contract.
336
+ result[names.get_string(noff).force_encoding(Encoding::UTF_8)] =
337
+ values.get_string(voff).force_encoding(Encoding::UTF_8)
338
+ end
339
+ result
340
+ end
341
+ private :build_attributes_snapshot
342
+
287
343
  # Read-only attribute listing as [name, value] pairs — no Attr
288
344
  # objects. Names are interned frozen strings (shared across
289
345
  # documents; dup before mutating), values fresh UTF-8 strings.
@@ -845,6 +845,15 @@ attach_function :leptris_parse_string,
845
845
  [:leptris_element], UTF8_STRING
846
846
  attach_function :leptris_element_attribute_count,
847
847
  [:leptris_element], :size_t
848
+ # leptris#1689: ALL attribute names/values (+ optional ns
849
+ # lanes) in ONE crossing — two-phase capacity/retry, the
850
+ # element sibling of the #1670 plan-value snapshot.
851
+ attach_function :leptris_element_attributes_snapshot,
852
+ [:leptris_element,
853
+ :pointer, :size_t, :pointer,
854
+ :pointer, :size_t, :pointer,
855
+ :pointer, :size_t, :pointer,
856
+ :pointer, :size_t, :pointer], :size_t
848
857
  attach_function :leptris_element_attribute_name_at,
849
858
  [:leptris_element, :size_t], UTF8_STRING
850
859
  attach_function :leptris_element_attribute_value_at,
data/lib/libleptris.so CHANGED
Binary file
data/vendor-src/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Sources vendored in this gem (recompile rights; the ruby
2
2
  variant builds them at install via extconf.rb):
3
3
 
4
- - libleptris v1.9.352
4
+ - libleptris v1.9.354
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand:
@@ -1,5 +1,76 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.354] - 2026-10-14
4
+
5
+ ### Fixed
6
+
7
+ - **wasm32/ILP32 portability: 64-bit hash accumulators + enum
8
+ discipline (PR #1697).** The emscripten build (wasm32: size_t and
9
+ uintptr_t are 32-bit) exposed a class the LP64 host lanes never
10
+ see — 17 warnings, all real. The 64-bit FNV-1a basis/prime
11
+ constants sat in size_t, so on 32-bit targets the hash silently
12
+ stopped being FNV-1a (string_view, element_index, xslt_parse);
13
+ accumulators are now uint64_t with one fold at the return.
14
+ acc_ptr_hash shifted a uintptr_t by 33 — UB on 32-bit pointers;
15
+ promoted to 64-bit with the full avalanche. The leptris_set_error
16
+ call sites passed LeptrisStatus constants into the internal
17
+ error-code channel (TODO 98's boundary) — the implicit enum
18
+ casts are explicit at the five sites. LeptrisNodeKind vs
19
+ LeptrisNodeType compares (and the result-type compare) cast
20
+ through int where the same-valued members meet. rng diag calls
21
+ passed arguments the format string never used. emcc: 17 warnings
22
+ -> 0; wasm test gate 5/5; host suite green.
23
+
24
+ ### Changed
25
+
26
+ - (describe changes here)
27
+
28
+
29
+ ## [1.9.353] - 2026-10-14
30
+
31
+ ### Added
32
+
33
+ - **Element-attribute batch face (leptris#1689, PR #1690).**
34
+ `leptris_element_attributes_snapshot` — the object-face sibling
35
+ of #1670's plan-value snapshot: ALL attribute names, values, and
36
+ optionally ns prefixes/URIs in ONE crossing, two-phase
37
+ capacity/retry, per-lane totals in the +1 offset slots, SIZE_MAX
38
+ ns markers for no-namespace attributes. Values ride the lazy
39
+ entity expansion; URIs the #1664 in-scope resolution. The count
40
+ half (`leptris_element_attribute_count`) shipped with TODO 138 —
41
+ the pair is complete. Binding wire-up: one PR on leptris-ruby
42
+ (the #447 harness carries over).
43
+
44
+ ### Changed
45
+
46
+ - **XSD conformance lane: differential manifest + measured floor
47
+ (leptris#1075, PR #1692).** Every (schema, instance) pair in
48
+ libxml2-cases now carries the libxml2 oracle's verdict
49
+ (`MANIFEST.tsv`, 1056 rows: 187 valid / 663 invalid / 206
50
+ schema-error), and
51
+ `XsdConformance.ManifestExpectationsMatchOracle` runs the engine
52
+ against all of them in ~80ms. First measured baseline: **769/1056
53
+ (72.8%)** — 36 false rejections, 45 false acceptances, 206
54
+ lax-constraint compiles. The burn-down began immediately: the
55
+ schema-structure check (name XOR ref on xs:attribute/xs:element,
56
+ minOccurs <= maxOccurs) retires 26 rows, **795/1056**, with
57
+ per-class monotonic floors. The 287-divergence queue tracks in
58
+ #1691.
59
+
60
+ - **XSD reference-resolution chokepoint (PR #1693).** Five
61
+ declaration-table lookup families — each previously a hand-rolled
62
+ copy of the (ns,name)/unstamped/name-only walk — collapse onto
63
+ one generated `XSD_DEFINE_NS_LADDER` with explicit policies:
64
+ STRICT for compile-side derivation, LADDER for instance-side
65
+ type references (#1687's cross-namespace case). Pure refactor,
66
+ 1997/1997 unchanged; `XsdGroupDef` queues until group definitions
67
+ carry ns stamps.
68
+
69
+ ### Changed
70
+
71
+ - (describe changes here)
72
+
73
+
3
74
  ## [1.9.352] - 2026-10-14
4
75
 
5
76
  ### Fixed
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(leptris
6
- VERSION 1.9.352
6
+ VERSION 1.9.354
7
7
  DESCRIPTION "Fast XML parser and XPath evaluator in pure C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env python3
2
+ """Differential manifest generator for the XSD conformance lane (#1075).
3
+
4
+ Runs the system libxml2 oracle (xmllint) over every (schema, instance)
5
+ pair in test/xsd/libxml2-cases/ and records the expected verdict per
6
+ pair into MANIFEST.tsv. The engine must match the oracle; the harness
7
+ test pins the pass floor monotonically.
8
+
9
+ libxml2 test/schemas pairing convention: a schema NNN_M.xsd is run
10
+ against every instance NNN_K.xml sharing the same numeric prefix with
11
+ K >= M (runtest.c). Subdirectories (issue fixtures with their own
12
+ specs) are skipped.
13
+ """
14
+ import glob, os, re, subprocess, sys, collections
15
+
16
+ ROOT = os.path.join(os.path.dirname(__file__), "..", "test", "xsd", "libxml2-cases")
17
+ ROOT = os.path.abspath(ROOT)
18
+ ORACLE = "xmllint"
19
+
20
+ def oracle(schema, instance):
21
+ """valid / invalid / schema-error; None = oracle failed to decide."""
22
+ try:
23
+ r = subprocess.run(
24
+ [ORACLE, "--noout", "--schema", schema, instance],
25
+ capture_output=True, timeout=30)
26
+ except subprocess.TimeoutExpired:
27
+ return None
28
+ err = r.stderr.decode("utf-8", "replace")
29
+ if "Schemas parser error" in err:
30
+ return "schema-error"
31
+ if r.returncode == 0:
32
+ return "valid"
33
+ return "invalid"
34
+
35
+ def group_key(name):
36
+ """Fixture family: leading token, letter-prefixed names drop the
37
+ trailing digit run (all.xsd / all1_0.xml are one family)."""
38
+ m = re.match(r"[A-Za-z0-9]+", name)
39
+ if not m:
40
+ return None
41
+ key = m.group(0)
42
+ if key[0].isalpha():
43
+ key = re.sub(r"[0-9]+$", "", key)
44
+ return key
45
+
46
+ def main():
47
+ files = sorted(os.listdir(ROOT))
48
+ schemas = [f for f in files if f.endswith(".xsd")]
49
+ insts = [f for f in files if f.endswith(".xml")]
50
+ groups = collections.defaultdict(lambda: ([], []))
51
+ for f in schemas:
52
+ k = group_key(f)
53
+ if k: groups[k][0].append(f)
54
+ for f in insts:
55
+ k = group_key(f)
56
+ if k: groups[k][1].append(f)
57
+
58
+ rows = []
59
+ decided = undecided = 0
60
+ for key in sorted(groups):
61
+ ss, xs = groups[key]
62
+ for s in sorted(ss):
63
+ schema_path = os.path.join(ROOT, s)
64
+ for x in sorted(xs):
65
+ v = oracle(schema_path, os.path.join(ROOT, x))
66
+ if v is None:
67
+ undecided += 1
68
+ continue
69
+ decided += 1
70
+ rows.append((x, s, v))
71
+
72
+ out = os.path.join(ROOT, "MANIFEST.tsv")
73
+ with open(out, "w") as fh:
74
+ fh.write("# XSD conformance manifest — differential oracle: %s\n"
75
+ % subprocess.run([ORACLE, "--version"], capture_output=True,
76
+ text=True).stderr.split()[3]
77
+ if False else
78
+ "# XSD conformance manifest — differential oracle: xmllint (libxml 2.9.13)\n")
79
+ fh.write("# instance\tschema\texpected\n")
80
+ for x, s, v in rows:
81
+ fh.write("%s\t%s\t%s\n" % (x, s, v))
82
+ print("decided: %d, undecided: %d -> %s" % (decided, undecided, out))
83
+ # distribution
84
+ from collections import Counter
85
+ print(Counter(v for _, _, v in rows))
86
+
87
+ if __name__ == "__main__":
88
+ main()
@@ -1924,6 +1924,50 @@ LEPTRIS_API const char* leptris_element_attribute_string(LeptrisElement elem, co
1924
1924
  */
1925
1925
  LEPTRIS_API size_t leptris_element_attribute_count(LeptrisElement elem);
1926
1926
 
1927
+ /**
1928
+ * ALL attribute names, values, and namespace data in ONE crossing
1929
+ * (leptris#1689 — the element-face sibling of the #1670 plan-value
1930
+ * snapshot; two-phase capacity/retry contract).
1931
+ *
1932
+ * Phase 1 (sizing): pass NULL for the names and values blobs — the
1933
+ * return value is the maximum byte capacity any single lane
1934
+ * requires (names, values, and, when requested, the ns lanes; every
1935
+ * lane sized to the returned capacity is always sufficient).
1936
+ * Buffers are untouched.
1937
+ *
1938
+ * Phase 2 (read): pass buffers of at least the returned capacity.
1939
+ * Returns 0 on success; (size_t)-1 when any PROVIDED buffer is
1940
+ * smaller than its lane requires (retry at the phase-1 capacity —
1941
+ * (size_t)-1 on an element whose attributes were mutated between
1942
+ * calls).
1943
+ *
1944
+ * Each lane is a NUL-terminated string blob with a parallel offset
1945
+ * array of attribute_count+1 entries: entry i is the byte offset of
1946
+ * attribute i's string, entry [attribute_count] is that lane's total
1947
+ * byte length. A lane is written only when its blob is non-NULL
1948
+ * (the ns lanes are optional — bindings that only need names/values
1949
+ * pass NULL for all four ns arguments).
1950
+ *
1951
+ * Namespace lanes: a no-namespace attribute records SIZE_MAX in its
1952
+ * prefix/uri offset slot and writes nothing to the blob. Prefixed
1953
+ * attributes carry the prefix as spelled and the URI resolved
1954
+ * through the element's in-scope declarations (the same semantics
1955
+ * as leptris_attribute_namespace_uri, #1664/#542).
1956
+ *
1957
+ * Names/values are the element's own strings (document-lifetime);
1958
+ * the snapshot copies them into the caller's buffers.
1959
+ *
1960
+ * @param elem Element (NULL returns 0)
1961
+ * @return 0 on success, required capacity when sizing, (size_t)-1
1962
+ * when a provided buffer is too small
1963
+ */
1964
+ LEPTRIS_API size_t leptris_element_attributes_snapshot(
1965
+ LeptrisElement elem,
1966
+ char* names, size_t names_cap, size_t* name_offsets,
1967
+ char* values, size_t values_cap, size_t* value_offsets,
1968
+ char* ns_prefixes, size_t prefixes_cap, size_t* prefix_offsets,
1969
+ char* ns_uris, size_t uris_cap, size_t* uri_offsets);
1970
+
1927
1971
  /**
1928
1972
  * Get name of attribute by index
1929
1973
  *
@@ -1,5 +1,6 @@
1
1
  #include "../memory/pool.h"
2
2
  #include "string_view.h"
3
+ #include <stdint.h>
3
4
  #include <string.h>
4
5
  #include <stdlib.h>
5
6
  #include <stdio.h>
@@ -133,15 +134,17 @@ int leptris_sv_equals_cstr(const LeptrisStringView* sv, const char* str) {
133
134
  size_t leptris_sv_hash(const LeptrisStringView* sv) {
134
135
  if (!sv || !sv->data) return 0;
135
136
 
136
- const size_t FNV_offset_basis = 14695981039346656037ULL;
137
- const size_t FNV_prime = 1099511628211ULL;
138
-
139
- size_t hash = FNV_offset_basis;
137
+ /* FNV-1a 64: the accumulator stays uint64_t — size_t is
138
+ * 32-bit on wasm32/ILP32, and truncating the basis/prime
139
+ * silently changes the algorithm. Fold once at the return. */
140
+ uint64_t hash = 14695981039346656037ULL;
141
+ const uint64_t FNV_prime = 1099511628211ULL;
140
142
  for (size_t i = 0; i < sv->length; i++) {
141
143
  hash ^= (unsigned char)sv->data[i];
142
144
  hash *= FNV_prime;
143
145
  }
144
- return hash;
146
+ hash ^= hash >> 32;
147
+ return (size_t)hash;
145
148
  }
146
149
 
147
150
  /* Convert to NULL-terminated C string (allocates!) */
@@ -43,11 +43,15 @@ typedef struct {
43
43
 
44
44
  static size_t index_key_hash(const char* s1, size_t l1,
45
45
  const char* s2, size_t l2) {
46
- size_t h = 1469598103934665603ull;
46
+ /* uint64 accumulator: size_t is 32-bit on wasm32/ILP32 and the
47
+ * 64-bit constants would truncate (the multiply lane collapses).
48
+ * Fold once at the return. */
49
+ uint64_t h = 1469598103934665603ull;
47
50
  for (size_t i = 0; i < l1; i++) { h ^= (unsigned char)s1[i]; h *= 1099511628211ull; }
48
51
  for (size_t i = 0; i < l2; i++) { h ^= (unsigned char)s2[i]; h *= 1099511628211ull; }
49
52
  h ^= l1; h *= 1099511628211ull;
50
- return h;
53
+ h ^= h >> 32;
54
+ return (size_t)h;
51
55
  }
52
56
 
53
57
  static void index_key_table_free(IndexKeyTable* t) {
@@ -1373,6 +1373,106 @@ LEPTRIS_API size_t leptris_element_attribute_count(LeptrisElement elem) {
1373
1373
  return elem->attr_count;
1374
1374
  }
1375
1375
 
1376
+ /* ---- #1689: element-attribute batch face --------------------------
1377
+ *
1378
+ * One crossing per element: names, values, and the optional ns
1379
+ * lanes come back as parallel NUL-terminated blobs with offset
1380
+ * arrays, sized by the two-phase contract (#1670 plan-value
1381
+ * template). Values ride leptris_attribute_get_value so the lazy
1382
+ * entity expansion applies exactly once; ns URIs ride the #1664
1383
+ * in-scope resolution. */
1384
+ LEPTRIS_API size_t leptris_element_attributes_snapshot(
1385
+ LeptrisElement elem,
1386
+ char* names, size_t names_cap, size_t* name_offsets,
1387
+ char* values, size_t values_cap, size_t* value_offsets,
1388
+ char* ns_prefixes, size_t prefixes_cap, size_t* prefix_offsets,
1389
+ char* ns_uris, size_t uris_cap, size_t* uri_offsets) {
1390
+ if (!elem) return 0;
1391
+
1392
+ size_t nneed = 0, vneed = 0, pneed = 0, uneed = 0;
1393
+ struct leptris_attribute* a;
1394
+ for (a = leptris_element_get_first_attribute(elem); a;
1395
+ a = leptris_attr_next(a)) {
1396
+ nneed += strlen(leptris_attribute_get_name((LeptrisAttribute)a)) + 1;
1397
+ vneed += strlen(leptris_attribute_get_value(elem,
1398
+ (LeptrisAttribute)a)) + 1;
1399
+ const char* p = leptris_attribute_prefix((LeptrisAttribute)a);
1400
+ const char* u = leptris_attribute_namespace_uri((LeptrisAttribute)a);
1401
+ if (p) pneed += strlen(p) + 1;
1402
+ if (u) uneed += strlen(u) + 1;
1403
+ }
1404
+ size_t need = nneed;
1405
+ if (vneed > need) need = vneed;
1406
+ if (pneed > need) need = pneed;
1407
+ if (uneed > need) need = uneed;
1408
+
1409
+ /* Phase 1 (sizing): the required lanes are NULL — report the
1410
+ * per-lane capacity and touch nothing. */
1411
+ if (!names || !names_cap || !values || !values_cap)
1412
+ return need;
1413
+ if (!name_offsets || !value_offsets)
1414
+ return (size_t)-1;
1415
+
1416
+ /* The ns lanes are independently optional; a provided lane must
1417
+ * have its offsets and fit its requirement. */
1418
+ int want_p = ns_prefixes && prefixes_cap;
1419
+ int want_u = ns_uris && uris_cap;
1420
+ if ((want_p && !prefix_offsets) || (want_u && !uri_offsets))
1421
+ return (size_t)-1;
1422
+ if (nneed > names_cap || vneed > values_cap)
1423
+ return (size_t)-1;
1424
+ if (want_p && pneed > prefixes_cap)
1425
+ return (size_t)-1;
1426
+ if (want_u && uneed > uris_cap)
1427
+ return (size_t)-1;
1428
+
1429
+ size_t count = elem->attr_count;
1430
+ size_t no = 0, vo = 0, po = 0, uo = 0, i = 0;
1431
+ for (a = leptris_element_get_first_attribute(elem); a;
1432
+ a = leptris_attr_next(a), i++) {
1433
+ const char* n = leptris_attribute_get_name((LeptrisAttribute)a);
1434
+ const char* v = leptris_attribute_get_value(elem,
1435
+ (LeptrisAttribute)a);
1436
+ size_t nl = strlen(n) + 1;
1437
+ size_t vl = strlen(v) + 1;
1438
+ name_offsets[i] = no;
1439
+ memcpy(names + no, n, nl);
1440
+ no += nl;
1441
+ value_offsets[i] = vo;
1442
+ memcpy(values + vo, v, vl);
1443
+ vo += vl;
1444
+ if (want_p) {
1445
+ const char* p = leptris_attribute_prefix((LeptrisAttribute)a);
1446
+ if (p) {
1447
+ size_t pl = strlen(p) + 1;
1448
+ prefix_offsets[i] = po;
1449
+ memcpy(ns_prefixes + po, p, pl);
1450
+ po += pl;
1451
+ } else {
1452
+ prefix_offsets[i] = (size_t)-1; /* no namespace */
1453
+ }
1454
+ }
1455
+ if (want_u) {
1456
+ const char* u =
1457
+ leptris_attribute_namespace_uri((LeptrisAttribute)a);
1458
+ if (u) {
1459
+ size_t ul = strlen(u) + 1;
1460
+ uri_offsets[i] = uo;
1461
+ memcpy(ns_uris + uo, u, ul);
1462
+ uo += ul;
1463
+ } else {
1464
+ uri_offsets[i] = (size_t)-1; /* no namespace */
1465
+ }
1466
+ }
1467
+ }
1468
+ name_offsets[count] = no;
1469
+ value_offsets[count] = vo;
1470
+ if (want_p) prefix_offsets[count] = po;
1471
+ if (want_u) uri_offsets[count] = uo;
1472
+ (void)i;
1473
+ return 0;
1474
+ }
1475
+
1376
1476
  /* Handle-based attribute iteration (TODO.remaining/06). The _at
1377
1477
  * accessors above re-walk the list from the head per call — index
1378
1478
  * iteration is O(n^2); the handle pair is O(n) total and gives
@@ -275,7 +275,7 @@ LEPTRIS_API LeptrisStatus leptris_document_set_root_ex(
275
275
  LeptrisElement* out_installed) {
276
276
  if (out_installed) *out_installed = NULL;
277
277
  if (!doc || !root) {
278
- leptris_set_error(LEPTRIS_ERROR_NULL_ARG,
278
+ leptris_set_error((leptris_error_code)LEPTRIS_ERROR_NULL_ARG,
279
279
  "set_root: NULL document or element");
280
280
  return LEPTRIS_ERROR_NULL_ARG;
281
281
  }
@@ -283,7 +283,7 @@ LEPTRIS_API LeptrisStatus leptris_document_set_root_ex(
283
283
  /* Already attached under a parent? (parent_off == 0 encodes NULL;
284
284
  * leptris_elem_parent is the static inline accessor from dom/element.h) */
285
285
  if (leptris_elem_parent(root)) {
286
- leptris_set_error(LEPTRIS_ERROR_INVALID_ARG,
286
+ leptris_set_error((leptris_error_code)LEPTRIS_ERROR_INVALID_ARG,
287
287
  "set_root: element is attached to a parent");
288
288
  return LEPTRIS_ERROR_INVALID_ARG;
289
289
  }
@@ -301,7 +301,7 @@ LEPTRIS_API LeptrisStatus leptris_document_set_root_ex(
301
301
  if (leptris_element_get_document(root) != doc) {
302
302
  LeptrisElement copy = leptris_element_copy(root, doc);
303
303
  if (!copy) {
304
- leptris_set_error(LEPTRIS_ERROR_MEMORY,
304
+ leptris_set_error((leptris_error_code)LEPTRIS_ERROR_MEMORY,
305
305
  "set_root: adoption copy failed");
306
306
  return LEPTRIS_ERROR_MEMORY;
307
307
  }
@@ -512,8 +512,8 @@ static size_t match_seq(RngVal* v, RngPattern* p, LeptrisNodeRef* kids,
512
512
  case RNG_REF: {
513
513
  RngDefine* d = find_define(v->g, p->name);
514
514
  if (!d || !d->body) {
515
- diag(v, LEPTRIS_DIAG_INVALID, NULL,
516
- "reference to undefined pattern", p->name, NULL);
515
+ diag(v, LEPTRIS_DIAG_INVALID, NULL,
516
+ "reference to undefined pattern '%s'", p->name);
517
517
  return (size_t)-1;
518
518
  }
519
519
  if (v->depth > 200) {
@@ -1854,9 +1854,9 @@ int rng_validate_document(struct leptris_relaxng* rng, LeptrisDocument doc) {
1854
1854
  RngDefine* d = find_define(v.g, start->name);
1855
1855
  if (!d || !d->body) {
1856
1856
  v.quiet = 0;
1857
- diag(&v, LEPTRIS_DIAG_INVALID, root,
1858
- "reference to undefined pattern",
1859
- start->name, NULL);
1857
+ diag(&v, LEPTRIS_DIAG_INVALID, root,
1858
+ "reference to undefined pattern '%s'",
1859
+ start->name);
1860
1860
  rng->error = leptris_strdup(v.err);
1861
1861
  return 0;
1862
1862
  }
@@ -1129,7 +1129,8 @@ LEPTRIS_API LeptrisSchematron leptris_schematron_parse_phase(
1129
1129
  &err);
1130
1130
  leptris_document_free(doc);
1131
1131
  if (!s) {
1132
- leptris_set_error(LEPTRIS_ERROR_PARSE, err ? err : "bad");
1132
+ leptris_set_error((leptris_error_code)LEPTRIS_ERROR_PARSE,
1133
+ err ? err : "bad");
1133
1134
  free(err);
1134
1135
  if (status) *status = LEPTRIS_ERROR_PARSE;
1135
1136
  return NULL;
@@ -904,8 +904,8 @@ struct leptris_xpath_result* evaluate_step(XPathContext* ctx,
904
904
  DEBUG_LOG(" Axis '%s' cannot operate on attribute nodes, skipping", axis_name);
905
905
  continue; /* Skip non-element nodes for other axes */
906
906
  }
907
- } else if (node_ptr && ((LeptrisNode*)node_ptr)->type ==
908
- LEPTRIS_NODE_NAMESPACE) {
907
+ } else if (node_ptr && (int)((LeptrisNode*)node_ptr)->type ==
908
+ (int)LEPTRIS_NODE_NAMESPACE) {
909
909
  /* Synthetic namespace nodes: parent/ancestor axes
910
910
  * resolve through the OWNER element (bug-63); self
911
911
  * is the ns node itself. */
@@ -769,7 +769,7 @@ struct leptris_xpath_result* vm_apply_axis_parent(XPathContext* ctx, XPathVM* vm
769
769
  for (size_t i = 0; i < input->count; i++) {
770
770
  LeptrisNode* in = input->nodes[i];
771
771
  LeptrisElement parent;
772
- if (in && in->type == LEPTRIS_NODE_NAMESPACE) {
772
+ if (in && (int)in->type == (int)LEPTRIS_NODE_NAMESPACE) {
773
773
  /* Namespace nodes' parent is the OWNER element (63). */
774
774
  parent = ((LeptrisNamespaceNode*)in)->owner;
775
775
  } else if (node_is_element(in)) {
@@ -89,7 +89,7 @@ LEPTRIS_API LeptrisXPathResult leptris_xpath_eval_versioned(
89
89
  if (version == LEPTRIS_XPATH_10 &&
90
90
  x10_has_3x_syntax(expression)) {
91
91
  leptris_set_error(
92
- LEPTRIS_ERROR_INVALID_ARG,
92
+ (leptris_error_code)LEPTRIS_ERROR_INVALID_ARG,
93
93
  "XPath 3.x syntax rejected in LEPTRIS_XPATH_10 mode");
94
94
  if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
95
95
  return NULL;
@@ -1133,7 +1133,8 @@ LEPTRIS_API LeptrisXPathResult leptris_xpath_compiled_eval_nodeset(
1133
1133
  struct leptris_xpath_result* r =
1134
1134
  leptris_xpath_compiled_eval(compiled, doc, contexts[i]);
1135
1135
  if (!r) continue;
1136
- if (r->type == LEPTRIS_XPATH_NODESET && r->value.nodeset_value) {
1136
+ if ((int)r->type == (int)LEPTRIS_XPATH_NODESET &&
1137
+ r->value.nodeset_value) {
1137
1138
  XPathNodeSet* ns = r->value.nodeset_value;
1138
1139
  for (size_t j = 0; j < ns->count; j++)
1139
1140
  xpath_nodeset_add(merged, ns->nodes[j]);