From a9aeb6471e2718c0a5514dfac0f66adb36d47eb2 Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Wed, 18 Nov 2026 20:00:01 +0000 Subject: [PATCH] @owned on core.os.d.ts's string functions: toFixed and Date's strings stop leaking under rc convertNumber, convertInteger, timestamp_to_string, time_to_string, time_format and time_format_locale each return `s`, a view of their local char[]. Under rc a view a function returns is copied at the return (#481), so each hands its caller a string of its own at +1. Unmarked, they were C functions to lib.ts: the caller copied the result again and never gave back the function's own string - one leaked per `toFixed`, `toExponential`, `toPrecision`, `Date.toString`, `toISOString` call. 1M `(i + 0.5).toFixed(2)`: 34.4 MB -> 5.8 MB, flat. Co-Authored-By: Claude Opus 5.5 --- src/core/core.os.d.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/core/core.os.d.ts b/src/core/core.os.d.ts index 5c2932d..355b598 100644 --- a/src/core/core.os.d.ts +++ b/src/core/core.os.d.ts @@ -3,8 +3,12 @@ // under -mm=own so is every Date method that calls one: a global Date lent to `d.getMonth()` was an // error. The scalar ones too: a scalar declaration is taken as no-drops only in a module no function // value can escape from, and the library, which declares non-scalar functions, is not one. -@nodrops declare function convertNumber(bufferSize: int, format: string, value: number): string; -@nodrops declare function convertInteger(bufferSize: int, format: string, value: long): string; +// @owned: these return a string their caller owns under -mm=rc - each body returns `s`, a view of +// its local char[], and a view the function returns is copied there (#481), so the caller is given +// a string of its own at +1. Unmarked, they were C functions to their callers: the result was +// copied again and the function's own string never given back (`toFixed` leaked one per call). +@nodrops @owned declare function convertNumber(bufferSize: int, format: string, value: number): string; +@nodrops @owned declare function convertInteger(bufferSize: int, format: string, value: long): string; @nodrops declare function init_time(); @@ -19,7 +23,7 @@ type tm = [tm_sec: i32, tm_min: i32, tm_hour: i32, tm_mday: i32, tm_mon: i32, tm @nodrops declare function gettimezone(): i32; -@nodrops declare function timestamp_to_string(maxsize: index, time: long): string; -@nodrops declare function time_to_string(maxsize: index, time: long, isUtc: boolean): string; -@nodrops declare function time_format(maxsize: index, format: string, time: long, isUtc: boolean): string; -@nodrops declare function time_format_locale(maxsize: index, format: string, time: long, locale: string, isUtc: boolean): string; \ No newline at end of file +@nodrops @owned declare function timestamp_to_string(maxsize: index, time: long): string; +@nodrops @owned declare function time_to_string(maxsize: index, time: long, isUtc: boolean): string; +@nodrops @owned declare function time_format(maxsize: index, format: string, time: long, isUtc: boolean): string; +@nodrops @owned declare function time_format_locale(maxsize: index, format: string, time: long, locale: string, isUtc: boolean): string; \ No newline at end of file