os: work towards being able to again use -autofree while recompiling the V compiler several times

This commit is contained in:
Delyan Angelov 2024-11-14 13:58:50 +02:00
parent 2831b61a0b
commit df51e840f9
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
2 changed files with 6 additions and 2 deletions

View file

@ -1016,6 +1016,7 @@ pub fn write_file_array(path string, buffer array) ! {
f.close() f.close()
} }
@[manualfree]
pub fn glob(patterns ...string) ![]string { pub fn glob(patterns ...string) ![]string {
mut matches := []string{} mut matches := []string{}
for pattern in patterns { for pattern in patterns {
@ -1025,6 +1026,8 @@ pub fn glob(patterns ...string) ![]string {
return matches return matches
} }
// last_error returns a V error, formed by the last libc error (from GetLastError() on windows and from `errno` on !windows)
@[manualfree]
pub fn last_error() IError { pub fn last_error() IError {
$if windows { $if windows {
code := int(C.GetLastError()) code := int(C.GetLastError())
@ -1050,7 +1053,7 @@ pub:
// Return a POSIX error: // Return a POSIX error:
// Code defaults to last error (from C.errno) // Code defaults to last error (from C.errno)
// Message defaults to POSIX error message for the error code // Message defaults to POSIX error message for the error code
@[inline] @[inline; manualfree]
pub fn error_posix(e SystemError) IError { pub fn error_posix(e SystemError) IError {
code := if e.code == error_code_not_set { C.errno } else { e.code } code := if e.code == error_code_not_set { C.errno } else { e.code }
message := if e.msg == '' { posix_get_error_msg(code) } else { e.msg } message := if e.msg == '' { posix_get_error_msg(code) } else { e.msg }
@ -1060,7 +1063,7 @@ pub fn error_posix(e SystemError) IError {
// Return a Win32 API error: // Return a Win32 API error:
// Code defaults to last error (calling C.GetLastError()) // Code defaults to last error (calling C.GetLastError())
// Message defaults to Win 32 API error message for the error code // Message defaults to Win 32 API error message for the error code
@[inline] @[inline; manualfree]
pub fn error_win32(e SystemError) IError { pub fn error_win32(e SystemError) IError {
$if windows { $if windows {
code := if e.code == error_code_not_set { int(C.GetLastError()) } else { e.code } code := if e.code == error_code_not_set { int(C.GetLastError()) } else { e.code }

View file

@ -295,6 +295,7 @@ fn init_os_args(argc int, argv &&u8) []string {
// } // }
// } // }
// ``` // ```
@[manualfree]
pub fn ls(path string) ![]string { pub fn ls(path string) ![]string {
if path == '' { if path == '' {
return error('ls() expects a folder, not an empty string') return error('ls() expects a folder, not an empty string')