leptris 1.9.349.0-ppc64le-linux → 1.9.351.0-ppc64le-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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/Rakefile +1 -1
  4. data/lib/leptris/version.rb +1 -1
  5. data/lib/libleptris.so +0 -0
  6. data/vendor-src/README.md +1 -1
  7. data/vendor-src/libleptris/CHANGELOG.md +80 -0
  8. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  9. data/vendor-src/libleptris/cli/commands/xquery.c +1 -1
  10. data/vendor-src/libleptris/src/leptris/common/simd_text.c +0 -12
  11. data/vendor-src/libleptris/src/leptris/common/simd_text.h +19 -0
  12. data/vendor-src/libleptris/src/leptris/common/simd_text_neon.c +0 -1
  13. data/vendor-src/libleptris/src/leptris/core.c +2 -5
  14. data/vendor-src/libleptris/src/leptris/dom/root_doc_map.h +3 -0
  15. data/vendor-src/libleptris/src/leptris/flat/direct_parse.c +8 -33
  16. data/vendor-src/libleptris/src/leptris/flat/direct_parse.h +4 -0
  17. data/vendor-src/libleptris/src/leptris/html/html_parse.c +0 -2
  18. data/vendor-src/libleptris/src/leptris/leptris.c +6 -41
  19. data/vendor-src/libleptris/src/leptris/leptris_internal.h +14 -0
  20. data/vendor-src/libleptris/src/leptris/memory/pool.h +4 -0
  21. data/vendor-src/libleptris/src/leptris/xpath/evaluator.c +0 -2
  22. data/vendor-src/libleptris/src/leptris/xpath/evaluator_operators.c +2 -8
  23. data/vendor-src/libleptris/src/leptris/xpath/functions.c +1 -5
  24. data/vendor-src/libleptris/src/leptris/xpath/functions.h +29 -0
  25. data/vendor-src/libleptris/src/leptris/xpath/functions_ext31.c +1 -19
  26. data/vendor-src/libleptris/src/leptris/xpath/xpath_carrier.h +32 -0
  27. data/vendor-src/libleptris/src/leptris/xpath/xpath_public.c +1 -15
  28. data/vendor-src/libleptris/src/leptris/xquery/xquery.c +1 -2
  29. data/vendor-src/libleptris/src/leptris/xsd/compile.c +158 -3
  30. data/vendor-src/libleptris/src/leptris/xsd/validate.c +13 -9
  31. data/vendor-src/libleptris/src/leptris/xsd/xsd_internal.h +8 -0
  32. data/vendor-src/libleptris/src/leptris/xslt/xslt_exec.c +0 -6
  33. data/vendor-src/libleptris/src/leptris/xslt/xslt_functions.c +0 -2
  34. data/vendor-src/libleptris/src/leptris/xslt/xslt_pattern.c +0 -1
  35. data/vendor-src/libleptris/src/leptris/xslt/xslt_public.c +1 -2
  36. data/vendor-src/libleptris/test/xquery/test_xquery.cpp +1 -1
  37. data/vendor-src/libleptris/test/xsd/libxml2-cases/fwd_ref_ext/lib/base.xsd +23 -0
  38. data/vendor-src/libleptris/test/xsd/libxml2-cases/fwd_ref_ext/lib/more.xsd +8 -0
  39. data/vendor-src/libleptris/test/xsd/libxml2-cases/fwd_ref_ext/root.xsd +10 -0
  40. data/vendor-src/libleptris/test/xsd/libxml2-cases/fwd_ref_ext/sub/wrap.xsd +3 -0
  41. data/vendor-src/libleptris/test/xsd/libxml2-cases/ns_simple_collision/m.xsd +14 -0
  42. data/vendor-src/libleptris/test/xsd/libxml2-cases/ns_simple_collision/w.xsd +14 -0
  43. data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +70 -0
  44. data/vendor-src/libleptris/vcpkg.json +1 -1
  45. metadata +8 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a5a0ec35167991f89cddabc3962c02db7a4b2d0d14f43dbc05005eb4c2dc444
4
- data.tar.gz: 2c319c7725758e36a6ddd96a9998c0217018af4d3f499426762234c51cbcf3e9
3
+ metadata.gz: e45b87e127109d3517dd3264aab7f0b3cbd7de894eb575067050df0f2787a46d
4
+ data.tar.gz: fc7ebd17537c4fb7d5d15766da666e4617f7c9a1d13b1c353c5691f2e92855e3
5
5
  SHA512:
