From 9099594a495840dfe1b7b93d3a01e7004756abb6 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 21 Jul 2022 21:01:30 +0300 Subject: [PATCH] all: wrap up unsafe { nil } (p. 3) --- vlib/builtin/array_d_gcboehm_opt.v | 2 +- vlib/builtin/builtin.c.v | 2 +- vlib/builtin/builtin_windows.c.v | 2 +- vlib/builtin/isnil_test.v | 2 +- vlib/builtin/js/map.js.v | 2 +- vlib/builtin/linux_bare/memory_managment.v | 6 +++--- vlib/builtin/map.v | 2 +- vlib/builtin/map_test.v | 4 ++-- vlib/builtin/prealloc.c.v | 2 +- vlib/builtin/wasm_bare/libc_impl.v | 2 +- vlib/datatypes/fsm/fsm.v | 2 +- vlib/datatypes/linked_list.v | 4 ++-- vlib/dlmalloc/dlmalloc_sys_nix.c.v | 12 ++++++------ vlib/dlmalloc/dlmalloc_sys_windows.c.v | 6 +++--- vlib/eventbus/eventbus.v | 2 +- vlib/gg/image.v | 2 +- vlib/js/dom/dom.js.v | 10 +++++----- vlib/js/js.js.v | 2 +- vlib/mysql/mysql.v | 2 +- vlib/os/environment.c.v | 2 +- vlib/os/os.c.v | 2 +- vlib/os/os_windows.c.v | 2 +- vlib/os/process_windows.c.v | 3 ++- vlib/picoev/picoev.v | 2 +- vlib/sync/channels.c.v | 10 +++++----- vlib/sync/pool/pool.v | 4 ++-- vlib/term/ui/input_windows.c.v | 2 +- vlib/term/ui/termios_nix.c.v | 2 +- vlib/time/time_windows.c.v | 4 ++-- vlib/v/ast/table.v | 2 +- vlib/v/ast/walker/walker_test.v | 2 +- vlib/v/checker/return.v | 2 +- vlib/v/checker/tests/fixed_array_conv.vv | 6 +++--- vlib/v/checker/tests/pointer_ops.vv | 4 ++-- vlib/v/checker/tests/voidptr_dereference_err.vv | 2 +- vlib/v/dotgraph/dotgraph.v | 4 ++-- vlib/v/fmt/tests/cast_input.vv | 7 +++---- vlib/v/fmt/tests/fntype_alias_keep.vv | 6 +++--- vlib/v/gen/c/assign.v | 4 ++-- vlib/v/gen/golang/golang.v | 2 +- vlib/v/gen/js/js.v | 4 ++-- vlib/v/preludes/test_runner.v | 2 +- ...ixed_array_containing_references_to_itself_test.v | 2 +- .../fn_returning_voidptr_casted_as_interface_test.v | 2 +- .../pass_voidptr_as_interface_reference_test.v | 2 +- .../voidptr_casted_as_an_interface_test.v | 2 +- vlib/v/tests/interface_embedding_method_call_test.v | 2 +- vlib/v/tests/multiret_with_ptrtype_test.v | 2 +- vlib/v/tests/return_voidptr_test.v | 8 ++++---- vlib/v/tests/struct_init_with_complex_fields_test.v | 2 +- vlib/v/tests/testcase_leak.vv | 2 +- 51 files changed, 86 insertions(+), 86 deletions(-) diff --git a/vlib/builtin/array_d_gcboehm_opt.v b/vlib/builtin/array_d_gcboehm_opt.v index b94231943f..238b6300a2 100644 --- a/vlib/builtin/array_d_gcboehm_opt.v +++ b/vlib/builtin/array_d_gcboehm_opt.v @@ -72,7 +72,7 @@ fn (mut a array) ensure_cap_noscan(required int) { } new_size := u64(cap) * u64(a.element_size) new_data := vcalloc_noscan(new_size) - if a.data != voidptr(0) { + if a.data != unsafe { nil } { unsafe { vmemcpy(new_data, a.data, u64(a.len) * u64(a.element_size)) } // TODO: the old data may be leaked when no GC is used (ref-counting?) } diff --git a/vlib/builtin/builtin.c.v b/vlib/builtin/builtin.c.v index c76914bf30..7bf4ed5555 100644 --- a/vlib/builtin/builtin.c.v +++ b/vlib/builtin/builtin.c.v @@ -653,4 +653,4 @@ pub fn print_backtrace() { __global g_main_argc = int(0) [markused] -__global g_main_argv = voidptr(0) +__global g_main_argv = unsafe { nil } diff --git a/vlib/builtin/builtin_windows.c.v b/vlib/builtin/builtin_windows.c.v index cd52408a2e..526ae6f06c 100644 --- a/vlib/builtin/builtin_windows.c.v +++ b/vlib/builtin/builtin_windows.c.v @@ -267,7 +267,7 @@ fn break_if_debugger_attached() { $if tinyc { unsafe { mut ptr := &voidptr(0) - *ptr = voidptr(0) + *ptr = nil _ = ptr } } $else { diff --git a/vlib/builtin/isnil_test.v b/vlib/builtin/isnil_test.v index 764d59272c..3d111ae43e 100644 --- a/vlib/builtin/isnil_test.v +++ b/vlib/builtin/isnil_test.v @@ -4,7 +4,7 @@ fn test_isnil_byteptr() { } fn test_isnil_voidptr() { - pv := voidptr(0) + pv := unsafe { nil } assert isnil(pv) } diff --git a/vlib/builtin/js/map.js.v b/vlib/builtin/js/map.js.v index 8813604756..45a6f71b61 100644 --- a/vlib/builtin/js/map.js.v +++ b/vlib/builtin/js/map.js.v @@ -20,7 +20,7 @@ fn (mut m map) internal_set(key JS.Any, val JS.Any) { } fn (mut m map) internal_get(key JS.Any) JS.Any { - mut val := JS.Any(voidptr(0)) + mut val := JS.Any(unsafe { nil }) //$if es5 { #if (typeof key != "string" && '$toJS' in key) key = key.$toJS(); #val = m.val.map[key] diff --git a/vlib/builtin/linux_bare/memory_managment.v b/vlib/builtin/linux_bare/memory_managment.v index 9da707e0a3..a7955872ad 100644 --- a/vlib/builtin/linux_bare/memory_managment.v +++ b/vlib/builtin/linux_bare/memory_managment.v @@ -43,11 +43,11 @@ fn system_alloc(_ voidptr, size usize) (voidptr, usize, u32) { if e == .enoerror { return a, size, 0 } - return voidptr(0), 0, 0 + return unsafe { nil }, 0, 0 } fn system_remap(_ voidptr, ptr voidptr, oldsize usize, newsize usize, can_move bool) voidptr { - return voidptr(0) + return unsafe { nil } } fn system_free_part(_ voidptr, ptr voidptr, oldsize usize, newsize usize) bool { @@ -87,6 +87,6 @@ fn get_linux_allocator() dlmalloc.Allocator { can_release_part: system_can_release_part allocates_zeros: system_allocates_zeros page_size: system_page_size - data: voidptr(0) + data: unsafe { nil } } } diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index 622ccdffd7..a102623cd8 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -488,7 +488,7 @@ fn (mut m map) get_and_set(key voidptr, zero voidptr) voidptr { // Key not found, insert key with zero-value m.set(key, zero) } - return voidptr(0) + return unsafe { nil } } // If `key` matches the key of an element in the container, diff --git a/vlib/builtin/map_test.v b/vlib/builtin/map_test.v index 4ed7a09860..b199a91fa2 100644 --- a/vlib/builtin/map_test.v +++ b/vlib/builtin/map_test.v @@ -210,8 +210,8 @@ fn test_various_map_value() { // m13['test'] = rune(0) // assert m13['test'] == rune(0) mut m14 := map[string]voidptr{} - m14['test'] = voidptr(0) - assert m14['test'] == voidptr(0) + m14['test'] = unsafe { nil } + assert m14['test'] == unsafe { nil } mut m15 := map[string]&u8{} m15['test'] = &u8(0) assert m15['test'] == &u8(0) diff --git a/vlib/builtin/prealloc.c.v b/vlib/builtin/prealloc.c.v index 20b4216156..9c399a2b7d 100644 --- a/vlib/builtin/prealloc.c.v +++ b/vlib/builtin/prealloc.c.v @@ -65,7 +65,7 @@ fn vmemory_block_malloc(n isize) &byte { [unsafe] fn prealloc_vinit() { unsafe { - g_memory_block = vmemory_block_new(voidptr(0), prealloc_block_size) + g_memory_block = vmemory_block_new(nil, prealloc_block_size) $if !freestanding { C.atexit(prealloc_vcleanup) } diff --git a/vlib/builtin/wasm_bare/libc_impl.v b/vlib/builtin/wasm_bare/libc_impl.v index 96ad8da060..2c902e79d1 100644 --- a/vlib/builtin/wasm_bare/libc_impl.v +++ b/vlib/builtin/wasm_bare/libc_impl.v @@ -148,7 +148,7 @@ fn bare_backtrace() string { fn __exit(code int) { unsafe { // the only way to abort process execution in WASM - mut x := &int(voidptr(0)) + mut x := &int(nil) *x = code } for {} diff --git a/vlib/datatypes/fsm/fsm.v b/vlib/datatypes/fsm/fsm.v index 3d8f309670..10506b4612 100644 --- a/vlib/datatypes/fsm/fsm.v +++ b/vlib/datatypes/fsm/fsm.v @@ -14,7 +14,7 @@ mut: struct Transition { mut: to string - condition_handler ConditionFn = voidptr(0) + condition_handler ConditionFn = unsafe { nil } } pub struct StateMachine { diff --git a/vlib/datatypes/linked_list.v b/vlib/datatypes/linked_list.v index d3c48b5b07..d979cf8f3f 100644 --- a/vlib/datatypes/linked_list.v +++ b/vlib/datatypes/linked_list.v @@ -87,14 +87,14 @@ pub fn (mut list LinkedList) pop() ?T { if unsafe { node.next == 0 } { // first node case // set to null - list.head = voidptr(0) + list.head = unsafe { nil } } else { for unsafe { node.next.next != 0 } { node = node.next } to_return = node.next.data // set to null - node.next = voidptr(0) + node.next = unsafe { nil } } list.len -= 1 return to_return diff --git a/vlib/dlmalloc/dlmalloc_sys_nix.c.v b/vlib/dlmalloc/dlmalloc_sys_nix.c.v index e2e39eb7d3..76d52b66c6 100644 --- a/vlib/dlmalloc/dlmalloc_sys_nix.c.v +++ b/vlib/dlmalloc/dlmalloc_sys_nix.c.v @@ -55,22 +55,22 @@ fn system_alloc(_ voidptr, size usize) (voidptr, usize, u32) { unsafe { mem_prot := MemProt(int(MemProt.prot_read) | int(MemProt.prot_write)) map_flags := MapFlags(int(MapFlags.map_private) | int(MapFlags.map_anonymous)) - addr := C.mmap(voidptr(0), size, int(mem_prot), int(map_flags), -1, 0) + addr := C.mmap(nil, size, int(mem_prot), int(map_flags), -1, 0) if addr == voidptr(-1) { - return voidptr(0), 0, 0 + return nil, 0, 0 } else { return addr, size, 0 } } } $else { - return voidptr(0), 0, 0 + return unsafe { nil }, 0, 0 } - return voidptr(0), 0, 0 + return unsafe { nil }, 0, 0 } fn system_remap(_ voidptr, ptr voidptr, oldsize usize, newsize usize, can_move bool) voidptr { - return voidptr(0) + return unsafe { nil } } fn system_free_part(_ voidptr, ptr voidptr, oldsize usize, newsize usize) bool { @@ -121,6 +121,6 @@ pub fn get_system_allocator() Allocator { can_release_part: system_can_release_part allocates_zeros: system_allocates_zeros page_size: system_page_size - data: voidptr(0) + data: unsafe { nil } } } diff --git a/vlib/dlmalloc/dlmalloc_sys_windows.c.v b/vlib/dlmalloc/dlmalloc_sys_windows.c.v index aa7e6b191f..1e2c820bd1 100644 --- a/vlib/dlmalloc/dlmalloc_sys_windows.c.v +++ b/vlib/dlmalloc/dlmalloc_sys_windows.c.v @@ -1,11 +1,11 @@ module dlmalloc fn system_alloc(_ voidptr, size usize) (voidptr, usize, u32) { - return voidptr(0), 0, 0 + return unsafe { nil }, 0, 0 } fn system_remap(_ voidptr, ptr voidptr, oldsize usize, newsize usize, can_move bool) voidptr { - return voidptr(0) + return unsafe { nil } } fn system_free_part(_ voidptr, ptr voidptr, oldsize usize, newsize usize) bool { @@ -37,6 +37,6 @@ pub fn get_system_allocator() Allocator { can_release_part: system_can_release_part allocates_zeros: system_allocates_zeros page_size: system_page_size - data: voidptr(0) + data: unsafe { nil } } } diff --git a/vlib/eventbus/eventbus.v b/vlib/eventbus/eventbus.v index 69cf1188a7..15af78ac23 100644 --- a/vlib/eventbus/eventbus.v +++ b/vlib/eventbus/eventbus.v @@ -20,7 +20,7 @@ mut: struct EventHandler { name string handler EventHandlerFn - receiver voidptr = voidptr(0) + receiver voidptr = unsafe { nil } once bool } diff --git a/vlib/gg/image.v b/vlib/gg/image.v index 02f63c6483..8e488b4701 100644 --- a/vlib/gg/image.v +++ b/vlib/gg/image.v @@ -10,7 +10,7 @@ pub struct DrawImageConfig { pub: flip_x bool flip_y bool - img &Image = voidptr(0) + img &Image = unsafe { nil } img_id int img_rect Rect // defines the size and position on image when rendering to the screen part_rect Rect // defines the size and position of part of the image to use when rendering diff --git a/vlib/js/dom/dom.js.v b/vlib/js/dom/dom.js.v index 6db238d1e0..8eff701499 100644 --- a/vlib/js/dom/dom.js.v +++ b/vlib/js/dom/dom.js.v @@ -343,7 +343,7 @@ pub const ( ) pub fn window() JS.Window { - mut x := JS.Any(voidptr(0)) + mut x := JS.Any(unsafe { nil }) #x = window; return x @@ -359,7 +359,7 @@ pub type EventCallback = fn (JS.Event) // that is EventTarget. When you need access only to Event itself you can just use `fn (JS.Event)` as listener. pub fn event_listener(callback fn (JS.EventTarget, JS.Event)) EventCallback { return fn [callback] (event JS.Event) { - mut target := JS.EventTarget(voidptr(0)) + mut target := JS.EventTarget(unsafe { nil }) #target = this; callback(target, event) } @@ -490,7 +490,7 @@ pub type OnDeviceOrientation = fn (ev JS.DeviceOrientationEvent) JS.Any pub fn on_device_motion(cb fn (win JS.Window, ev JS.DeviceMotionEvent) JS.Any) OnDeviceMotion { clos := fn [cb] (ev JS.DeviceMotionEvent) JS.Any { - mut win := JS.Any(voidptr(0)) + mut win := JS.Any(unsafe { nil }) #win = this; return cb(win, ev) @@ -500,7 +500,7 @@ pub fn on_device_motion(cb fn (win JS.Window, ev JS.DeviceMotionEvent) JS.Any) O pub fn on_device_orientation(cb fn (win JS.Window, ev JS.DeviceOrientationEvent) JS.Any) OnDeviceOrientation { clos := fn [cb] (ev JS.DeviceOrientationEvent) JS.Any { - mut win := JS.Any(voidptr(0)) + mut win := JS.Any(unsafe { nil }) #win = this; return cb(win, ev) @@ -837,7 +837,7 @@ pub fn event_type(ev JS.Event) string { } pub fn create_event(typ string, bubbles bool, cancelable bool, composed bool) JS.Event { - mut ev := JS.Event(voidptr(0)) + mut ev := JS.Event(unsafe { nil }) #ev = new Event(typ.str,bubbles.val,cancelable.val,composed.val); return ev diff --git a/vlib/js/js.js.v b/vlib/js/js.js.v index 6fe2774514..ce557bee00 100644 --- a/vlib/js/js.js.v +++ b/vlib/js/js.js.v @@ -23,7 +23,7 @@ pub interface JS.Response { } pub fn fetch(input string, init map[string]JS.Any) promise.Promise { - p_init := JS.Any(voidptr(0)) + p_init := JS.Any(unsafe { nil }) p := promise.Promise{p_init} #let obj = {}; for (let [key,val] of init.map) { obj[key] = val; } diff --git a/vlib/mysql/mysql.v b/vlib/mysql/mysql.v index 5bf3a4d032..45b091a49b 100644 --- a/vlib/mysql/mysql.v +++ b/vlib/mysql/mysql.v @@ -158,7 +158,7 @@ pub fn (mut conn Connection) set_option(option_type int, val voidptr) { // get_option - return the value of an option, settable by `set_option`. // https://dev.mysql.com/doc/c-api/5.7/en/mysql-get-option.html pub fn (conn &Connection) get_option(option_type int) ?voidptr { - ret := voidptr(0) + ret := unsafe { nil } if C.mysql_get_option(conn.conn, option_type, &ret) != 0 { return error_with_code(get_error_msg(conn.conn), get_errno(conn.conn)) } diff --git a/vlib/os/environment.c.v b/vlib/os/environment.c.v index a27c9d578c..71d676d1c8 100644 --- a/vlib/os/environment.c.v +++ b/vlib/os/environment.c.v @@ -33,7 +33,7 @@ pub fn getenv_opt(key string) ?string { return string_from_wide(s) } $else { s := C.getenv(&char(key.str)) - if s == voidptr(0) { + if s == nil { return none } // Note: C.getenv *requires* that the result be copied. diff --git a/vlib/os/os.c.v b/vlib/os/os.c.v index ce57cc8182..1a106cc934 100644 --- a/vlib/os/os.c.v +++ b/vlib/os/os.c.v @@ -264,7 +264,7 @@ pub fn vfopen(path string, mode string) ?&C.FILE { if path.len == 0 { return error('vfopen called with ""') } - mut fp := voidptr(0) + mut fp := unsafe { nil } $if windows { fp = C._wfopen(path.to_wide(), mode.to_wide()) } $else { diff --git a/vlib/os/os_windows.c.v b/vlib/os/os_windows.c.v index e2d596b33f..63ac8d17db 100644 --- a/vlib/os/os_windows.c.v +++ b/vlib/os/os_windows.c.v @@ -271,7 +271,7 @@ const ( // ptr_win_get_error_msg return string (voidptr) // representation of error, only for windows. fn ptr_win_get_error_msg(code u32) voidptr { - mut buf := voidptr(0) + mut buf := unsafe { nil } // Check for code overflow if code > u32(os.max_error_code) { return buf diff --git a/vlib/os/process_windows.c.v b/vlib/os/process_windows.c.v index ddfb3659c1..4b79f6b1d0 100644 --- a/vlib/os/process_windows.c.v +++ b/vlib/os/process_windows.c.v @@ -190,7 +190,8 @@ fn (mut p Process) win_read_string(idx int, maxbytes int) (string, int) { return '', 0 } mut bytes_avail := int(0) - if !C.PeekNamedPipe(rhandle, voidptr(0), int(0), voidptr(0), &bytes_avail, voidptr(0)) { + if !C.PeekNamedPipe(rhandle, unsafe { nil }, int(0), unsafe { nil }, &bytes_avail, + unsafe { nil }) { return '', 0 } if bytes_avail == 0 { diff --git a/vlib/picoev/picoev.v b/vlib/picoev/picoev.v index afadc6f1d4..f64fc4ad74 100644 --- a/vlib/picoev/picoev.v +++ b/vlib/picoev/picoev.v @@ -57,7 +57,7 @@ pub: port int = 8080 cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response) err_cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response, IError) = default_err_cb - user_data voidptr = voidptr(0) + user_data voidptr = unsafe { nil } timeout_secs int = 8 max_headers int = 100 } diff --git a/vlib/sync/channels.c.v b/vlib/sync/channels.c.v index b32cd38ebd..9d76a4a7b7 100644 --- a/vlib/sync/channels.c.v +++ b/vlib/sync/channels.c.v @@ -124,10 +124,10 @@ pub fn (mut ch Channel) close() { if !C.atomic_compare_exchange_strong_u16(&ch.closed, &open_val, 1) { return } - mut nulladr := unsafe { voidptr(0) } + mut nulladr := unsafe { nil } for !C.atomic_compare_exchange_weak_ptr(unsafe { &voidptr(&ch.adr_written) }, &nulladr, voidptr(-1)) { - nulladr = unsafe { voidptr(0) } + nulladr = unsafe { nil } } ch.readsem_im.post() ch.readsem.post() @@ -191,10 +191,10 @@ fn (mut ch Channel) try_push_priv(src voidptr, no_block bool) ChanState { { // there is a reader waiting for us unsafe { C.memcpy(wradr, src, ch.objsize) } - mut nulladr := unsafe { voidptr(0) } + mut nulladr := unsafe { nil } for !C.atomic_compare_exchange_weak_ptr(unsafe { &voidptr(&ch.adr_written) }, &nulladr, wradr) { - nulladr = unsafe { voidptr(0) } + nulladr = unsafe { nil } } ch.readsem_im.post() return .success @@ -382,7 +382,7 @@ fn (mut ch Channel) try_pop_priv(dest voidptr, no_block bool) ChanState { { // there is a writer waiting for us unsafe { C.memcpy(dest, rdadr, ch.objsize) } - mut nulladr := unsafe { voidptr(0) } + mut nulladr := unsafe { nil } for !C.atomic_compare_exchange_weak_ptr(unsafe { &voidptr(&ch.adr_read) }, &nulladr, rdadr) { nulladr = unsafe { nil } diff --git a/vlib/sync/pool/pool.v b/vlib/sync/pool/pool.v index bd73913c91..4727055b80 100644 --- a/vlib/sync/pool/pool.v +++ b/vlib/sync/pool/pool.v @@ -7,7 +7,7 @@ import runtime fn C.atomic_fetch_add_u32(voidptr, u32) u32 pub const ( - no_result = voidptr(0) + no_result = unsafe { nil } ) pub struct PoolProcessor { @@ -48,7 +48,7 @@ pub fn new_pool_processor(context PoolProcessorConfig) &PoolProcessor { mut pool := PoolProcessor{ items: [] results: [] - shared_context: voidptr(0) + shared_context: unsafe { nil } thread_contexts: [] njobs: context.maxjobs ntask: 0 diff --git a/vlib/term/ui/input_windows.c.v b/vlib/term/ui/input_windows.c.v index c37f7dbbdd..db7c810878 100644 --- a/vlib/term/ui/input_windows.c.v +++ b/vlib/term/ui/input_windows.c.v @@ -114,7 +114,7 @@ pub fn (mut ctx Context) run() ? { } if !ctx.paused { sw.restart() - if ctx.cfg.event_fn != voidptr(0) { + if ctx.cfg.event_fn != unsafe { nil } { ctx.parse_events() } ctx.frame() diff --git a/vlib/term/ui/termios_nix.c.v b/vlib/term/ui/termios_nix.c.v index 37ce5eb020..1043129808 100644 --- a/vlib/term/ui/termios_nix.c.v +++ b/vlib/term/ui/termios_nix.c.v @@ -233,7 +233,7 @@ fn (mut ctx Context) termios_loop() { } if !ctx.paused { sw.restart() - if ctx.cfg.event_fn != voidptr(0) { + if ctx.cfg.event_fn != unsafe { nil } { unsafe { len := C.read(C.STDIN_FILENO, &u8(ctx.read_buf.data) + ctx.read_buf.len, ctx.read_buf.cap - ctx.read_buf.len) diff --git a/vlib/time/time_windows.c.v b/vlib/time/time_windows.c.v index 0053bc2f67..50fae4c78f 100644 --- a/vlib/time/time_windows.c.v +++ b/vlib/time/time_windows.c.v @@ -110,7 +110,7 @@ pub fn (t Time) local() Time { millisecond: u16(t.microsecond / 1000) } st_local := SystemTime{} - C.SystemTimeToTzSpecificLocalTime(voidptr(0), &st_utc, &st_local) + C.SystemTimeToTzSpecificLocalTime(unsafe { nil }, &st_utc, &st_local) t_local := Time{ year: st_local.year month: st_local.month @@ -133,7 +133,7 @@ fn win_now() Time { st_utc := SystemTime{} C.FileTimeToSystemTime(&ft_utc, &st_utc) st_local := SystemTime{} - C.SystemTimeToTzSpecificLocalTime(voidptr(0), &st_utc, &st_local) + C.SystemTimeToTzSpecificLocalTime(unsafe { nil }, &st_utc, &st_local) t := Time{ year: st_local.year month: st_local.month diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index cc56ee541b..b60414ff48 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -33,7 +33,7 @@ pub mut: used_vweb_types []Type // vweb context types, filled in by checker, when pref.skip_unused = true; used_maps int // how many times maps were used, filled in by checker, when pref.skip_unused = true; panic_handler FnPanicHandler = default_table_panic_handler - panic_userdata voidptr = voidptr(0) // can be used to pass arbitrary data to panic_handler; + panic_userdata voidptr = unsafe { nil } // can be used to pass arbitrary data to panic_handler; panic_npanics int cur_fn &FnDecl = unsafe { 0 } // previously stored in Checker.cur_fn and Gen.cur_fn cur_concrete_types []Type // current concrete types, e.g. diff --git a/vlib/v/ast/walker/walker_test.v b/vlib/v/ast/walker/walker_test.v index cd261fab39..66eaa31f90 100644 --- a/vlib/v/ast/walker/walker_test.v +++ b/vlib/v/ast/walker/walker_test.v @@ -46,7 +46,7 @@ fn test_inspect() { module main ' file := parse_text(source) - walker.inspect(file, voidptr(0), fn (node &ast.Node, data voidptr) bool { + walker.inspect(file, unsafe { nil }, fn (node &ast.Node, data voidptr) bool { // Second visit must be ast.Stmt if node is ast.Stmt { if node !is ast.Module { diff --git a/vlib/v/checker/return.v b/vlib/v/checker/return.v index 550ee6fc1c..1ca9a846fd 100644 --- a/vlib/v/checker/return.v +++ b/vlib/v/checker/return.v @@ -144,7 +144,7 @@ pub fn (mut c Checker) return_stmt(mut node ast.Return) { if mut r_expr is ast.Ident { if mut r_expr.obj is ast.Var { mut obj := unsafe { &r_expr.obj } - if c.fn_scope != voidptr(0) { + if c.fn_scope != unsafe { nil } { obj = c.fn_scope.find_var(r_expr.obj.name) or { obj } } if obj.is_stack_obj && !c.inside_unsafe { diff --git a/vlib/v/checker/tests/fixed_array_conv.vv b/vlib/v/checker/tests/fixed_array_conv.vv index 8c343c4f81..db9a7f2bb4 100644 --- a/vlib/v/checker/tests/fixed_array_conv.vv +++ b/vlib/v/checker/tests/fixed_array_conv.vv @@ -1,5 +1,5 @@ -arr := [2,3]! -mut p := voidptr(0) +arr := [2, 3]! +mut p := unsafe { nil } p = arr mut ip := &int(0) ip = arr @@ -10,5 +10,5 @@ _ = ip unsafe { _ = memdup(arr, 1) _ = tos(arr, 1) - fn (p &int){}(arr) + fn (p &int) {}(arr) } diff --git a/vlib/v/checker/tests/pointer_ops.vv b/vlib/v/checker/tests/pointer_ops.vv index 37a4554da1..b6c6429571 100644 --- a/vlib/v/checker/tests/pointer_ops.vv +++ b/vlib/v/checker/tests/pointer_ops.vv @@ -1,7 +1,7 @@ // void* arithmetic is not allowed in MSVC, so ban it fn test_voidptr() { unsafe { - mut p := voidptr(0) + mut p := nil _ = p + 1 p++ p += 3 @@ -14,4 +14,4 @@ fn test_voidptr() { } } -struct Foo{} +struct Foo {} diff --git a/vlib/v/checker/tests/voidptr_dereference_err.vv b/vlib/v/checker/tests/voidptr_dereference_err.vv index 97e46b5fdd..0c092d2ec3 100644 --- a/vlib/v/checker/tests/voidptr_dereference_err.vv +++ b/vlib/v/checker/tests/voidptr_dereference_err.vv @@ -1,5 +1,5 @@ fn main() { - mut a := voidptr(0) + mut a := unsafe { nil } mut b := 123 a = &b println(*a) diff --git a/vlib/v/dotgraph/dotgraph.v b/vlib/v/dotgraph/dotgraph.v index 2651b15e64..9366b316b1 100644 --- a/vlib/v/dotgraph/dotgraph.v +++ b/vlib/v/dotgraph/dotgraph.v @@ -38,7 +38,7 @@ pub struct NewNodeConfig { node_name string should_highlight bool tooltip string - ctx voidptr = voidptr(0) + ctx voidptr = unsafe { nil } name2node_fn FnLabel2NodeName = node_name } @@ -58,7 +58,7 @@ pub fn (mut d DotGraph) new_node(nlabel string, cfg NewNodeConfig) { pub struct NewEdgeConfig { should_highlight bool - ctx voidptr = voidptr(0) + ctx voidptr = unsafe { nil } name2node_fn FnLabel2NodeName = node_name } diff --git a/vlib/v/fmt/tests/cast_input.vv b/vlib/v/fmt/tests/cast_input.vv index f0d9793aa3..4a9f85333c 100644 --- a/vlib/v/fmt/tests/cast_input.vv +++ b/vlib/v/fmt/tests/cast_input.vv @@ -2,14 +2,13 @@ import v.ast { InfixExpr } import v.table { Type } fn test_as() { - _ := sum_expr() as ast.InfixExpr + _ := sum_expr() as InfixExpr _ := sum_expr() as ast.PrefixExpr } fn test_cast() { _ := f32(0) - _ := table.Type(0) + _ := Type(0) _ := ast.Expr(sum_expr()) - _ := voidptr(0) + _ := unsafe { nil } } - diff --git a/vlib/v/fmt/tests/fntype_alias_keep.vv b/vlib/v/fmt/tests/fntype_alias_keep.vv index 8e530a70fb..f8e4e30b0c 100644 --- a/vlib/v/fmt/tests/fntype_alias_keep.vv +++ b/vlib/v/fmt/tests/fntype_alias_keep.vv @@ -17,10 +17,10 @@ pub type MouseMoveFn = fn (e MouseMoveEvent, func voidptr) [heap] pub struct Window { pub mut: - ui &UI = voidptr(0) + ui &UI = unsafe { nil } children []Widget - child_window &Window = voidptr(0) - parent_window &Window = voidptr(0) + child_window &Window = unsafe { nil } + parent_window &Window = unsafe { nil } has_textbox bool // for initial focus tab_index int just_tabbed bool diff --git a/vlib/v/gen/c/assign.v b/vlib/v/gen/c/assign.v index fe1297eb5b..b3a5ac3505 100644 --- a/vlib/v/gen/c/assign.v +++ b/vlib/v/gen/c/assign.v @@ -158,7 +158,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) { ret_styp := g.typ(val.decl.return_type) g.write('$ret_styp (*$ident.name) (') def_pos := g.definitions.len - g.fn_decl_params(val.decl.params, voidptr(0), false) + g.fn_decl_params(val.decl.params, unsafe { nil }, false) g.definitions.go_back(g.definitions.len - def_pos) g.write(') = ') } else { @@ -344,7 +344,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) { g.write('$ret_styp ($msvc_call_conv*${g.get_ternary_name(ident.name)}) (') def_pos := g.definitions.len - g.fn_decl_params(func.func.params, voidptr(0), false) + g.fn_decl_params(func.func.params, unsafe { nil }, false) g.definitions.go_back(g.definitions.len - def_pos) g.write(')$call_conv_attribute_suffix') } else { diff --git a/vlib/v/gen/golang/golang.v b/vlib/v/gen/golang/golang.v index ee30937c1e..d471d159c7 100644 --- a/vlib/v/gen/golang/golang.v +++ b/vlib/v/gen/golang/golang.v @@ -44,7 +44,7 @@ pub mut: in_lambda_depth int inside_const bool is_mbranch_expr bool // match a { x...y { } } - fn_scope &ast.Scope = voidptr(0) + fn_scope &ast.Scope = unsafe { nil } wsinfix_depth int nlines int } diff --git a/vlib/v/gen/js/js.v b/vlib/v/gen/js/js.v index 3ad9bd9671..28c44a37e5 100644 --- a/vlib/v/gen/js/js.v +++ b/vlib/v/gen/js/js.v @@ -1124,7 +1124,7 @@ fn (mut g JsGen) gen_ctemp_var(tvar ast.CTempVar) { fn (mut g JsGen) gen_assert_metainfo(node ast.AssertStmt) string { mod_path := g.file.path - fn_name := if g.fn_decl == voidptr(0) || g.fn_decl.is_anon { 'anon' } else { g.fn_decl.name } + fn_name := if g.fn_decl == unsafe { nil } || g.fn_decl.is_anon { 'anon' } else { g.fn_decl.name } line_nr := node.pos.line_nr src := node.expr.str() metaname := 'v_assert_meta_info_$g.new_tmp_var()' @@ -1244,7 +1244,7 @@ fn (mut g JsGen) gen_assert_stmt(mut node ast.AssertStmt) { } g.writeln('} else {') g.inc_indent() - fname := if g.fn_decl == voidptr(0) || g.fn_decl.is_anon { 'anon' } else { g.fn_decl.name } + fname := if g.fn_decl == unsafe { nil } || g.fn_decl.is_anon { 'anon' } else { g.fn_decl.name } g.writeln('builtin__eprintln(new string("$mod_path:${node.pos.line_nr + 1}: FAIL: fn ${fname}(): assert $s_assertion"));') g.writeln('builtin__exit(1);') g.dec_indent() diff --git a/vlib/v/preludes/test_runner.v b/vlib/v/preludes/test_runner.v index b59f6b5c67..f482493983 100644 --- a/vlib/v/preludes/test_runner.v +++ b/vlib/v/preludes/test_runner.v @@ -102,7 +102,7 @@ pub fn change_test_runner(x &TestRunner) { if pobj != 0 { test_runner.free() unsafe { - (&C.main__TestRunner(&test_runner))._object = voidptr(0) + (&C.main__TestRunner(&test_runner))._object = nil } } test_runner = *x diff --git a/vlib/v/tests/const_fixed_array_containing_references_to_itself_test.v b/vlib/v/tests/const_fixed_array_containing_references_to_itself_test.v index c7526268f3..f40843817c 100644 --- a/vlib/v/tests/const_fixed_array_containing_references_to_itself_test.v +++ b/vlib/v/tests/const_fixed_array_containing_references_to_itself_test.v @@ -2,7 +2,7 @@ struct Abc { prev &Abc } -const a = [Abc{voidptr(0)}, Abc{unsafe { &a[0] }}, Abc{unsafe { &a[1] }}]! +const a = [Abc{unsafe { nil }}, Abc{unsafe { &a[0] }}, Abc{unsafe { &a[1] }}]! fn test_fixed_array() { eprintln(a) diff --git a/vlib/v/tests/interface_edge_cases/fn_returning_voidptr_casted_as_interface_test.v b/vlib/v/tests/interface_edge_cases/fn_returning_voidptr_casted_as_interface_test.v index 86b72ec381..33db8af7db 100644 --- a/vlib/v/tests/interface_edge_cases/fn_returning_voidptr_casted_as_interface_test.v +++ b/vlib/v/tests/interface_edge_cases/fn_returning_voidptr_casted_as_interface_test.v @@ -15,7 +15,7 @@ struct Abc { fn (a Abc) xyz() {} fn resource__null() &IAbc { - return voidptr(0) + return unsafe { nil } } fn test_fn_returning_voidptr_casted_as_interface_works() { diff --git a/vlib/v/tests/interface_edge_cases/pass_voidptr_as_interface_reference_test.v b/vlib/v/tests/interface_edge_cases/pass_voidptr_as_interface_reference_test.v index 8de1486e53..661c85340e 100644 --- a/vlib/v/tests/interface_edge_cases/pass_voidptr_as_interface_reference_test.v +++ b/vlib/v/tests/interface_edge_cases/pass_voidptr_as_interface_reference_test.v @@ -15,5 +15,5 @@ fn test_passing_voidptr_as_an_interface_reference() { assert f(&i) == '&IAbc(Abc{})' // a voidptr() cast is an escape hatch, that should be allowed // but perhaps it should be forced by the compiler to be in unsafe{} - assert f(unsafe { voidptr(0) }) == '&IAbc(0x0)' + assert f(unsafe { nil }) == '&IAbc(0x0)' } diff --git a/vlib/v/tests/interface_edge_cases/voidptr_casted_as_an_interface_test.v b/vlib/v/tests/interface_edge_cases/voidptr_casted_as_an_interface_test.v index 3c30e043f7..e9fce35552 100644 --- a/vlib/v/tests/interface_edge_cases/voidptr_casted_as_an_interface_test.v +++ b/vlib/v/tests/interface_edge_cases/voidptr_casted_as_an_interface_test.v @@ -15,7 +15,7 @@ fn f(i &IAbc) string { } fn test_voidptr_casted_as_an_interface_reference() { - mut pi := &IAbc(voidptr(0)) + mut pi := &IAbc(unsafe { nil }) dump(pi) assert f(pi) == '&IAbc(0x0)' // diff --git a/vlib/v/tests/interface_embedding_method_call_test.v b/vlib/v/tests/interface_embedding_method_call_test.v index 6b315d2f5d..ddbd473122 100644 --- a/vlib/v/tests/interface_embedding_method_call_test.v +++ b/vlib/v/tests/interface_embedding_method_call_test.v @@ -45,7 +45,7 @@ interface PopView { [heap] pub struct Button { mut: - window &Window = voidptr(0) + window &Window = unsafe { nil } } pub fn (mut b Button) init(window &Window) { diff --git a/vlib/v/tests/multiret_with_ptrtype_test.v b/vlib/v/tests/multiret_with_ptrtype_test.v index db13a53f1f..666f11f614 100644 --- a/vlib/v/tests/multiret_with_ptrtype_test.v +++ b/vlib/v/tests/multiret_with_ptrtype_test.v @@ -1,5 +1,5 @@ fn multi_voidptr_ret() (voidptr, bool) { - return voidptr(0), true + return unsafe { nil }, true } fn multi_byteptr_ret() (&u8, bool) { diff --git a/vlib/v/tests/return_voidptr_test.v b/vlib/v/tests/return_voidptr_test.v index e40e1673dd..ecf8890147 100644 --- a/vlib/v/tests/return_voidptr_test.v +++ b/vlib/v/tests/return_voidptr_test.v @@ -3,24 +3,24 @@ struct Zest { } fn (t Zest) get_a_finger_to_the_moon() voidptr { - return voidptr(0) + return unsafe { nil } } fn get_the_dao_way() voidptr { - return voidptr(0) + return unsafe { nil } } fn test_returning_a_void_pointer_from_a_method() { t := &Zest{ val: 123 } - z := voidptr(0) + z := unsafe { nil } assert z == t.get_a_finger_to_the_moon() assert t.get_a_finger_to_the_moon() == 0 } fn test_returning_a_void_pointer_from_a_function() { - z := voidptr(0) + z := unsafe { nil } assert z == get_the_dao_way() assert get_the_dao_way() == 0 } diff --git a/vlib/v/tests/struct_init_with_complex_fields_test.v b/vlib/v/tests/struct_init_with_complex_fields_test.v index f119e98b34..723285a3ed 100644 --- a/vlib/v/tests/struct_init_with_complex_fields_test.v +++ b/vlib/v/tests/struct_init_with_complex_fields_test.v @@ -4,7 +4,7 @@ type Fnc = fn () struct Foo { Bar - fnc_fn Fnc = voidptr(0) + fnc_fn Fnc = unsafe { nil } } struct App { diff --git a/vlib/v/tests/testcase_leak.vv b/vlib/v/tests/testcase_leak.vv index fd73606a2b..ae0d81e527 100644 --- a/vlib/v/tests/testcase_leak.vv +++ b/vlib/v/tests/testcase_leak.vv @@ -7,6 +7,6 @@ fn main() { mut y := unsafe { malloc(1000) } // unsafe { free(y) } // leak if commented out - y = voidptr(0) + y = unsafe { nil } gc_check_leaks() }