diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 96fd45928b..0587ec11d2 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -95,7 +95,7 @@ fn (mut a array) ensure_cap(required int) { cap *= 2 } new_size := cap * a.element_size - mut new_data := byteptr(0) + mut new_data := &byte(0) if a.cap > 0 { new_data = unsafe { realloc_data(a.data, a.cap * a.element_size, new_size) } } else { @@ -128,7 +128,7 @@ pub fn (a array) repeat(count int) array { ary_clone := ary.clone() unsafe { C.memcpy(arr.get_unsafe(i * a.len), &ary_clone, a.len * a.element_size) } } else { - unsafe { C.memcpy(arr.get_unsafe(i * a.len), byteptr(a.data), a.len * a.element_size) } + unsafe { C.memcpy(arr.get_unsafe(i * a.len), &byte(a.data), a.len * a.element_size) } } } return arr @@ -213,7 +213,7 @@ pub fn (mut a array) trim(index int) { [inline; unsafe] fn (a array) get_unsafe(i int) voidptr { unsafe { - return byteptr(a.data) + i * a.element_size + return &byte(a.data) + i * a.element_size } } @@ -225,7 +225,7 @@ fn (a array) get(i int) voidptr { } } unsafe { - return byteptr(a.data) + i * a.element_size + return &byte(a.data) + i * a.element_size } } @@ -235,7 +235,7 @@ fn (a array) get_with_check(i int) voidptr { return 0 } unsafe { - return byteptr(a.data) + i * a.element_size + return &byte(a.data) + i * a.element_size } } @@ -257,7 +257,7 @@ pub fn (a array) last() voidptr { } } unsafe { - return byteptr(a.data) + (a.len - 1) * a.element_size + return &byte(a.data) + (a.len - 1) * a.element_size } } @@ -270,7 +270,7 @@ pub fn (mut a array) pop() voidptr { } } new_len := a.len - 1 - last_elem := unsafe { byteptr(a.data) + (new_len) * a.element_size } + last_elem := unsafe { &byte(a.data) + (new_len) * a.element_size } a.len = new_len // NB: a.cap is not changed here *on purpose*, so that // further << ops on that array will be more efficient. @@ -305,9 +305,9 @@ fn (a array) slice(start int, _end int) array { panic('array.slice: slice bounds out of range ($start < 0)') } } - mut data := byteptr(0) + mut data := &byte(0) unsafe { - data = byteptr(a.data) + start * a.element_size + data = &byte(a.data) + start * a.element_size } l := end - start res := array{ @@ -363,7 +363,7 @@ pub fn (a &array) clone() array { } if !isnil(a.data) { - unsafe { C.memcpy(byteptr(arr.data), a.data, a.cap * a.element_size) } + unsafe { C.memcpy(&byte(arr.data), a.data, a.cap * a.element_size) } } return arr } @@ -381,9 +381,9 @@ fn (a &array) slice_clone(start int, _end int) array { panic('array.slice: slice bounds out of range ($start < 0)') } } - mut data := byteptr(0) + mut data := &byte(0) unsafe { - data = byteptr(a.data) + start * a.element_size + data = &byte(a.data) + start * a.element_size } l := end - start res := array{ @@ -398,7 +398,7 @@ fn (a &array) slice_clone(start int, _end int) array { // we manually inline this for single operations for performance without -prod [inline; unsafe] fn (mut a array) set_unsafe(i int, val voidptr) { - unsafe { C.memcpy(byteptr(a.data) + a.element_size * i, val, a.element_size) } + unsafe { C.memcpy(&byte(a.data) + a.element_size * i, val, a.element_size) } } // Private function. Used to implement assigment to the array element. @@ -408,12 +408,12 @@ fn (mut a array) set(i int, val voidptr) { panic('array.set: index out of range (i == $i, a.len == $a.len)') } } - unsafe { C.memcpy(byteptr(a.data) + a.element_size * i, val, a.element_size) } + unsafe { C.memcpy(&byte(a.data) + a.element_size * i, val, a.element_size) } } fn (mut a array) push(val voidptr) { a.ensure_cap(a.len + 1) - unsafe { C.memmove(byteptr(a.data) + a.element_size * a.len, val, a.element_size) } + unsafe { C.memmove(&byte(a.data) + a.element_size * a.len, val, a.element_size) } a.len++ } @@ -446,10 +446,10 @@ pub fn (mut a array) reverse_in_place() { unsafe { mut tmp_value := malloc(a.element_size) for i in 0 .. a.len / 2 { - C.memcpy(tmp_value, byteptr(a.data) + i * a.element_size, a.element_size) - C.memcpy(byteptr(a.data) + i * a.element_size, byteptr(a.data) + + C.memcpy(tmp_value, &byte(a.data) + i * a.element_size, a.element_size) + C.memcpy(&byte(a.data) + i * a.element_size, &byte(a.data) + (a.len - 1 - i) * a.element_size, a.element_size) - C.memcpy(byteptr(a.data) + (a.len - 1 - i) * a.element_size, tmp_value, a.element_size) + C.memcpy(&byte(a.data) + (a.len - 1 - i) * a.element_size, tmp_value, a.element_size) } free(tmp_value) } @@ -545,7 +545,7 @@ pub fn (b []byte) hex() string { pub fn copy(dst []byte, src []byte) int { min := if dst.len < src.len { dst.len } else { src.len } if min > 0 { - unsafe { C.memcpy(byteptr(dst.data), src.data, min) } + unsafe { C.memcpy(&byte(dst.data), src.data, min) } } return min } @@ -619,8 +619,8 @@ pub fn (a1 []string) eq(a2 []string) bool { size_of_string := int(sizeof(string)) for i in 0 .. a1.len { offset := i * size_of_string - s1 := &string(unsafe { byteptr(a1.data) + offset }) - s2 := &string(unsafe { byteptr(a2.data) + offset }) + s1 := unsafe { &string(&byte(a1.data) + offset) } + s2 := unsafe { &string(&byte(a2.data) + offset) } if *s1 != *s2 { return false } diff --git a/vlib/builtin/builtin.v b/vlib/builtin/builtin.v index 1e48fb8053..48c1a3839c 100644 --- a/vlib/builtin/builtin.v +++ b/vlib/builtin/builtin.v @@ -4,8 +4,8 @@ module builtin __global ( - g_m2_buf byteptr - g_m2_ptr byteptr + g_m2_buf &byte + g_m2_ptr &byte ) // isnil returns true if an object is nil (only for C objects). diff --git a/vlib/builtin/builtin_nix.c.v b/vlib/builtin/builtin_nix.c.v index aa22fc83ff..165cced966 100644 --- a/vlib/builtin/builtin_nix.c.v +++ b/vlib/builtin/builtin_nix.c.v @@ -71,7 +71,7 @@ fn print_backtrace_skipping_top_frames_freebsd(skipframes int) bool { return true } -fn C.tcc_backtrace(fmt charptr, other ...charptr) int +fn C.tcc_backtrace(fmt &char) int fn print_backtrace_skipping_top_frames_linux(skipframes int) bool { $if android { eprintln('On Android no backtrace is available.') @@ -86,7 +86,7 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool { return false } $else { $if tinyc { - C.tcc_backtrace('Backtrace') + C.tcc_backtrace(c'Backtrace') return false } buffer := [100]voidptr{} @@ -100,7 +100,7 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool { //////csymbols := backtrace_symbols(*voidptr(&buffer[skipframes]), nr_actual_frames) csymbols := C.backtrace_symbols(voidptr(&buffer[skipframes]), nr_actual_frames) for i in 0 .. nr_actual_frames { - sframes << unsafe { tos2(byteptr(csymbols[i])) } + sframes << unsafe { tos2(&byte(csymbols[i])) } } for sframe in sframes { executable := sframe.all_before('(') diff --git a/vlib/builtin/builtin_windows.c.v b/vlib/builtin/builtin_windows.c.v index 0a2260877f..950f96cad8 100644 --- a/vlib/builtin/builtin_windows.c.v +++ b/vlib/builtin/builtin_windows.c.v @@ -36,7 +36,7 @@ pub mut: f_size_of_struct u32 f_key voidptr f_line_number u32 - f_file_name byteptr + f_file_name &byte f_address u64 } @@ -46,7 +46,7 @@ fn C.SymSetOptions(symoptions u32) u32 // returns handle fn C.GetCurrentProcess() voidptr -fn C.SymInitialize(h_process voidptr, p_user_search_path byteptr, b_invade_process int) int +fn C.SymInitialize(h_process voidptr, p_user_search_path &byte, b_invade_process int) int fn C.CaptureStackBackTrace(frames_to_skip u32, frames_to_capture u32, p_backtrace voidptr, p_backtrace_hash voidptr) u16 @@ -176,7 +176,7 @@ fn print_backtrace_skipping_top_frames_mingw(skipframes int) bool { return false } -fn C.tcc_backtrace(fmt charptr, other ...charptr) int +fn C.tcc_backtrace(fmt &char) int fn print_backtrace_skipping_top_frames_tcc(skipframes int) bool { $if tinyc { @@ -184,7 +184,7 @@ fn print_backtrace_skipping_top_frames_tcc(skipframes int) bool { eprintln('backtraces are disabled') return false } $else { - C.tcc_backtrace('Backtrace') + C.tcc_backtrace(c'Backtrace') return true } } $else { diff --git a/vlib/builtin/cfns.c.v b/vlib/builtin/cfns.c.v index d209fab9da..6f3f286ed9 100644 --- a/vlib/builtin/cfns.c.v +++ b/vlib/builtin/cfns.c.v @@ -1,18 +1,18 @@ module builtin // -fn C.memcpy(dest byteptr, src byteptr, n int) voidptr +fn C.memcpy(dest &byte, src &byte, n int) voidptr -fn C.memcmp(byteptr, byteptr, int) int +fn C.memcmp(&byte, &byte, int) int -fn C.memmove(byteptr, byteptr, int) voidptr +fn C.memmove(&byte, &byte, int) voidptr [trusted] -fn C.calloc(int, int) byteptr +fn C.calloc(int, int) &byte -fn C.malloc(int) byteptr +fn C.malloc(int) &byte -fn C.realloc(a byteptr, b int) byteptr +fn C.realloc(a &byte, b int) &byte fn C.free(ptr voidptr) @@ -25,7 +25,7 @@ fn C.sprintf(a ...voidptr) int fn C.strlen(s &char) int -fn C.sscanf(byteptr, byteptr, ...byteptr) int +fn C.sscanf(&byte, &byte, ...&byte) int [trusted] fn C.isdigit(c int) bool @@ -46,13 +46,13 @@ pub fn proc_pidpath(int, voidptr, int) int fn C.realpath(&char, &char) &char // fn C.chmod(byteptr, mode_t) int -fn C.chmod(byteptr, u32) int +fn C.chmod(&byte, u32) int -fn C.printf(byteptr, ...voidptr) int +fn C.printf(&byte, ...voidptr) int -fn C.puts(byteptr) int +fn C.puts(&byte) int -fn C.fputs(str byteptr, stream &C.FILE) int +fn C.fputs(str &byte, stream &C.FILE) int fn C.fflush(&C.FILE) int @@ -83,11 +83,11 @@ fn C.posix_spawnp(child_pid &int, exefile &char, file_actions voidptr, attrp voi fn C.execve(cmd_path &char, args voidptr, envs voidptr) int -fn C.execvp(cmd_path charptr, args &charptr) int +fn C.execvp(cmd_path &char, args &&char) int -fn C._execve(cmd_path charptr, args voidptr, envs voidptr) int +fn C._execve(cmd_path &char, args voidptr, envs voidptr) int -fn C._execvp(cmd_path charptr, args &charptr) int +fn C._execvp(cmd_path &char, args &&char) int [trusted] fn C.fork() int @@ -173,7 +173,7 @@ fn C.strerror(int) &char fn C.snprintf(str &char, size size_t, format &char, opt ...voidptr) int -fn C.fprintf(byteptr, ...byteptr) +fn C.fprintf(&byte, ...&byte) [trusted] fn C.WIFEXITED(status int) bool @@ -224,11 +224,11 @@ fn C.CreateProcessW(lpApplicationName &u16, lpCommandLine &u16, lpProcessAttribu fn C.ReadFile(hFile voidptr, lpBuffer voidptr, nNumberOfBytesToRead u32, lpNumberOfBytesRead C.LPDWORD, lpOverlapped voidptr) bool -fn C.GetFileAttributesW(lpFileName byteptr) u32 +fn C.GetFileAttributesW(lpFileName &byte) u32 -fn C.RegQueryValueEx(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData byteptr, lpcbData &u32) voidptr +fn C.RegQueryValueEx(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &byte, lpcbData &u32) voidptr -fn C.RegQueryValueExW(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData byteptr, lpcbData &u32) int +fn C.RegQueryValueExW(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &byte, lpcbData &u32) int fn C.RegOpenKeyEx(hKey voidptr, lpSubKey &u16, ulOptions u32, samDesired u32, phkResult voidptr) voidptr @@ -236,7 +236,7 @@ fn C.RegOpenKeyExW(hKey voidptr, lpSubKey &u16, ulOptions u32, samDesired u32, p fn C.RegSetValueEx() voidptr -fn C.RegSetValueExW(hKey voidptr, lpValueName &u16, Reserved u32, dwType u32, lpData byteptr, lpcbData u32) int +fn C.RegSetValueExW(hKey voidptr, lpValueName &u16, Reserved u32, dwType u32, lpData &byte, lpcbData u32) int fn C.RegCloseKey(hKey voidptr) @@ -308,7 +308,7 @@ fn C.LocalFree() fn C.FindFirstFileW(lpFileName &u16, lpFindFileData voidptr) voidptr -fn C.FindFirstFile(lpFileName byteptr, lpFindFileData voidptr) voidptr +fn C.FindFirstFile(lpFileName &byte, lpFindFileData voidptr) voidptr fn C.FindNextFile(hFindFile voidptr, lpFindFileData voidptr) int @@ -337,7 +337,7 @@ fn C.closesocket(int) int fn C.vschannel_init(&C.TlsContext) -fn C.request(&C.TlsContext, int, &u16, byteptr, &byteptr) +fn C.request(&C.TlsContext, int, &u16, &byte, &&byte) fn C.vschannel_cleanup(&C.TlsContext) @@ -345,19 +345,19 @@ fn C.URLDownloadToFile(int, &u16, &u16, int, int) fn C.GetLastError() u32 -fn C.CreateDirectory(byteptr, int) bool +fn C.CreateDirectory(&byte, int) bool // win crypto fn C.BCryptGenRandom(int, voidptr, int, int) int // win synchronization -fn C.CreateMutex(int, bool, byteptr) voidptr +fn C.CreateMutex(int, bool, &byte) voidptr fn C.WaitForSingleObject(voidptr, int) int fn C.ReleaseMutex(voidptr) bool -fn C.CreateEvent(int, bool, bool, byteptr) voidptr +fn C.CreateEvent(int, bool, bool, &byte) voidptr fn C.SetEvent(voidptr) int diff --git a/vlib/builtin/isnil_test.v b/vlib/builtin/isnil_test.v index 6b6a487056..15df9f0b79 100644 --- a/vlib/builtin/isnil_test.v +++ b/vlib/builtin/isnil_test.v @@ -1,5 +1,5 @@ fn test_isnil_byteptr() { - pb := byteptr(0) + pb := &byte(0) assert isnil(pb) } diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index c8a6b66b84..bba178d376 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -1539,7 +1539,7 @@ pub fn (s &string) free() { return } if s.is_lit == -98761234 { - C.printf('double string.free() detected\n') + C.printf(c'double string.free() detected\n') return } if s.is_lit == 1 || s.len == 0 { diff --git a/vlib/os/file.c.v b/vlib/os/file.c.v index f9539802a6..39cec934ff 100644 --- a/vlib/os/file.c.v +++ b/vlib/os/file.c.v @@ -182,7 +182,7 @@ pub fn (mut f File) writeln(s string) ?int { if written == 0 && s.len != 0 { return error('0 bytes written') } - x := C.fputs('\n', f.cfile) + x := C.fputs(c'\n', f.cfile) if x < 0 { return error('could not add newline') } diff --git a/vlib/time/parse.v b/vlib/time/parse.v index f86bd5cb3a..a53b6ea0d8 100644 --- a/vlib/time/parse.v +++ b/vlib/time/parse.v @@ -50,7 +50,7 @@ const ( fn parse_iso8601_date(s string) ?(int, int, int) { year, month, day, dummy := 0, 0, 0, byte(0) - count := unsafe { C.sscanf(&char(s.str), '%4d-%2d-%2d%c', &year, &month, &day, &dummy) } + count := unsafe { C.sscanf(&char(s.str), c'%4d-%2d-%2d%c', &year, &month, &day, &dummy) } if count != 3 { return time.err_invalid_8601 } @@ -66,13 +66,13 @@ fn parse_iso8601_time(s string) ?(int, int, int, int, i64, bool) { offset_hour := 0 offset_minute := 0 mut count := unsafe { - C.sscanf(&char(s.str), '%2d:%2d:%2d.%6d%c%2d:%2d', &hour_, &minute_, &second_, + C.sscanf(&char(s.str), c'%2d:%2d:%2d.%6d%c%2d:%2d', &hour_, &minute_, &second_, µsecond_, &char(&plus_min_z), &offset_hour, &offset_minute) } // Missread microsecond ([Sec Hour Minute].len == 3 < 4) if count < 4 { count = unsafe { - C.sscanf(&char(s.str), '%2d:%2d:%2d%c%2d:%2d', &hour_, &minute_, &second_, + C.sscanf(&char(s.str), c'%2d:%2d:%2d%c%2d:%2d', &hour_, &minute_, &second_, &char(&plus_min_z), &offset_hour, &offset_minute) } count++ // Increment count because skipped microsecond