leptris 1.9.429.0 → 1.9.432.1
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/CHANGELOG.md +4 -0
- data/Rakefile +1 -1
- data/lib/leptris/vendor/aarch64-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/aarch64-linux/libutf8proc.so.3 +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/libutf8proc.so.3 +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/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +32 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/benchmarks/modification/bench_append_attr_pugixml.cpp +42 -14
- data/vendor-src/libleptris/src/CMakeLists.txt +0 -2
- data/vendor-src/libleptris/src/leptris/html/html_parse.c +92 -1
- data/vendor-src/libleptris/src/leptris/memory/pool.c +69 -3
- data/vendor-src/libleptris/src/leptris/memory/pool.h +8 -0
- data/vendor-src/libleptris/src/leptris/rng/validate.c +320 -27
- data/vendor-src/libleptris/src/leptris/xsd/datatypes.c +11 -5
- data/vendor-src/libleptris/test/CMakeLists.txt +1 -0
- data/vendor-src/libleptris/test/fuzz/corpus/html_reconstruction_nest_min.bin +0 -0
- data/vendor-src/libleptris/test/html/test_html_amplification.cpp +78 -0
- data/vendor-src/libleptris/test/memory/test_mut_recycle.cpp +28 -2
- data/vendor-src/libleptris/test/rng/include-cases/i2093-base.rng +9 -0
- data/vendor-src/libleptris/test/rng/include-cases/i2093-ext.rng +7 -0
- data/vendor-src/libleptris/test/rng/test_rng.cpp +659 -0
- data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +22 -0
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6fb86b5a28f17bdcebad9e055e93da1276e37204223f7dddbcbbb2b3618f4274
|
|
4
|
+
data.tar.gz: 3a474fbf9c46513f2a4b74d9c8a541d8884463ad02bcbd1fa764d0880b634863
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 252217b71f6b62797f834c25f60d53e64fe9ffbab0a36d047182d55cdbb6e74ecba0820c85d084ea8833f42a8a2a25487324bdee4cb3a3ae4f9574b0712ca1a8
|
|
7
|
+
data.tar.gz: 1789373474273e70b02c67bf025991412494a59f7f3c4f6985b56b69b2d52089c95d6822eaf62009a787ecf1500aa0270222637accb04b23658bff48eb4cdf7c
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
### Fixed
|
|
4
4
|
|
|
5
|
+
- RelaxNG: a `combine="interleave"` define can add an element between
|
|
6
|
+
the members of a base sequence again (regression in 1.9.428.0, fixed
|
|
7
|
+
by engine 1.9.429; leptris/leptris#2094). Regression spec with the
|
|
8
|
+
include-override schema pair from #650.
|
|
5
9
|
- Rebuild the native object under the Ruby that performs final packaging.
|
|
6
10
|
Restoring the job Ruby after the per-minor release loop could reuse the
|
|
7
11
|
last minor's object and overwrite the job minor's bundle with a different
|
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.432"
|
|
12
12
|
|
|
13
13
|
# THE SSOT for the per-minor native bundle list (ruby#645): one line,
|
|
14
14
|
# space-separated, consumed by the Rakefile, the per-minor builder's
|
|
Binary file
|
|
Binary file
|
|
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
data/vendor-src/README.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [1.9.432] - 2026-11-21
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **RELAX NG: refs keep the element branch — the externalRef-splice regression on the 1.9.431 ride.** The 1.9.431 content classifier propagated the leaf mark through ref expansion, so content like `element(e){ref payload}` with `payload = text` routed to the text branch, whose leaf loop cannot resolve refs — every externalRef-spliced text element rejected with "content mismatch" (the ruby v188 lockstep suite caught it: 1273 examples, exactly that one failure). Refs now descend for element patterns but leave the leaf mark unset; the beside-attribute data fix (#2080) is untouched — direct text leaves still route to the text branch.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## [1.9.431] - 2026-11-21
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- **RELAX NG: the data leaf lexes beside attribute patterns** — an attribute pattern (optional or required) beside a `<data>` leaf disabled the datatype lex entirely, so `not-base64!!` validated as base64Binary and garbage validated as every leaf datatype. The content classifier now descends wrappers and refs and answers from the leaves (leptris#2080 residual; one of the two openmath#25 gates).
|
|
16
|
+
- **XSD: anyURI collapses whitespace before the lexical check** — XSD Part 2's collapse facet: space-padded and whitespace-only values trim before the check and the collapsed empty string is a legal anyURI (Jing accepts both; the engine rejected outright — the entire remaining CD-loading delta in the openmath corpus). Interior control characters still reject (leptris#1883's anyURI row; the second openmath#25 gate).
|
|
17
|
+
- **HTML: the foster splice never links a node into a chain cycle** — the 682-byte fuzz input's "229MB tree" was ~8 nodes linked in a sibling cycle and walked forever; foster splices now unlink nodes from every chain and maintain parent back-pointers (leptris#2096; the reconstruct-on-characters behavior is kept per WHATWG 13.2.6.4.7).
|
|
18
|
+
- **Pool: recycled extension blocks always get a tracking node, and blocks smaller than the list header never park** — the AdoptedAttrs arena-boundary sweep caught both in #2105's own CI.
|
|
19
|
+
|
|
20
|
+
### Performance
|
|
21
|
+
|
|
22
|
+
- **Pool: arena extension blocks recycle across the mutation document cycle** — a create/build/free cycle re-malloc'd and re-faulted hundreds of same-size blocks; extensions now park/pop on a capped thread-local exact-size list. The corrected mutation rows all beat pugixml on CI: append 2.85x, mut-doc-cycle 15.9 vs 16.0 ns/child, attrparse 1.21x (leptris#2054 closed; the bench methodology warms the recycle layers and reports min-of-3).
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## [1.9.430] - 2026-11-20
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- **RELAX NG: the OpenMath corpus now validates verdict-identical to Jing — 345/345 documents, zero mismatches.** The attr-choice collection walk treated the cyclic content graph (`omel → OME/notom → omel`) as a tree and collected the same attribute-choice once per lap up to the selection cap while the branch search's depth cap is lower, so every element whose content could reach the cycle rejected with "attribute combination matches no branch of the attribute choice" after seconds of re-walking — the corpus-wide failure since 1.9.427 (#2079), independent of the interleave work. alg1-001: 30s-wrong-verdict → sub-millisecond-valid. The walk now carries a pointer set and visits each node once. leptris#2103, disposition on #2088.
|
|
31
|
+
- **RELAX NG regression (1.9.428–429)**: zero-width group members hold and advance the interleave cursor instead of finishing the group, so the simplest OMATTR attribution document — valid on 1.9.428, rejected on 1.9.429 — validates again; misplaced merged elements find their own element pattern. leptris#2099.
|
|
32
|
+
- RELAX NG: the interleave cursor machine memoizes its search states. An interleave of repeats followed by a sibling — `interleave(a*, b*), c` over `(a b)×N c` — spent the whole 200 000-step budget already at N = 10; it now takes a few hundred steps, polynomial in the child count. The failure diagnosis keeps the remainder of the interleave branch that consumed a child, so a document with an unrelated error no longer also reports `element "flavor" not allowed here` for a correctly placed merged element. By @andrew2net. leptris#2098.
|
|
33
|
+
- Build: drop the stale amalgamation rename of xslt_register_ufn_handlers. leptris#2100.
|
|
34
|
+
|
|
3
35
|
## [1.9.429] - 2026-11-19
|
|
4
36
|
|
|
5
37
|
### Fixed
|
|
@@ -69,9 +69,18 @@ int main(void) {
|
|
|
69
69
|
* and re-faults them on the carve memsets. */
|
|
70
70
|
const int N_CYCLE = 20000;
|
|
71
71
|
const int CYCLE_CHILDREN = 1024;
|
|
72
|
+
/* Methodology (#2054, corrected 2026-11-20): the recycle layers
|
|
73
|
+
* (pool-block/page park-pop, arena span retain, mutation block
|
|
74
|
+
* caches, extension recycling) are ADAPTIVE - their limits grow
|
|
75
|
+
* on demand, so the first few thousand cycles pay warm-up while
|
|
76
|
+
* a cached-block steady state NEVER calls malloc (verified: an
|
|
77
|
+
* LD_PRELOAD counter shows zero malloc/free across the whole
|
|
78
|
+
* warmed run). A cold single block measures allocator warm-up,
|
|
79
|
+
* not mutation cost. Warm 5k cycles first, then min-of-3 - the
|
|
80
|
+
* same discipline the attr rows use. pugixml has no cross-doc
|
|
81
|
+
* cache, so its number is unchanged by the warm-up. */
|
|
72
82
|
{
|
|
73
|
-
|
|
74
|
-
for (int i = 0; i < N_CYCLE; i++) {
|
|
83
|
+
for (int i = 0; i < 5000; i++) {
|
|
75
84
|
LeptrisDocument d = leptris_document_create();
|
|
76
85
|
LeptrisElement root = leptris_element_create(d, "root");
|
|
77
86
|
leptris_document_set_root(d, root);
|
|
@@ -81,21 +90,40 @@ int main(void) {
|
|
|
81
90
|
}
|
|
82
91
|
leptris_document_free(d);
|
|
83
92
|
}
|
|
84
|
-
double
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
double best = 1e18;
|
|
94
|
+
for (int rep = 0; rep < 3; rep++) {
|
|
95
|
+
double t0 = now_ns();
|
|
96
|
+
for (int i = 0; i < N_CYCLE; i++) {
|
|
97
|
+
LeptrisDocument d = leptris_document_create();
|
|
98
|
+
LeptrisElement root = leptris_element_create(d, "root");
|
|
99
|
+
leptris_document_set_root(d, root);
|
|
100
|
+
for (int c = 0; c < CYCLE_CHILDREN; c++) {
|
|
101
|
+
LeptrisElement e = leptris_element_create(d, "c");
|
|
102
|
+
leptris_element_append_child(root, e);
|
|
103
|
+
}
|
|
104
|
+
leptris_document_free(d);
|
|
105
|
+
}
|
|
106
|
+
double t1 = now_ns();
|
|
107
|
+
double v = (t1 - t0) / ((double)N_CYCLE * CYCLE_CHILDREN);
|
|
108
|
+
if (v < best) best = v;
|
|
109
|
+
}
|
|
110
|
+
printf("mutcycle leptris: %7.1f ns/child\n", best);
|
|
87
111
|
}
|
|
88
112
|
{
|
|
89
|
-
double
|
|
90
|
-
for (int
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
root.append_child("
|
|
113
|
+
double best = 1e18;
|
|
114
|
+
for (int rep = 0; rep < 3; rep++) {
|
|
115
|
+
double t0 = now_ns();
|
|
116
|
+
for (int i = 0; i < N_CYCLE; i++) {
|
|
117
|
+
pugi::xml_document d;
|
|
118
|
+
pugi::xml_node root = d.append_child("root");
|
|
119
|
+
for (int c = 0; c < CYCLE_CHILDREN; c++)
|
|
120
|
+
root.append_child("c");
|
|
121
|
+
}
|
|
122
|
+
double t1 = now_ns();
|
|
123
|
+
double v = (t1 - t0) / ((double)N_CYCLE * CYCLE_CHILDREN);
|
|
124
|
+
if (v < best) best = v;
|
|
95
125
|
}
|
|
96
|
-
|
|
97
|
-
printf("mutcycle pugixml: %7.1f ns/child\n",
|
|
98
|
-
(t1 - t0) / ((double)N_CYCLE * CYCLE_CHILDREN));
|
|
126
|
+
printf("mutcycle pugixml: %7.1f ns/child\n", best);
|
|
99
127
|
}
|
|
100
128
|
|
|
101
129
|
/* ---- attr-parse: parse 20k docs, 4 elems x 16 attrs ---- */
|
|
@@ -176,8 +176,6 @@ if(LEPTRIS_AMALGAMATED)
|
|
|
176
176
|
"leptris/common/format_number.c:parse_pattern=fmt_num_parse_pattern"
|
|
177
177
|
"leptris/sax/iterparse.c:set_error=iterparse_set_error"
|
|
178
178
|
"leptris/xpath/vm.c:xpath_context_document=vm_xpath_context_document"
|
|
179
|
-
"leptris/xpath/xpath_public.c:xslt_register_ufn_handlers=xslt_register_ufn_handlers_impl"
|
|
180
|
-
"leptris/xslt/xslt_functions.c:xslt_register_ufn_handlers=xslt_register_ufn_handlers_impl"
|
|
181
179
|
"leptris/xslt/xslt_exec.c:utf8_encode=xslt_utf8_encode"
|
|
182
180
|
"leptris/xslt/xslt_exec.c:ws_only=xslt_ws_only"
|
|
183
181
|
"leptris/rng/validate.c:match_seq=rng_match_seq"
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
#include "../leptris_internal.h"
|
|
15
15
|
#include "../dom/element.h"
|
|
16
16
|
#include "../dom/text.h"
|
|
17
|
+
#include "../dom/edges.h"
|
|
17
18
|
#include "../dom/comment.h"
|
|
18
19
|
#include "../dom/doctype.h"
|
|
19
20
|
#include "../dom/root_doc_map.h"
|
|
@@ -3948,6 +3949,71 @@ static int h_id_table_ctx(uint8_t id) {
|
|
|
3948
3949
|
id == h_id_thead || id == h_id_tfoot || id == h_id_tr;
|
|
3949
3950
|
}
|
|
3950
3951
|
|
|
3952
|
+
/* Unlink n from EVERY chain that currently holds it. A fostered node
|
|
3953
|
+
* was just appended into the table subtree: splicing it before the
|
|
3954
|
+
* table without removing those links left it reachable from two
|
|
3955
|
+
* chains at once, and the sibling walk could loop back into the
|
|
3956
|
+
* nodes it came from - the whole tree walker (count, serialize)
|
|
3957
|
+
* circled a handful of nodes hundreds of millions of times (#2096).
|
|
3958
|
+
* The open stack bounds the search; repeat until no chain holds the
|
|
3959
|
+
* node, so a previously double-linked node heals too. */
|
|
3960
|
+
static void h_chain_unlink(HBuilder* b, LeptrisNodeRef n) {
|
|
3961
|
+
if (!n) return;
|
|
3962
|
+
int found = 1;
|
|
3963
|
+
while (found) {
|
|
3964
|
+
found = 0;
|
|
3965
|
+
for (size_t i = b->depth; i-- > 0;) {
|
|
3966
|
+
LeptrisElement p = b->open[i];
|
|
3967
|
+
LeptrisNodeRef first = leptris_node_first_child_internal(
|
|
3968
|
+
(LeptrisNode*)p);
|
|
3969
|
+
if (first == n) {
|
|
3970
|
+
leptris_elem_set_first_child(
|
|
3971
|
+
p, leptris_node_get_next_sibling(n));
|
|
3972
|
+
if (leptris_node_get_type(n) ==
|
|
3973
|
+
LEPTRIS_NODE_TYPE_ELEMENT)
|
|
3974
|
+
p->child_count--;
|
|
3975
|
+
found = 1;
|
|
3976
|
+
break;
|
|
3977
|
+
}
|
|
3978
|
+
LeptrisNodeRef prev = first;
|
|
3979
|
+
while (prev) {
|
|
3980
|
+
LeptrisNodeRef nx =
|
|
3981
|
+
leptris_node_get_next_sibling(prev);
|
|
3982
|
+
if (nx == n) {
|
|
3983
|
+
leptris_node_set_next_sibling(
|
|
3984
|
+
prev, leptris_node_get_next_sibling(n));
|
|
3985
|
+
if (leptris_node_get_type(n) ==
|
|
3986
|
+
LEPTRIS_NODE_TYPE_ELEMENT)
|
|
3987
|
+
p->child_count--;
|
|
3988
|
+
found = 1;
|
|
3989
|
+
break;
|
|
3990
|
+
}
|
|
3991
|
+
prev = nx;
|
|
3992
|
+
}
|
|
3993
|
+
if (found) break;
|
|
3994
|
+
}
|
|
3995
|
+
if (!found && b->top_head) {
|
|
3996
|
+
if (b->top_head == n) {
|
|
3997
|
+
b->top_head = leptris_node_get_next_sibling(n);
|
|
3998
|
+
found = 1;
|
|
3999
|
+
} else {
|
|
4000
|
+
LeptrisNodeRef prev = b->top_head;
|
|
4001
|
+
while (prev) {
|
|
4002
|
+
LeptrisNodeRef nx =
|
|
4003
|
+
leptris_node_get_next_sibling(prev);
|
|
4004
|
+
if (nx == n) {
|
|
4005
|
+
leptris_node_set_next_sibling(
|
|
4006
|
+
prev, leptris_node_get_next_sibling(n));
|
|
4007
|
+
found = 1;
|
|
4008
|
+
break;
|
|
4009
|
+
}
|
|
4010
|
+
prev = nx;
|
|
4011
|
+
}
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
}
|
|
4015
|
+
}
|
|
4016
|
+
|
|
3951
4017
|
/* Insert n into parent's child chain BEFORE `before`. Same surgery
|
|
3952
4018
|
* pattern as the head-content lift (first_child + sibling links +
|
|
3953
4019
|
* element child_count). */
|
|
@@ -3972,8 +4038,12 @@ static void h_insert_before(HBuilder* b, LeptrisElement parent,
|
|
|
3972
4038
|
}
|
|
3973
4039
|
}
|
|
3974
4040
|
leptris_node_set_next_sibling(n, (LeptrisNodeRef)before);
|
|
3975
|
-
if (leptris_node_get_type(n) == LEPTRIS_NODE_TYPE_ELEMENT)
|
|
4041
|
+
if (leptris_node_get_type(n) == LEPTRIS_NODE_TYPE_ELEMENT) {
|
|
3976
4042
|
parent->child_count++;
|
|
4043
|
+
leptris_elem_set_parent((LeptrisElement)n, parent);
|
|
4044
|
+
} else if (leptris_node_get_type(n) == LEPTRIS_NODE_TYPE_TEXT) {
|
|
4045
|
+
leptris_textnode_set_parent((LeptrisTextNode*)n, parent);
|
|
4046
|
+
}
|
|
3977
4047
|
}
|
|
3978
4048
|
|
|
3979
4049
|
/* O(1) append for open-stack parents (#1225): route through the
|
|
@@ -4276,6 +4346,7 @@ static void h_append(HBuilder* b, LeptrisNodeRef n) {
|
|
|
4276
4346
|
}
|
|
4277
4347
|
if (oi >= 0) {
|
|
4278
4348
|
LeptrisElement tc = b->open[oi];
|
|
4349
|
+
h_chain_unlink(b, n);
|
|
4279
4350
|
LeptrisNodeRef nxt =
|
|
4280
4351
|
leptris_node_get_next_sibling(
|
|
4281
4352
|
(LeptrisNodeRef)tc);
|
|
@@ -4300,6 +4371,18 @@ static void h_append(HBuilder* b, LeptrisNodeRef n) {
|
|
|
4300
4371
|
leptris_node_set_next_sibling(
|
|
4301
4372
|
(LeptrisNodeRef)tc, n);
|
|
4302
4373
|
}
|
|
4374
|
+
{
|
|
4375
|
+
LeptrisElement npar = leptris_node_parent_inline(
|
|
4376
|
+
(LeptrisNode*)tc);
|
|
4377
|
+
if (leptris_node_get_type(n) ==
|
|
4378
|
+
LEPTRIS_NODE_TYPE_ELEMENT)
|
|
4379
|
+
leptris_elem_set_parent(
|
|
4380
|
+
(LeptrisElement)n, npar);
|
|
4381
|
+
else if (leptris_node_get_type(n) ==
|
|
4382
|
+
LEPTRIS_NODE_TYPE_TEXT)
|
|
4383
|
+
leptris_textnode_set_parent(
|
|
4384
|
+
(LeptrisTextNode*)n, npar);
|
|
4385
|
+
}
|
|
4303
4386
|
b->depth = (size_t)oi;
|
|
4304
4387
|
return;
|
|
4305
4388
|
}
|
|
@@ -4307,6 +4390,7 @@ static void h_append(HBuilder* b, LeptrisNodeRef n) {
|
|
|
4307
4390
|
if (ti >= 1) {
|
|
4308
4391
|
LeptrisElement table = b->open[ti];
|
|
4309
4392
|
LeptrisElement tparent = b->open[ti - 1];
|
|
4393
|
+
h_chain_unlink(b, n);
|
|
4310
4394
|
h_insert_before(b, tparent, table, n);
|
|
4311
4395
|
return;
|
|
4312
4396
|
}
|
|
@@ -4314,6 +4398,7 @@ static void h_append(HBuilder* b, LeptrisNodeRef n) {
|
|
|
4314
4398
|
/* Table sits directly on the top chain — splice n
|
|
4315
4399
|
* into the chain BEFORE the table node. */
|
|
4316
4400
|
LeptrisElement table = b->open[0];
|
|
4401
|
+
h_chain_unlink(b, n);
|
|
4317
4402
|
if (b->top_head == (LeptrisNodeRef)table) {
|
|
4318
4403
|
leptris_node_set_next_sibling(
|
|
4319
4404
|
n, b->top_head);
|
|
@@ -4332,6 +4417,12 @@ static void h_append(HBuilder* b, LeptrisNodeRef n) {
|
|
|
4332
4417
|
n, (LeptrisNodeRef)table);
|
|
4333
4418
|
}
|
|
4334
4419
|
}
|
|
4420
|
+
if (leptris_node_get_type(n) == LEPTRIS_NODE_TYPE_ELEMENT)
|
|
4421
|
+
leptris_elem_set_parent((LeptrisElement)n, NULL);
|
|
4422
|
+
else if (leptris_node_get_type(n) ==
|
|
4423
|
+
LEPTRIS_NODE_TYPE_TEXT)
|
|
4424
|
+
leptris_textnode_set_parent((LeptrisTextNode*)n,
|
|
4425
|
+
NULL);
|
|
4335
4426
|
return;
|
|
4336
4427
|
}
|
|
4337
4428
|
}
|
|
@@ -85,6 +85,39 @@ struct pool_recycle_list {
|
|
|
85
85
|
static LEPTRIS_THREAD_LOCAL struct pool_recycle_list t_recycle_pools;
|
|
86
86
|
static LEPTRIS_THREAD_LOCAL struct pool_recycle_list t_recycle_pages;
|
|
87
87
|
|
|
88
|
+
/* ASAN: recycling hides use-after-free (a freed-then-parked block
|
|
89
|
+
* stays valid); the retain pool stands down for the same reason
|
|
90
|
+
* (arena.c's ARENA_RETAIN_ASAN). */
|
|
91
|
+
#if defined(__has_feature)
|
|
92
|
+
#if __has_feature(address_sanitizer)
|
|
93
|
+
#define POOL_RECYCLE_ASAN 1
|
|
94
|
+
#endif
|
|
95
|
+
#elif defined(__SANITIZE_ADDRESS__)
|
|
96
|
+
#define POOL_RECYCLE_ASAN 1
|
|
97
|
+
#endif
|
|
98
|
+
|
|
99
|
+
/* Arena-extension blocks (#2054's mut-doc-cycle row): a mutation
|
|
100
|
+
* document that outgrows its 64KB span pays one malloc per oversized
|
|
101
|
+
* request, and pool_destroy's arena path freed each block straight
|
|
102
|
+
* back to malloc - a create/build/free cycle re-mallocs and
|
|
103
|
+
* re-faults hundreds of same-size blocks. Park them on a capped
|
|
104
|
+
* thread-local list at destroy, pop an exact-size match on the next
|
|
105
|
+
* extension: same uninitialized-memory contract as malloc, pages
|
|
106
|
+
* stay warm. Stands down under custom allocators (with the pages
|
|
107
|
+
* list) and ASAN. */
|
|
108
|
+
#ifndef POOL_RECYCLE_ASAN
|
|
109
|
+
static LEPTRIS_THREAD_LOCAL struct pool_recycle_list t_recycle_exts;
|
|
110
|
+
/* Park a block only if worth it: beyond this size one malloc's
|
|
111
|
+
* bookkeeping is noise against the copy/fault cost, and a huge
|
|
112
|
+
* parked block is RSS held hostage by one outlier document. Below
|
|
113
|
+
* sizeof(pool_parked) parking is impossible — the list header is
|
|
114
|
+
* written INTO the block, so a smaller block would overflow its own
|
|
115
|
+
* allocation (the Windows heap-corruption 0xc0000374 the windows
|
|
116
|
+
* lane caught on #2105). */
|
|
117
|
+
#define POOL_EXT_PARK_MAX_BYTES (256u * 1024u)
|
|
118
|
+
#define POOL_EXT_PARK_MIN_BYTES (sizeof(struct pool_parked))
|
|
119
|
+
#endif
|
|
120
|
+
|
|
88
121
|
static int pool_recycle_active(void) {
|
|
89
122
|
return !leptris_custom_allocator_active();
|
|
90
123
|
}
|
|
@@ -92,8 +125,14 @@ static int pool_recycle_active(void) {
|
|
|
92
125
|
/* leptris_thread_cleanup: return every parked block to the
|
|
93
126
|
* allocator so a finishing thread holds no pool memory. */
|
|
94
127
|
void leptris_pool_drain_recycler(void) {
|
|
128
|
+
#ifndef POOL_RECYCLE_ASAN
|
|
129
|
+
struct pool_recycle_list* lists[3] = {&t_recycle_pools, &t_recycle_pages,
|
|
130
|
+
&t_recycle_exts};
|
|
131
|
+
for (int i = 0; i < 3; i++) {
|
|
132
|
+
#else
|
|
95
133
|
struct pool_recycle_list* lists[2] = {&t_recycle_pools, &t_recycle_pages};
|
|
96
134
|
for (int i = 0; i < 2; i++) {
|
|
135
|
+
#endif
|
|
97
136
|
struct pool_parked* p = lists[i]->head;
|
|
98
137
|
while (p) {
|
|
99
138
|
struct pool_parked* next = p->next;
|
|
@@ -375,10 +414,21 @@ void leptris_pool_destroy(LeptrisMemoryPool* pool) {
|
|
|
375
414
|
* tracked extension blocks — free those, then the arena (when
|
|
376
415
|
* owned) and the pool struct. */
|
|
377
416
|
if (pool->arena) {
|
|
417
|
+
const int can_recycle_ext = pool_recycle_active() &&
|
|
418
|
+
!pool->alloc_hook && !pool->dealloc_hook;
|
|
378
419
|
LeptrisBigAlloc* big = pool->first_big_alloc;
|
|
379
420
|
while (big) {
|
|
380
421
|
LeptrisBigAlloc* next = big->next;
|
|
381
|
-
|
|
422
|
+
#ifndef POOL_RECYCLE_ASAN
|
|
423
|
+
size_t esize = ALIGN_SIZE(big->size);
|
|
424
|
+
if (!can_recycle_ext ||
|
|
425
|
+
esize > POOL_EXT_PARK_MAX_BYTES ||
|
|
426
|
+
esize < POOL_EXT_PARK_MIN_BYTES ||
|
|
427
|
+
!pool_recycle_park(&t_recycle_exts, big->ptr, esize))
|
|
428
|
+
#endif
|
|
429
|
+
{
|
|
430
|
+
leptris_free_hook(big->ptr);
|
|
431
|
+
}
|
|
382
432
|
leptris_free_hook(big);
|
|
383
433
|
big = next;
|
|
384
434
|
}
|
|
@@ -503,7 +553,18 @@ static void* pool_alloc_oversized(LeptrisMemoryPool* pool, size_t size) {
|
|
|
503
553
|
* directly (NOT a recursive pool_alloc) so a near-full arena can't
|
|
504
554
|
* loop. Freed by leptris_pool_destroy via the big-alloc list. */
|
|
505
555
|
static void* pool_alloc_arena_extension(LeptrisMemoryPool* pool, size_t size) {
|
|
506
|
-
|
|
556
|
+
size_t asize = ALIGN_SIZE(size);
|
|
557
|
+
void* ptr = NULL;
|
|
558
|
+
#ifndef POOL_RECYCLE_ASAN
|
|
559
|
+
/* A recycled block serves the request, but it must STILL get a
|
|
560
|
+
* tracking node on THIS pool's big-alloc list: pool_contains and
|
|
561
|
+
* the destroy walk only know claimed blocks, and an unclaimed
|
|
562
|
+
* recycled block leaks at destroy and reads as not-pool-owned
|
|
563
|
+
* (the AdoptedAttrs boundary sweep caught both). */
|
|
564
|
+
if (pool_recycle_active())
|
|
565
|
+
ptr = pool_recycle_pop(&t_recycle_exts, asize);
|
|
566
|
+
#endif
|
|
567
|
+
if (!ptr) ptr = leptris_alloc_hook(asize);
|
|
507
568
|
if (!ptr) return NULL;
|
|
508
569
|
LeptrisBigAlloc* node =
|
|
509
570
|
(LeptrisBigAlloc*)leptris_alloc_hook(sizeof(LeptrisBigAlloc));
|
|
@@ -512,7 +573,12 @@ static void* pool_alloc_arena_extension(LeptrisMemoryPool* pool, size_t size) {
|
|
|
512
573
|
return NULL;
|
|
513
574
|
}
|
|
514
575
|
node->ptr = ptr;
|
|
515
|
-
|
|
576
|
+
/* The BLOCK is asize bytes (aligned, and recycled blocks come
|
|
577
|
+
* back at their aligned length): the tracking node must claim
|
|
578
|
+
* the true length or leptris_pool_contains leaves the alignment
|
|
579
|
+
* tail unclaimed and attributes living there read as
|
|
580
|
+
* not-pool-owned (the AdoptedAttrs boundary sweep caught it). */
|
|
581
|
+
node->size = asize;
|
|
516
582
|
node->next = NULL;
|
|
517
583
|
*pool->last_big_alloc_link = node;
|
|
518
584
|
pool->last_big_alloc_link = &node->next;
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
#ifndef LEPTRIS_MEMORY_POOL_H
|
|
16
16
|
#define LEPTRIS_MEMORY_POOL_H
|
|
17
17
|
|
|
18
|
+
#ifdef __cplusplus
|
|
19
|
+
extern "C" {
|
|
20
|
+
#endif
|
|
21
|
+
|
|
18
22
|
#include <stddef.h>
|
|
19
23
|
#include <stdint.h>
|
|
20
24
|
#include "../../include/leptris/types.h" /* Allocator hook typedefs + opaque types */
|
|
@@ -442,4 +446,8 @@ void leptris_hash_table_for_each(StringHashTable* table,
|
|
|
442
446
|
LeptrisHashTableIterator iter,
|
|
443
447
|
void* user_data);
|
|
444
448
|
|
|
449
|
+
#ifdef __cplusplus
|
|
450
|
+
}
|
|
451
|
+
#endif
|
|
452
|
+
|
|
445
453
|
#endif /* LEPTRIS_MEMORY_POOL_H */
|