builtin: fix print mem leak on windows
parent
fe0b587b1f
commit
88fa935376
|
@ -91,6 +91,9 @@ pub fn print(s string) {
|
|||
wide_str := s.to_wide()
|
||||
wide_len := C.wcslen(wide_str)
|
||||
C.WriteConsole(output_handle, wide_str, wide_len, &bytes_written, 0)
|
||||
unsafe {
|
||||
free(wide_str)
|
||||
}
|
||||
} else {
|
||||
C.WriteFile(output_handle, s.str, s.len, &bytes_written, 0)
|
||||
}
|
||||
|
@ -99,6 +102,27 @@ pub fn print(s string) {
|
|||
}
|
||||
}
|
||||
|
||||
const (
|
||||
new_line_character = '\n'
|
||||
)
|
||||
pub fn println(s string) {
|
||||
$if windows {
|
||||
print(s)
|
||||
print(new_line_character)
|
||||
} $else {
|
||||
// TODO: a syscall sys_write on linux works, except for the v repl.
|
||||
// Probably it is a stdio buffering issue. Needs more testing...
|
||||
// $if linux {
|
||||
// $if !android {
|
||||
// snl := s + '\n'
|
||||
// C.syscall(/* sys_write */ 1, /* stdout_value */ 1, snl.str, s.len+1)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
C.printf('%.*s\n', s.len, s.str)
|
||||
}
|
||||
}
|
||||
|
||||
__global total_m i64=0
|
||||
__global nr_mallocs int=0
|
||||
|
||||
|
|
|
@ -24,19 +24,6 @@ fn builtin_init() {
|
|||
// Do nothing
|
||||
}
|
||||
|
||||
pub fn println(s string) {
|
||||
// TODO: a syscall sys_write on linux works, except for the v repl.
|
||||
// Probably it is a stdio buffering issue. Needs more testing...
|
||||
// $if linux {
|
||||
// $if !android {
|
||||
// snl := s + '\n'
|
||||
// C.syscall(/* sys_write */ 1, /* stdout_value */ 1, snl.str, s.len+1)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
C.printf('%.*s\n', s.len, s.str)
|
||||
}
|
||||
|
||||
fn print_backtrace_skipping_top_frames(xskipframes int) bool {
|
||||
skipframes := xskipframes + 2
|
||||
$if macos {
|
||||
|
|
|
@ -139,7 +139,3 @@ fn print_backtrace_skipping_top_frames_mingw(skipframes int) bool {
|
|||
eprintln('print_backtrace_skipping_top_frames_mingw is not implemented')
|
||||
return false
|
||||
}
|
||||
|
||||
pub fn println(s string) {
|
||||
print('$s\n')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue