1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: wrap up unsafe { nil } (p. 3)

This commit is contained in:
Alexander Medvednikov
2022-07-21 21:01:30 +03:00
parent a68d03ac59
commit 9099594a49
51 changed files with 86 additions and 86 deletions

View File

@@ -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?)
}

View File

@@ -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 }

View File

@@ -267,7 +267,7 @@ fn break_if_debugger_attached() {
$if tinyc {
unsafe {
mut ptr := &voidptr(0)
*ptr = voidptr(0)
*ptr = nil
_ = ptr
}
} $else {

View File

@@ -4,7 +4,7 @@ fn test_isnil_byteptr() {
}
fn test_isnil_voidptr() {
pv := voidptr(0)
pv := unsafe { nil }
assert isnil(pv)
}

View File

@@ -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]

View File

@@ -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 }
}
}

View File

@@ -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,

View File

@@ -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)

View File

@@ -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)
}

View File

@@ -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 {}