6
- metadata.gz: 5905b71cf7c8c5417381d08c7e3b2ab01e289c4ac94d8d4e395a139f1e4ac5c0322bc9659c31e14cf03442550c05056e6cb803ce91e6c4bb1c39556ae27291fc
7
- data.tar.gz: ba028358a0661bdbfb0adbfc50e5d26ec347ccf3197480e2a93bb3707e5260487a97721021a87bd0288953e77a98a33752d9fffe31a7d939b0b43797ac272b77
6
+ metadata.gz: 29a9bff9d47c7715c05f85a0eec1ed7bb7cfb77b79fe291eb2a037dced75c92de41f0df27f39a095093868ca9a3c4ce73f782ef0aa3c7fb6c2e8ef41359bad63
7
+ data.tar.gz: 42e741cf955bec6c0976c92d1971a2d1fd79ceeff6ae7ee63641a7b6a2d4b1b89328d1f44a5bc3ee997e780307bcbbd967b0dcec7556f80631f1f9596836096c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## [1.9.351.0] - 2026-10-14
2
+
3
+ ### Fixed — engine sync (libleptris 1.9.350/1.9.351)
4
+
5
+ - **Chain-compiled XSD: forward-referenced extension bases fold
6
+ after the schema merges, subfiles resolve their own relative
7
+ schemaLocations, and attribute types resolve (ns, name)-first
8
+ (leptris-ruby#440; libleptris 1.9.350, PR leptris/leptris#1679)**:
9
+ the corpus-stuck-at-8 family. The engine's visited memo (#1644)
10
+ stopped each schema unit being captured twice and unmasked three
11
+ latent defects: the extension fold ran at capture time (a base
12
+ defined after its derived type — CT_TcPr -> CT_TcPrInner —
13
+ silently dropped), a subfile's own schemaLocations resolved
14
+ against the COMPILED file's directory (wml.xsd's same-dir
15
+ shared-*.xsd imports vanished), and attribute type names resolved
16
+ by bare local name (wml's ST_Jc shadowed shared-math's, so
17
+ m:defJc val="centerGroup" failed). Pinned through the binding API
18
+ in spec/xml/xsd_chain_shapes_spec.rb (tempdir chain trees — no
19
+ vendored corpus needed).
20
+ - **GCC LTO carrier link (#1681, libleptris 1.9.350/1.9.351)**:
21
+ ppc64le/s390x/truffleruby legs failed the engine link
22
+ (undefined xpath_carrier_node_of) — fixed engine-side; the
23
+ #445-family legs go green. libleptris 1.9.351 additionally
24
+ removed every function-scope extern (84 sites across 18 TUs), so
25
+ the class cannot recur.
26
+
1
27
  ## [1.9.346.0] - 2026-10-12
2
28
 
3
29
  ### Fixed — engine sync (libleptris 1.9.346)
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.349"
11
+ LIBLEPTRIS_VERSION = "1.9.351"
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.349.0"
4
+ VERSION = "1.9.351.0"
5
5
  end
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.349
4
+ - libleptris v1.9.351
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand:
@@ -1,5 +1,85 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.351] - 2026-10-13
4
+
5
+ ### Changed
6
+
7
+ - **Block-scope externs removed engine-wide (leptris#1681,
8
+ PR #1684).** #1683 fixed the one symbol GCC LTO internalized
9
+ out from under a function-scope reference; this removes the
10
+ class — the count of block-scope extern declarations is now
11
+ zero across all 18 TUs that carried them (84 sites). Every
12
+ cross-TU symbol resolves through a shared internal header:
13
+ most declarations already existed and the TUs just didn't
14
+ include them; new homes were added where none existed (the
15
+ XSLT/Schematron bridge registrations, EXSLT pack, fn31 pack
16
+ and shared helpers in xpath/functions.h; per-arch simd
17
+ kernels in common/simd_text.h; xsd_builtin_valid in
18
+ xsd/xsd_internal.h; the HTML tree-builder document
19
+ constructor and the parse-default TLS in leptris_internal.h;
20
+ direct_parse_flags in flat/direct_parse.h;
21
+ leptris_root_doc_unregister_doc in dom/root_doc_map.h;
22
+ leptris_pool_drain_recycler in memory/pool.h). No ABI
23
+ change: symbols keep their definitions and visibility; only
24
+ the declaration home moved. Verified under gcc-16 -flto
25
+ (the configuration where the class manifests): shared +
26
+ CLI + tests link with zero errors; full suite 1996/1996 on
27
+ clang Release.
28
+
29
+
30
+ ## [1.9.350] - 2026-10-13
31
+
32
+ ### Fixed
33
+
34
+ - **GCC LTO: the XPath carrier decode survives link
35
+ internalization (leptris#1681, PR #1683).** The binding's
36
+ ppc64le (qemu, gcc-12), s390x (qemu, alpine) and truffleruby
37
+ source-install legs failed the engine link with `undefined
38
+ reference to xpath_carrier_node_of`: with Release LTO on, GCC
39
+ internalizes a hidden out-of-line definition when the only
40
+ cross-TU references are block-scope externs. The decode is now
41
+ `static inline` in a shared internal header
42
+ (xpath/xpath_carrier.h) — the definition travels with every
43
+ referencing TU, so internalization cannot orphan the externs.
44
+ The interim definition-side attributes (9985185d) stay and
45
+ remain no-ops for clang. Verified under gcc-16 -flto: the full
46
+ build (shared + CLI + tests) links clean, test_xquery 72/72.
47
+
48
+ - **Chain-compiled XSD: forward-referenced extension bases fold
49
+ after the schema merges, and subfiles resolve their own
50
+ schemaLocations (leptris-ruby#440, PR #1679).** Two defects in
51
+ the flat merged-import compile, both masked until the #1644
52
+ visited memo made each file capture exactly once. (A) The
53
+ content-model extension fold ran at CAPTURE time, so a base
54
+ defined AFTER its derived type in the same file (CT_TcPr
55
+ extends CT_TcPrInner, wml.xsd:2339 -> :2351) resolved to
56
+ nothing and its content was silently dropped - the direct
57
+ compile of wml.xsd had been saved only by dml's re-import
58
+ capturing the file twice. Extensions whose base is not yet
59
+ captured (or is itself still deferred) now record the base
60
+ name and fold in a post-capture resolver that iterates to a
61
+ fixpoint, splicing base content first and inherited attribute
62
+ rows before the derived type's own - with the same one-root-
63
+ particle sequence normalization capture applies. (B) The
64
+ subfile's OWN relative schemaLocations resolved against the
65
+ COMPILED file's directory: wml-2010 -> word12 -> ../iso/
66
+ wml.xsd worked, but wml.xsd's same-dir shared-*.xsd imports
67
+ then resolved against microsoft/ and silently vanished,
68
+ truncating every model referencing them. Each import unit now
69
+ threads base_dir to the subfile's directory for its own
70
+ capture and restores it on every exit path. (C) Attribute
71
+ type names resolved by bare local name, so same-name
72
+ simpleTypes across namespaces shadowed each other - wml's
73
+ ST_Jc (no centerGroup) beat shared-math's ST_Jc (centerGroup)
74
+ and m:defJc's val="centerGroup" failed lexical validation.
75
+ XsdSimple now carries the declaring unit's targetNamespace and
76
+ the lexical checks resolve (ns, name)-first, falling back to
77
+ unstamped and then cross-namespace spellings (prefix-stripped
78
+ names legitimately cross namespaces). Fixtures:
79
+ fwd_ref_ext/ (forward-ref chain through chameleon + subfile
80
+ dirs), ns_simple_collision/ (ST_Jc shadowing both ways).
81
+
82
+
3
83
  ## [1.9.349] - 2026-10-13
4
84
 
5
85
  ### Fixed
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(leptris
6
- VERSION 1.9.349
6
+ VERSION 1.9.351
7
7
  DESCRIPTION "Fast XML parser and XPath evaluator in pure C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  #include "../cli.h"
11
+ #include "../../src/leptris/xpath/xpath_carrier.h"
11
12
  #include "../options.h"
12
13
  #include "../error.h"
13
14
  #include "../src/include/leptris.h"
@@ -121,7 +122,6 @@ static cli_result_t xquery_run(int argc, char** argv) {
121
122
  } else if (leptris_xpath_result_type(r) == LEPTRIS_XPATH_NODESET) {
122
123
  /* carrier-by-pointer (fold-left-009/016): synth members may
123
124
  * carry a node pointer — render its markup. */
124
- extern void* xpath_carrier_node_of(const char* s);
125
125
  size_t n = leptris_xpath_result_count(r);
126
126
  for (size_t k = 0; k < n; k++) {
127
127
  if (k) putchar(' ');
@@ -97,9 +97,6 @@ static void dispatch_init(void) {
97
97
  leptris_cpu_level lvl = leptris_cpu_detect();
98
98
  #if defined(LEPTRIS_ARCH_X86) && defined(LEPTRIS_HAS_AVX2_BUILD)
99
99
  if (lvl >= LEPTRIS_CPU_AVX2) {
100
- extern int leptris_text_contains_avx2(const char*, size_t, char);
101
- extern ptrdiff_t leptris_text_find3_avx2(const char*, size_t, char, char, char);
102
- extern size_t leptris_text_count_char_avx2(const char*, size_t, char);
103
100
  g_contains_fn = leptris_text_contains_avx2;
104
101
  g_find3_fn = leptris_text_find3_avx2;
105
102
  g_count_fn = leptris_text_count_char_avx2;
@@ -108,13 +105,6 @@ static void dispatch_init(void) {
108
105
  #endif
109
106
  #if defined(LEPTRIS_ARCH_ARM) && defined(__aarch64__)
110
107
  if (lvl >= LEPTRIS_CPU_NEON) {
111
- extern int leptris_text_contains_neon(const char*, size_t, char);
112
- extern ptrdiff_t leptris_text_find3_neon(const char*, size_t, char, char, char);
113
- extern size_t leptris_text_count_char_neon(const char*, size_t, char);
114
- extern void leptris_text_count3_neon(const char*, size_t, char, char, char,
115
- size_t*, size_t*, size_t*);
116
- extern void leptris_copy_count3_neon(char*, const char*, size_t, char, char, char,
117
- size_t*, size_t*, size_t*);
118
108
  g_contains_fn = leptris_text_contains_neon;
119
109
  g_find3_fn = leptris_text_find3_neon;
120
110
  g_count_fn = leptris_text_count_char_neon;
@@ -227,8 +217,6 @@ size_t leptris_text_scan_events(const char* buf, size_t len,
227
217
  g_scan_fn = scan_events_scalar;
228
218
  #if defined(LEPTRIS_ARCH_ARM) && defined(__aarch64__)
229
219
  if (leptris_cpu_detect() >= LEPTRIS_CPU_NEON) {
230
- extern size_t leptris_text_scan_events_neon(const char*, size_t,
231
- LeptrisScanEvent*, size_t);
232
220
  g_scan_fn = leptris_text_scan_events_neon;
233
221
  }
234
222
  #endif
@@ -90,6 +90,25 @@ extern unsigned char leptris_dp_class_table[256];
90
90
  * rely on leptris_text_scan_events to call it). */
91
91
  void leptris_dp_class_table_init(void);
92
92
 
93
+ /* Per-arch kernels (simd_text_avx2.c / simd_text_neon.c): declared
94
+ * unconditionally, defined only under their platform gates. */
95
+ int leptris_text_contains_avx2(const char* s, size_t len, char c);
96
+ ptrdiff_t leptris_text_find3_avx2(const char* s, size_t len,
97
+ char a, char b, char c);
98
+ size_t leptris_text_count_char_avx2(const char* s, size_t len, char c);
99
+ int leptris_text_contains_neon(const char* s, size_t len, char c);
100
+ ptrdiff_t leptris_text_find3_neon(const char* s, size_t len,
101
+ char a, char b, char c);
102
+ size_t leptris_text_count_char_neon(const char* s, size_t len, char c);
103
+ void leptris_text_count3_neon(const char* s, size_t len,
104
+ char a, char b, char c,
105
+ size_t* ca, size_t* cb, size_t* cc);
106
+ void leptris_copy_count3_neon(char* dst, const char* src, size_t len,
107
+ char a, char b, char c,
108
+ size_t* ca, size_t* cb, size_t* cc);
109
+ size_t leptris_text_scan_events_neon(const char* buf, size_t len,
110
+ LeptrisScanEvent* events, size_t max);
111
+
93
112
  /* Append events for every structural byte to out (capacity max).
94
113
  * Returns the number of events written; returns max unchanged as
95
114
  * an overflow signal (caller must detect return == max and treat
@@ -214,7 +214,6 @@ void leptris_copy_count3_neon(char* dst, const char* src, size_t len,
214
214
  * each bit appears once (no carries). */
215
215
  size_t leptris_text_scan_events_neon(const char* buf, size_t len,
216
216
  LeptrisScanEvent* out, size_t max) {
217
- extern void leptris_dp_class_table_init(void);
218
217
  leptris_dp_class_table_init();
219
218
  const uint8x16_t k_lt = vdupq_n_u8('<');
220
219
  const uint8x16_t k_gt = vdupq_n_u8('>');
@@ -12,6 +12,8 @@
12
12
  #include "../../include/leptris.h"
13
13
  #include "../leptris_internal.h"
14
14
  #include "common/port.h"
15
+ #include "memory/arena.h"
16
+ #include "dom/compact.h"
15
17
 
16
18
  /* Library version. Single source of truth; CMakeLists.txt should
17
19
  * keep this in sync with project(leptris VERSION ...). */
@@ -71,10 +73,6 @@ LEPTRIS_API void leptris_version_components(int* major, int* minor, int* patch)
71
73
  }
72
74
 
73
75
  LEPTRIS_API void leptris_thread_cleanup(void) {
74
- extern void leptris_xpath_drain_thread_caches(void);
75
- extern void leptris_root_doc_drain_thread_caches(void);
76
- extern void leptris_pool_drain_recycler(void);
77
- extern void leptris_arena_retain_drain(void);
78
76
  leptris_xpath_drain_thread_caches();
79
77
  leptris_root_doc_drain_thread_caches();
80
78
  leptris_pool_drain_recycler();
@@ -155,7 +153,6 @@ LEPTRIS_API int leptris_document_get_strict(LeptrisDocument doc) {
155
153
  }
156
154
 
157
155
  LEPTRIS_API void leptris_explicit_cleanup(void) {
158
- extern void leptris_compact_cleanup(void);
159
156
  leptris_compact_cleanup();
160
157
  }
161
158
 
@@ -15,6 +15,9 @@ extern "C" {
15
15
 
16
16
  void leptris_root_doc_register(LeptrisElement root, struct leptris_document* doc);
17
17
  void leptris_root_doc_unregister(LeptrisElement root);
18
+ /* #1038: unregister every element registered for this document
19
+ * (fallback-path registrations). Returns the number removed. */
20
+ size_t leptris_root_doc_unregister_doc(struct leptris_document* doc);
18
21
  struct leptris_document* leptris_root_doc_lookup(LeptrisElement root);
19
22
  void leptris_root_doc_memo_invalidate(const struct leptris_document* doc);
20
23
  /* Test hook (#1242): the memo's current root, or NULL. */
@@ -37,11 +37,18 @@
37
37
  #include "../common/port.h"
38
38
  #include "../common/simd_text.h"
39
39
  #include "../dtd/model.h"
40
-
40
+ #include "../include/leptris/dtd.h" /* leptris_dtd_free is LEPTRIS_API */
41
+ #include "../dom/diag.h"
42
+ #include "../memory/pool.h"
41
43
  #include <string.h>
42
44
  #include <stdlib.h>
43
45
  #include <stdio.h>
44
46
 
47
+ /* File-scope externs: engine config TLS defined in core.c (declared
48
+ * in leptris_internal.h; this TU reads it without the umbrella) and
49
+ * a compact-mode hook. File scope, not block scope — block-scope
50
+ * externs break GCC LTO (leptris#1681). */
51
+ extern LEPTRIS_THREAD_LOCAL int g_leptris_max_depth;
45
52
  extern LEPTRIS_THREAD_LOCAL int g_leptris_strict_mode;
46
53
  extern void leptris_compact_set_current_document(struct leptris_document* doc);
47
54
  int leptris_element_add_namespace(struct leptris_element* elem,
@@ -636,10 +643,6 @@ static inline int dp_add_attr_inline(DParser* p, LeptrisElement elem,
636
643
  }
637
644
  if (dup) {
638
645
  if (p->doc) {
639
- extern struct LeptrisDiag* leptris_diag_emit(
640
- struct LeptrisDiag**, int*, int*,
641
- LeptrisDiagKind, LeptrisNodeRef,
642
- const char*, ...);
643
646
  char qname[130];
644
647
  size_t ql = attr->name_view.length < 129
645
648
  ? attr->name_view.length : 129;
@@ -889,7 +892,6 @@ static LEPTRIS_NOINLINE int dp_parse_doctype(char** pos_io, char* end,
889
892
  subset_start, (size_t)(subset_end - subset_start),
890
893
  pool);
891
894
  if (parsed) {
892
- extern void leptris_dtd_free(struct LeptrisDTD*);
893
895
  if (dtd) {
894
896
  /* a second <!DOCTYPE: the first model wins (the
895
897
  * duplicate-attribute keep-first rule); the
@@ -1597,7 +1599,6 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
1597
1599
  p.pool = pool;
1598
1600
  p.doc = doc;
1599
1601
  {
1600
- extern LEPTRIS_THREAD_LOCAL int g_leptris_max_depth;
1601
1602
  size_t dcap = g_leptris_max_depth > 0
1602
1603
  ? (size_t)g_leptris_max_depth : (size_t)DP_MAX_DEPTH;
1603
1604
  if (!dp_stacks_init(&p, dcap)) goto fail;
@@ -1979,7 +1980,6 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
1979
1980
  /* Respect custom depth limit (g_leptris_max_depth)
1980
1981
  * when set by the caller; fall back to the
1981
1982
  * compile-time default otherwise. */
1982
- extern LEPTRIS_THREAD_LOCAL int g_leptris_max_depth;
1983
1983
  int max_depth = g_leptris_max_depth > 0
1984
1984
  ? g_leptris_max_depth : DP_MAX_DEPTH;
1985
1985
  if (p.depth >= max_depth) goto fail;
@@ -2097,11 +2097,6 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
2097
2097
  while ((int)p.depth - 1 > anc) {
2098
2098
  LeptrisElement ce =
2099
2099
  p.open_stack[p.depth - 1];
2100
- extern struct LeptrisDiag*
2101
- leptris_diag_emit(
2102
- struct LeptrisDiag**, int*, int*,
2103
- LeptrisDiagKind, LeptrisNodeRef,
2104
- const char*, ...);
2105
2100
  leptris_diag_emit(
2106
2101
  &p.doc->parse_diags,
2107
2102
  &p.doc->parse_diag_count,
@@ -2121,10 +2116,6 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
2121
2116
  }
2122
2117
  goto close_matched;
2123
2118
  }
2124
- extern struct LeptrisDiag* leptris_diag_emit(
2125
- struct LeptrisDiag**, int*, int*,
2126
- LeptrisDiagKind, LeptrisNodeRef,
2127
- const char*, ...);
2128
2119
  leptris_diag_emit(
2129
2120
  &p.doc->parse_diags,
2130
2121
  &p.doc->parse_diag_count,
@@ -2347,10 +2338,6 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
2347
2338
  * implicitly; the tree commits. */
2348
2339
  while (p.depth > 0) {
2349
2340
  LeptrisElement ce = p.open_stack[p.depth - 1];
2350
- extern struct LeptrisDiag* leptris_diag_emit(
2351
- struct LeptrisDiag**, int*, int*,
2352
- LeptrisDiagKind, LeptrisNodeRef,
2353
- const char*, ...);
2354
2341
  leptris_diag_emit(
2355
2342
  &p.doc->parse_diags, &p.doc->parse_diag_count,
2356
2343
  &p.doc->parse_diag_cap,
@@ -2493,7 +2480,6 @@ fail:
2493
2480
  * RECOVER diag (e.g. duplicate attribute) can precede the
2494
2481
  * failure — nightly-fuzz leak-75e0ee81, 2304 bytes. */
2495
2482
  {
2496
- extern void leptris_diag_free(struct LeptrisDiag**, int*, int*);
2497
2483
  leptris_diag_free(&doc->parse_diags, &doc->parse_diag_count,
2498
2484
  &doc->parse_diag_cap);
2499
2485
  }
@@ -2503,7 +2489,6 @@ fail:
2503
2489
  * assigns doc->dtd; without this free the model leaks
2504
2490
  * (nightly-fuzz leak-e3246602, 8 bytes). */
2505
2491
  {
2506
- extern void leptris_dtd_free(struct LeptrisDTD*);
2507
2492
  if (p.dtd) leptris_dtd_free(p.dtd);
2508
2493
  }
2509
2494
  free(doc->line_breaks);
@@ -2746,7 +2731,6 @@ static int il_scan_body(char* s, size_t len, int drop_ws, IlCtx* c,
2746
2731
  c->last_child[c->depth - 1] = ri;
2747
2732
 
2748
2733
  if (!r.self_closing) {
2749
- extern LEPTRIS_THREAD_LOCAL int g_leptris_max_depth;
2750
2734
  int max_depth = g_leptris_max_depth > 0
2751
2735
  ? g_leptris_max_depth : DP_MAX_DEPTH;
2752
2736
  if (c->depth >= max_depth) return 0;
@@ -2856,7 +2840,6 @@ static int il_scan_body(char* s, size_t len, int drop_ws, IlCtx* c,
2856
2840
  int leptris_il_scan(char* s, size_t len, int drop_ws, IlCtx* c,
2857
2841
  uint32_t* root_out, size_t* trail_off,
2858
2842
  size_t* trail_len) {
2859
- extern LEPTRIS_THREAD_LOCAL int g_leptris_max_depth;
2860
2843
  size_t dcap = g_leptris_max_depth > 0
2861
2844
  ? (size_t)g_leptris_max_depth : (size_t)LEPTRIS_IL_MAX_DEPTH;
2862
2845
  if (!il_stacks_init(c, dcap)) return 0;
@@ -2872,10 +2855,6 @@ int leptris_il_scan(char* s, size_t len, int drop_ws, IlCtx* c,
2872
2855
  static struct leptris_document* dp_il_build(
2873
2856
  char* scratch, size_t len, IlCtx* c, uint32_t root_rec,
2874
2857
  size_t trail_off, size_t trail_len, int drop_ws) {
2875
- extern LeptrisArena* leptris_arena_create(size_t);
2876
- extern LeptrisMemoryPool* leptris_pool_create_arena_backed(
2877
- LeptrisArena*, int);
2878
- extern void leptris_arena_destroy(LeptrisArena*);
2879
2858
 
2880
2859
  /* scratch (with its NUL runway) is caller-built and becomes the
2881
2860
  * document's parse_scratch; pristine is the immutable copy. */
@@ -3113,10 +3092,6 @@ static struct leptris_document* dp_il_build(
3113
3092
  }
3114
3093
  if (dup) {
3115
3094
  if (doc) {
3116
- extern struct LeptrisDiag* leptris_diag_emit(
3117
- struct LeptrisDiag**, int*, int*,
3118
- LeptrisDiagKind, LeptrisNodeRef,
3119
- const char*, ...);
3120
3095
  char qn[130];
3121
3096
  size_t ql = a->name_len < 129
3122
3097
  ? a->name_len : 129;
@@ -38,4 +38,8 @@ struct leptris_document* direct_parse(const char* xml, size_t len);
38
38
  */
39
39
  struct leptris_document* direct_parse_inplace(char* buf, size_t len);
40
40
 
41
+ /* Flags variant — carries LEPTRIS_PARSE_* flags (recover mode #1660). */
42
+ struct leptris_document* direct_parse_flags(const char* xml, size_t len,
43
+ unsigned parse_flags);
44
+
41
45
  #endif /* LEPTRIS_FLAT_DIRECT_PARSE_H */
@@ -5526,8 +5526,6 @@ static LeptrisDocument html_parse_shared(
5526
5526
  * extension blocks in a different malloc region, pushing every
5527
5527
  * borrowed pointer out of the int32 compact range (measured
5528
5528
  * 776k overflow-table inserts on the 2.6 MB table shape). */
5529
- extern struct leptris_document* leptris_document_create_with_arena_size(
5530
- size_t arena_size);
5531
5529
  struct leptris_document* doc =
5532
5530
  (struct leptris_document*)leptris_document_create_with_arena_size(
5533
5531
  len * 10 + (1u << 18));
@@ -26,17 +26,18 @@
26
26
  * is the sole parser. */
27
27
  #include "common/entities.h"
28
28
  #include "common/port.h"
29
+ #include "leptris/flat/direct_parse.h"
30
+ #include "leptris/memory/pool.h"
31
+ #include "leptris/dom/root_doc_map.h"
32
+ #include "leptris/dom/diag.h"
33
+ #include "leptris/dom/compact.h"
34
+ #include "leptris/xpath/functions.h"
29
35
  #include <string.h>
30
36
  #include <math.h>
31
37
  #include <stdlib.h>
32
38
  #include <stdio.h>
33
39
  #include <ctype.h>
34
40
 
35
- /* Thread-local globals defined in core.c — extern so leptris_parse can
36
- * read the strict-mode default at document creation time. */
37
- extern LEPTRIS_THREAD_LOCAL int g_leptris_strict_mode;
38
- extern LEPTRIS_THREAD_LOCAL int g_leptris_max_depth;
39
-
40
41
 
41
42
  /* ============================================================================
42
43
  * Utility Macros
@@ -70,13 +71,6 @@ extern LEPTRIS_THREAD_LOCAL int g_leptris_max_depth;
70
71
  * Forward Declarations
71
72
  * ============================================================================ */
72
73
 
73
- /* Forward declarations for new parser/serializer */
74
- /* Legacy parser (parser_new.c) deleted — direct_parse + flat_parse
75
- * cover the full XML feature set. These extern declarations are
76
- * retained as a marker; the functions no longer exist. */
77
- extern void leptris_element_free(LeptrisElement elem);
78
- extern void leptris_doctype_free(LeptrisDoctypeNode* doctype);
79
-
80
74
  /* ============================================================================
81
75
  * Internal Parse Function Implementation
82
76
  * ============================================================================ */
@@ -125,7 +119,6 @@ struct leptris_document* leptris_parse(const char* xml, size_t len) {
125
119
  * parser (parser_new.c) have been removed. One parser, like
126
120
  * pugixml. If direct_parse returns NULL, the input is genuinely
127
121
  * malformed. */
128
- extern struct leptris_document* direct_parse(const char*, size_t);
129
122
  return direct_parse(xml, len);
130
123
  }
131
124
 
@@ -139,7 +132,6 @@ struct leptris_document* leptris_parse(const char* xml, size_t len) {
139
132
  * outlives the document.
140
133
  */
141
134
  static struct leptris_document* leptris_parse_inplace(char* xml, size_t len) {
142
- extern struct leptris_document* direct_parse_inplace(char*, size_t);
143
135
  return direct_parse_inplace(xml, len);
144
136
  }
145
137
 
@@ -185,12 +177,6 @@ void leptris_parse_options_init(leptris_parse_options* opts) {
185
177
  * contiguous region. */
186
178
  struct leptris_document* leptris_document_create_with_arena_size(
187
179
  size_t arena_size) {
188
- extern LeptrisMemoryPool* leptris_pool_create_arena_backed(
189
- LeptrisArena*, int);
190
- extern void* leptris_pool_alloc(LeptrisMemoryPool* pool, size_t size);
191
- extern void* leptris_pool_get_base(LeptrisMemoryPool* pool);
192
- extern LeptrisArena* leptris_arena_create(size_t);
193
- extern void leptris_arena_destroy(LeptrisArena*);
194
180
 
195
181
  /* #1127: every document owns exactly one arena — created
196
182
  * documents take the same arena-backed pool the parser uses
@@ -210,7 +196,6 @@ struct leptris_document* leptris_document_create_with_arena_size(
210
196
  struct leptris_document* doc =
211
197
  (struct leptris_document*)leptris_pool_alloc(pool, sizeof(struct leptris_document));
212
198
  if (!doc) {
213
- extern void leptris_pool_destroy(LeptrisMemoryPool* pool);
214
199
  leptris_pool_destroy(pool);
215
200
  return NULL;
216
201
  }
@@ -247,8 +232,6 @@ LEPTRIS_API LeptrisDocument leptris_document_create_html(void) {
247
232
  * destroy cycle per element. */
248
233
  struct leptris_document* leptris_document_create_on_arena(
249
234
  LeptrisArena* arena) {
250
- extern LeptrisMemoryPool* leptris_pool_create_arena_backed(
251
- LeptrisArena*, int);
252
235
  if (!arena) return NULL;
253
236
  LeptrisMemoryPool* pool =
254
237
  leptris_pool_create_arena_backed(arena, 0);
@@ -257,7 +240,6 @@ struct leptris_document* leptris_document_create_on_arena(
257
240
  (struct leptris_document*)leptris_pool_alloc(
258
241
  pool, sizeof(struct leptris_document));
259
242
  if (!doc) {
260
- extern void leptris_pool_destroy(LeptrisMemoryPool*);
261
243
  leptris_pool_destroy(pool);
262
244
  return NULL;
263
245
  }
@@ -316,11 +298,7 @@ LEPTRIS_API LeptrisStatus leptris_document_set_root_ex(
316
298
  * loses the element (Nokogiri steal observability); the
317
299
  * installed root is a new handle, reported through
318
300
  * out_installed for bindings to wrap. */
319
- extern struct leptris_document* leptris_element_get_document(
320
- LeptrisElement elem);
321
301
  if (leptris_element_get_document(root) != doc) {
322
- extern LeptrisElement leptris_element_copy(
323
- LeptrisElement src, LeptrisDocument dest_doc);
324
302
  LeptrisElement copy = leptris_element_copy(root, doc);
325
303
  if (!copy) {
326
304
  leptris_set_error(LEPTRIS_ERROR_MEMORY,
@@ -361,8 +339,6 @@ LEPTRIS_API LeptrisStatus leptris_document_set_root_ex(
361
339
 
362
340
  doc->root = root;
363
341
  doc->new_dom_root = root;
364
- extern void leptris_root_doc_register(LeptrisElement root,
365
- struct leptris_document* doc);
366
342
  leptris_root_doc_register(root, doc);
367
343
  /* #612: keep the document-child chain coherent — the document
368
344
  * node's view must list the NEW root at the old root's slot
@@ -671,9 +647,6 @@ LEPTRIS_API LeptrisDocument leptris_parse_string_flags(const char* xml,
671
647
  size_t length,
672
648
  LeptrisParseFlags flags,
673
649
  LeptrisStatus* status) {
674
- extern struct leptris_document* direct_parse_flags(const char* xml,
675
- size_t len,
676
- unsigned parse_flags);
677
650
  LeptrisDocument doc = direct_parse_flags(xml, length, (unsigned)flags);
678
651
  if (status) {
679
652
  *status = doc ? LEPTRIS_OK : LEPTRIS_ERROR_PARSE;
@@ -937,8 +910,6 @@ LEPTRIS_API void leptris_document_adopt_child(LeptrisDocument parent,
937
910
 
938
911
  LEPTRIS_API void leptris_document_free(struct leptris_document* doc) {
939
912
  {
940
- extern void leptris_root_doc_memo_invalidate(
941
- const struct leptris_document* doc);
942
913
  leptris_root_doc_memo_invalidate(doc);
943
914
  }
944
915
  if (!doc) return;
@@ -968,7 +939,6 @@ LEPTRIS_API void leptris_document_free(struct leptris_document* doc) {
968
939
 
969
940
  /* Parse diagnostics (#1200): the recover-channel list. */
970
941
  {
971
- extern void leptris_diag_free(struct LeptrisDiag**, int*, int*);
972
942
  leptris_diag_free(&doc->parse_diags, &doc->parse_diag_count,
973
943
  &doc->parse_diag_cap);
974
944
  }
@@ -988,7 +958,6 @@ LEPTRIS_API void leptris_document_free(struct leptris_document* doc) {
988
958
  }
989
959
 
990
960
  /* Free custom XPath function registrations (TODO 148 Phase 5). */
991
- extern void leptris_xpath_free_custom_fns(struct leptris_document*);
992
961
  leptris_xpath_free_custom_fns(doc);
993
962
 
994
963
  /* Constructed-node anchors (#691): snapshot copies and
@@ -1066,12 +1035,10 @@ LEPTRIS_API void leptris_document_free(struct leptris_document* doc) {
1066
1035
  * down; a programmatic root set via leptris_document_set_root
1067
1036
  * was read after its block was freed — ASAN use-after-free.) */
1068
1037
  if (doc->ref_count == 0) {
1069
- extern void leptris_compact_cleanup_document(struct leptris_document* doc);
1070
1038
  leptris_compact_cleanup_document(doc);
1071
1039
  }
1072
1040
 
1073
1041
  if (doc->new_dom_root) {
1074
- extern void leptris_root_doc_unregister(LeptrisElement);
1075
1042
  leptris_root_doc_unregister((LeptrisElement)doc->new_dom_root);
1076
1043
  }
1077
1044
  /* #1038: fallback-path registrations (detached elements) die
@@ -1079,8 +1046,6 @@ LEPTRIS_API void leptris_document_free(struct leptris_document* doc) {
1079
1046
  * declaration must match root_doc_map.c's size_t return or the
1080
1047
  * amalgamated single-TU build fails (#1217). */
1081
1048
  {
1082
- extern size_t leptris_root_doc_unregister_doc(
1083
- struct leptris_document*);
1084
1049
  leptris_root_doc_unregister_doc(doc);
1085
1050
  }
1086
1051
 
@@ -39,6 +39,9 @@
39
39
  /* StringView for zero-copy string handling */
40
40
  #include "common/string_view.h"
41
41
 
42
+ /* LEPTRIS_THREAD_LOCAL for the parse-default TLS below. */
43
+ #include "common/port.h"
44
+
42
45
  /* Forward declarations - actual typedefs in respective headers */
43
46
  struct leptris_element; /* typedef in dom/element.h */
44
47
  struct leptris_compact_overflow_entry; /* typedef in dom/compact.h */
@@ -477,6 +480,17 @@ extern void leptris_document_ensure_promoted(struct leptris_document* doc);
477
480
  /* Get current strict parsing mode */
478
481
  extern LEPTRIS_API int leptris_get_strict_mode(void);
479
482
 
483
+ /* Thread-local parse defaults, defined in core.c: the strict-mode
484
+ * default read at document creation and the custom element-depth
485
+ * gate read by the parser. */
486
+ extern LEPTRIS_THREAD_LOCAL int g_leptris_strict_mode;
487
+ extern LEPTRIS_THREAD_LOCAL int g_leptris_max_depth;
488
+
489
+ /* Quasi-internal document constructor used by the HTML tree
490
+ * builder (content-derived arena span sizing, #1218). */
491
+ struct leptris_document* leptris_document_create_with_arena_size(
492
+ size_t arena_size);
493
+
480
494
  /* Namespace structure - Matches ext/leptris/leptris.h _namespace */
481
495
  struct leptris_namespace {
482
496
  char* prefix; /* Namespace prefix (NULL = default namespace) */
@@ -173,6 +173,10 @@ int leptris_pool_is_arena_backed(const LeptrisMemoryPool* pool);
173
173
  */
174
174
  void leptris_pool_destroy(LeptrisMemoryPool* pool);
175
175
 
176
+ /* Release this thread's recycler pages back to the global pool
177
+ * (leptris_thread_cleanup). */
178
+ void leptris_pool_drain_recycler(void);
179
+
176
180
  /**
177
181
  * Get the base pointer for compact pointer decoding
178
182
  *