leptris 1.9.406.1 → 1.9.408.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/ext/leptris/native/native.c +37 -0
- data/lib/leptris/vendor/aarch64-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/aarch64-linux-musl/libleptris.so +0 -0
- data/lib/leptris/vendor/arm-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/arm-linux-musl/libleptris.so +0 -0
- data/lib/leptris/vendor/arm64-darwin/libleptris.dylib +0 -0
- data/lib/leptris/vendor/ppc64le-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/s390x-linux-musl/libleptris.so +0 -0
- data/lib/leptris/vendor/x86_64-darwin/libleptris.dylib +0 -0
- data/lib/leptris/vendor/x86_64-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/x86_64-linux-musl/libleptris.so +0 -0
- data/lib/leptris/version.rb +1 -1
- data/lib/leptris/xml/descriptor.rb +21 -2
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +23 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/src/leptris/descriptor/plan.c +79 -13
- data/vendor-src/libleptris/src/leptris/memory/arena.c +137 -9
- data/vendor-src/libleptris/src/leptris/memory/arena.h +10 -0
- data/vendor-src/libleptris/src/leptris/xsd/compile.c +41 -1
- data/vendor-src/libleptris/src/leptris/xsd/validate.c +92 -1
- data/vendor-src/libleptris/test/abi/test_descriptor.cpp +211 -0
- data/vendor-src/libleptris/test/memory/test_arena.cpp +109 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/attgD019-set/attgD019.xsd +23 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/attgD019-set/attgD019a.xsd +4 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/stE-union-fixed/stE050.xml +1 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/stE-union-fixed/stE050.xsd +7 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/stE-union-fixed/stE055.xml +1 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/stE-union-fixed/stE055.xsd +7 -0
- data/vendor-src/libleptris/test/xsd/test_i1957_1958.cpp +35 -0
- data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +26 -0
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 34d1611db686219acbaed081b637a0c36b53959fedcba506b79b77802363f421
|
|
4
|
+
data.tar.gz: 79a9c1ebfe9f121a760d341b24f2f30d85c3fff51522bf4ab6007ab20b09e9a3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 346ea572efb4315248b5b20eb5c03e4a29893f96002f74fce3d0b77f6d2d270414e48e2581e4c39739eb3d6b832443a56b3c9d4c8ace66709d06aa718b2e35e3
|
|
7
|
+
data.tar.gz: 1f9a9215433bc6fb69a87becf524f3d25efd0e24e98a916e0dbf1efce8434255ca33f3b64b577cbdab99715ff7fb55c52c5d89da1b8e3d8508893a624ba8f6ad
|
data/Rakefile
CHANGED
|
@@ -8,7 +8,7 @@ RSpec::Core::RakeTask.new(:spec)
|
|
|
8
8
|
# Pin for `rake compile` and the platform-gem builds. Keep in lockstep
|
|
9
9
|
# with .github/workflows/build.yml (which calls `rake compile`) and the
|
|
10
10
|
# CHANGELOG when libleptris releases.
|
|
11
|
-
LIBLEPTRIS_VERSION = "1.9.
|
|
11
|
+
LIBLEPTRIS_VERSION = "1.9.408"
|
|
12
12
|
# Vendored alongside libleptris for fn:normalize-unicode (TODO
|
|
13
13
|
# .restructure/20): built per platform with a RELOCATABLE @rpath
|
|
14
14
|
# install name, loaded by ffi.rb before libleptris so the
|
data/ext/leptris/native/native.c
CHANGED
|
@@ -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",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/leptris/version.rb
CHANGED
|
@@ -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
|
-
|
|
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])
|
data/vendor-src/README.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [1.9.408] - 2026-11-05
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- emit default-xmlns declarations for prefix-less EXACT rows (#1969) (descriptor)
|
|
8
|
+
- the union value-space fix + default-xmlns emission (leptris-rs#45, leptris#1969) (engine)
|
|
9
|
+
- union-typed fixed constraints compare in the value space (leptris-rs#45) (xsd)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## [1.9.407] - 2026-11-05
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- deep-copy attr and element ns_prefix past the spec buffers (descriptor)
|
|
18
|
+
- keep sys/mman.h off the Windows include path (memory)
|
|
19
|
+
|
|
20
|
+
### Performance
|
|
21
|
+
|
|
22
|
+
- oversized arena spans return to the OS on drop (#1947) (memory)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
3
26
|
## [1.9.406] - 2026-11-03
|
|
4
27
|
|
|
5
28
|
### Added
|
|
@@ -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;
|
|
@@ -1510,7 +1525,8 @@ static char* dp_wrapper_name(const struct leptris_plan_result* v) {
|
|
|
1510
1525
|
|
|
1511
1526
|
static int dp_emit_element_open(const struct leptris_plan_result* v,
|
|
1512
1527
|
const char* name, dp_sb* b,
|
|
1513
|
-
const dp_decls* decls, int is_root
|
|
1528
|
+
const dp_decls* decls, int is_root,
|
|
1529
|
+
const char* default_claim) {
|
|
1514
1530
|
if (!dp_sb_putn(b, "<", 1) || !dp_sb_puts(b, name)) return 0;
|
|
1515
1531
|
if (is_root && decls) {
|
|
1516
1532
|
for (size_t i = 0; i < decls->n; i++) {
|
|
@@ -1520,6 +1536,17 @@ static int dp_emit_element_open(const struct leptris_plan_result* v,
|
|
|
1520
1536
|
return 0;
|
|
1521
1537
|
}
|
|
1522
1538
|
}
|
|
1539
|
+
/* leptris#1969: a prefix-less EXACT binding is the DEFAULT
|
|
1540
|
+
* namespace — emit the bare local name and declare xmlns="uri"
|
|
1541
|
+
* when the claim differs from the in-scope default (the root
|
|
1542
|
+
* hoists it once; deeper same-uri nodes inherit). Attribute
|
|
1543
|
+
* rows never take this form (W3C: attributes cannot
|
|
1544
|
+
* default-bind). */
|
|
1545
|
+
if (default_claim) {
|
|
1546
|
+
if (!dp_sb_puts(b, " xmlns=\"") ||
|
|
1547
|
+
!dp_sb_puts(b, default_claim) || !dp_sb_putn(b, "\"", 1))
|
|
1548
|
+
return 0;
|
|
1549
|
+
}
|
|
1523
1550
|
for (size_t a = 0; a < v->attr_count; a++) {
|
|
1524
1551
|
/* leptris#1941: a row with an emission binding spells
|
|
1525
1552
|
* "prefix:local" (dp_wrapper_name's element contract);
|
|
@@ -1569,14 +1596,17 @@ static int dp_sb_indent_newline(dp_sb* b, const dp_fmt* fmt, int depth) {
|
|
|
1569
1596
|
static int dp_emit_value(const struct leptris_plan_result* v,
|
|
1570
1597
|
const dp_plan* container, const LeptrisPlan pool,
|
|
1571
1598
|
dp_sb* b, const dp_decls* decls, int is_root,
|
|
1572
|
-
const dp_fmt* fmt, int depth
|
|
1599
|
+
const dp_fmt* fmt, int depth,
|
|
1600
|
+
const char* cur_default);
|
|
1573
1601
|
|
|
1574
1602
|
static int dp_emit_element(const struct leptris_plan_result* v,
|
|
1575
1603
|
const char* name, const LeptrisPlan pool,
|
|
1576
1604
|
const dp_plan* kids_container, dp_sb* b,
|
|
1577
1605
|
const dp_decls* decls, int is_root,
|
|
1578
|
-
const dp_fmt* fmt, int depth
|
|
1579
|
-
|
|
1606
|
+
const dp_fmt* fmt, int depth,
|
|
1607
|
+
const char* cur_default) {
|
|
1608
|
+
if (!dp_emit_element_open(v, name, b, decls, is_root, cur_default))
|
|
1609
|
+
return 0;
|
|
1580
1610
|
const struct leptris_plan_result** kids = NULL;
|
|
1581
1611
|
size_t nk = 0, cap = 0;
|
|
1582
1612
|
if (!dp_flatten_kids(v, &kids, &nk, &cap)) {
|
|
@@ -1601,6 +1631,10 @@ static int dp_emit_element(const struct leptris_plan_result* v,
|
|
|
1601
1631
|
* parent), so a nested member resolved its kids' rows against
|
|
1602
1632
|
* the parent's rows and a CONTENT row serialized as an
|
|
1603
1633
|
* empty-named wrapper. */
|
|
1634
|
+
/* leptris#1969: this element's own claim sets the kids'
|
|
1635
|
+
* in-scope default (a default-xmlns re-declaration nests). */
|
|
1636
|
+
const char* kid_default = cur_default;
|
|
1637
|
+
if (v->ns_uri && !v->ns_prefix) kid_default = v->ns_uri;
|
|
1604
1638
|
int ok = 1;
|
|
1605
1639
|
for (size_t i = 0; i < nk && ok; i++) {
|
|
1606
1640
|
if (indent_kids && !dp_sb_indent_newline(b, fmt, depth + 1)) {
|
|
@@ -1608,7 +1642,8 @@ static int dp_emit_element(const struct leptris_plan_result* v,
|
|
|
1608
1642
|
break;
|
|
1609
1643
|
}
|
|
1610
1644
|
ok = dp_emit_value(kids[i], kids_container, pool, b, NULL, 0,
|
|
1611
|
-
fmt, indent_kids ? depth + 1 : depth
|
|
1645
|
+
fmt, indent_kids ? depth + 1 : depth,
|
|
1646
|
+
kid_default);
|
|
1612
1647
|
}
|
|
1613
1648
|
free((void*)kids);
|
|
1614
1649
|
if (!ok) return 0;
|
|
@@ -1623,7 +1658,8 @@ static int dp_emit_element(const struct leptris_plan_result* v,
|
|
|
1623
1658
|
static int dp_emit_value(const struct leptris_plan_result* v,
|
|
1624
1659
|
const dp_plan* container, const LeptrisPlan pool,
|
|
1625
1660
|
dp_sb* b, const dp_decls* decls, int is_root,
|
|
1626
|
-
const dp_fmt* fmt, int depth
|
|
1661
|
+
const dp_fmt* fmt, int depth,
|
|
1662
|
+
const char* cur_default) {
|
|
1627
1663
|
if (v->kind == LEPTRIS_PLAN_VALUE_RAW)
|
|
1628
1664
|
return dp_sb_puts(b, v->str ? v->str : "");
|
|
1629
1665
|
if (v->kind == LEPTRIS_PLAN_VALUE_ELEMENT) {
|
|
@@ -1673,8 +1709,17 @@ static int dp_emit_value(const struct leptris_plan_result* v,
|
|
|
1673
1709
|
kids_container =
|
|
1674
1710
|
&poolp->plans[cap->child_plan_index];
|
|
1675
1711
|
}
|
|
1712
|
+
/* leptris#1969: this node's default-xmlns claim (a ns_uri
|
|
1713
|
+
* without a prefix). Emitted only when it differs from the
|
|
1714
|
+
* in-scope default; the kids inherit the claim. */
|
|
1715
|
+
const char* claim =
|
|
1716
|
+
(v->ns_uri && !v->ns_prefix) ? v->ns_uri : NULL;
|
|
1717
|
+
const char* open_claim =
|
|
1718
|
+
(claim && (!cur_default || strcmp(claim, cur_default) != 0))
|
|
1719
|
+
? claim
|
|
1720
|
+
: NULL;
|
|
1676
1721
|
int ok = dp_emit_element(v, name, pool, kids_container, b,
|
|
1677
|
-
decls, is_root, fmt, depth);
|
|
1722
|
+
decls, is_root, fmt, depth, open_claim);
|
|
1678
1723
|
free(name);
|
|
1679
1724
|
return ok;
|
|
1680
1725
|
}
|
|
@@ -1688,7 +1733,16 @@ static int dp_emit_value(const struct leptris_plan_result* v,
|
|
|
1688
1733
|
/* The row is the wrapper element around this text. */
|
|
1689
1734
|
char* name = dp_wrapper_name(v);
|
|
1690
1735
|
if (!name) return 0;
|
|
1736
|
+
/* leptris#1969: the wrapper's own default-xmlns claim. */
|
|
1737
|
+
const char* wclaim =
|
|
1738
|
+
(v->ns_uri && !v->ns_prefix &&
|
|
1739
|
+
(!cur_default || strcmp(v->ns_uri, cur_default) != 0))
|
|
1740
|
+
? v->ns_uri
|
|
1741
|
+
: NULL;
|
|
1691
1742
|
int ok = dp_sb_putn(b, "<", 1) && dp_sb_puts(b, name) &&
|
|
1743
|
+
(wclaim ? dp_sb_puts(b, " xmlns=\"") &&
|
|
1744
|
+
dp_sb_puts(b, wclaim) && dp_sb_putn(b, "\"", 1)
|
|
1745
|
+
: 1) &&
|
|
1692
1746
|
dp_sb_putn(b, ">", 1) && dp_sb_escape(b, text, 0) &&
|
|
1693
1747
|
dp_sb_puts(b, "</") && dp_sb_puts(b, name) &&
|
|
1694
1748
|
dp_sb_putn(b, ">", 1);
|
|
@@ -1717,7 +1771,7 @@ static char* dp_serialize_impl(LeptrisPlan plan,
|
|
|
1717
1771
|
}
|
|
1718
1772
|
dp_sb b = {0};
|
|
1719
1773
|
int ok = dp_emit_value(rv, NULL, (const LeptrisPlan)plan, &b,
|
|
1720
|
-
&decls, 1, fmt, 0);
|
|
1774
|
+
&decls, 1, fmt, 0, NULL);
|
|
1721
1775
|
dp_decls_free(&decls);
|
|
1722
1776
|
if (!ok) {
|
|
1723
1777
|
free(b.s);
|
|
@@ -1982,18 +2036,23 @@ static struct leptris_plan_result* plan_result_build_windowed(
|
|
|
1982
2036
|
} else if (cr->child_plan_index >= 0 &&
|
|
1983
2037
|
cr->child_plan_index <
|
|
1984
2038
|
(int32_t)pool->plan_count &&
|
|
1985
|
-
pool->plans[cr->child_plan_index].
|
|
2039
|
+
pool->plans[cr->child_plan_index].ns_uri &&
|
|
1986
2040
|
pool->plans[cr->child_plan_index].ns_form ==
|
|
1987
2041
|
LEPTRIS_PLAN_NS_EXACT) {
|
|
1988
2042
|
ns_src = &pool->plans[cr->child_plan_index];
|
|
1989
|
-
} else if (cp->
|
|
2043
|
+
} else if (cp->ns_uri &&
|
|
1990
2044
|
cp->ns_form == LEPTRIS_PLAN_NS_EXACT) {
|
|
1991
2045
|
ns_src = cp;
|
|
1992
2046
|
}
|
|
1993
2047
|
if (ns_src) {
|
|
1994
|
-
|
|
2048
|
+
/* leptris#1969: ns_prefix NULL + ns_uri set is
|
|
2049
|
+
* the DEFAULT-xmlns claim (bare local name,
|
|
2050
|
+
* xmlns="uri" hoisted on the emitting root). */
|
|
2051
|
+
v->ns_prefix = ns_src->ns_prefix
|
|
2052
|
+
? dp_strdup(ns_src->ns_prefix)
|
|
2053
|
+
: NULL;
|
|
1995
2054
|
v->ns_uri = dp_strdup(ns_src->ns_uri);
|
|
1996
|
-
if (!v->
|
|
2055
|
+
if (!v->ns_uri) goto oom;
|
|
1997
2056
|
}
|
|
1998
2057
|
} else if (cp->ns_prefix &&
|
|
1999
2058
|
cp->ns_form == LEPTRIS_PLAN_NS_EXACT) {
|
|
@@ -2002,6 +2061,13 @@ static struct leptris_plan_result* plan_result_build_windowed(
|
|
|
2002
2061
|
v->ns_prefix = dp_strdup(cp->ns_prefix);
|
|
2003
2062
|
v->ns_uri = dp_strdup(cp->ns_uri);
|
|
2004
2063
|
if (!v->ns_prefix || !v->ns_uri) goto oom;
|
|
2064
|
+
} else if (cp->ns_uri &&
|
|
2065
|
+
cp->ns_form == LEPTRIS_PLAN_NS_EXACT) {
|
|
2066
|
+
/* leptris#1969: the root op binds the plan's own
|
|
2067
|
+
* DEFAULT namespace (prefix-less EXACT) —
|
|
2068
|
+
* xmlns="uri" hoists on the output root. */
|
|
2069
|
+
v->ns_uri = dp_strdup(cp->ns_uri);
|
|
2070
|
+
if (!v->ns_uri) goto oom;
|
|
2005
2071
|
}
|
|
2006
2072
|
if (sp == 0) {
|
|
2007
2073
|
if (root) {
|
|
@@ -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
|
-
|
|
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 =
|
|
339
|
-
|
|
340
|
-
|
|
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
|
-
|
|
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
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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). */
|