leptris 1.9.340.0-arm-linux → 1.9.341.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 +11 -0
  3. data/Rakefile +1 -1
  4. data/ext/leptris/native/native.c +18 -1
  5. data/lib/leptris/version.rb +1 -1
  6. data/lib/leptris/xml/descriptor.rb +39 -3
  7. data/lib/leptris/xml/element.rb +18 -7
  8. data/lib/leptris/xml/ffi.rb +20 -0
  9. data/lib/leptris/xml/native.so +0 -0
  10. data/lib/leptris/xml/node.rb +22 -0
  11. data/lib/libleptris.so +0 -0
  12. data/vendor-src/README.md +1 -1
  13. data/vendor-src/libleptris/CHANGELOG.md +49 -0
  14. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  15. data/vendor-src/libleptris/src/include/leptris/descriptor.h +27 -0
  16. data/vendor-src/libleptris/src/leptris/descriptor/plan.c +226 -12
  17. data/vendor-src/libleptris/src/leptris/serialize/serialize.c +38 -0
  18. data/vendor-src/libleptris/src/leptris/xsd/compile.c +79 -0
  19. data/vendor-src/libleptris/test/abi/test_descriptor.cpp +120 -0
  20. data/vendor-src/libleptris/test/dom/test_dom.cpp +77 -0
  21. data/vendor-src/libleptris/test/serializer/test_serialize.cpp +25 -0
  22. data/vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/a1.xsd +5 -0
  23. data/vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/a2.xsd +4 -0
  24. data/vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/b1.xsd +5 -0
  25. data/vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/b2.xsd +4 -0
  26. data/vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/s.xsd +3 -0
  27. data/vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/w.xsd +5 -0
  28. data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +15 -0
  29. data/vendor-src/libleptris/vcpkg.json +1 -1
  30. metadata +7 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d0e0d99be47e5b77f7b3d482d683d3e8247199258dd61ecaa733d4b25f54464
4
- data.tar.gz: 2d34476b27c4e6d026ddeab49c9f11dfb4c9f9efc2258ac1b305bacbe6f81cac
3
+ metadata.gz: 9bbbab612bfe67926410800b80e4cdb8d9f210c6f58414dfa08be812ec94bf23
4
+ data.tar.gz: c55050347c62887096b9c3d2f4b00ce7814f95a5bdb691c7424d8fc55372ea88
5
5
  SHA512:
6
- metadata.gz: 022ded1665d829afa6731228fc4ec892adc671789fd6fed3a8b42bba937fe0b8f891b3ace3a7a0ab52410d21f9935da523a0aa0a4d7ea17fff0a6712f1287e04
7
- data.tar.gz: d3ebeea50843ee2fcb31685aa21704fbfc20deb4e2bb2a7da85da5eace64bb38a2f63eba805ffb7fe8e5762350adb8a2183dc16061aaca9d6d54ac65a16ab29c
6
+ metadata.gz: 94b0121b2fc062f872c3a22b4173c2ceb18ffc8c894696b1e525d01b3acbe52f9813b0b4f4694126b849a731a20941a97378d8aae5e9c6e60636b5199a31110b
7
+ data.tar.gz: b1c925a2de51a17dc90da01ae36a957fc1b7252683a6ecff904dcf8f2791add34802980a23d6044c2473ae49dca30a3084bb5bebf8eff2d38960dde6ecbbfc63
data/CHANGELOG.md CHANGED
@@ -1165,6 +1165,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1165
1165
 
1166
1166
  ## [Unreleased]
1167
1167
 
