From c40198b016969c280b7ca1c9f4999414892838e4 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 1 Mar 2025 21:54:17 +0100 Subject: [PATCH] - `new_*` functions in general moved to version without `new_` prefix. - `string::new_from_*` changed to `string::from_*`. - `String.to_utf16_copy` and related changed to `String.to_utf16`. - `String.to_utf16_tcopy` and related changed to `String.to_temp_utf16` - `mem::temp_new` changed to `mem::tnew`. - `mem::temp_alloc` and related changed to `mem::talloc`. - `mem::temp_new_array` changed to `mem::temp_array`. --- lib/std/core/dstring.c3 | 2 +- lib/std/core/mem.c3 | 14 +++++----- lib/std/core/private/main_stub.c3 | 2 +- lib/std/core/string.c3 | 30 ++++++++++++---------- lib/std/io/file.c3 | 2 +- lib/std/io/os/chdir.c3 | 2 +- lib/std/io/os/file_libc.c3 | 6 ++--- lib/std/io/os/fileinfo.c3 | 4 +-- lib/std/io/os/getcwd.c3 | 2 +- lib/std/io/os/ls.c3 | 4 +-- lib/std/io/os/mkdir.c3 | 2 +- lib/std/io/os/rmdir.c3 | 2 +- lib/std/io/os/rmtree.c3 | 6 ++--- lib/std/io/os/temp_directory.c3 | 4 +-- lib/std/io/path.c3 | 8 +++--- lib/std/math/random/math.seeder.c3 | 2 +- lib/std/os/env.c3 | 10 ++++---- lib/std/os/linux/linux.c3 | 4 +-- lib/std/os/subprocess.c3 | 8 +++--- releasenotes.md | 10 ++++++++ test/src/test_suite_runner.c3 | 4 +-- test/test_suite/expressions/opt_in_conv.c3 | 2 +- test/test_suite/macros/ref_macro_method.c3 | 2 +- test/unit/stdlib/mem/temp_mem.c3 | 10 ++++---- 24 files changed, 77 insertions(+), 65 deletions(-) diff --git a/lib/std/core/dstring.c3 b/lib/std/core/dstring.c3 index 0bb453343..2d382028c 100644 --- a/lib/std/core/dstring.c3 +++ b/lib/std/core/dstring.c3 @@ -308,7 +308,7 @@ fn void DString.append_chars(&self, String str) fn Char32[] DString.copy_utf32(&self, Allocator allocator) { - return self.str_view().to_utf32_copy(allocator) @inline!!; + return self.str_view().to_utf32(allocator) @inline!!; } fn void DString.append_string(&self, DString str) diff --git a/lib/std/core/mem.c3 b/lib/std/core/mem.c3 index 5166995bc..abc730579 100644 --- a/lib/std/core/mem.c3 +++ b/lib/std/core/mem.c3 @@ -644,7 +644,7 @@ macro @clone(value) @builtin @nodiscard macro @tclone(value) @builtin @nodiscard { - return temp_new($typeof(value), value); + return tnew($typeof(value), value); } fn void* malloc(usz size) @builtin @inline @nodiscard @@ -745,7 +745,7 @@ macro alloc_aligned($Type) @nodiscard @require $vacount < 2 : "Too many arguments." @require $vacount == 0 ||| $assignable($vaexpr[0], $Type) : "The second argument must be an initializer for the type" *> -macro temp_new($Type, ...) @nodiscard +macro tnew($Type, ...) @nodiscard { $if $vacount == 0: return ($Type*)tcalloc($Type.sizeof) @inline; @@ -760,7 +760,7 @@ macro temp_new($Type, ...) @nodiscard @require $vacount < 2 : "Too many arguments." @require $vacount == 0 ||| $assignable($vaexpr[0], $Type) : "The second argument must be an initializer for the type" *> -macro temp_new_with_padding($Type, usz padding, ...) @nodiscard +macro temp_with_padding($Type, usz padding, ...) @nodiscard { $if $vacount == 0: return ($Type*)tcalloc($Type.sizeof + padding) @inline; @@ -771,12 +771,12 @@ macro temp_new_with_padding($Type, usz padding, ...) @nodiscard $endif } -macro temp_alloc($Type) @nodiscard +macro talloc($Type) @nodiscard { return tmalloc($Type.sizeof); } -macro temp_alloc_with_padding($Type, usz padding) @nodiscard +macro talloc_with_padding($Type, usz padding) @nodiscard { return tmalloc($Type.sizeof + padding); } @@ -815,12 +815,12 @@ macro alloc_array_aligned($Type, usz elements) @nodiscard return allocator::alloc_array_aligned(allocator::heap(), $Type, elements); } -macro temp_alloc_array($Type, usz elements) @nodiscard +macro talloc_array($Type, usz elements) @nodiscard { return (($Type*)tmalloc($Type.sizeof * elements, $Type.alignof))[:elements]; } -macro temp_new_array($Type, usz elements) @nodiscard +macro temp_array($Type, usz elements) @nodiscard { return (($Type*)tcalloc($Type.sizeof * elements, $Type.alignof))[:elements]; } diff --git a/lib/std/core/private/main_stub.c3 b/lib/std/core/private/main_stub.c3 index 1cdf2d4f8..b4dc0fa61 100644 --- a/lib/std/core/private/main_stub.c3 +++ b/lib/std/core/private/main_stub.c3 @@ -80,7 +80,7 @@ macro String[] wargs_strings(int argc, Char16** argv) @private { Char16* arg = argv[i]; Char16[] argstring = arg[:_strlen(arg)]; - list[i] = string::new_from_utf16(mem, argstring) ?? "?".copy(mem); + list[i] = string::from_utf16(mem, argstring) ?? "?".copy(mem); } return list[:argc]; } diff --git a/lib/std/core/string.c3 b/lib/std/core/string.c3 index 2980b56fc..94d9f3be5 100644 --- a/lib/std/core/string.c3 +++ b/lib/std/core/string.c3 @@ -553,7 +553,7 @@ fn String ZString.tcopy(z) @return! UnicodeResult.INVALID_UTF8 "If the string contained an invalid UTF-8 sequence" @return! AllocationFailure "If allocation of the string fails" *> -fn Char16[]! String.to_utf16_copy(s, Allocator allocator) +fn Char16[]! String.to_utf16(s, Allocator allocator) { usz len16 = conv::utf16len_for_utf8(s); Char16* data = allocator::alloc_array_try(allocator, Char16, len16 + 1)!; @@ -562,16 +562,16 @@ fn Char16[]! String.to_utf16_copy(s, Allocator allocator) return data[:len16]; } -fn Char16[]! String.to_utf16_tcopy(s) => s.to_utf16_copy(tmem()); +fn Char16[]! String.to_temp_utf16(s) => s.to_utf16(tmem()); -fn WString! String.to_wstring_copy(s, Allocator allocator) +fn WString! String.to_wstring(s, Allocator allocator) { - return (WString)s.to_utf16_copy(allocator).ptr; + return (WString)s.to_utf16(allocator).ptr; } -fn WString! String.to_wstring_tcopy(s) => s.to_wstring_copy(tmem()); +fn WString! String.to_temp_wstring(s) => s.to_wstring(tmem()); -fn Char32[]! String.to_utf32_copy(s, Allocator allocator) +fn Char32[]! String.to_utf32(s, Allocator allocator) { usz codepoints = conv::utf8_codepoints(s); Char32* data = allocator::alloc_array_try(allocator, Char32, codepoints + 1)!; @@ -580,6 +580,8 @@ fn Char32[]! String.to_utf32_copy(s, Allocator allocator) return data[:codepoints]; } +fn Char32[]! String.to_temp_utf32(s, Allocator allocator) => s.to_utf32(tmem()); + <* Convert a string to ASCII lower case in place. @@ -643,7 +645,7 @@ fn String String.to_upper_tcopy(s) return s.to_upper_copy(tmem()); } -fn String! new_from_utf32(Allocator allocator, Char32[] utf32) +fn String! from_utf32(Allocator allocator, Char32[] utf32) { usz len = conv::utf8len_for_utf32(utf32); char* data = allocator::malloc_try(allocator, len + 1)!; @@ -653,7 +655,7 @@ fn String! new_from_utf32(Allocator allocator, Char32[] utf32) return (String)data[:len]; } -fn String! new_from_utf16(Allocator allocator, Char16[] utf16) +fn String! from_utf16(Allocator allocator, Char16[] utf16) { usz len = conv::utf8len_for_utf16(utf16); char* data = allocator::malloc_try(allocator, len + 1)!; @@ -663,16 +665,16 @@ fn String! new_from_utf16(Allocator allocator, Char16[] utf16) return (String)data[:len]; } -fn String! new_from_wstring(Allocator allocator, WString wstring) +fn String! from_wstring(Allocator allocator, WString wstring) { usz utf16_len; while (wstring[utf16_len] != 0) utf16_len++; Char16[] utf16 = wstring[:utf16_len]; - return new_from_utf16(allocator, utf16); + return from_utf16(allocator, utf16); } -fn String! temp_from_wstring(WString wstring) => new_from_wstring(tmem(), wstring) @inline; -fn String! temp_from_utf16(Char16[] utf16) => new_from_utf16(tmem(), utf16) @inline; +fn String! tfrom_wstring(WString wstring) => from_wstring(tmem(), wstring) @inline; +fn String! tfrom_utf16(Char16[] utf16) => from_utf16(tmem(), utf16) @inline; fn usz String.utf8_codepoints(s) { @@ -820,7 +822,7 @@ fn String! Splitter.next(&self) } } -macro String new_from_struct(Allocator allocator, x) +macro String from_struct(Allocator allocator, x) { DString s; @stack_mem(512; Allocator mem) @@ -831,4 +833,4 @@ macro String new_from_struct(Allocator allocator, x) }; } -macro String temp_from_struct(x) => new_from_struct(tmem(), x); +macro String tfrom_struct(x) => from_struct(tmem(), x); diff --git a/lib/std/io/file.c3 b/lib/std/io/file.c3 index 37361b3ea..f39f07409 100644 --- a/lib/std/io/file.c3 +++ b/lib/std/io/file.c3 @@ -77,7 +77,7 @@ fn void! File.memopen(File* file, char[] data, String mode) { @pool() { - file.file = libc::memopen(data.ptr, data.len, mode.zstr_tcopy(), file.file); + file.file = libc::memopen(data.ptr, data.len, mode.to_temp_zstr(), file.file); // TODO errors }; } diff --git a/lib/std/io/os/chdir.c3 b/lib/std/io/os/chdir.c3 index c2a57ac52..1356edcb2 100644 --- a/lib/std/io/os/chdir.c3 +++ b/lib/std/io/os/chdir.c3 @@ -21,7 +21,7 @@ macro void! native_chdir(Path path) @pool() { // TODO improve with better error handling. - if (win32::setCurrentDirectoryW(path.str_view().to_utf16_tcopy()!!)) return; + if (win32::setCurrentDirectoryW(path.str_view().to_temp_utf16()!!)) return; }; return IoError.GENERAL_ERROR?; $default: diff --git a/lib/std/io/os/file_libc.c3 b/lib/std/io/os/file_libc.c3 index 8aaa8d94f..72a428317 100644 --- a/lib/std/io/os/file_libc.c3 +++ b/lib/std/io/os/file_libc.c3 @@ -8,7 +8,7 @@ import libc; fn void*! native_fopen(String filename, String mode) @inline => @pool() { $if env::WIN32: - void* file = libc::_wfopen(filename.to_wstring_tcopy(), mode.to_wstring_tcopy())!; + void* file = libc::_wfopen(filename.to_temp_wstring(), mode.to_temp_wstring())!; $else void* file = libc::fopen(filename.zstr_tcopy(), mode.zstr_tcopy()); $endif @@ -18,7 +18,7 @@ fn void*! native_fopen(String filename, String mode) @inline => @pool() fn void! native_remove(String filename) => @pool() { $if env::WIN32: - CInt result = libc::_wremove(filename.to_wstring_tcopy())!; + CInt result = libc::_wremove(filename.to_temp_wstring())!; $else CInt result = libc::remove(filename.zstr_tcopy()); $endif @@ -42,7 +42,7 @@ fn void! native_remove(String filename) => @pool() fn void*! native_freopen(void* file, String filename, String mode) @inline => @pool() { $if env::WIN32: - file = libc::_wfreopen(filename.to_wstring_tcopy(), mode.to_wstring_tcopy(), file)!; + file = libc::_wfreopen(filename.to_temp_wstring(), mode.to_temp_wstring(), file)!; $else file = libc::freopen(filename.zstr_tcopy(), mode.zstr_tcopy(), file); $endif diff --git a/lib/std/io/os/fileinfo.c3 b/lib/std/io/os/fileinfo.c3 index ab6d3a8e8..f24fafb4c 100644 --- a/lib/std/io/os/fileinfo.c3 +++ b/lib/std/io/os/fileinfo.c3 @@ -40,7 +40,7 @@ fn void! native_stat(Stat* stat, String path) @if(env::DARWIN || env::LINUX || e fn usz! native_file_size(String path) @if(env::WIN32) => @pool() { Win32_FILE_ATTRIBUTE_DATA data; - win32::getFileAttributesExW(path.to_wstring_tcopy()!, Win32_GET_FILEEX_INFO_LEVELS.STANDARD, &data); + win32::getFileAttributesExW(path.to_temp_wstring()!, Win32_GET_FILEEX_INFO_LEVELS.STANDARD, &data); Win32_LARGE_INTEGER size; size.lowPart = data.nFileSizeLow; size.highPart = data.nFileSizeHigh; @@ -74,7 +74,7 @@ fn bool native_file_or_dir_exists(String path) $case env::WIN32: @pool() { - return (bool)win32::pathFileExistsW(path.to_utf16_tcopy()) ?? false; + return (bool)win32::pathFileExistsW(path.to_temp_utf16()) ?? false; }; $case env::POSIX: @pool() diff --git a/lib/std/io/os/getcwd.c3 b/lib/std/io/os/getcwd.c3 index 69f649612..f2f84efd5 100644 --- a/lib/std/io/os/getcwd.c3 +++ b/lib/std/io/os/getcwd.c3 @@ -17,7 +17,7 @@ macro String! getcwd(Allocator allocator = allocator::heap()) free = true; } Char16[] str16 = res[:win32::wcslen(res)]; - return string::new_from_utf16(allocator, str16); + return string::from_utf16(allocator, str16); $case env::POSIX: const usz DEFAULT_BUFFER = 256; diff --git a/lib/std/io/os/ls.c3 b/lib/std/io/os/ls.c3 index 4bc446801..a6ca6b5a1 100644 --- a/lib/std/io/os/ls.c3 +++ b/lib/std/io/os/ls.c3 @@ -31,7 +31,7 @@ fn PathList! native_ls(Path dir, bool no_dirs, bool no_symlinks, String mask, Al @pool(allocator) { - WString result = dir.str_view().tconcat(`\*`).to_wstring_tcopy()!!; + WString result = dir.str_view().tconcat(`\*`).to_temp_wstring()!!; Win32_WIN32_FIND_DATAW find_data; Win32_HANDLE find = win32::findFirstFileW(result, &find_data); if (find == win32::INVALID_HANDLE_VALUE) return IoError.CANNOT_READ_DIR?; @@ -41,7 +41,7 @@ fn PathList! native_ls(Path dir, bool no_dirs, bool no_symlinks, String mask, Al if (no_dirs && (find_data.dwFileAttributes & win32::FILE_ATTRIBUTE_DIRECTORY)) continue; @pool(allocator) { - String filename = string::temp_from_wstring((WString)&find_data.cFileName)!; + String filename = string::tfrom_wstring((WString)&find_data.cFileName)!; if (filename == ".." || filename == ".") continue; list.push(path::new(allocator, filename)!); }; diff --git a/lib/std/io/os/mkdir.c3 b/lib/std/io/os/mkdir.c3 index 385c00338..1a2b4b5f4 100644 --- a/lib/std/io/os/mkdir.c3 +++ b/lib/std/io/os/mkdir.c3 @@ -29,7 +29,7 @@ macro bool! native_mkdir(Path path, MkdirPermissions permissions) @pool() { // TODO security attributes - if (win32::createDirectoryW(path.str_view().to_utf16_tcopy()!!, null)) return true; + if (win32::createDirectoryW(path.str_view().to_temp_utf16()!!, null)) return true; switch (win32::getLastError()) { case win32::ERROR_ACCESS_DENIED: diff --git a/lib/std/io/os/rmdir.c3 b/lib/std/io/os/rmdir.c3 index 970b1d319..80f8f5dc6 100644 --- a/lib/std/io/os/rmdir.c3 +++ b/lib/std/io/os/rmdir.c3 @@ -26,7 +26,7 @@ macro bool! native_rmdir(Path path) $case env::WIN32: @pool() { - if (win32::removeDirectoryW(path.str_view().to_utf16_tcopy()!!)) return true; + if (win32::removeDirectoryW(path.str_view().to_temp_utf16()!!)) return true; switch (win32::getLastError()) { case win32::ERROR_ACCESS_DENIED: diff --git a/lib/std/io/os/rmtree.c3 b/lib/std/io/os/rmtree.c3 index 866e89e34..210fdf917 100644 --- a/lib/std/io/os/rmtree.c3 +++ b/lib/std/io/os/rmtree.c3 @@ -39,7 +39,7 @@ fn void! native_rmtree(Path path) { Win32_WIN32_FIND_DATAW find_data; String s = path.str_view().tconcat("\\*"); - Win32_HANDLE find = win32::findFirstFileW(s.to_utf16_tcopy(), &find_data)!; + Win32_HANDLE find = win32::findFirstFileW(s.to_temp_utf16(), &find_data)!; if (find == win32::INVALID_HANDLE_VALUE) return IoError.CANNOT_READ_DIR?; defer win32::findClose(find); @@ -47,7 +47,7 @@ fn void! native_rmtree(Path path) { @pool() { - String filename = string::new_from_wstring(tmem(), (WString)&find_data.cFileName)!; + String filename = string::tfrom_wstring((WString)&find_data.cFileName)!; if (filename == "." || filename == "..") continue; Path file_path = path.tappend(filename)!; if (find_data.dwFileAttributes & win32::FILE_ATTRIBUTE_DIRECTORY) @@ -56,7 +56,7 @@ fn void! native_rmtree(Path path) } else { - win32::deleteFileW(file_path.str_view().to_wstring_tcopy()!!); + win32::deleteFileW(file_path.str_view().to_temp_wstring()!!); } }; } while (win32::findNextFileW(find, &find_data) != 0); diff --git a/lib/std/io/os/temp_directory.c3 b/lib/std/io/os/temp_directory.c3 index 75c50449d..d1f82c9ae 100644 --- a/lib/std/io/os/temp_directory.c3 +++ b/lib/std/io/os/temp_directory.c3 @@ -15,9 +15,9 @@ fn Path! native_temp_directory(Allocator allocator) @if(env::WIN32) => @pool(all { Win32_DWORD len = win32::getTempPathW(0, null); if (!len) return IoError.GENERAL_ERROR?; - Char16[] buff = mem::temp_alloc_array(Char16, len + (usz)1); + Char16[] buff = mem::talloc_array(Char16, len + (usz)1); if (!win32::getTempPathW(len, buff)) return IoError.GENERAL_ERROR?; - return path::new(allocator, string::temp_from_utf16(buff[:len])); + return path::new(allocator, string::tfrom_utf16(buff[:len])); } module std::io::os @if(env::NO_LIBC); diff --git a/lib/std/io/path.c3 b/lib/std/io/path.c3 index 2420b5161..3f7ff5735 100644 --- a/lib/std/io/path.c3 +++ b/lib/std/io/path.c3 @@ -159,7 +159,7 @@ fn Path! temp(String path, PathEnv path_env = DEFAULT_ENV) fn Path! from_win32_wstring(Allocator allocator, WString path) => @pool(allocator) { - return path::new(allocator, string::temp_from_wstring(path)!); + return path::new(allocator, string::tfrom_wstring(path)!); } fn Path! for_windows(Allocator allocator, String path) @@ -261,10 +261,10 @@ fn Path! Path.absolute(self, Allocator allocator) @pool(allocator) { const usz BUFFER_LEN = 4096; - WString buffer = (WString)mem::temp_alloc_array(Char16, BUFFER_LEN); - buffer = win32::_wfullpath(buffer, path_str.to_wstring_tcopy()!, BUFFER_LEN); + WString buffer = (WString)mem::talloc_array(Char16, BUFFER_LEN); + buffer = win32::_wfullpath(buffer, path_str.to_temp_wstring()!, BUFFER_LEN); if (!buffer) return PathResult.INVALID_PATH?; - return { string::new_from_wstring(allocator, buffer), WIN32, allocator }; + return { string::from_wstring(allocator, buffer), WIN32, allocator }; }; $else String cwd = os::getcwd(tmem())!; diff --git a/lib/std/math/random/math.seeder.c3 b/lib/std/math/random/math.seeder.c3 index 84de920bf..aed70d118 100644 --- a/lib/std/math/random/math.seeder.c3 +++ b/lib/std/math/random/math.seeder.c3 @@ -26,7 +26,7 @@ fn void seeder(char[] input, char[] out_buffer) usz out_chars = out_buffer.len; @pool() { - ulong[] words = mem::temp_alloc_array(ulong, (out_chars + 7) / 8); + ulong[] words = mem::talloc_array(ulong, (out_chars + 7) / 8); words[..] = ODD_PHI64; usz words_len_2 = words.len * 2; diff --git a/lib/std/os/env.c3 b/lib/std/os/env.c3 index 1d60b0f9a..d4e69ffb5 100644 --- a/lib/std/os/env.c3 +++ b/lib/std/os/env.c3 @@ -20,7 +20,7 @@ fn String! get_var(Allocator allocator, String name) => @pool(allocator) // https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getenvironmentvariable const usz BUFSIZE = 1024; WString buff = (WString)tcalloc(BUFSIZE * 2 + 2); - WString wstr = name.to_wstring_tcopy()!; + WString wstr = name.to_temp_wstring()!; usz len = win32::getEnvironmentVariableW(wstr, buff, BUFSIZE); if (len == 0) return SearchResult.MISSING?; if (len > BUFSIZE) @@ -28,7 +28,7 @@ fn String! get_var(Allocator allocator, String name) => @pool(allocator) buff = (WString)tmalloc(len * 2 + 2); win32::getEnvironmentVariableW(wstr, buff, (Win32_DWORD)len); } - return string::new_from_wstring(allocator, buff); + return string::from_wstring(allocator, buff); $default: return ""; $endswitch @@ -48,14 +48,14 @@ fn bool set_var(String name, String value, bool overwrite = true) => @pool() { $switch $case env::WIN32: - WString wname = name.to_wstring_tcopy()!!; + WString wname = name.to_temp_wstring()!!; if (!overwrite) { Char16[8] buff; if (win32::getEnvironmentVariableW(wname, &buff, 8) > 0) return true; } // https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setenvironmentvariable - return (win32::setEnvironmentVariableW(wname, value.to_wstring_tcopy()) ?? 1) == 0; + return (win32::setEnvironmentVariableW(wname, value.to_temp_wstring()) ?? 1) == 0; $case env::LIBC && !env::WIN32: return libc::setenv(name.zstr_tcopy(), value.zstr_tcopy(), (int)overwrite) == 0; $default: @@ -106,7 +106,7 @@ fn bool clear_var(String name) => @pool() { $switch $case env::WIN32: - WString wname = name.to_wstring_tcopy()!!; + WString wname = name.to_temp_wstring()!!; return win32::setEnvironmentVariableW(wname, null) == 0; $case env::LIBC && !env::WIN32: return libc::unsetenv(name.zstr_tcopy()) == 0; diff --git a/lib/std/os/linux/linux.c3 b/lib/std/os/linux/linux.c3 index 50bf56107..3c530ef01 100644 --- a/lib/std/os/linux/linux.c3 +++ b/lib/std/os/linux/linux.c3 @@ -130,7 +130,7 @@ fn ulong! elf_module_image_base(String path) @local fn void! backtrace_add_from_exec(Allocator allocator, BacktraceList* list, void* addr) @local { - char[] buf = mem::temp_alloc_array(char, 1024); + char[] buf = mem::talloc_array(char, 1024); String exec_path = process::execute_stdout_to_buffer(buf, {"realpath", "-e", string::tformat("/proc/%d/exe", posix::getpid())})!; String obj_name = exec_path.copy(allocator); @@ -140,7 +140,7 @@ fn void! backtrace_add_from_exec(Allocator allocator, BacktraceList* list, void* fn void! backtrace_add_from_dlinfo(Allocator allocator, BacktraceList* list, void* addr, Linux_Dl_info* info) @local { - char[] buf = mem::temp_alloc_array(char, 1024); + char[] buf = mem::talloc_array(char, 1024); void* obj_addr = addr - (uptr)info.dli_fbase + (uptr)elf_module_image_base(info.dli_fname.str_view())!; ZString obj_path = info.dli_fname; diff --git a/lib/std/os/subprocess.c3 b/lib/std/os/subprocess.c3 index 2d374970e..159a9af0f 100644 --- a/lib/std/os/subprocess.c3 +++ b/lib/std/os/subprocess.c3 @@ -109,7 +109,7 @@ fn WString convert_command_line_win32(String[] command_line) @inline @if(env::WI str.append('"'); } str.append('\0'); - return str.str_view().to_wstring_tcopy()!!; + return str.str_view().to_temp_wstring()!!; } <* @@ -149,7 +149,7 @@ fn SubProcess! create(String[] command_line, SubProcessOptions options = {}, Str env.append("\0"); } env.append("\0"); - used_environment = env.str_view().to_wstring_tcopy()!; + used_environment = env.str_view().to_temp_wstring()!; } int fd = win32::_open_osfhandle((iptr)wr, 0); if (fd != -1) @@ -244,7 +244,7 @@ fn SubProcess! create(String[] command_line, SubProcessOptions options = {}, Str *> fn ZString* tcopy_command_line(String[] command_line) @local @inline @if(env::POSIX) { - ZString* copy = mem::temp_alloc_array(ZString, command_line.len + 1); + ZString* copy = mem::talloc_array(ZString, command_line.len + 1); foreach (i, str : command_line) { copy[i] = str.zstr_tcopy(); @@ -257,7 +257,7 @@ const ZString[1] EMPTY_ENVIRONMENT @if(env::POSIX) = { null }; fn ZString* tcopy_env(String[] environment) @local @inline @if(env::POSIX) { if (!environment.len) return &EMPTY_ENVIRONMENT; - ZString* copy = mem::temp_alloc_array(ZString, environment.len + 1); + ZString* copy = mem::talloc_array(ZString, environment.len + 1); copy[environment.len] = null; foreach (i, str : environment) { diff --git a/releasenotes.md b/releasenotes.md index 944c72f86..19ce0ab71 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -19,6 +19,16 @@ ### Fixes - Fix address sanitizer to work on MachO targets (e.g. MacOS). +### Stdlib changes +- `new_*` functions in general moved to version without `new_` prefix. +- `string::new_from_*` changed to `string::from_*`. +- `String.to_utf16_copy` and related changed to `String.to_utf16`. +- `String.to_utf16_tcopy` and related changed to `String.to_temp_utf16` +- `mem::temp_new` changed to `mem::tnew`. +- `mem::temp_alloc` and related changed to `mem::talloc`. +- `mem::temp_new_array` changed to `mem::temp_array`. + + ## 0.6.8 Change list ### Changes / improvements diff --git a/test/src/test_suite_runner.c3 b/test/src/test_suite_runner.c3 index 5d43d7e30..80b0a7649 100644 --- a/test/src/test_suite_runner.c3 +++ b/test/src/test_suite_runner.c3 @@ -132,13 +132,13 @@ fn void RunFile.add_line(&self, String line) fn RunFile*! create_input_file(String filename) { File file = file::open_path(test_dir.tappend(filename), "wb")!; - RunFile *run_file = mem::temp_new(RunFile, { .name = filename, .file = file, .is_output = false }); + RunFile *run_file = mem::tnew(RunFile, { .name = filename, .file = file, .is_output = false }); return run_file; } fn RunFile*! create_output_file(String filename) { - RunFile *run_file = mem::temp_new(RunFile, { .name = filename, .is_output = true }); + RunFile *run_file = mem::tnew(RunFile, { .name = filename, .is_output = true }); return run_file; } diff --git a/test/test_suite/expressions/opt_in_conv.c3 b/test/test_suite/expressions/opt_in_conv.c3 index f411901c7..6b1dce090 100644 --- a/test/test_suite/expressions/opt_in_conv.c3 +++ b/test/test_suite/expressions/opt_in_conv.c3 @@ -3,7 +3,7 @@ import std; fn void main() { String s = "Hello"; - Char16* title = String.to_utf16_copy(s, mem).ptr; // #error: It is not possible to cast from + Char16* title = String.to_utf16(s, mem).ptr; // #error: It is not possible to cast from int! a; float b = (float)a; // #error: It is not possible to cast from } \ No newline at end of file diff --git a/test/test_suite/macros/ref_macro_method.c3 b/test/test_suite/macros/ref_macro_method.c3 index d34738a2d..a1cb8662b 100644 --- a/test/test_suite/macros/ref_macro_method.c3 +++ b/test/test_suite/macros/ref_macro_method.c3 @@ -12,7 +12,7 @@ fn void main() usz values_len = 10; MyStruct ms = { - .dyn = mem::temp_new_array(DString, values_len).ptr, + .dyn = mem::temp_array(DString, values_len).ptr, }; for (usz i; i < values_len; ++i) diff --git a/test/unit/stdlib/mem/temp_mem.c3 b/test/unit/stdlib/mem/temp_mem.c3 index 8d47a8491..2b67564f6 100644 --- a/test/unit/stdlib/mem/temp_mem.c3 +++ b/test/unit/stdlib/mem/temp_mem.c3 @@ -9,7 +9,7 @@ fn String add(String s, Allocator a, int x) tmp = "foo".tconcat(s); tmp = add(tmp, a, x - 1); }; - ulong* y = mem::temp_alloc(ulong); + ulong* y = mem::talloc(ulong); *y = 0xAAAA_AAAA_AAAA_AAAA; return tmp.concat(a, "a"); } @@ -26,10 +26,10 @@ fn String inner2(String s, Allocator a) { @pool(a) { - ulong* z1 = mem::temp_alloc(ulong); + ulong* z1 = mem::talloc(ulong); *z1 = 0xAAAA_AAAA_AAAA_AAAA; String y = inner3(s, a); - ulong* z = mem::temp_alloc(ulong); + ulong* z = mem::talloc(ulong); *z = 0xAAAA_AAAA_AAAA_AAAA; return y; }; @@ -39,10 +39,10 @@ fn String inner3(String s, Allocator a) { @pool(a) { - ulong* z1 = mem::temp_alloc(ulong); + ulong* z1 = mem::talloc(ulong); *z1 = 0xAAAA_AAAA_AAAA_AAAA; String y = inner4(s, a); - ulong* z = mem::temp_alloc(ulong); + ulong* z = mem::talloc(ulong); *z = 0xAAAA_AAAA_AAAA_AAAA; return y; };