leptris 1.9.406.1-ppc64le-linux → 1.9.407.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46b29dea54ee68d6c509699d970ad377685c39aebb8ed59df4ecdd37b6e42942
4
- data.tar.gz: ea69400fe5f0cbd7058ff455192670253dc8011f94f99810a019e538216ca54a
3
+ metadata.gz: 05a532c037c0c208d5e97db92be06ae208d26e29577596b258554859e6bc0f52
4
+ data.tar.gz: 7e001f9b74c8a080714602f887e626967bf584133837eb1d4c8d0adbbf248c4b
5
5
  SHA512:
6
- metadata.gz: 5fe10864208dd6ee472c1817ea80cd5c77acbbca49be850220601e7f089a1b6a521a50672c06aaddecb7bca898afe55cc2cff2ea76fc91b0ceaf814a50d2259e
7
- data.tar.gz: f8df0a1dfc047adfece8e2b04f38f855437cc7718f242b4e4ee1e54eb3f252f8af339746292328c556e31d2b35c74ca8693a49f1ee9fc96d547fb7b41e38318f
6
+ metadata.gz: dad9ad4ce0f3cfa38e5ea202cfd05954549bf966fc31761966417edcb1ce9e23ec12127704265d8af0d036a0fdff38c018d7aa32a7e768ffb042030c0f5e65e3
7
+ data.tar.gz: 9e844726a5cf23d9abd994b72a789729824b6ad6f3b209a078bc863335a640c528d9f9884046e5866449f388d4e30ec2a869b62c882afaaf822c11b50e7acb0a
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.406"
11
+ LIBLEPTRIS_VERSION = "1.9.407"
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
@@ -2840,6 +2840,41 @@ static VALUE nf_walk_addresses(VALUE self, VALUE root)
2840
2840
  return rb_ary_new3(3, names, addrs, depths);
2841
2841
  }
2842
2842
 
