From 5e656603a514adb783b21d295b0e58d20ea380f2 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 4 Feb 2026 14:27:52 +0100 Subject: [PATCH] - Remove dependency on temp allocator in File.open. --- lib/std/io/os/file_libc.c3 | 20 ++++++++++---------- releasenotes.md | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/std/io/os/file_libc.c3 b/lib/std/io/os/file_libc.c3 index 49f612add..49855ae24 100644 --- a/lib/std/io/os/file_libc.c3 +++ b/lib/std/io/os/file_libc.c3 @@ -5,22 +5,22 @@ import libc; @require mode.len > 0 @require filename.len > 0 *> -fn void*? native_fopen(String filename, String mode) @inline => @pool() +fn void*? native_fopen(String filename, String mode) @inline => @stack_mem(256; Allocator smem) { $if env::WIN32: - void* file = libc::_wfopen(filename.to_temp_wstring(), mode.to_temp_wstring())!; + void* file = libc::_wfopen(filename.to_wstring(smem), mode.to_wstring(smem))!; $else - void* file = libc::fopen(filename.zstr_tcopy(), mode.zstr_tcopy()); + void* file = libc::fopen(filename.zstr_copy(smem), mode.zstr_copy(smem)); $endif - return file ?: file_open_errno()~; + return file ?: file_open_errno()~; } -fn void? native_remove(String filename) => @pool() +fn void? native_remove(String filename) => @stack_mem(256; Allocator smem) { $if env::WIN32: - CInt result = libc::_wremove(filename.to_temp_wstring())!; + CInt result = libc::_wremove(filename.to_wstring(smem))!; $else - CInt result = libc::remove(filename.zstr_tcopy()); + CInt result = libc::remove(filename.zstr_copy(smem)); $endif if (result) { @@ -39,12 +39,12 @@ fn void? native_remove(String filename) => @pool() @require mode.len > 0 @require filename.len > 0 *> -fn void*? native_freopen(void* file, String filename, String mode) @inline => @pool() +fn void*? native_freopen(void* file, String filename, String mode) @inline => @stack_mem(256; Allocator smem) { $if env::WIN32: - file = libc::_wfreopen(filename.to_temp_wstring(), mode.to_temp_wstring(), file)!; + file = libc::_wfreopen(filename.to_wstring(smem), mode.to_wstring(smem), file)!; $else - file = libc::freopen(filename.zstr_tcopy(), mode.zstr_tcopy(), file); + file = libc::freopen(filename.zstr_copy(smem), mode.zstr_copy(smem), file); $endif return file ?: file_open_errno()~; } diff --git a/releasenotes.md b/releasenotes.md index 4b8ea5079..5d76b981c 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -8,6 +8,7 @@ ### Stdlib changes - Summarize sort macros as generic function wrappers to reduce the amount of generated code. #2831 - Remove dependency on temp allocator in String.join. +- Remove dependency on temp allocator in File.open. ### Fixes - Add error message if directory with output file name already exists