Merge branch 'r3d/zero-leak' into lang/uifree

This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 11:40:43 +03:00
commit 2fe4018d28
9 changed files with 114 additions and 16 deletions

View file

@ -490,6 +490,7 @@ namespace Json {
alias encode(value) = json_encode
alias parse(text) = json_parse
alias free(value) = json_free
alias free_all(value) = json_free_all
}
namespace Xml {
alias parse(text) = xml_parse

View file

@ -403,6 +403,21 @@ function value_free(v: Val) -> void {
free(v)
}
function json_free(v: Val) -> void { value_free(v) }
# ... and its strings too - every string value and object key the parser made - for a tree whose
# reader copied what it keeps (render3d's glTF documents): a parse left otherwise gives back the
# nodes and keeps every name, ~640 KB a model
function value_free_all(v: Val) -> void {
if v == null { return }
if v.tag == 4 and v.txt != null { free(v.txt) }
if v.kids != null {
for i in 0 .. len(v.kids) { value_free_all(v.kids[i]) }
if v.keys != null { for i in 0 .. len(v.keys) { if v.keys[i] != null { free(v.keys[i]) } } }
free(v.kids)
free(v.keys)
}
free(v)
}
function json_free_all(v: Val) -> void { value_free_all(v) }
function jp_value(p: JP) -> Val {
jp_skip_ws(p)
@ -486,6 +501,7 @@ function jp_number(p: JP) -> Val {
frac = (digits[di] * 65536 + frac) / 10
di -= 1
}
free(digits) # one list per decimal in the document, never given back
var raw = ip * 65536 + frac
raw = jp_exponent(p, raw)
if neg != 0 { raw = -raw }