1168
+ ## [1.9.341.0] - 2026-10-12
1169
+
1170
+ ### Changed
1171
+
1172
+ - **Ride libleptris v1.9.341** — XSD import-DAG dedup (the
1173
+ dml-main multi-GB/minutes compile fix, leptris#1644 /
1174
+ leptris-ruby#423), indent_html last-block-child nesting
1175
+ (leptris#1647), and the absorb/copy survival specs
1176
+ (leptris#1646).
1177
+
1178
+
1168
1179
  ### Added — Descriptor typed scalars + the fused materialize entry (#230's consumer contract)
1169
1180
 
1170
1181
  - **Typed scalars**: attribute and child plan rows accept
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.340"
11
+ LIBLEPTRIS_VERSION = "1.9.341"
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
@@ -56,6 +56,7 @@ typedef void *(*elem_new_attrs_fn)(void *, const char *, const char **,
56
56
  typedef void *(*text_create_fn)(void *, const char *);
57
57
  typedef void *(*create_child_fn)(void *, const char *);
58
58
  typedef int (*append_child_fn)(void *, void *);
59
+ typedef int (*append_child_installed_fn)(void *, void *, void **);
59
60
  typedef int (*set_attr_fn)(void *, const char *, const char *);
60
61
  typedef int (*set_root_fn)(void *, void *);
61
62
  typedef void (*doc_free_fn)(void *);
@@ -90,6 +91,7 @@ static elem_new_attrs_fn f_elem_new_with_attrs;
90
91
  static text_create_fn f_text_create;
91
92
  static create_child_fn f_create_child;
92
93
  static append_child_fn f_append_child;
94
+ static append_child_installed_fn f_append_child_installed;
93
95
  static append_child_fn f_prepend_child, f_insert_after, f_insert_before;
94
96
  typedef void *(*elem_new_attrs_fn)(void *, const char *, const char **,
95
97
  const char **, size_t);
@@ -241,6 +243,8 @@ static void resolve_symbols(const char *lib_path)
241
243
  f_text_create = (text_create_fn)lib_sym(h, "leptris_text_node_create");
242
244
  f_create_child = (create_child_fn)lib_sym(h, "leptris_element_create_child");
243
245
  f_append_child = (append_child_fn)lib_sym(h, "leptris_element_append_child");
246
+ f_append_child_installed = (append_child_installed_fn)lib_sym(
247
+ h, "leptris_element_add_child_addr_installed");
244
248
  f_prepend_child = (append_child_fn)lib_sym(h, "leptris_element_prepend_child");
245
249
  f_insert_after = (append_child_fn)lib_sym(h, "leptris_element_insert_after");
246
250
  f_insert_before = (append_child_fn)lib_sym(h, "leptris_element_insert_before");
@@ -789,9 +793,22 @@ static VALUE nf_append_binding_child(VALUE self, VALUE document,
789
793
  * mutation merely discards memos. */
790
794
  rb_ivar_set(document, id_iv_version,
791
795
  LONG2FIX(FIX2LONG(rb_ivar_get(document, id_iv_version)) + 1));
796
+ /* leptris#1636: cross-pool children are adopted by COPY inside
797
+ * the engine — return the INSTALLED address so the caller can
798
+ * rebase its wrapper. 0 means the move was by reference; the
799
+ * argument address stays valid. The twin reads element-form
800
+ * fields on the child (get_document misreads non-element
801
+ * structs), so text/comment/PI children keep the legacy face. */
802
+ if (f_append_child_installed &&
803
+ f_node_type(child) == NT_ELEMENT) {
804
+ void *installed = NULL;
805
+ st = f_append_child_installed(parent, child, &installed);
806
+ check_status_c(st);
807
+ return ULL2NUM((unsigned long long)(uintptr_t)installed);
808
+ }
792
809
  st = f_append_child(parent, child);
793
810
  check_status_c(st);
794
- return Qtrue;
811
+ return ULL2NUM(0);
795
812
  }
796
813
 
797
814
  /* Batch append (leptris-ruby#366): one crossing for N children.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.9.340.0"
4
+ VERSION = "1.9.341.0"
5
5
  end
@@ -410,11 +410,28 @@ class Leptris::XML::Descriptor
410
410
  # declared exactly once, on the output root, first-encounter
411
411
  # order. Text and attribute values are escaped; RAW members are
412
412
  # verbatim.
413
- def serialize(plan_value)
413
+ def serialize(plan_value, indent: 0, indent_unit: nil)
414
414
  result_ptr = plan_value.result_ptr
415
415
  status = ::FFI::MemoryPointer.new(:int)
416
- raw = Leptris::XML::FFI.leptris_plan_serialize(
417
- @handle, result_ptr, status)
416
+ raw =
417
+ if indent.to_i > 0
418
+ # libleptris 1.9.341 (leptris-ruby#425): the ext face owns
419
+ # the formatting; the optionless call keeps the compact
420
+ # historical shape.
421
+ opts = Leptris::XML::FFI::PlanSerializeOptions.new
422
+ opts[:indent] = indent.to_i
423
+ unit_anchor = nil
424
+ if indent_unit
425
+ unit_anchor = ::FFI::MemoryPointer.from_string(indent_unit.to_s)
426
+ opts[:indent_unit] = unit_anchor
427
+ end
428
+ Leptris::XML::FFI.leptris_plan_serialize_ext(
429
+ @handle, result_ptr, opts,
430
+ Leptris::XML::FFI::PlanSerializeOptions.size, status)
431
+ else
432
+ Leptris::XML::FFI.leptris_plan_serialize(
433
+ @handle, result_ptr, status)
434
+ end
418
435
  if raw.null?
419
436
  raise Leptris::XML::Error,
420
437
  "plan serialize failed (status=#{status.read_int})"
@@ -422,6 +439,25 @@ class Leptris::XML::Descriptor
422
439
  Leptris::XML::FFI.read_owned_string(raw)
423
440
  end
424
441
 
442
+ # libleptris 1.9.341 (leptris-ruby#426): install a built result
443
+ # as a native document tree — build_result -> this -> the
444
+ # document writer, with no string round trip. Attributes carry
445
+ # verbatim (wire spellings); root namespace declarations ride as
446
+ # xmlns attributes. Only an ELEMENT root is accepted. The
447
+ # returned document owns its pool (GC/freed like any parsed
448
+ # document).
449
+ def to_document(plan_value)
450
+ result_ptr = plan_value.result_ptr
451
+ status = ::FFI::MemoryPointer.new(:int)
452
+ raw = Leptris::XML::FFI.leptris_document_from_plan_result(
453
+ @handle, result_ptr, status)
454
+ if raw.null?
455
+ raise Leptris::XML::Error,
456
+ "document from plan result failed (status=#{status.read_int})"
457
+ end
458
+ Leptris::XML::Document.wrap(raw)
459
+ end
460
+
425
461
  # The fused loop (#1269b): source bytes → typed rows in ONE C
426
462
  # call — leptris_plan_materialize runs parse, walk, and free
427
463
  # natively; the returned PlanValue tree is standalone and the
@@ -696,9 +696,16 @@ class Leptris::XML::Element < Leptris::XML::Node
696
696
  # C-side version bump invalidates this document's memos.
697
697
  if native_fast_children?
698
698
  # The face raises on failure (TODO.perf/36); Qnil = the
699
- # child needs the lift — the full path handles it.
700
- unless Leptris::XML::Native.append_binding_child(
701
- @document, @c_address, node_or_markup.c_address).nil?
699
+ # child needs the lift — the full path handles it. The
700
+ # return is the INSTALLED address (leptris#1636): the
701
+ # engine adopts cross-pool children by copy, and the
702
+ # wrapper must follow the installed node or it addresses
703
+ # the foreign original, freed with its source document.
704
+ installed = Leptris::XML::Native.append_binding_child(
705
+ @document, @c_address, node_or_markup.c_address)
706
+ unless installed.nil?
707
+ Leptris::XML::Node.rebase_installed!(node_or_markup,
708
+ installed, @document)
702
709
  return node_or_markup
703
710
  end
704
711
  end
@@ -706,11 +713,15 @@ class Leptris::XML::Element < Leptris::XML::Node
706
713
  unless Leptris::XML::Element.skip_adoption_lift?(node_or_markup)
707
714
  Leptris::XML::Element.lift_namespaces_for_adoption(node_or_markup, namespaces)
708
715
  end
709
- # Address-based attach (#408): same status contract, no
710
- # FFI::Pointer mint for either side.
716
+ # Address-based attach (#408 + leptris#1636): the installed
717
+ # twin returns the adopted address — rebase the wrapper when
718
+ # the engine copied the child out of its pool.
719
+ installed_out = ::FFI::MemoryPointer.new(:uint64)
711
720
  Leptris::XML::FFI.check_status(
712
- Leptris::XML::FFI.leptris_element_add_child_addr(
713
- @c_address, node_or_markup.c_address))
721
+ Leptris::XML::FFI.leptris_element_add_child_addr_installed(
722
+ @c_address, node_or_markup.c_address, installed_out))
723
+ Leptris::XML::Node.rebase_installed!(
724
+ node_or_markup, installed_out.read_uint64, @document)
714
725
  node_or_markup
715
726
  when String
716
727
  # TODO.perf/34: one dispatch parses the markup and appends
@@ -449,6 +449,26 @@ module Leptris
449
449
  # content. Caller-freed string (leptris_free_string).
450
450
  attach_function :leptris_plan_serialize,
451
451
  [:leptris_plan, :leptris_plan_result, :pointer], :pointer
452
+ # libleptris 1.9.341 (leptris-ruby#425): formatting-bearing
453
+ # plan serialization. Zero-init = the compact historical
454
+ # form; indent > 0 pretty-prints element boundaries (one
455
+ # newline + indent per level, RAW/CONTENT runs verbatim
456
+ # inline); indent_unit replaces the two-space default
457
+ # (requires indent > 0). options NULL is the compact form;
458
+ # opts_size must cover the struct as compiled here.
459
+ class PlanSerializeOptions < ::FFI::Struct
460
+ layout :indent, :int,
461
+ :indent_unit, :pointer
462
+ end
463
+ attach_function :leptris_plan_serialize_ext,
464
+ [:leptris_plan, :leptris_plan_result, :pointer, :size_t,
465
+ :pointer], :pointer
466
+ # libleptris 1.9.341 (leptris-ruby#426): materialize a built
467
+ # result as a native document tree — build_result -> this ->
468
+ # the document writer, no string round trip. Only an ELEMENT
469
+ # root is accepted.
470
+ attach_function :leptris_document_from_plan_result,
471
+ [:leptris_plan, :leptris_plan_result, :pointer], :pointer
452
472
  attach_function :leptris_plan_value_kind,
453
473
  [:leptris_plan_result], :int
454
474
  attach_function :leptris_plan_value_name,
Binary file
@@ -255,6 +255,28 @@ class Leptris::XML::Node
255
255
  # structural stamps (stamped against the SOURCE version) and the
256
256
  # source document's sibling/parent stamps. Scope-owned nodes
257
257
  # answer nil from #document and never memoize — nothing to do.
258
+ # leptris#1636: after an address-based attach the engine may have
259
+ # adopted a cross-pool child BY COPY — the wrapper must follow the
260
+ # installed node, or it addresses the foreign original, freed with
261
+ # its source document (the Windows SEGV in fast_element_xml).
262
+ def self.rebase_installed!(node, installed_address, target_document)
263
+ return if installed_address.nil? || installed_address.zero? ||
264
+ installed_address == node.c_address
265
+ node.rebase_to(installed_address, target_document)
266
+ end
267
+
268
+ # Point the wrapper at a different native node and forget every
269
+ # memo derived from the old one. The owning document follows
270
+ # +new_document+ (post-adoption, the node lives in the target).
271
+ def rebase_to(installed_address, new_document)
272
+ @c_address = installed_address
273
+ @c_ptr = nil
274
+ invalidate_structural_stamps!
275
+ @document = new_document
276
+ @pub_document = new_document
277
+ nil
278
+ end
279
+
258
280
  def self.invalidate_cross_document!(node, target_document)
259
281
  source = node.document
260
282
  return if source.nil? || source.equal?(target_document)
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.340
4
+ - libleptris v1.9.341
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand:
@@ -1,5 +1,54 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.341] - 2026-10-11
4
+
5
+ ### Fixed
6
+
7
+ - **XSD compilation of large multi-import schemas (leptris#1644,
8
+ leptris-ruby#423).** `xsd_capture_root` recursed into
9
+ `xs:include`/`xs:import`/`xs:redefine` with no visited set —
10
+ `include_depth<16` bounds depth only, so a dense import DAG (every
11
+ OOXML schema family) was re-parsed and re-captured along every
12
+ path through the graph. dml-main.xsd (155 KB): >300s / 3.5GB+
13
+ timeout -> **0.0s / 8MB**; the "per-compile accumulation" (6.7GB
14
+ across sequential compiles) was allocator survival of that blowup —
15
+ now a 12MB plateau returned fully after each free. Each unique
16
+ schema unit is captured exactly once (lexically normalized path
17
+ key, marked before recursing so cycles close). Red-first spec
18
+ `ImportDagCapturesEachUnitOnce` (6-file DAG fixture).
19
+ - **`indent_html`: a LAST block child now nests (leptris#1647).**
20
+ The single-child inline rule set `mixed=1`, which the layout
21
+ machinery inherits down the subtree — a trailing block child
22
+ (body > div > p+span) glued to its parent's tag and its own
23
+ children fell flat. indent_html-only refinement
24
+ (`html_block_child_needs_lines`): a block parent whose single
25
+ child is itself a line-taking block breaks before its children
26
+ and before its close tag; `head>title` stays inline; the legacy
27
+ 16.2 byte shape is untouched.
28
+
29
+ ### Added
30
+
31
+ - **`leptris_plan_serialize_ext` (#425, leptris-ruby#425)**:
32
+ formatting-bearing plan serialization — `indent` (+ optional
33
+ `indent_unit`) pretty-prints element boundaries; RAW/CONTENT
34
+ runs stay verbatim inline (the byte-exact mixed-content rule).
35
+ The 3-arg face is the compact default, unchanged. Options ride
36
+ the growable size-tagged struct pattern (#129).
37
+ - **`leptris_document_from_plan_result` (#426,
38
+ leptris-ruby#426)**: materialize a built result as a native
39
+ document tree — build_result → this → the document writer, no
40
+ string round trip. Attributes verbatim, #1626 root declarations
41
+ as xmlns attributes, op-order member emission (#1625's rank)
42
+ preserved; non-ELEMENT roots rejected.
43
+ - **Absorb/copy attach survival specs (leptris#1646)**: both C-level
44
+ attach shapes (absorb-move and adopt-by-copy) pinned as
45
+ `DomAbsorbSurvival.*` with post-free reads of names, text,
46
+ attributes, and the expanded-QName prefix/URI views — the engine
47
+ is ASAN-clean on both; the residual dangling is binding-side
48
+ (leptris-ruby#1636's wrapper rebase, landed on the binding).
49
+
50
+ ## [Unreleased]
51
+
3
52
  ## [1.9.340] - 2026-10-11
4
53
 
5
54
  ### Added
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(leptris
6
- VERSION 1.9.340
6
+ VERSION 1.9.341
7
7
  DESCRIPTION "Fast XML parser and XPath evaluator in pure C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -303,6 +303,33 @@ LEPTRIS_API char* leptris_plan_serialize(LeptrisPlan plan,
303
303
  const LeptrisPlanResult result,
304
304
  LeptrisStatus* status);
305
305
 
306
+ /* #425: formatting-bearing plan serialization (leptris-ruby#425).
307
+ * Zero-initialize; every field defaults to the compact historical
308
+ * form. indent > 0 pretty-prints element boundaries (one newline
309
+ * + indent per level; RAW/CONTENT runs stay verbatim inline);
310
+ * indent_unit replaces the two-space default per level.
311
+ * options NULL = the compact form. opts_size must cover the
312
+ * struct as compiled by the caller (growable, #129 pattern). */
313
+ typedef struct {
314
+ int indent; /* spaces per level; 0 = compact */
315
+ const char* indent_unit; /* NULL = spaces; requires indent > 0 */
316
+ } leptris_plan_serialize_options;
317
+
318
+ LEPTRIS_API char* leptris_plan_serialize_ext(
319
+ LeptrisPlan plan, const LeptrisPlanResult result,
320
+ const leptris_plan_serialize_options* options, size_t options_size,
321
+ LeptrisStatus* status);
322
+
323
+ /* #426 (leptris-ruby#426): materialize a built result as a native
324
+ * document tree — build_result -> this -> the document writer,
325
+ * with no string round trip. Attributes carry verbatim (wire
326
+ * spellings); root namespace declarations ride as xmlns
327
+ * attributes. Only an ELEMENT root is accepted. Caller frees with
328
+ * leptris_document_free. */
329
+ LEPTRIS_API LeptrisDocument leptris_document_from_plan_result(
330
+ LeptrisPlan plan, const LeptrisPlanResult result,
331
+ LeptrisStatus* status);
332
+
306
333
  /* ---- Result accessors (NULL-tolerant: NULL in, 0/NULL out) ------- */
307
334
 
308
335
  LEPTRIS_API LeptrisPlanValueKind leptris_plan_value_kind(const LeptrisPlanResult v);
@@ -1384,14 +1384,40 @@ static int dp_emit_element_open(const struct leptris_plan_result* v,
1384
1384
  return 1;
1385
1385
  }
1386
1386
 
1387
+ /* #425: plan-serialize formatting — depth-tracked indent for
1388
+ * element boundaries. NULL fmt = the compact historical form.
1389
+ * RAW/CONTENT runs stay verbatim inline (the byte-exact
1390
+ * mixed-content rule, #534 discipline): a subtree with any
1391
+ * non-element kid is emitted compact as a whole. */
1392
+ typedef struct {
1393
+ int indent; /* spaces per level; 0 = compact */
1394
+ const char* unit; /* NULL = spaces */
1395
+ } dp_fmt;
1396
+
1397
+ static int dp_sb_indent_newline(dp_sb* b, const dp_fmt* fmt, int depth) {
1398
+ if (!dp_sb_putn(b, "\n", 1)) return 0;
1399
+ /* One unit (or one indent-step of spaces) PER LEVEL. */
1400
+ if (fmt->unit) {
1401
+ size_t ul = strlen(fmt->unit);
1402
+ for (int i = 0; i < depth; i++)
1403
+ if (!dp_sb_putn(b, fmt->unit, ul)) return 0;
1404
+ return 1;
1405
+ }
1406
+ for (int i = 0; i < depth * fmt->indent; i++)
1407
+ if (!dp_sb_putn(b, " ", 1)) return 0;
1408
+ return 1;
1409
+ }
1410
+
1387
1411
  static int dp_emit_value(const struct leptris_plan_result* v,
1388
1412
  const dp_plan* container, const LeptrisPlan pool,
1389
- dp_sb* b, const dp_decls* decls, int is_root);
1413
+ dp_sb* b, const dp_decls* decls, int is_root,
1414
+ const dp_fmt* fmt, int depth);
1390
1415
 
1391
1416
  static int dp_emit_element(const struct leptris_plan_result* v,
1392
1417
  const char* name, const LeptrisPlan pool,
1393
1418
  const dp_plan* kids_container, dp_sb* b,
1394
- const dp_decls* decls, int is_root) {
1419
+ const dp_decls* decls, int is_root,
1420
+ const dp_fmt* fmt, int depth) {
1395
1421
  if (!dp_emit_element_open(v, name, b, decls, is_root)) return 0;
1396
1422
  const struct leptris_plan_result** kids = NULL;
1397
1423
  size_t nk = 0, cap = 0;
@@ -1408,23 +1434,38 @@ static int dp_emit_element(const struct leptris_plan_result* v,
1408
1434
  return 0;
1409
1435
  }
1410
1436
  qsort((void*)kids, nk, sizeof(*kids), dp_kid_pos_cmp);
1437
+ int indent_kids = fmt && fmt->indent > 0;
1438
+ for (size_t i = 0; i < nk && indent_kids; i++)
1439
+ if (kids[i]->kind == LEPTRIS_PLAN_VALUE_RAW)
1440
+ indent_kids = 0;
1411
1441
  /* #1565: kid ROWS live in the plan that WALKED this element —
1412
1442
  * container_plan is the plan whose row CAPTURED it (the
1413
1443
  * parent), so a nested member resolved its kids' rows against
1414
1444
  * the parent's rows and a CONTENT row serialized as an
1415
1445
  * empty-named wrapper. */
1416
1446
  int ok = 1;
1417
- for (size_t i = 0; i < nk && ok; i++)
1418
- ok = dp_emit_value(kids[i], kids_container, pool, b, NULL, 0);
1447
+ for (size_t i = 0; i < nk && ok; i++) {
1448
+ if (indent_kids && !dp_sb_indent_newline(b, fmt, depth + 1)) {
1449
+ ok = 0;
1450
+ break;
1451
+ }
1452
+ ok = dp_emit_value(kids[i], kids_container, pool, b, NULL, 0,
1453
+ fmt, indent_kids ? depth + 1 : depth);
1454
+ }
1419
1455
  free((void*)kids);
1420
1456
  if (!ok) return 0;
1421
- return dp_sb_puts(b, "</") && dp_sb_puts(b, name) &&
1422
- dp_sb_putn(b, ">", 1);
1457
+ if (indent_kids && !dp_sb_indent_newline(b, fmt, depth)) return 0;
1458
+ ok = dp_sb_puts(b, "</") && dp_sb_puts(b, name) &&
1459
+ dp_sb_putn(b, ">", 1);
1460
+ if (ok && is_root && fmt && fmt->indent > 0)
1461
+ ok = dp_sb_putn(b, "\n", 1);
1462
+ return ok;
1423
1463
  }
1424
1464
 
1425
1465
  static int dp_emit_value(const struct leptris_plan_result* v,
1426
1466
  const dp_plan* container, const LeptrisPlan pool,
1427
- dp_sb* b, const dp_decls* decls, int is_root) {
1467
+ dp_sb* b, const dp_decls* decls, int is_root,
1468
+ const dp_fmt* fmt, int depth) {
1428
1469
  if (v->kind == LEPTRIS_PLAN_VALUE_RAW)
1429
1470
  return dp_sb_puts(b, v->str ? v->str : "");
1430
1471
  if (v->kind == LEPTRIS_PLAN_VALUE_ELEMENT) {
@@ -1475,7 +1516,7 @@ static int dp_emit_value(const struct leptris_plan_result* v,
1475
1516
  &poolp->plans[cap->child_plan_index];
1476
1517
  }
1477
1518
  int ok = dp_emit_element(v, name, pool, kids_container, b,
1478
- decls, is_root);
1519
+ decls, is_root, fmt, depth);
1479
1520
  free(name);
1480
1521
  return ok;
1481
1522
  }
@@ -1500,9 +1541,9 @@ static int dp_emit_value(const struct leptris_plan_result* v,
1500
1541
  return dp_sb_escape(b, text, 0);
1501
1542
  }
1502
1543
 
1503
- LEPTRIS_API char* leptris_plan_serialize(LeptrisPlan plan,
1504
- const LeptrisPlanResult result,
1505
- LeptrisStatus* status) {
1544
+ static char* dp_serialize_impl(LeptrisPlan plan,
1545
+ const LeptrisPlanResult result,
1546
+ const dp_fmt* fmt, LeptrisStatus* status) {
1506
1547
  if (status) *status = LEPTRIS_OK;
1507
1548
  if (!plan || !result) {
1508
1549
  if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
@@ -1518,7 +1559,7 @@ LEPTRIS_API char* leptris_plan_serialize(LeptrisPlan plan,
1518
1559
  }
1519
1560
  dp_sb b = {0};
1520
1561
  int ok = dp_emit_value(rv, NULL, (const LeptrisPlan)plan, &b,
1521
- &decls, 1);
1562
+ &decls, 1, fmt, 0);
1522
1563
  dp_decls_free(&decls);
1523
1564
  if (!ok) {
1524
1565
  free(b.s);
@@ -1535,6 +1576,179 @@ LEPTRIS_API char* leptris_plan_serialize(LeptrisPlan plan,
1535
1576
  return b.s;
1536
1577
  }
1537
1578
 
1579
+ LEPTRIS_API char* leptris_plan_serialize(LeptrisPlan plan,
1580
+ const LeptrisPlanResult result,
1581
+ LeptrisStatus* status) {
1582
+ return dp_serialize_impl(plan, result, NULL, status);
1583
+ }
1584
+
1585
+ /* #425: formatting-bearing variant — indent > 0 pretty-prints
1586
+ * element boundaries (RAW/CONTENT runs stay verbatim inline);
1587
+ * indent_unit replaces the two-space default per level. options
1588
+ * NULL = the compact historical form. opts_size must cover the
1589
+ * struct the caller compiled against (growable, #129 pattern). */
1590
+ LEPTRIS_API char* leptris_plan_serialize_ext(
1591
+ LeptrisPlan plan, const LeptrisPlanResult result,
1592
+ const leptris_plan_serialize_options* options, size_t options_size,
1593
+ LeptrisStatus* status) {
1594
+ if (status) *status = LEPTRIS_OK;
1595
+ if (options && options_size < sizeof(*options)) {
1596
+ if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
1597
+ return NULL;
1598
+ }
1599
+ dp_fmt fmt;
1600
+ memset(&fmt, 0, sizeof(fmt));
1601
+ if (options) {
1602
+ fmt.indent = options->indent;
1603
+ fmt.unit = options->indent_unit;
1604
+ }
1605
+ return dp_serialize_impl(plan, result, &fmt, status);
1606
+ }
1607
+
1608
+ /* #426: materialize a built result as a native document tree —
1609
+ * the consumer path becomes build_result -> this -> the document
1610
+ * writer, with no string round trip. Attributes carry verbatim
1611
+ * (wire spellings); the #1626 root declarations ride as xmlns
1612
+ * attributes. Caller frees with leptris_document_free. */
1613
+ static LeptrisElement dp_mint_element(LeptrisDocument doc,
1614
+ const struct leptris_plan_result* v,
1615
+ const dp_plan* container,
1616
+ const LeptrisPlan pool);
1617
+
1618
+ static int dp_mint_kids(LeptrisDocument doc, LeptrisElement parent,
1619
+ const struct leptris_plan_result* v,
1620
+ const dp_plan* kids_container,
1621
+ const LeptrisPlan pool) {
1622
+ const struct leptris_plan_result** kids = NULL;
1623
+ size_t nk = 0, cap = 0;
1624
+ if (!dp_flatten_kids(v, &kids, &nk, &cap)) {
1625
+ free((void*)kids);
1626
+ return 0;
1627
+ }
1628
+ qsort((void*)kids, nk, sizeof(*kids), dp_kid_pos_cmp);
1629
+ int ok = 1;
1630
+ for (size_t i = 0; i < nk && ok; i++) {
1631
+ const struct leptris_plan_result* k = kids[i];
1632
+ if (k->kind == LEPTRIS_PLAN_VALUE_ELEMENT) {
1633
+ LeptrisElement el =
1634
+ dp_mint_element(doc, k, kids_container, pool);
1635
+ if (!el) {
1636
+ ok = 0;
1637
+ break;
1638
+ }
1639
+ ok = leptris_element_append_child(parent, el) == LEPTRIS_OK;
1640
+ } else if (k->kind == LEPTRIS_PLAN_VALUE_RAW ||
1641
+ (kids_container && k->row_index != UINT32_MAX &&
1642
+ k->row_index < kids_container->child_count &&
1643
+ kids_container->child_plans[k->row_index].kind ==
1644
+ LEPTRIS_PLAN_KIND_CONTENT)) {
1645
+ LeptrisNodeRef t =
1646
+ leptris_text_node_create(doc, k->str ? k->str : "");
1647
+ ok = t && leptris_element_append_child(
1648
+ parent, (LeptrisElement)t) == LEPTRIS_OK;
1649
+ } else {
1650
+ char* name = dp_wrapper_name(k);
1651
+ if (!name) {
1652
+ ok = 0;
1653
+ break;
1654
+ }
1655
+ LeptrisElement w = leptris_element_new_with_attributes(
1656
+ doc, name, NULL, NULL, 0);
1657
+ free(name);
1658
+ if (!w) {
1659
+ ok = 0;
1660
+ break;
1661
+ }
1662
+ ok = leptris_element_set_text(w, k->str ? k->str : "") ==
1663
+ LEPTRIS_OK &&
1664
+ leptris_element_append_child(parent, w) == LEPTRIS_OK;
1665
+ }
1666
+ }
1667
+ free((void*)kids);
1668
+ return ok;
1669
+ }
1670
+
1671
+ static LeptrisElement dp_mint_element(LeptrisDocument doc,
1672
+ const struct leptris_plan_result* v,
1673
+ const dp_plan* container,
1674
+ const LeptrisPlan pool) {
1675
+ /* Name/kids resolution mirrors dp_emit_value. */
1676
+ const struct leptris_plan* poolp = (const struct leptris_plan*)pool;
1677
+ const dp_plan* self = &poolp->plans[v->container_plan];
1678
+ const char* local = NULL;
1679
+ if (v->name) {
1680
+ const char* colon = strchr(v->name, ':');
1681
+ local = colon ? colon + 1 : v->name;
1682
+ } else {
1683
+ local = self->element_name;
1684
+ }
1685
+ char* name = v->ns_prefix
1686
+ ? dp_join_colon(v->ns_prefix, local ? local : "")
1687
+ : dp_strdup(local ? local : "");
1688
+ if (!name) return NULL;
1689
+ LeptrisElement el = leptris_element_new_with_attributes(
1690
+ doc, name, v->attr_names, v->attr_values, v->attr_count);
1691
+ free(name);
1692
+ if (!el) return NULL;
1693
+ const dp_plan* kids_container = &poolp->plans[v->container_plan];
1694
+ if (container && v->row_index != UINT32_MAX &&
1695
+ v->row_index < container->child_count) {
1696
+ const leptris_child_plan* cap =
1697
+ &container->child_plans[v->row_index];
1698
+ if (cap->child_plan_index >= 0 &&
1699
+ (uint32_t)cap->child_plan_index < poolp->plan_count)
1700
+ kids_container = &poolp->plans[cap->child_plan_index];
1701
+ }
1702
+ if (!dp_mint_kids(doc, el, v, kids_container, pool)) return NULL;
1703
+ return el;
1704
+ }
1705
+
1706
+ LEPTRIS_API LeptrisDocument leptris_document_from_plan_result(
1707
+ LeptrisPlan plan, const LeptrisPlanResult result,
1708
+ LeptrisStatus* status) {
1709
+ if (status) *status = LEPTRIS_OK;
1710
+ if (!plan || !result) {
1711
+ if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
1712
+ return NULL;
1713
+ }
1714
+ const struct leptris_plan_result* rv =
1715
+ (const struct leptris_plan_result*)result;
1716
+ if (rv->kind != LEPTRIS_PLAN_VALUE_ELEMENT) {
1717
+ if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
1718
+ return NULL;
1719
+ }
1720
+ LeptrisDocument doc = leptris_document_create();
1721
+ if (!doc) {
1722
+ if (status) *status = LEPTRIS_ERROR_MEMORY;
1723
+ return NULL;
1724
+ }
1725
+ dp_decls decls = {0};
1726
+ int ok = dp_collect_decls(rv, &decls);
1727
+ LeptrisElement root = NULL;
1728
+ if (ok) {
1729
+ root = dp_mint_element(doc, rv, NULL, (const LeptrisPlan)plan);
1730
+ ok = root != NULL;
1731
+ }
1732
+ for (size_t i = 0; ok && i < decls.n; i++) {
1733
+ char* dn = dp_join_colon("xmlns", decls.p[i]);
1734
+ if (!dn) {
1735
+ ok = 0;
1736
+ break;
1737
+ }
1738
+ ok = leptris_element_set_attribute(root, dn, decls.u[i]) ==
1739
+ LEPTRIS_OK;
1740
+ free(dn);
1741
+ }
1742
+ if (ok) ok = leptris_document_set_root(doc, root) == LEPTRIS_OK;
1743
+ dp_decls_free(&decls);
1744
+ if (!ok) {
1745
+ leptris_document_free(doc);
1746
+ if (status) *status = LEPTRIS_ERROR_MEMORY;
1747
+ return NULL;
1748
+ }
1749
+ return doc;
1750
+ }
1751
+
1538
1752
  LEPTRIS_API LeptrisPlanResult leptris_plan_result_build(
1539
1753
  LeptrisPlan plan, const leptris_plan_row_op* ops, size_t count,
1540
1754
  LeptrisStatus* status) {
@@ -595,6 +595,39 @@ static int html_break_after_elem(LeptrisElement elem,
595
595
  return 1;
596
596
  }
597
597
 
598
+ /* leptris#1647 (indent_html only): a block element whose SINGLE
599
+ * child is itself a block keeps the line layout — the child's own
600
+ * block content must not glue to the parent's tag (and the parent
601
+ * must not poison the subtree with mixed=1). The legacy §16.2
602
+ * shape is untouched: its site rules stay inline for a single
603
+ * child. p* parents stay inline (site-rule parity). */
604
+ static int html_block_child_needs_lines(LeptrisElement elem,
605
+ const char* name, size_t len,
606
+ int flags) {
607
+ if (!html_breaks_block(name, len, flags)) return 0;
608
+ if (name[0] == 'p') return 0;
609
+ LeptrisNode* c =
610
+ leptris_node_first_child_internal((LeptrisNode*)elem);
611
+ if (!c || leptris_node_get_next_sibling(c)) return 0;
612
+ if (c->type != LEPTRIS_NODE_TYPE_ELEMENT) return 0;
613
+ /* The child must itself take the line layout: it breaks its own
614
+ * children (site 1), or it nests a further element. A block
615
+ * whose only child is text (head>title) stays inline. */
616
+ {
617
+ LeptrisElement ce = (LeptrisElement)c;
618
+ const char* cn = elem_name(ce);
619
+ size_t cnl = (ce->name_len != 0xFF) ? (size_t)ce->name_len
620
+ : strlen(cn);
621
+ if (html_break_before_children(ce, cn, cnl,
622
+ html_elem_sem_flags(ce)))
623
+ return 1;
624
+ for (LeptrisNode* g = leptris_node_first_child_internal(c); g;
625
+ g = leptris_node_get_next_sibling(g))
626
+ if (g->type == LEPTRIS_NODE_TYPE_ELEMENT) return 1;
627
+ }
628
+ return 0;
629
+ }
630
+
598
631
  /* Emit the CDATA BODY, splitting "]]>" across section closes. The
599
632
  * caller owns the surrounding <![CDATA[ / ]]> brackets (run merging).
600
633
  * The close scan runs to len-3 INCLUSIVE — a "]]>" at the very END
@@ -1639,6 +1672,8 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
1639
1672
  * the newlines. Elements that keep their children
1640
1673
  * inline (single-child rule) own no whitespace. */
1641
1674
  int brk_bc = html_break_before_children(e, name, nl, hf);
1675
+ if (!brk_bc)
1676
+ brk_bc = html_block_child_needs_lines(e, name, nl, hf);
1642
1677
  if (brk_bc) {
1643
1678
  mixed = buf->ws_mixed
1644
1679
  ? ser_children_have_any_text(fc)
@@ -1650,6 +1685,9 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
1650
1685
  if (brk_bc) buffer_append_newline(buf);
1651
1686
  }
1652
1687
  close_brk = html_break_before_close(e, name, nl, hf);
1688
+ if (!close_brk && buf->indent_html)
1689
+ close_brk =
1690
+ html_block_child_needs_lines(e, name, nl, hf);
1653
1691
  } else {
1654
1692
  /* #129 indent_text: the formatter owns ALL whitespace —
1655
1693
  * no element is "mixed" for layout purposes. */
@@ -46,6 +46,12 @@ struct leptris_xsd_schema {
46
46
  int version_11; /* xs:schema @version = "1.1" */
47
47
  char* base_dir; /* schemaLocation resolution (file compile) */
48
48
  int include_depth; /* include/import recursion guard */
49
+ /* leptris#1644: already-captured schema units (canonical
50
+ * location per entry) — the include/import DAG is dense and
51
+ * cyclic; without this set every DAG path re-parses and
52
+ * re-captures the whole subtree (multi-GB / minutes). */
53
+ char** visited;
54
+ size_t visited_len, visited_cap;
49
55
  void* validator; /* slice-4 parked error list */
50
56
  char* error;
51
57
  };
@@ -688,6 +694,70 @@ fail:
688
694
  * the owning schema's base_dir (string-compiled schemas have none
689
695
  * and skip them); the referenced root's declarations merge into
690
696
  * the same tables. */
697
+ /* leptris#1644: lexical path normalization — collapse "." and
698
+ * ".." segments (and duplicate separators) so the same file reached
699
+ * through different relative spellings yields one dedup key.
700
+ * Purely lexical: no filesystem access, portable. */
701
+ static void xsd_path_normalize(const char* in, char* out, size_t outsz) {
702
+ struct {
703
+ const char* p;
704
+ size_t len;
705
+ } comps[512];
706
+ size_t n = 0;
707
+ int is_abs = in[0] == '/';
708
+ const char* q = in;
709
+ while (*q) {
710
+ while (*q == '/') q++;
711
+ if (!*q) break;
712
+ const char* start = q;
713
+ while (*q && *q != '/') q++;
714
+ size_t len = (size_t)(q - start);
715
+ if (len == 1 && start[0] == '.') continue;
716
+ if (len == 2 && start[0] == '.' && start[1] == '.') {
717
+ if (n > 0)
718
+ n--; /* ".." pops; a leading pop on an absolute
719
+ path would escape the root — drop it */
720
+ continue;
721
+ }
722
+ if (n < sizeof(comps) / sizeof(comps[0])) {
723
+ comps[n].p = start;
724
+ comps[n].len = len;
725
+ n++;
726
+ }
727
+ }
728
+ size_t o = 0;
729
+ if (is_abs && o < outsz) out[o++] = '/';
730
+ for (size_t i = 0; i < n; i++) {
731
+ if (o && o < outsz && out[o - 1] != '/') out[o++] = '/';
732
+ if (o + comps[i].len >= outsz) break;
733
+ memcpy(out + o, comps[i].p, comps[i].len);
734
+ o += comps[i].len;
735
+ }
736
+ if (o == 0 && outsz > 1) out[o++] = '.';
737
+ out[o] = 0;
738
+ }
739
+
740
+ static int xsd_visited_has(struct leptris_xsd_schema* s,
741
+ const char* path) {
742
+ for (size_t i = 0; i < s->visited_len; i++)
743
+ if (strcmp(s->visited[i], path) == 0) return 1;
744
+ return 0;
745
+ }
746
+
747
+ static void xsd_visited_add(struct leptris_xsd_schema* s,
748
+ const char* path) {
749
+ if (s->visited_len == s->visited_cap) {
750
+ size_t nc = s->visited_cap ? s->visited_cap * 2 : 8;
751
+ char** nv = (char**)realloc(s->visited, nc * sizeof(*nv));
752
+ if (!nv) return; /* dedup degrades to the old behavior */
753
+ s->visited = nv;
754
+ s->visited_cap = nc;
755
+ }
756
+ char* dup = xsd_strdup(path);
757
+ if (!dup) return;
758
+ s->visited[s->visited_len++] = dup;
759
+ }
760
+
691
761
  static void xsd_capture_root(struct leptris_xsd_schema* s,
692
762
  LeptrisElement root) {
693
763
  for (LeptrisNodeRef n =
@@ -712,6 +782,13 @@ static void xsd_capture_root(struct leptris_xsd_schema* s,
712
782
  char path[4096];
713
783
  snprintf(path, sizeof(path), "%s/%s", s->base_dir,
714
784
  loc);
785
+ /* leptris#1644: capture each schema unit once per
786
+ * compile — mark before recursing so cycles close
787
+ * (w.xsd includes a1.xsd includes w.xsd). */
788
+ char canon[4096];
789
+ xsd_path_normalize(path, canon, sizeof(canon));
790
+ if (xsd_visited_has(s, canon)) continue;
791
+ xsd_visited_add(s, canon);
715
792
  size_t flen = 0;
716
793
  char* text = xsd_read_file(path, &flen);
717
794
  if (text) {
@@ -1000,6 +1077,8 @@ LEPTRIS_API void leptris_xsd_free(LeptrisXsdSchema schema) {
1000
1077
  g = gn;
1001
1078
  }
1002
1079
  if (s->default_open) xsd_cm_free(s->default_open);
1080
+ for (size_t i = 0; i < s->visited_len; i++) free(s->visited[i]);
1081
+ free(s->visited);
1003
1082
  free(s->target_ns);
1004
1083
  free(s->base_dir);
1005
1084
  if (s->validator)
@@ -2231,4 +2231,124 @@ TEST(Plan408, AddChildByAddress) {
2231
2231
  leptris_document_free(doc);
2232
2232
  }
2233
2233
 
2234
+ /* #425: the ext face — indent on element boundaries, compact
2235
+ * default; the 3-arg face stays byte-identical to before. */
2236
+ TEST(Plan425, SerializeExtIndentsBoundaries) {
2237
+ LeptrisStatus st = LEPTRIS_OK;
2238
+ leptris_element_plan plans[2] = {};
2239
+ plans[0].element_name = "r";
2240
+ plans[1].element_name = "a";
2241
+
2242
+ leptris_child_plan kids[2] = {};
2243
+ kids[0].wire_name = "a";
2244
+ kids[0].kind = LEPTRIS_PLAN_KIND_SCALAR;
2245
+ kids[0].child_plan_index = 1;
2246
+ kids[1].wire_name = "b";
2247
+ kids[1].kind = LEPTRIS_PLAN_KIND_SCALAR;
2248
+
2249
+ plans[0].child_count = 2;
2250
+ plans[0].child_plans = kids;
2251
+
2252
+ leptris_plan_spec spec = {};
2253
+ spec.abi_version = leptris_plan_abi_version();
2254
+ spec.plan_count = 2;
2255
+ spec.plans = plans;
2256
+ LeptrisPlan plan = leptris_plan_build(&spec, &st);
2257
+ ASSERT_NE(plan, nullptr);
2258
+
2259
+ leptris_plan_row_op ops[] = {
2260
+ {LEPTRIS_PLAN_OP_ELEMENT, 0, UINT32_MAX, NULL, NULL, 0},
2261
+ {LEPTRIS_PLAN_OP_SCALAR, 0, 0, NULL, "v1", 2},
2262
+ {LEPTRIS_PLAN_OP_SCALAR, 0, 1, NULL, "v2", 2},
2263
+ {LEPTRIS_PLAN_OP_END, 0, 0, NULL, NULL, 0},
2264
+ };
2265
+ LeptrisPlanResult r = leptris_plan_result_build(plan, ops, 4, &st);
2266
+ ASSERT_NE(r, nullptr);
2267
+
2268
+ /* Compact (default) — unchanged shape. */
2269
+ char* compact = leptris_plan_serialize(plan, r, &st);
2270
+ ASSERT_NE(compact, nullptr);
2271
+ EXPECT_STREQ(compact, "<r><a>v1</a><b>v2</b></r>");
2272
+
2273
+ /* Ext: indent=2 — newline+indent before each child open and
2274
+ * before the root close. */
2275
+ leptris_plan_serialize_options opts = {};
2276
+ opts.indent = 2;
2277
+ char* pretty = leptris_plan_serialize_ext(plan, r, &opts,
2278
+ sizeof(opts), &st);
2279
+ ASSERT_NE(pretty, nullptr);
2280
+ EXPECT_STREQ(pretty,
2281
+ "<r>\n <a>v1</a>\n <b>v2</b>\n</r>\n");
2282
+
2283
+ /* Ext with a shorter opts_size than the struct is rejected. */
2284
+ EXPECT_EQ(leptris_plan_serialize_ext(plan, r, &opts, 1, &st),
2285
+ nullptr);
2286
+
2287
+ leptris_free_string(compact);
2288
+ leptris_free_string(pretty);
2289
+ leptris_plan_result_free(r);
2290
+ leptris_plan_free(plan);
2291
+ }
2292
+
2293
+ /* #426: build_result -> native document -> the document writer,
2294
+ * with no string round trip. */
2295
+ TEST(Plan426, FromPlanResultMintsNativeDocument) {
2296
+ LeptrisStatus st = LEPTRIS_OK;
2297
+ leptris_element_plan plans[2] = {};
2298
+ plans[0].element_name = "r";
2299
+ plans[1].element_name = "a";
2300
+
2301
+ leptris_child_plan kids[2] = {};
2302
+ kids[0].wire_name = "a";
2303
+ kids[0].kind = LEPTRIS_PLAN_KIND_SCALAR;
2304
+ kids[0].child_plan_index = 1;
2305
+ kids[1].wire_name = "b";
2306
+ kids[1].kind = LEPTRIS_PLAN_KIND_SCALAR;
2307
+
2308
+ plans[0].child_count = 2;
2309
+ plans[0].child_plans = kids;
2310
+
2311
+ leptris_plan_spec spec = {};
2312
+ spec.abi_version = leptris_plan_abi_version();
2313
+ spec.plan_count = 2;
2314
+ spec.plans = plans;
2315
+ LeptrisPlan plan = leptris_plan_build(&spec, &st);
2316
+ ASSERT_NE(plan, nullptr);
2317
+
2318
+ leptris_plan_row_op ops[] = {
2319
+ {LEPTRIS_PLAN_OP_ELEMENT, 0, UINT32_MAX, NULL, NULL, 0},
2320
+ {LEPTRIS_PLAN_OP_ATTR, 0, 0, "k", "1", 1},
2321
+ {LEPTRIS_PLAN_OP_SCALAR, 0, 0, NULL, "v1", 2},
2322
+ {LEPTRIS_PLAN_OP_SCALAR, 0, 1, NULL, "v2", 2},
2323
+ {LEPTRIS_PLAN_OP_END, 0, 0, NULL, NULL, 0},
2324
+ };
2325
+ LeptrisPlanResult r = leptris_plan_result_build(plan, ops, 5, &st);
2326
+ ASSERT_NE(r, nullptr);
2327
+
2328
+ LeptrisDocument doc = leptris_document_from_plan_result(plan, r, &st);
2329
+ ASSERT_NE(doc, nullptr);
2330
+ LeptrisElement root = leptris_document_root(doc);
2331
+ ASSERT_NE(root, nullptr);
2332
+ EXPECT_STREQ(leptris_element_name(root), "r");
2333
+ EXPECT_STREQ(leptris_element_attribute(root, "k"), "1");
2334
+ EXPECT_EQ(leptris_element_child_count(root), 2u);
2335
+ LeptrisElement first = leptris_element_first_child_any(root);
2336
+ ASSERT_NE(first, nullptr);
2337
+ EXPECT_STREQ(leptris_element_name(first), "a");
2338
+ EXPECT_STREQ(leptris_element_text(first), "v1");
2339
+
2340
+ /* Non-ELEMENT roots are rejected. */
2341
+ leptris_plan_row_op scalar_ops[] = {
2342
+ {LEPTRIS_PLAN_OP_SCALAR, 0, 0, NULL, "x", 1}};
2343
+ LeptrisPlanResult scalar_root =
2344
+ leptris_plan_result_build(plan, scalar_ops, 1, &st);
2345
+ EXPECT_EQ(leptris_document_from_plan_result(plan, scalar_root, &st),
2346
+ nullptr);
2347
+
2348
+ leptris_plan_result_free(scalar_root);
2349
+ leptris_plan_result_free(r);
2350
+ leptris_plan_free(plan);
2351
+ leptris_document_free(doc);
2352
+ }
2353
+
2234
2354
  } // namespace
@@ -2959,3 +2959,80 @@ TEST(DomAttachInstalled, NullShapeAndStatusContract) {
2959
2959
  LEPTRIS_ERROR_NULL_ARG);
2960
2960
  leptris_document_free(d);
2961
2961
  }
2962
+
2963
+ namespace {
2964
+ /* leptris#1646: reads every element's name, text, attribute names, and
2965
+ * expanded-QName prefix/URI views — the pool-backed views suspected of
2966
+ * dangling once the source document is freed. NULL text is legal; views
2967
+ * must be readable, not necessarily non-empty. */
2968
+ void ReadAllViews(LeptrisElement e) {
2969
+ const char* name = leptris_element_name(e);
2970
+ ASSERT_NE(name, nullptr);
2971
+ if (const char* text = leptris_element_text(e)) (void)strlen(text);
2972
+ const char* px = nullptr;
2973
+ const char* uri = nullptr;
2974
+ leptris_element_expanded_name(e, nullptr, &px, &uri);
2975
+ if (px) (void)strlen(px);
2976
+ if (uri) (void)strlen(uri);
2977
+ for (LeptrisAttribute a = leptris_element_first_attribute(e); a;
2978
+ a = leptris_attribute_next(a)) {
2979
+ const char* an = leptris_attribute_get_name(a);
2980
+ ASSERT_NE(an, nullptr);
2981
+ }
2982
+ for (LeptrisNodeRef c = leptris_node_first_child(leptris_element_as_node(e)); c;
2983
+ c = leptris_node_next_sibling(c)) {
2984
+ if (leptris_node_get_type(c) == LEPTRIS_NODE_TYPE_ELEMENT)
2985
+ ReadAllViews((LeptrisElement)c);
2986
+ }
2987
+ }
2988
+ } // namespace
2989
+
2990
+ /* leptris#1646 — the two attach shapes whose survival the issue asked to
2991
+ * pin at the C level: (A) absorb-move, where dst's document absorbs src's
2992
+ * pool and the source document is then freed; (B) plain cross-document
2993
+ * append, which adopts by copy. In both, everything reachable from dst
2994
+ * must remain readable and serializable after leptris_document_free(src). */
2995
+ TEST(DomAbsorbSurvival, AbsorbedChildrenSurviveSourceFree) {
2996
+ static const char kSrc[] = "<w><a id=\"k1\" xmlns:p=\"urn:p\"><b>p:t</b><c>deep text</c></a></w>";
2997
+ LeptrisStatus st = LEPTRIS_OK;
2998
+ LeptrisDocument dst = leptris_parse_string("<r/>", strlen("<r/>"), &st);
2999
+ ASSERT_NE(dst, nullptr);
3000
+ LeptrisDocument src = leptris_parse_string(kSrc, strlen(kSrc), &st);
3001
+ ASSERT_NE(src, nullptr);
3002
+ LeptrisElement droot = leptris_document_root(dst);
3003
+ LeptrisElement sroot = leptris_document_root(src);
3004
+ ASSERT_EQ(leptris_document_absorb(dst, src), LEPTRIS_OK);
3005
+ LeptrisNodeRef moved = leptris_node_first_child(leptris_element_as_node(sroot));
3006
+ ASSERT_NE(moved, nullptr);
3007
+ EXPECT_EQ(leptris_element_append_child(droot, (LeptrisElement)moved), LEPTRIS_OK);
3008
+
3009
+ leptris_document_free(src);
3010
+ char* out = leptris_document_serialize(dst, nullptr);
3011
+ ASSERT_NE(out, nullptr);
3012
+ EXPECT_STREQ(out, "<r><a xmlns:p=\"urn:p\" id=\"k1\"><b>p:t</b><c>deep text</c></a></r>");
3013
+ leptris_free_string(out);
3014
+ ReadAllViews(droot);
3015
+ leptris_document_free(dst);
3016
+ }
3017
+
3018
+ TEST(DomAbsorbSurvival, CopyAttachSurvivesSourceFree) {
3019
+ static const char kSrc[] = "<w><a id=\"k1\" xmlns:p=\"urn:p\"><b>p:t</b><c>deep text</c></a></w>";
3020
+ LeptrisStatus st = LEPTRIS_OK;
3021
+ LeptrisDocument dst = leptris_parse_string("<r/>", strlen("<r/>"), &st);
3022
+ ASSERT_NE(dst, nullptr);
3023
+ LeptrisDocument src = leptris_parse_string(kSrc, strlen(kSrc), &st);
3024
+ ASSERT_NE(src, nullptr);
3025
+ LeptrisElement droot = leptris_document_root(dst);
3026
+ LeptrisElement sroot = leptris_document_root(src);
3027
+ LeptrisNodeRef orig = leptris_node_first_child(leptris_element_as_node(sroot));
3028
+ ASSERT_NE(orig, nullptr);
3029
+ EXPECT_EQ(leptris_element_append_child(droot, (LeptrisElement)orig), LEPTRIS_OK);
3030
+
3031
+ leptris_document_free(src);
3032
+ char* out = leptris_document_serialize(dst, nullptr);
3033
+ ASSERT_NE(out, nullptr);
3034
+ EXPECT_STREQ(out, "<r><a xmlns:p=\"urn:p\" id=\"k1\"><b>p:t</b><c>deep text</c></a></r>");
3035
+ leptris_free_string(out);
3036
+ ReadAllViews(droot);
3037
+ leptris_document_free(dst);
3038
+ }
@@ -802,6 +802,31 @@ TEST(SerializeOptions, IndentHtmlNestsBlockChildren) {
802
802
  leptris_document_free(doc);
803
803
  }
804
804
 
805
+ /* Issue #1647: the LAST block child of its parent must nest like
806
+ * any other — the pending-indent flush at close-parent has to fire
807
+ * for the trailing block (a following sibling used to mask it). */
808
+ TEST(SerializeOptions, IndentHtmlNestsLastBlockChild) {
809
+ const char xml[] = "<html><head><title>T</title></head><body>"
810
+ "<div id=\"a\"><p>x</p><span>y</span></div></body></html>";
811
+ LeptrisStatus st = LEPTRIS_OK;
812
+ LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
813
+ ASSERT_NE(doc, nullptr);
814
+ char* s = html_force_serialize(doc, 2, 1, 0);
815
+ ASSERT_NE(s, nullptr);
816
+ EXPECT_EQ(std::string(s),
817
+ "<html>\n"
818
+ " <head><title>T</title></head>\n"
819
+ " <body>\n"
820
+ " <div id=\"a\">\n"
821
+ " <p>x</p>\n"
822
+ " <span>y</span>\n"
823
+ " </div>\n"
824
+ " </body>\n"
825
+ "</html>");
826
+ leptris_free_string(s);
827
+ leptris_document_free(doc);
828
+ }
829
+
805
830
  TEST(SerializeOptions, IndentHtmlLegacyStaysNewlineOnly) {
806
831
  const char xml[] = "<html><body><div><p>one</p><p>two</p></div>"
807
832
  "</body></html>";
@@ -0,0 +1,5 @@
1
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
2
+ <xs:include schemaLocation="a2.xsd"/>
3
+ <xs:include schemaLocation="b2.xsd"/>
4
+ <xs:element name="a1" type="xs:string"/>
5
+ </xs:schema>
@@ -0,0 +1,4 @@
1
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
2
+ <xs:include schemaLocation="s.xsd"/>
3
+ <xs:element name="a2" type="xs:string"/>
4
+ </xs:schema>
@@ -0,0 +1,5 @@
1
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
2
+ <xs:include schemaLocation="a2.xsd"/>
3
+ <xs:include schemaLocation="b2.xsd"/>
4
+ <xs:element name="b1" type="xs:string"/>
5
+ </xs:schema>
@@ -0,0 +1,4 @@
1
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
2
+ <xs:include schemaLocation="s.xsd"/>
3
+ <xs:element name="b2" type="xs:string"/>
4
+ </xs:schema>
@@ -0,0 +1,3 @@
1
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
2
+ <xs:element name="s" type="xs:string"/>
3
+ </xs:schema>
@@ -0,0 +1,5 @@
1
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
2
+ <xs:include schemaLocation="a1.xsd"/>
3
+ <xs:include schemaLocation="b1.xsd"/>
4
+ <xs:element name="w" type="xs:string"/>
5
+ </xs:schema>
@@ -152,6 +152,21 @@ TEST(Libxml2Corpus, EveryFixtureCompilesOrFailsCleanly) {
152
152
 
153
153
  } // namespace
154
154
 
155
+ // leptris#1644: a dense include/import DAG must capture each schema
156
+ // unit exactly once. Without a visited set, every path through the
157
+ // DAG re-parses and re-captures the whole subtree (the dml-main
158
+ // blowup: multi-GB / minutes at include_depth 16). Unique captures
159
+ // here: 6 element declarations + 8 include markers = 14;
160
+ // path-enumerated capture reports 21 (a2/b2 twice, s four times).
161
+ TEST(XsdCompile, ImportDagCapturesEachUnitOnce) {
162
+ LeptrisStatus st = LEPTRIS_OK;
163
+ LeptrisXsdSchema s = leptris_xsd_compile_file(
164
+ LEPTRIS_XSD_CASES_DIR "/import_dag/w.xsd", &st);
165
+ ASSERT_NE(s, (LeptrisXsdSchema)0) << "status " << (int)st;
166
+ EXPECT_EQ(leptris_xsd_declaration_count(s), 14u);
167
+ leptris_xsd_free(s);
168
+ }
169
+
155
170
  // ---- slice 2: lexical validation ----------------------------------
156
171
  namespace {
157
172
 
@@ -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.340",
4
+ "version": "1.9.341",
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",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.340.0
4
+ version: 1.9.341.0
5
5
  platform: arm-linux
6
6
  authors:
7
7
  - Ribose Inc.
@@ -1324,6 +1324,12 @@ files:
1324
1324
  - vendor-src/libleptris/test/xsd/libxml2-cases/import2_0.imp
1325
1325
  - vendor-src/libleptris/test/xsd/libxml2-cases/import2_0.xml
1326
1326
  - vendor-src/libleptris/test/xsd/libxml2-cases/import2_0.xsd
1327
+ - vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/a1.xsd
1328
+ - vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/a2.xsd
1329
+ - vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/b1.xsd
1330
+ - vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/b2.xsd
1331
+ - vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/s.xsd
1332
+ - vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/w.xsd
1327
1333
  - vendor-src/libleptris/test/xsd/libxml2-cases/include1_0.inc
1328
1334
  - vendor-src/libleptris/test/xsd/libxml2-cases/include1_0.xml
1329
1335
  - vendor-src/libleptris/test/xsd/libxml2-cases/include1_0.xsd