From 60c880a0cc7e126a1dd3b47d1e3498b8a3471072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kr=C3=BCger?= <45282134+UweKrueger@users.noreply.github.com> Date: Tue, 15 Jun 2021 13:47:11 +0200 Subject: [PATCH] vlib: use `malloc_noscan()` where possible (#10465) --- examples/ttf_font/example_ttf.v | 2 +- vlib/builtin/int.v | 10 +++++----- vlib/builtin/rune.v | 2 +- vlib/builtin/utf8.c.v | 4 ++-- vlib/builtin/utf8.v | 2 +- vlib/crypto/rand/rand_linux.c.v | 2 +- vlib/crypto/rand/rand_solaris.c.v | 2 +- vlib/darwin/darwin.v | 2 +- vlib/encoding/base64/base64.v | 4 ++-- vlib/encoding/utf8/utf8_util.v | 2 +- vlib/glm/glm.v | 4 ++-- vlib/mysql/mysql.v | 2 +- vlib/net/http/backend_windows.c.v | 2 +- vlib/os/fd.c.v | 2 +- vlib/os/os_c.v | 30 +++++++++++++++--------------- vlib/os/os_linux.c.v | 27 --------------------------- vlib/os/os_nix.c.v | 6 +++--- vlib/os/os_windows.c.v | 2 +- vlib/picoev/picoev.v | 4 ++-- vlib/rand/rand.v | 6 +++--- vlib/strconv/format_mem.v | 2 +- vlib/strings/strings.c.v | 4 ++-- vlib/term/ui/termios_nix.c.v | 4 ++-- vlib/time/parse.v | 2 +- vlib/v/builder/msvc.v | 2 +- vlib/v/scanner/scanner.v | 2 +- vlib/x/ttf/common.v | 2 +- vlib/x/ttf/render_sokol_cpu.v | 4 ++-- 28 files changed, 56 insertions(+), 83 deletions(-) diff --git a/examples/ttf_font/example_ttf.v b/examples/ttf_font/example_ttf.v index 216440a75d..1a7b04bcc6 100644 --- a/examples/ttf_font/example_ttf.v +++ b/examples/ttf_font/example_ttf.v @@ -145,7 +145,7 @@ fn main() { app.ttf_render << &ttf.TTF_render_Sokol{ bmp: &ttf.BitMap{ tf: &(app.tf[0]) - buf: unsafe { malloc(32000000) } + buf: unsafe { malloc_noscan(32000000) } buf_size: (32000000) color: 0xFF0000FF // style: .raw diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index 20dcf80455..941862a744 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -42,7 +42,7 @@ fn (nn int) str_l(max int) string { is_neg = true } mut index := max - mut buf := malloc(max + 1) + mut buf := malloc_noscan(max + 1) buf[index] = 0 index-- @@ -119,7 +119,7 @@ pub fn (nn u32) str() string { return '0' } max := 12 - mut buf := malloc(max + 1) + mut buf := malloc_noscan(max + 1) mut index := max buf[index] = 0 index-- @@ -163,7 +163,7 @@ pub fn (nn i64) str() string { return '0' } max := 20 - mut buf := malloc(max + 1) + mut buf := malloc_noscan(max + 1) mut is_neg := false if n < 0 { n = -n @@ -210,7 +210,7 @@ pub fn (nn u64) str() string { return '0' } max := 20 - mut buf := malloc(max + 1) + mut buf := malloc_noscan(max + 1) mut index := max buf[index] = 0 index-- @@ -423,7 +423,7 @@ pub fn (b byte) str() string { // Example: assert byte(97).ascii_str() == 'a' pub fn (b byte) ascii_str() string { mut str := string{ - str: unsafe { malloc(2) } + str: unsafe { malloc_noscan(2) } len: 1 } unsafe { diff --git a/vlib/builtin/rune.v b/vlib/builtin/rune.v index 37284c47f1..7e7cc65ff1 100644 --- a/vlib/builtin/rune.v +++ b/vlib/builtin/rune.v @@ -45,7 +45,7 @@ pub fn (b []byte) clone() []byte { // TODO remove this once runes are implemented pub fn (b []byte) bytestr() string { unsafe { - buf := malloc(b.len + 1) + buf := malloc_noscan(b.len + 1) C.memcpy(buf, b.data, b.len) buf[b.len] = 0 return tos(buf, b.len) diff --git a/vlib/builtin/utf8.c.v b/vlib/builtin/utf8.c.v index c7e7157fc8..f2ead3aaf9 100644 --- a/vlib/builtin/utf8.c.v +++ b/vlib/builtin/utf8.c.v @@ -9,7 +9,7 @@ pub fn (_str string) to_wide() &u16 { unsafe { num_chars := (C.MultiByteToWideChar(cp_utf8, 0, &char(_str.str), _str.len, 0, 0)) - mut wstr := &u16(malloc((num_chars + 1) * 2)) // sizeof(wchar_t) + mut wstr := &u16(malloc_noscan((num_chars + 1) * 2)) // sizeof(wchar_t) if wstr != 0 { C.MultiByteToWideChar(cp_utf8, 0, &char(_str.str), _str.len, wstr, num_chars) C.memset(&byte(wstr) + num_chars * 2, 0, 2) @@ -38,7 +38,7 @@ pub fn string_from_wide2(_wstr &u16, len int) string { $if windows { unsafe { num_chars := C.WideCharToMultiByte(cp_utf8, 0, _wstr, len, 0, 0, 0, 0) - mut str_to := malloc(num_chars + 1) + mut str_to := malloc_noscan(num_chars + 1) if str_to != 0 { C.WideCharToMultiByte(cp_utf8, 0, _wstr, len, &char(str_to), num_chars, 0, 0) diff --git a/vlib/builtin/utf8.v b/vlib/builtin/utf8.v index f55d1b087a..6f3745a1a1 100644 --- a/vlib/builtin/utf8.v +++ b/vlib/builtin/utf8.v @@ -11,7 +11,7 @@ pub fn utf8_char_len(b byte) int { // utf32 == Codepoint pub fn utf32_to_str(code u32) string { unsafe { - mut buffer := malloc(5) + mut buffer := malloc_noscan(5) return utf32_to_str_no_malloc(code, buffer) } } diff --git a/vlib/crypto/rand/rand_linux.c.v b/vlib/crypto/rand/rand_linux.c.v index 5cacccf0e5..52ff3da160 100644 --- a/vlib/crypto/rand/rand_linux.c.v +++ b/vlib/crypto/rand/rand_linux.c.v @@ -11,7 +11,7 @@ const ( // read returns an array of `bytes_needed` random bytes read from the OS. pub fn read(bytes_needed int) ?[]byte { - mut buffer := unsafe { malloc(bytes_needed) } + mut buffer := unsafe { malloc_noscan(bytes_needed) } mut bytes_read := 0 mut remaining_bytes := bytes_needed // getrandom syscall wont block if requesting <= 256 bytes diff --git a/vlib/crypto/rand/rand_solaris.c.v b/vlib/crypto/rand/rand_solaris.c.v index cec2e9a84c..8d0ba0cd85 100644 --- a/vlib/crypto/rand/rand_solaris.c.v +++ b/vlib/crypto/rand/rand_solaris.c.v @@ -14,7 +14,7 @@ const ( // read returns an array of `bytes_needed` random bytes read from the OS. pub fn read(bytes_needed int) ?[]byte { - mut buffer := unsafe { malloc(bytes_needed) } + mut buffer := unsafe { malloc_noscan(bytes_needed) } mut bytes_read := 0 mut remaining_bytes := bytes_needed // getrandom syscall wont block if requesting <= 256 bytes diff --git a/vlib/darwin/darwin.v b/vlib/darwin/darwin.v index a43912dfd9..b86636e101 100644 --- a/vlib/darwin/darwin.v +++ b/vlib/darwin/darwin.v @@ -42,7 +42,7 @@ pub fn resource_path() string { panic('CFBundleCopyResourcesDirectoryURL failed') } buffer_size := 4096 - mut buffer := unsafe { malloc(buffer_size) } + mut buffer := unsafe { malloc_noscan(buffer_size) } unsafe { buffer[0] = 0 } diff --git a/vlib/encoding/base64/base64.v b/vlib/encoding/base64/base64.v index 8610471fc2..203ff0b812 100644 --- a/vlib/encoding/base64/base64.v +++ b/vlib/encoding/base64/base64.v @@ -35,7 +35,7 @@ pub fn decode_str(data string) string { return '' } unsafe { - buffer := malloc(size + 1) + buffer := malloc_noscan(size + 1) buffer[size] = 0 return tos(buffer, decode_in_buffer(data, buffer)) } @@ -62,7 +62,7 @@ fn alloc_and_encode(src &byte, len int) string { return '' } unsafe { - buffer := malloc(size + 1) + buffer := malloc_noscan(size + 1) buffer[size] = 0 return tos(buffer, encode_from_buffer(buffer, src, len)) } diff --git a/vlib/encoding/utf8/utf8_util.v b/vlib/encoding/utf8/utf8_util.v index d95db92dc2..bfdc99092c 100644 --- a/vlib/encoding/utf8/utf8_util.v +++ b/vlib/encoding/utf8/utf8_util.v @@ -404,7 +404,7 @@ fn utf8_to_upper(in_cp int) int { fn up_low(s string, upper_flag bool) string { mut index := 0 mut tab_char := 0 - mut str_res := unsafe { malloc(s.len + 1) } + mut str_res := unsafe { malloc_noscan(s.len + 1) } for { ch_len := utf8_char_len(s[index]) diff --git a/vlib/glm/glm.v b/vlib/glm/glm.v index fd08a61b3d..abd798189f 100644 --- a/vlib/glm/glm.v +++ b/vlib/glm/glm.v @@ -129,7 +129,7 @@ fn rotate(m Mat4, angle f32, vec Vec3) Mat4 { } */ fn f32_calloc(n int) &f32 { - return voidptr(vcalloc(n * int(sizeof(f32)))) + return voidptr(vcalloc_noscan(n * int(sizeof(f32)))) } // fn translate(vec Vec3) *f32 { @@ -382,7 +382,7 @@ fn ortho_js(left f32, right f32, bottom f32, top f32) &f32 { bt := 1.0 / (bottom - top) nf := f32(1.0) / 1.0 // (mynear -myfar) unsafe { - mut out := &f32(malloc(int(sizeof(f32) * 16))) + mut out := &f32(malloc_noscan(int(sizeof(f32) * 16))) out[0] = -2.0 * lr out[1] = 0 out[2] = 0 diff --git a/vlib/mysql/mysql.v b/vlib/mysql/mysql.v index 0e04133b6c..8a9fbb3f5f 100644 --- a/vlib/mysql/mysql.v +++ b/vlib/mysql/mysql.v @@ -126,7 +126,7 @@ pub fn (conn &Connection) tables(wildcard string) ?[]string { // taking into account the current character set of the connection. pub fn (conn &Connection) escape_string(s string) string { unsafe { - to := malloc(2 * s.len + 1) + to := malloc_noscan(2 * s.len + 1) C.mysql_real_escape_string_quote(conn.conn, to, s.str, s.len, `\'`) return to.vstring() } diff --git a/vlib/net/http/backend_windows.c.v b/vlib/net/http/backend_windows.c.v index 702afee234..ffa8ce1dfa 100644 --- a/vlib/net/http/backend_windows.c.v +++ b/vlib/net/http/backend_windows.c.v @@ -12,7 +12,7 @@ fn C.new_tls_context() C.TlsContext fn (req &Request) ssl_do(port int, method Method, host_name string, path string) ?Response { mut ctx := C.new_tls_context() C.vschannel_init(&ctx) - mut buff := unsafe { malloc(C.vsc_init_resp_buff_size) } + mut buff := unsafe { malloc_noscan(C.vsc_init_resp_buff_size) } addr := host_name sdata := req.build_request_headers(method, host_name, path) $if trace_http_request ? { diff --git a/vlib/os/fd.c.v b/vlib/os/fd.c.v index 1bb59fd836..de69e38cb9 100644 --- a/vlib/os/fd.c.v +++ b/vlib/os/fd.c.v @@ -49,7 +49,7 @@ pub fn fd_read(fd int, maxbytes int) (string, int) { return '', 0 } unsafe { - mut buf := malloc(maxbytes + 1) + mut buf := malloc_noscan(maxbytes + 1) nbytes := C.read(fd, buf, maxbytes) if nbytes < 0 { free(buf) diff --git a/vlib/os/os_c.v b/vlib/os/os_c.v index b95406b72e..c3741db449 100644 --- a/vlib/os/os_c.v +++ b/vlib/os/os_c.v @@ -108,7 +108,7 @@ pub fn read_file(path string) ?string { // C.fseek(fp, 0, SEEK_SET) // same as `C.rewind(fp)` below C.rewind(fp) unsafe { - mut str := malloc(fsize + 1) + mut str := malloc_noscan(fsize + 1) nelements := int(C.fread(str, 1, fsize, fp)) is_eof := int(C.feof(fp)) is_error := int(C.ferror(fp)) @@ -496,7 +496,7 @@ pub fn get_raw_line() string { $if windows { unsafe { max_line_chars := 256 - buf := malloc(max_line_chars * 2) + buf := malloc_noscan(max_line_chars * 2) h_input := C.GetStdHandle(C.STD_INPUT_HANDLE) mut bytes_read := u32(0) if is_atty(0) > 0 { @@ -538,7 +538,7 @@ pub fn get_raw_stdin() []byte { unsafe { block_bytes := 512 mut old_size := block_bytes - mut buf := malloc(block_bytes) + mut buf := malloc_noscan(block_bytes) h_input := C.GetStdHandle(C.STD_INPUT_HANDLE) mut bytes_read := 0 mut offset := 0 @@ -584,7 +584,7 @@ pub fn read_file_array(path string) []T { C.rewind(fp) // read the actual data from the file len := fsize / tsize - buf := unsafe { malloc(fsize) } + buf := unsafe { malloc_noscan(fsize) } nread := C.fread(buf, tsize, len, fp) C.fclose(fp) return unsafe { @@ -619,7 +619,7 @@ pub fn on_segfault(f voidptr) { [manualfree] pub fn executable() string { $if linux { - mut xresult := vcalloc(max_path_len) + mut xresult := vcalloc_noscan(max_path_len) count := C.readlink(c'/proc/self/exe', &char(xresult), max_path_len) if count < 0 { eprintln('os.executable() failed at reading /proc/self/exe to get exe path') @@ -630,7 +630,7 @@ pub fn executable() string { $if windows { max := 512 size := max * 2 // max_path_len * sizeof(wchar_t) - mut result := unsafe { &u16(vcalloc(size)) } + mut result := unsafe { &u16(vcalloc_noscan(size)) } len := C.GetModuleFileName(0, result, max) // determine if the file is a windows symlink attrs := C.GetFileAttributesW(result) @@ -639,7 +639,7 @@ pub fn executable() string { // gets handle with GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 file := C.CreateFile(result, 0x80000000, 1, 0, 3, 0x80, 0) if file != voidptr(-1) { - final_path := unsafe { &u16(vcalloc(size)) } + final_path := unsafe { &u16(vcalloc_noscan(size)) } // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlew final_len := C.GetFinalPathNameByHandleW(file, final_path, size, 0) if final_len < size { @@ -655,7 +655,7 @@ pub fn executable() string { return unsafe { string_from_wide2(result, len) } } $if macos { - mut result := vcalloc(max_path_len) + mut result := vcalloc_noscan(max_path_len) pid := C.getpid() ret := proc_pidpath(pid, result, max_path_len) if ret <= 0 { @@ -665,7 +665,7 @@ pub fn executable() string { return unsafe { result.vstring() } } $if freebsd { - mut result := vcalloc(max_path_len) + mut result := vcalloc_noscan(max_path_len) mib := [1 /* CTL_KERN */, 14 /* KERN_PROC */, 12 /* KERN_PROC_PATHNAME */, -1] size := max_path_len unsafe { C.sysctl(mib.data, 4, result, &size, 0, 0) } @@ -679,7 +679,7 @@ pub fn executable() string { $if haiku { } $if netbsd { - mut result := vcalloc(max_path_len) + mut result := vcalloc_noscan(max_path_len) count := C.readlink(c'/proc/curproc/exe', &char(result), max_path_len) if count < 0 { eprintln('os.executable() failed at reading /proc/curproc/exe to get exe path') @@ -688,7 +688,7 @@ pub fn executable() string { return unsafe { result.vstring_with_len(count) } } $if dragonfly { - mut result := vcalloc(max_path_len) + mut result := vcalloc_noscan(max_path_len) count := C.readlink(c'/proc/curproc/file', &char(result), max_path_len) if count < 0 { eprintln('os.executable() failed at reading /proc/curproc/file to get exe path') @@ -751,7 +751,7 @@ pub fn getwd() string { $if windows { max := 512 // max_path_len * sizeof(wchar_t) unsafe { - buf := &u16(vcalloc(max * 2)) + buf := &u16(vcalloc_noscan(max * 2)) if C._wgetcwd(buf, max) == 0 { free(buf) return '' @@ -759,7 +759,7 @@ pub fn getwd() string { return string_from_wide(buf) } } $else { - buf := vcalloc(max_path_len) + buf := vcalloc_noscan(max_path_len) unsafe { if C.getcwd(&char(buf), max_path_len) == 0 { free(buf) @@ -782,7 +782,7 @@ pub fn real_path(fpath string) string { $if windows { // GetFullPathName doesn't work with symbolic links, // so if it is not a file, get full path - fullpath = unsafe { &u16(vcalloc(max_path_len * 2)) } + fullpath = unsafe { &u16(vcalloc_noscan(max_path_len * 2)) } // TODO: check errors if path len is not enough ret := C.GetFullPathName(fpath.to_wide(), max_path_len, fullpath, 0) if ret == 0 { @@ -791,7 +791,7 @@ pub fn real_path(fpath string) string { } res = unsafe { string_from_wide(fullpath) } } $else { - fullpath = vcalloc(max_path_len) + fullpath = vcalloc_noscan(max_path_len) ret := &char(C.realpath(&char(fpath.str), &char(fullpath))) if ret == 0 { unsafe { free(fullpath) } diff --git a/vlib/os/os_linux.c.v b/vlib/os/os_linux.c.v index fb5e6eee50..e178795b63 100644 --- a/vlib/os/os_linux.c.v +++ b/vlib/os/os_linux.c.v @@ -17,30 +17,3 @@ pub const ( sys_mkdir = 83 sys_creat = 85 ) - -/* -// TODO no pub => error -pub fn write(fd int, data voidptr, nbytes int) int { - return syscall5( - 1, // SYS_write - fd, - data, - nbytes, - 0, // ignored - 0 // ignored - ) -} - -pub fn println(s string) { - write(1, (s + '\n').str, s.len) -} - -fn mmap(start voidptr, len, prot, flags, fd, off int) byteptr { - return syscall6(9, start, len, prot, flags, fd, off) // sys_mmap -} - -pub fn malloc(n int) byteptr { - println('malloc($n)') - return mmap(0, n, 3, 4098, //prot_read|prot_write, - -1,0) //map_private|map_anonymous, -*/ diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index ab5a855b7f..f70cf623c8 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -68,7 +68,7 @@ pub fn uname() Uname { mut u := Uname{} utsize := sizeof(C.utsname) unsafe { - x := malloc(int(utsize)) + x := malloc_noscan(int(utsize)) d := &C.utsname(x) if C.uname(d) == 0 { u.sysname = cstring_to_vstring(d.sysname) @@ -85,7 +85,7 @@ pub fn uname() Uname { pub fn hostname() string { mut hstnme := '' size := 256 - mut buf := unsafe { &char(malloc(size)) } + mut buf := unsafe { &char(malloc_noscan(size)) } if C.gethostname(buf, size) == 0 { hstnme = unsafe { cstring_to_vstring(buf) } unsafe { free(buf) } @@ -203,7 +203,7 @@ pub fn execute(cmd string) Result { output: 'exec("$cmd") failed' } } - buf := unsafe { malloc(4096) } + buf := unsafe { malloc_noscan(4096) } mut res := strings.new_builder(1024) defer { unsafe { res.free() } diff --git a/vlib/os/os_windows.c.v b/vlib/os/os_windows.c.v index 9e22976491..d187aff61d 100644 --- a/vlib/os/os_windows.c.v +++ b/vlib/os/os_windows.c.v @@ -167,7 +167,7 @@ pub fn get_file_handle(path string) HANDLE { pub fn get_module_filename(handle HANDLE) ?string { unsafe { mut sz := 4096 // Optimized length - mut buf := &u16(malloc(4096)) + mut buf := &u16(malloc_noscan(4096)) for { status := int(C.GetModuleFileNameW(handle, voidptr(&buf), sz)) match status { diff --git a/vlib/picoev/picoev.v b/vlib/picoev/picoev.v index b21c79a93e..7c11d03dbf 100644 --- a/vlib/picoev/picoev.v +++ b/vlib/picoev/picoev.v @@ -243,8 +243,8 @@ pub fn new(config Config) &Picoev { timeout_secs: config.timeout_secs max_headers: config.max_headers date: C.get_date() - buf: unsafe { malloc(picoev.max_fds * picoev.max_read + 1) } - out: unsafe { malloc(picoev.max_fds * picoev.max_write + 1) } + buf: unsafe { malloc_noscan(picoev.max_fds * picoev.max_read + 1) } + out: unsafe { malloc_noscan(picoev.max_fds * picoev.max_write + 1) } } C.picoev_add(loop, fd, int(Event.read), 0, accept_callback, pv) go update_date(mut pv) diff --git a/vlib/rand/rand.v b/vlib/rand/rand.v index 52dc0a3f86..ef832500da 100644 --- a/vlib/rand/rand.v +++ b/vlib/rand/rand.v @@ -197,7 +197,7 @@ pub fn string_from_set(charset string, len int) string { if len == 0 { return '' } - mut buf := unsafe { malloc(len + 1) } + mut buf := unsafe { malloc_noscan(len + 1) } for i in 0 .. len { unsafe { buf[i] = charset[intn(charset.len)] @@ -228,7 +228,7 @@ pub fn ascii(len int) string { // See https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random) pub fn uuid_v4() string { buflen := 36 - mut buf := unsafe { malloc(37) } + mut buf := unsafe { malloc_noscan(37) } mut i_buf := 0 mut x := u64(0) mut d := byte(0) @@ -281,7 +281,7 @@ pub fn ulid() string { // ulid_at_millisecond does the same as `ulid` but takes a custom Unix millisecond timestamp via `unix_time_milli`. pub fn ulid_at_millisecond(unix_time_milli u64) string { buflen := 26 - mut buf := unsafe { malloc(27) } + mut buf := unsafe { malloc_noscan(27) } mut t := unix_time_milli mut i := 9 for i >= 0 { diff --git a/vlib/strconv/format_mem.v b/vlib/strconv/format_mem.v index 8b3804ff6f..61e9947b2c 100644 --- a/vlib/strconv/format_mem.v +++ b/vlib/strconv/format_mem.v @@ -440,7 +440,7 @@ pub fn format_es(f f64, p BF_param) string { [direct_array_access] pub fn remove_tail_zeros(s string) string { unsafe{ - mut buf := malloc(s.len + 1) + mut buf := malloc_noscan(s.len + 1) mut i_d := 0 mut i_s := 0 diff --git a/vlib/strings/strings.c.v b/vlib/strings/strings.c.v index 9f7b0b6157..c020f5b402 100644 --- a/vlib/strings/strings.c.v +++ b/vlib/strings/strings.c.v @@ -5,7 +5,7 @@ pub fn repeat(c byte, n int) string { if n <= 0 { return '' } - mut bytes := unsafe { malloc(n + 1) } + mut bytes := unsafe { malloc_noscan(n + 1) } unsafe { C.memset(bytes, c, n) bytes[n] = `0` @@ -22,7 +22,7 @@ pub fn repeat_string(s string, n int) string { } slen := s.len blen := slen * n - mut bytes := unsafe { malloc(blen + 1) } + mut bytes := unsafe { malloc_noscan(blen + 1) } for bi in 0 .. n { bislen := bi * slen for si in 0 .. slen { diff --git a/vlib/term/ui/termios_nix.c.v b/vlib/term/ui/termios_nix.c.v index 88f20de2ee..fb5ff76b25 100644 --- a/vlib/term/ui/termios_nix.c.v +++ b/vlib/term/ui/termios_nix.c.v @@ -173,7 +173,7 @@ fn get_cursor_position() (int, int) { print('\033[6n') mut s := '' unsafe { - buf := malloc(25) + buf := malloc_noscan(25) len := C.read(C.STDIN_FILENO, buf, 24) buf[len] = 0 s = tos(buf, len) @@ -196,7 +196,7 @@ fn supports_truecolor() bool { print('\x1bP\$qm\x1b\\') mut s := '' unsafe { - buf := malloc(25) + buf := malloc_noscan(25) len := C.read(C.STDIN_FILENO, buf, 24) buf[len] = 0 s = tos(buf, len) diff --git a/vlib/time/parse.v b/vlib/time/parse.v index de9d928d0b..5233476ca5 100644 --- a/vlib/time/parse.v +++ b/vlib/time/parse.v @@ -36,7 +36,7 @@ pub fn parse_rfc2822(s string) ?Time { pos := months_string.index(fields[2]) or { return error('Invalid time format: $s') } mm := pos / 3 + 1 unsafe { - tmstr := malloc(s.len * 2) + tmstr := malloc_noscan(s.len * 2) count := C.snprintf(&char(tmstr), (s.len * 2), c'%s-%02d-%s %s', fields[3].str, mm, fields[1].str, fields[4].str) return parse(tos(tmstr, count)) diff --git a/vlib/v/builder/msvc.v b/vlib/v/builder/msvc.v index c8555237cd..903c0fb623 100644 --- a/vlib/v/builder/msvc.v +++ b/vlib/v/builder/msvc.v @@ -46,7 +46,7 @@ fn find_windows_kit_internal(key RegKey, versions []string) ?string { continue } alloc_length := (required_bytes + 2) - mut value := &u16(malloc(int(alloc_length))) + mut value := &u16(malloc_noscan(int(alloc_length))) if isnil(value) { continue } diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index f2c6148120..96dd6b14ed 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -237,7 +237,7 @@ fn (s Scanner) num_lit(start int, end int) string { } unsafe { txt := s.text.str - mut b := malloc(end - start + 1) // add a byte for the endstring 0 + mut b := malloc_noscan(end - start + 1) // add a byte for the endstring 0 mut i1 := 0 for i := start; i < end; i++ { if txt[i] != scanner.num_sep { diff --git a/vlib/x/ttf/common.v b/vlib/x/ttf/common.v index 6fec0b76f5..ad88d33e3f 100644 --- a/vlib/x/ttf/common.v +++ b/vlib/x/ttf/common.v @@ -87,7 +87,7 @@ fn (mut bmp BitMap) format_texture() { // write out a .ppm file pub fn (mut bmp BitMap) save_as_ppm(file_name string) { tmp_buf := bmp.buf - mut buf := unsafe { malloc(bmp.buf_size) } + mut buf := unsafe { malloc_noscan(bmp.buf_size) } unsafe { C.memcpy(buf, tmp_buf, bmp.buf_size) } bmp.buf = buf diff --git a/vlib/x/ttf/render_sokol_cpu.v b/vlib/x/ttf/render_sokol_cpu.v index 074842bc9b..c993250dba 100644 --- a/vlib/x/ttf/render_sokol_cpu.v +++ b/vlib/x/ttf/render_sokol_cpu.v @@ -56,7 +56,7 @@ pub fn (mut tf_skl TTF_render_Sokol) create_text(in_txt string, in_font_size f32 unsafe { free(tf_skl.bmp.buf) } } dprintln('create_text Alloc: $sz bytes') - tf_skl.bmp.buf = unsafe { malloc(sz) } + tf_skl.bmp.buf = unsafe { malloc_noscan(sz) } tf_skl.bmp.buf_size = sz } @@ -94,7 +94,7 @@ pub fn (mut tf_skl TTF_render_Sokol) create_text_block(in_txt string, in_w int, unsafe { free(tf_skl.bmp.buf) } } dprintln('Alloc: $sz bytes') - tf_skl.bmp.buf = unsafe { malloc(sz) } + tf_skl.bmp.buf = unsafe { malloc_noscan(sz) } tf_skl.bmp.buf_size = sz }