2843
+ /* ---- Raw child addresses (leptris-ruby#587 shadow lane) ----------
2844
+ * The per-node counterpart of walk_addresses: ONE crossing returns
2845
+ * the parent's direct children as raw addresses + node kinds — no
2846
+ * wrapper mint, no identity-cache writes; kinds are the f_children_ex
2847
+ * ints (0 = element). Accepts a NativeNode handle or a raw address
2848
+ * Integer. Read-only consumers pair it with the address-keyed read
2849
+ * faces; a mutable, identity-backed handle mints through the normal
2850
+ * wrap path on first write. */
2851
+ static VALUE nf_children_addrs(VALUE self, VALUE parent)
2852
+ {
2853
+ void **buf;
2854
+ int *kinds;
2855
+ void *ptr;
2856
+ int count, i;
2857
+ VALUE addrs, kind_vals;
2858
+ (void)self;
2859
+ if (RB_INTEGER_TYPE_P(parent)) {
2860
+ ptr = (void *)(uintptr_t)NUM2ULL(parent);
2861
+ } else {
2862
+ struct native_node *n;
2863
+ TypedData_Get_Struct(parent, struct native_node, &nn_type, n);
2864
+ ptr = n->ptr;
2865
+ }
2866
+ count = fetch_children_two_call(ptr, &buf, &kinds);
2867
+ addrs = rb_ary_new2(count > 0 ? count : 0);
2868
+ kind_vals = rb_ary_new2(count > 0 ? count : 0);
2869
+ for (i = 0; i < count; i++) {
2870
+ rb_ary_push(addrs, ULL2NUM((uint64_t)(uintptr_t)buf[i]));
2871
+ rb_ary_push(kind_vals, INT2NUM(kinds[i]));
2872
+ }
2873
+ ruby_xfree(buf);
2874
+ ruby_xfree(kinds);
2875
+ return rb_ary_new3(2, addrs, kind_vals);
2876
+ }
2877
+
2843
2878
  /* ---- Struct plan executor (moxml "miles faster" round) ------------
2844
2879
  * The consumer's shape compiles to spec: name (interned String) ->
2845
2880
  * [Struct class, attrs Hash (name -> slot Symbol), text slot Symbol
@@ -4283,6 +4318,8 @@ static void leptris_native_setup(void)
4283
4318
  nf_walk_columnar, 1);
4284
4319
  rb_define_module_function(m_native, "walk_addresses",
4285
4320
  nf_walk_addresses, 1);
4321
+ rb_define_module_function(m_native, "children_addrs",
4322
+ nf_children_addrs, 1);
4286
4323
  rb_define_module_function(m_native, "attribute_pairs",
4287
4324
  nf_attribute_pairs, 2);
4288
4325
  rb_define_module_function(m_native, "plan_structs",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.9.406.1"
4
+ VERSION = "1.9.407.0"
5
5
  end
@@ -166,7 +166,14 @@ class Leptris::XML::Descriptor
166
166
  tree_index = plans.size - 1
167
167
  memo[key] = tree_index
168
168
  duped[:children] = (duped[:children] || []).map do |row|
169
- if row[:kind] == :nested
169
+ # leptris#1966: :ordered_deferred rows carry child :plan trees
170
+ # exactly like :nested rows (lutaml's emission_rows_for
171
+ # materializes the deferred subtree) — skipping them here
172
+ # left deferred subtrees WITHOUT descriptor slots, so the
173
+ # slot numbering diverged from the emission graph at the
174
+ # first deferred row and the ops' plan_index pointed at the
175
+ # wrong plan (engine status=-5 on the theme/styles shapes).
176
+ if row[:kind] == :nested || row[:kind] == :ordered_deferred
170
177
  row.merge(child_plan_index: flatten_plan(row.fetch(:plan), plans,
171
178
  memo))
172
179
  else
@@ -426,8 +433,20 @@ class Leptris::XML::Descriptor
426
433
  raw = Leptris::XML::FFI.leptris_plan_result_build(
427
434
  @handle, memory, ops.size, status)
428
435
  if raw.null?
436
+ # leptris#1966 ask 2: the bare "status=-5" sent three consumers
437
+ # hunting an ABI bug that did not exist. Carry the op-stream
438
+ # shape — op count, plan count, and the ops at the highest
439
+ # plan_index — so an out-of-range reference is visible at a
440
+ # glance.
441
+ max_pi = ops.filter_map { |o| o[:plan_index] }.max
442
+ at_max = ops.each_index
443
+ .select { |i| ops[i][:plan_index] == max_pi }
444
+ .first(3)
429
445
  raise Leptris::XML::Error,
430
- "plan result build failed (status=#{status.read_int})"
446
+ "plan result build failed (status=#{status.read_int}; " \
447
+ "ops=#{ops.size} plans=#{@plans.size} " \
448
+ "max_plan_index=#{max_pi.inspect} " \
449
+ "ops_at_max=#{at_max.map { |i| [i, ops[i][:kind], ops[i][:row_index]] }.inspect})"
431
450
  end
432
451
  Leptris::XML::PlanValue.new(ResultHandle.new(raw),
433
452
  owner: true, plans: @plans, plan: @plans[0])
Binary file
Binary file
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.406
4
+ - libleptris v1.9.407
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand:
@@ -1,5 +1,18 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.407] - 2026-11-05
4
+
5
+ ### Fixed
6
+
7
+ - deep-copy attr and element ns_prefix past the spec buffers (descriptor)
8
+ - keep sys/mman.h off the Windows include path (memory)
9
+
10
+ ### Performance
11
+
12
+ - oversized arena spans return to the OS on drop (#1947) (memory)
13
+
14
+
15
+
3
16
  ## [1.9.406] - 2026-11-03
4
17
 
5
18
  ### Added
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(leptris
6
- VERSION 1.9.406
6
+ VERSION 1.9.407
7
7
  DESCRIPTION "Fast XML parser and XPath evaluator in pure C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -370,6 +370,7 @@ static void dp_plan_free(LeptrisPlan p) {
370
370
  for (uint32_t a = 0; a < d->attribute_count; a++) {
371
371
  free((char *)d->attribute_plans[a].wire_name);
372
372
  free((char *)d->attribute_plans[a].ns_uri);
373
+ free((char *)d->attribute_plans[a].ns_prefix);
373
374
  for (uint16_t pi = 0;
374
375
  pi < d->attribute_plans[a].predicate_count; pi++) {
375
376
  free((char*)d->attribute_plans[a]
@@ -449,9 +450,12 @@ LEPTRIS_API LeptrisPlan leptris_plan_build(const leptris_plan_spec* spec,
449
450
  if (s->ns_uri) {
450
451
  d->ns_uri = dp_strdup(s->ns_uri);
451
452
  if (!d->ns_uri) goto oom;
453
+ }
454
+ /* #1967: the prefix must copy OUTSIDE the ns_uri branch — a
455
+ * plan carrying a prefix with no URI otherwise keeps the
456
+ * caller's anchor pointer. */
452
457
  d->ns_prefix = s->ns_prefix ? dp_strdup(s->ns_prefix) : NULL;
453
458
  if (s->ns_prefix && !d->ns_prefix) goto oom;
454
- }
455
459
  d->flags = s->flags;
456
460
 
457
461
  if (s->attribute_count) {
@@ -508,6 +512,17 @@ LEPTRIS_API LeptrisPlan leptris_plan_build(const leptris_plan_spec* spec,
508
512
  dp_strdup(s->attribute_plans[a].wire_name);
509
513
  if (!d->attribute_plans[a].wire_name) goto oom;
510
514
  }
515
+ /* #1967: attr ns_prefix rode the struct copy — a
516
+ * dangling pointer into the caller's build buffers
517
+ * once the bindings GC their anchors (the #1585
518
+ * lesson; child rows already retain). */
519
+ d->attribute_plans[a].ns_prefix =
520
+ s->attribute_plans[a].ns_prefix
521
+ ? dp_strdup(s->attribute_plans[a].ns_prefix)
522
+ : NULL;
523
+ if (s->attribute_plans[a].ns_prefix &&
524
+ !d->attribute_plans[a].ns_prefix)
525
+ goto oom;
511
526
  uint16_t pc = s->attribute_plans[a].predicate_count;
512
527
  if (pc) {
513
528
  if (!s->attribute_plans[a].predicates) goto oom;
@@ -1,6 +1,38 @@
1
1
  /* lib/src/memory/arena.c — Contiguous per-document arena (TODO 183)
2
2
  * Copyright (c) 2024, Ribose Inc.
3
3
  */
4
+ /* glibc hides MAP_ANONYMOUS under -std=c99 (__STRICT_ANSI__); the
5
+ * feature-test macros must precede every include of this TU. The
6
+ * build adds _POSIX_C_SOURCE=200809L publicly, which puts Apple's
7
+ * headers in strict mode — _DARWIN_C_SOURCE restores the BSD names
8
+ * (MAP_ANON/MAP_ANONYMOUS) there. */
9
+ #if defined(__linux__) && !defined(_DEFAULT_SOURCE)
10
+ #define _DEFAULT_SOURCE 1
11
+ #endif
12
+ #if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
13
+ #define _DARWIN_C_SOURCE 1
14
+ #endif
15
+
16
+ /* ---- #1947 lever 2: direct (anonymous-mmap) spans ---------------------
17
+ *
18
+ * A span above the retain budget can never be parked (retain_give
19
+ * frees it unconditionally), so acquiring it through malloc buys
20
+ * nothing and the freed pages linger in allocator magazines — the
21
+ * ~2 GB post-drop residency the XMI/CityGML pipeline reports. Oversized
22
+ * spans are taken mmap-direct and returned with munmap on destroy, so
23
+ * the drop face collapses RSS deterministically.
24
+ *
25
+ * Stands down under ASAN (the malloc path keeps use-after-free visible
26
+ * to the shadow) and under custom allocators (hooked accounting must
27
+ * see every byte the library takes). Within-budget spans keep the
28
+ * park-and-reuse lane — the repeated-parse fault fix depends on it. */
29
+ #if defined(_WIN32)
30
+ #define LEPTRIS_HAS_DIRECT_SPANS 1
31
+ #elif !defined(__wasm__) && !defined(__EMSCRIPTEN__) && \
32
+ (defined(__unix__) || defined(__APPLE__) || defined(__MACH__))
33
+ #define LEPTRIS_HAS_DIRECT_SPANS 1
34
+ #endif
35
+
4
36
  #include "arena.h"
5
37
 
6
38
  #include "../common/port.h" /* LEPTRIS_THREAD_LOCAL */
@@ -8,8 +40,19 @@
8
40
  #include <stdlib.h>
9
41
  #include <stdio.h>
10
42
  #include <string.h>
11
- #if defined(__linux__)
12
- #include <sys/mman.h> /* madvise(MADV_HUGEPAGE) — Linux only */
43
+ #if defined(__linux__) || \
44
+ (defined(LEPTRIS_HAS_DIRECT_SPANS) && !defined(_WIN32))
45
+ #include <sys/mman.h> /* madvise(MADV_HUGEPAGE), mmap/munmap */
46
+ #endif
47
+
48
+ #if defined(_WIN32)
49
+ #include <windows.h>
50
+ #endif
51
+
52
+ /* BSD headers name it MAP_ANON; the POSIX spelling may be absent. */
53
+ #if defined(LEPTRIS_HAS_DIRECT_SPANS) && !defined(MAP_ANONYMOUS) && \
54
+ defined(MAP_ANON)
55
+ #define MAP_ANONYMOUS MAP_ANON
13
56
  #endif
14
57
 
15
58
  /* Allocation hooks (core.c): honoring the public
@@ -296,6 +339,66 @@ char* leptris_arena_buffer_alloc(size_t size) {
296
339
  return base ? base : (char*)leptris_alloc_hook(size);
297
340
  }
298
341
 
342
+ /* ---- Direct-span transport (#1947) ----------------------------------- */
343
+
344
+ static size_t g_span_direct_taken;
345
+ static size_t g_span_direct_released;
346
+
347
+ int leptris_arena_has_direct_spans(void) {
348
+ #if defined(LEPTRIS_HAS_DIRECT_SPANS)
349
+ return 1;
350
+ #else
351
+ return 0;
352
+ #endif
353
+ }
354
+
355
+ void leptris_arena_span_stats(size_t* direct_taken, size_t* direct_released) {
356
+ if (direct_taken) *direct_taken = g_span_direct_taken;
357
+ if (direct_released) *direct_released = g_span_direct_released;
358
+ }
359
+
360
+ #if defined(_WIN32)
361
+
362
+ static int span_direct_acquire(char** out, size_t size) {
363
+ void* p = VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT,
364
+ PAGE_READWRITE);
365
+ if (!p) return 0;
366
+ *out = (char*)p;
367
+ return 1;
368
+ }
369
+
370
+ static void span_direct_release(char* base, size_t size) {
371
+ (void)size;
372
+ VirtualFree(base, 0, MEM_RELEASE);
373
+ }
374
+
375
+ #elif defined(LEPTRIS_HAS_DIRECT_SPANS)
376
+
377
+ static int span_direct_acquire(char** out, size_t size) {
378
+ void* p = mmap(NULL, size, PROT_READ | PROT_WRITE,
379
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
380
+ if (p == MAP_FAILED) return 0;
381
+ *out = (char*)p;
382
+ return 1;
383
+ }
384
+
385
+ static void span_direct_release(char* base, size_t size) {
386
+ munmap(base, size);
387
+ }
388
+
389
+ #else
390
+
391
+ static int span_direct_acquire(char** out, size_t size) {
392
+ (void)out; (void)size;
393
+ return 0;
394
+ }
395
+
396
+ static void span_direct_release(char* base, size_t size) {
397
+ (void)base; (void)size;
398
+ }
399
+
400
+ #endif
401
+
299
402
  void leptris_arena_buffer_release(void* p, size_t size) {
300
403
  if (!p) return;
301
404
  retain_give((char*)p, size);
@@ -335,13 +438,30 @@ LeptrisArena* leptris_arena_create(size_t size) {
335
438
  return NULL;
336
439
  size_t want = size + hdr;
337
440
  size_t capacity = want;
338
- char* span = retain_take(want, &capacity);
339
- if (!span) {
340
- span = (char*)leptris_alloc_hook(want);
441
+ char* span = NULL;
442
+ int direct = 0;
443
+ #ifndef ARENA_RETAIN_ASAN
444
+ /* #1947: above the retain budget the span can never be parked, so
445
+ * the libc lane only adds magazine residency. Take it direct. */
446
+ if (want > ARENA_RETAIN_MAX_BYTES && !leptris_custom_allocator_active() &&
447
+ span_direct_acquire(&span, want)) {
341
448
  capacity = want;
342
- if (!span) return NULL;
449
+ direct = 1;
450
+ retain_lock();
451
+ g_span_direct_taken++;
452
+ retain_unlock();
343
453
  arena_advise_hugepages(span, capacity);
344
454
  }
455
+ #endif
456
+ if (!span) {
457
+ span = retain_take(want, &capacity);
458
+ if (!span) {
459
+ span = (char*)leptris_alloc_hook(want);
460
+ capacity = want;
461
+ if (!span) return NULL;
462
+ arena_advise_hugepages(span, capacity);
463
+ }
464
+ }
345
465
  LeptrisArena* arena = (LeptrisArena*)span;
346
466
  arena->span = span;
347
467
  arena->base = span + hdr;
@@ -351,6 +471,7 @@ LeptrisArena* leptris_arena_create(size_t size) {
351
471
  arena->size = capacity - hdr;
352
472
  arena->used = 0;
353
473
  arena->failed = 0;
474
+ arena->direct = direct;
354
475
  return arena;
355
476
  }
356
477
 
@@ -364,9 +485,16 @@ void leptris_arena_destroy(LeptrisArena* arena) {
364
485
  if (!arena) return;
365
486
  /* The header lives inside the span — releasing the block
366
487
  * releases everything. */
367
- retain_give(arena->span, arena->size +
368
- ((sizeof(LeptrisArena) + ARENA_ALIGNMENT - 1) &
369
- ~(ARENA_ALIGNMENT - 1)));
488
+ const size_t hdr = (sizeof(LeptrisArena) + ARENA_ALIGNMENT - 1) &
489
+ ~(ARENA_ALIGNMENT - 1);
490
+ if (arena->direct) {
491
+ span_direct_release(arena->span, arena->size + hdr);
492
+ retain_lock();
493
+ g_span_direct_released++;
494
+ retain_unlock();
495
+ return;
496
+ }
497
+ retain_give(arena->span, arena->size + hdr);
370
498
  }
371
499
 
372
500
  void* leptris_arena_alloc(LeptrisArena* arena, size_t size) {
@@ -39,6 +39,8 @@ typedef struct leptris_arena {
39
39
  size_t size; /* Bump-region capacity (span capacity minus header) */
40
40
  size_t used; /* Bump pointer — bytes handed out so far */
41
41
  size_t failed; /* 1 once any request has been refused (sticky) */
42
+ int direct; /* 1 when the span is an anonymous mmap owned by the
43
+ * arena — destroy must munmap, not park or free */
42
44
  } LeptrisArena;
43
45
 
44
46
  /* Create an arena of `size` bytes (one malloc). Returns NULL on
@@ -59,6 +61,14 @@ void leptris_arena_destroy(LeptrisArena* arena);
59
61
  /* Release retained arena blocks (leptris_thread_cleanup drain). */
60
62
  void leptris_arena_retain_drain(void);
61
63
 
64
+ /* #1947 lever 2: spans above the retain budget never park, so they
65
+ * bypass the libc allocator — anonymous mmap on acquire, munmap on
66
+ * destroy — and a dropped document's pages return to the OS
67
+ * deterministically instead of lingering in allocator magazines.
68
+ * Internal observability for specs; not part of the public ABI. */
69
+ int leptris_arena_has_direct_spans(void);
70
+ void leptris_arena_span_stats(size_t* direct_taken, size_t* direct_released);
71
+
62
72
  /* Bump-allocate `size` bytes, 8-byte aligned. NOT zeroed.
63
73
  * Returns NULL when the request does not fit in remaining space —
64
74
  * no fallback allocation, ever (see the contract above). */
@@ -8,6 +8,7 @@
8
8
  #include <leptris.h>
9
9
  #include <leptris/descriptor.h>
10
10
  #include <cstring>
11
+ #include <cstdio>
11
12
  #include <string>
12
13
 
13
14
  namespace {
@@ -785,6 +786,117 @@ TEST(PlanBuild, CopiesTheSpecStrings) {
785
786
  leptris_document_free(doc);
786
787
  }
787
788
 
789
+ /* #1967: every spec string the plan carries must be retained past
790
+ * build — the bindings anchor ns_prefix in FFI buffers that die with
791
+ * the build call, so a struct-copied pointer reads freed heap bytes
792
+ * at serialize time. The attr row's ns_prefix missed the dp_strdup
793
+ * the element plans (#1551) and child rows (#1585) already had, and
794
+ * the element plan's copy sat inside the ns_uri branch (a prefix
795
+ * with no URI never copied). Mirrors CopiesTheSpecStrings: the spec
796
+ * buffers are freed right after build, then the plan serializes. */
797
+ TEST(PlanBuild, CopiesAttrAndElementNsPrefixesPastSpecFree) {
798
+ LeptrisStatus st = LEPTRIS_OK;
799
+
800
+ /* Heap-anchored like the bindings' FFI::MemoryPointer strings:
801
+ * freed the moment build returns, so a retained pointer reads
802
+ * freed heap bytes. (Stack buffers would survive the whole test
803
+ * and hide the defect.) */
804
+ char* root_prefix_buf = strdup("w");
805
+ char* attr_name_buf = strdup("val");
806
+ char* attr_prefix_buf = strdup("w");
807
+
808
+ leptris_attr_plan* attrs =
809
+ (leptris_attr_plan*)calloc(1, sizeof(leptris_attr_plan));
810
+ attrs[0].wire_name = attr_name_buf;
811
+ attrs[0].kind = LEPTRIS_PLAN_KIND_SCALAR;
812
+ attrs[0].ns_form = LEPTRIS_PLAN_NS_EXACT;
813
+ attrs[0].ns_uri = "urn:w";
814
+ attrs[0].ns_prefix = attr_prefix_buf;
815
+
816
+ /* Element plan: prefix WITHOUT a uri — the un-nesting defect. */
817
+ leptris_element_plan* plans =
818
+ (leptris_element_plan*)calloc(1, sizeof(leptris_element_plan));
819
+ plans[0].element_name = "updateFields";
820
+ plans[0].ns_form = LEPTRIS_PLAN_NS_EXACT;
821
+ plans[0].ns_uri = "urn:w";
822
+ plans[0].ns_prefix = root_prefix_buf;
823
+ plans[0].attribute_count = 1;
824
+ plans[0].attribute_plans = attrs;
825
+
826
+ leptris_plan_spec spec = {};
827
+ spec.abi_version = leptris_plan_abi_version();
828
+ spec.plan_count = 1;
829
+ spec.plans = plans;
830
+
831
+ LeptrisPlan plan = leptris_plan_build(&spec, &st);
832
+ ASSERT_NE(plan, nullptr);
833
+ /* Anchor drop: the bindings free their buffers as soon as build
834
+ * returns. */
835
+ free(attrs);
836
+ free(plans);
837
+ free(root_prefix_buf);
838
+ free(attr_name_buf);
839
+ free(attr_prefix_buf);
840
+
841
+ leptris_plan_row_op ops[3] = {};
842
+ ops[0].kind = LEPTRIS_PLAN_OP_ELEMENT;
843
+ ops[0].row_index = 0xFFFFFFFFu;
844
+ ops[1].kind = LEPTRIS_PLAN_OP_ATTR;
845
+ ops[1].row_index = 0;
846
+ ops[1].name = "val";
847
+ ops[1].value = "0";
848
+ ops[1].value_len = 1;
849
+ ops[2].kind = LEPTRIS_PLAN_OP_END;
850
+
851
+ /* Two serializations: the first may still read live bytes; the
852
+ * second runs after churn has had a chance to reuse the freed
853
+ * buffers' memory. */
854
+ for (int round = 0; round < 2; round++) {
855
+ if (round == 1) {
856
+ /* Churn through the plan-build allocation paths
857
+ * themselves (the repro that surfaced #1967): build and
858
+ * drop descriptors so their internal dp_strdup traffic
859
+ * consumes and rewrites the freed anchor chunks. Plain
860
+ * strdup cycles do not reliably reuse them under
861
+ * macOS's nano allocator. */
862
+ for (int i = 0; i < 50; i++) {
863
+ leptris_element_plan churn_plans[8] = {};
864
+ leptris_child_plan churn_kids[8][1] = {};
865
+ for (int j = 0; j < 8; j++) {
866
+ churn_plans[j].element_name = "elem";
867
+ churn_plans[j].ns_form = LEPTRIS_PLAN_NS_EXACT;
868
+ churn_plans[j].ns_uri = "urn:w";
869
+ churn_plans[j].ns_prefix = "wx";
870
+ churn_plans[j].child_count = 1;
871
+ churn_plans[j].child_plans = churn_kids[j];
872
+ churn_kids[j][0].wire_name = "CT_RPr";
873
+ churn_kids[j][0].kind = LEPTRIS_PLAN_KIND_SCALAR;
874
+ churn_kids[j][0].child_plan_index = -1;
875
+ }
876
+ leptris_plan_spec churn_spec = {};
877
+ churn_spec.abi_version = leptris_plan_abi_version();
878
+ churn_spec.plan_count = 8;
879
+ churn_spec.plans = churn_plans;
880
+ LeptrisPlan churned = leptris_plan_build(&churn_spec, &st);
881
+ ASSERT_NE(churned, nullptr);
882
+ leptris_plan_free(churned);
883
+ }
884
+ }
885
+ LeptrisPlanResult r =
886
+ leptris_plan_result_build(plan, ops, 3, &st);
887
+ ASSERT_NE(r, nullptr);
888
+ char* out = leptris_plan_serialize(plan, r, &st);
889
+ ASSERT_NE(out, nullptr);
890
+ EXPECT_STREQ(out,
891
+ "<w:updateFields xmlns:w=\"urn:w\" w:val=\"0\"/>")
892
+ << "round " << round;
893
+ leptris_free_string(out);
894
+ leptris_plan_result_free(r);
895
+ }
896
+
897
+ leptris_plan_free(plan);
898
+ }
899
+
788
900
  TEST(PlanAccessors, NullTolerant) {
789
901
  EXPECT_EQ(leptris_plan_value_kind(nullptr), LEPTRIS_PLAN_VALUE_ELEMENT);
790
902
  EXPECT_EQ(leptris_plan_value_name(nullptr), nullptr);
@@ -415,3 +415,112 @@ TEST(LeptrisArena, SameSizeReuseSurvivesMixedSizeTraffic) {
415
415
  leptris_arena_destroy(h);
416
416
  }
417
417
  }
418
+
419
+ // ---- #1947 lever 2: oversized spans bypass the libc allocator ------
420
+ // A span above the retain budget can never be parked (retain_give
421
+ // frees it unconditionally), so acquiring it through malloc buys
422
+ // nothing and the freed pages linger in allocator magazines — the
423
+ // ~2 GB post-drop residency the CityGML pipeline reports. Spans over
424
+ // ARENA_RETAIN_MAX_BYTES are taken mmap-direct and returned with
425
+ // munmap on destroy, so the drop face collapses RSS deterministically.
426
+ //
427
+ // The stats hook counts direct spans; it is internal (arena.h) — the
428
+ // public ABI surface is untouched.
429
+ TEST(ArenaDirectSpans, OversizedCreateGoesDirectNotMalloc) {
430
+ #if defined(ARENA_TESTS_ASAN)
431
+ GTEST_SKIP() << "direct spans disabled under ASAN (malloc path keeps UAF visible)";
432
+ #endif
433
+ if (!leptris_arena_has_direct_spans())
434
+ GTEST_SKIP() << "platform has no anonymous-mmap span path";
435
+ leptris_arena_retain_drain();
436
+ size_t taken0 = 0, released0 = 0;
437
+ leptris_arena_span_stats(&taken0, &released0);
438
+
439
+ const size_t kBig = 128u * 1024u * 1024u; /* > ARENA_RETAIN_MAX_BYTES */
440
+ LeptrisArena* a = leptris_arena_create(kBig);
441
+ ASSERT_NE(a, nullptr);
442
+ /* The bump region must still offer the full budget — direct
443
+ * acquisition is a transport swap, not a capacity change. */
444
+ EXPECT_EQ(leptris_arena_remaining(a), kBig);
445
+
446
+ size_t taken1 = 0, released1 = 0;
447
+ leptris_arena_span_stats(&taken1, &released1);
448
+ EXPECT_EQ(taken1, taken0 + 1) << "oversized span was not taken direct";
449
+ EXPECT_EQ(released1, released0);
450
+ leptris_arena_destroy(a);
451
+ }
452
+
453
+ TEST(ArenaDirectSpans, OversizedDestroyMunmapsInsteadOfParking) {
454
+ #if defined(ARENA_TESTS_ASAN)
455
+ GTEST_SKIP() << "direct spans disabled under ASAN (malloc path keeps UAF visible)";
456
+ #endif
457
+ if (!leptris_arena_has_direct_spans())
458
+ GTEST_SKIP() << "platform has no anonymous-mmap span path";
459
+ leptris_arena_retain_drain();
460
+ size_t taken0 = 0, released0 = 0;
461
+ leptris_arena_span_stats(&taken0, &released0);
462
+
463
+ const size_t kBig = 128u * 1024u * 1024u;
464
+ LeptrisArena* a = leptris_arena_create(kBig);
465
+ ASSERT_NE(a, nullptr);
466
+ leptris_arena_destroy(a);
467
+
468
+ size_t taken1 = 0, released1 = 0;
469
+ leptris_arena_span_stats(&taken1, &released1);
470
+ EXPECT_EQ(taken1, taken0 + 1);
471
+ EXPECT_EQ(released1, released0 + 1)
472
+ << "oversized span was parked or freed via libc instead of munmap";
473
+ }
474
+
475
+ TEST(ArenaDirectSpans, StandDownUnderCustomAllocator) {
476
+ #if defined(ARENA_TESTS_ASAN)
477
+ GTEST_SKIP() << "direct spans disabled under ASAN";
478
+ #endif
479
+ if (!leptris_arena_has_direct_spans())
480
+ GTEST_SKIP() << "platform has no anonymous-mmap span path";
481
+ leptris_arena_retain_drain();
482
+ leptris_set_memory_management_functions(
483
+ recycle_counting_alloc, recycle_counting_free);
484
+ g_recycle_allocs = 0;
485
+ g_recycle_frees = 0;
486
+ size_t taken0 = 0, released0 = 0;
487
+ leptris_arena_span_stats(&taken0, &released0);
488
+
489
+ LeptrisArena* a = leptris_arena_create(128u * 1024u * 1024u);
490
+ ASSERT_NE(a, nullptr);
491
+ leptris_arena_destroy(a);
492
+
493
+ size_t taken1 = 0, released1 = 0;
494
+ leptris_arena_span_stats(&taken1, &released1);
495
+ /* Hooked accounting must see the whole cycle — no direct lane. */
496
+ EXPECT_EQ(taken1, taken0);
497
+ EXPECT_EQ(released1, released0);
498
+ EXPECT_EQ(g_recycle_allocs, 1);
499
+ EXPECT_EQ(g_recycle_frees, 1);
500
+
501
+ leptris_arena_retain_drain();
502
+ leptris_set_memory_management_functions(NULL, NULL);
503
+ }
504
+
505
+ TEST(ArenaDirectSpans, WithinBudgetSpanNeverGoesDirect) {
506
+ #if defined(ARENA_TESTS_ASAN)
507
+ GTEST_SKIP() << "retain cache disabled under ASAN";
508
+ #endif
509
+ if (!leptris_arena_has_direct_spans())
510
+ GTEST_SKIP() << "platform has no anonymous-mmap span path";
511
+ leptris_arena_retain_drain();
512
+ size_t taken0 = 0, released0 = 0;
513
+ leptris_arena_span_stats(&taken0, &released0);
514
+
515
+ LeptrisArena* a = leptris_arena_create(1u * 1024u * 1024u);
516
+ ASSERT_NE(a, nullptr);
517
+ leptris_arena_destroy(a);
518
+
519
+ size_t taken1 = 0, released1 = 0;
520
+ leptris_arena_span_stats(&taken1, &released1);
521
+ /* Retain-budget spans keep the park-and-reuse lane: the repeated
522
+ * parse fault fix depends on it. */
523
+ EXPECT_EQ(taken1, taken0);
524
+ EXPECT_EQ(released1, released0);
525
+ leptris_arena_retain_drain();
526
+ }
@@ -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.406",
4
+ "version": "1.9.407",
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.406.1
4
+ version: 1.9.407.0
5
5
  platform: ppc64le-linux
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-04 00:00:00.000000000 Z
11
+ date: 2026-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi