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

vfmt: voidptr(0) => unsafe { nil } (p.1)

This commit is contained in:
Alexander Medvednikov
2022-07-21 20:45:57 +03:00
parent be9f8cc777
commit caa0c2f153
17 changed files with 153 additions and 123 deletions

View File

@ -229,8 +229,8 @@ mut:
treebins [n_tree_bins]&TreeChunk
dvsize usize
topsize usize
dv &Chunk = voidptr(0)
top &Chunk = voidptr(0)
dv &Chunk = unsafe { nil }
top &Chunk = unsafe { nil }
footprint usize
max_footprint usize
seg Segment
@ -247,13 +247,13 @@ pub fn new(system_allocator Allocator) Dlmalloc {
treebins: unsafe { [dlmalloc.n_tree_bins]&TreeChunk{} }
dvsize: 0
topsize: 0
dv: voidptr(0)
top: voidptr(0)
dv: unsafe { nil }
top: unsafe { nil }
footprint: 0
max_footprint: 0
seg: Segment{voidptr(0), 0, voidptr(0), 0}
seg: Segment{unsafe { nil }, 0, unsafe { nil }, 0}
trim_check: 0
least_addr: voidptr(0)
least_addr: unsafe { nil }
release_checks: 0
system_allocator: system_allocator
max_request: 4294901657
@ -498,7 +498,7 @@ fn (mut dl Dlmalloc) unlink_large_chunk(chunk_ &TreeChunk) {
unsafe {
mut chunk := chunk_
mut xp := &TreeChunk(chunk.parent)
mut r := &TreeChunk(voidptr(0))
mut r := &TreeChunk(unsafe { nil })
if voidptr(chunk.next()) != voidptr(chunk) {
mut f := chunk.prev()
r = chunk.next()
@ -523,7 +523,7 @@ fn (mut dl Dlmalloc) unlink_large_chunk(chunk_ &TreeChunk) {
rp = cp
}
r = *rp
*rp = &TreeChunk(voidptr(0))
*rp = &TreeChunk(unsafe { nil })
}
}
@ -635,7 +635,7 @@ pub fn (mut dl Dlmalloc) free_(mem voidptr) {
dl.top = p
p.head = tsize | dlmalloc.pinuse
if voidptr(p) == voidptr(dl.dv) {
dl.dv = voidptr(0)
dl.dv = unsafe { nil }
dl.dvsize = 0
}
@ -748,7 +748,7 @@ fn (mut dl Dlmalloc) release_unused_segments() usize {
if !p.inuse() && chunk_top >= top {
mut tp := &TreeChunk(p)
if voidptr(p) == voidptr(dl.dv) {
dl.dv = voidptr(0)
dl.dv = unsafe { nil }
dl.dvsize = 0
} else {
dl.unlink_large_chunk(tp)
@ -843,8 +843,8 @@ fn (mut dl Dlmalloc) insert_large_chunk(chunk_ &TreeChunk, size usize) {
mut h := dl.treebin_at(idx)
chunk.index = idx
chunk.child[0] = voidptr(0)
chunk.child[1] = voidptr(0)
chunk.child[0] = unsafe { nil }
chunk.child[1] = unsafe { nil }
mut chunkc := chunk.chunk()
if !dl.treemap_is_marked(idx) {
@ -879,7 +879,7 @@ fn (mut dl Dlmalloc) insert_large_chunk(chunk_ &TreeChunk, size usize) {
tc.prev = chunkc
chunkc.prev = f
chunkc.next = tc
chunk.parent = voidptr(0)
chunk.parent = unsafe { nil }
break
}
}
@ -988,7 +988,7 @@ fn (mut dl Dlmalloc) malloc_real(size usize) voidptr {
}
}
} else if size >= dl.max_request {
return voidptr(0)
return unsafe { nil }
} else {
nb = pad_request(size)
if dl.treemap != 0 {
@ -1013,7 +1013,7 @@ fn (mut dl Dlmalloc) malloc_real(size usize) voidptr {
} else {
dvs := dl.dvsize
dl.dvsize = 0
dl.dv = voidptr(0)
dl.dv = unsafe { nil }
p.set_inuse_and_pinuse(dvs)
}
ret := p.to_mem()
@ -1140,7 +1140,7 @@ fn (mut dl Dlmalloc) sys_alloc(size usize) voidptr {
return ret
}
}
return voidptr(0)
return unsafe { nil }
}
[unsafe]
@ -1183,13 +1183,13 @@ fn (mut dl Dlmalloc) tmalloc_small(size usize) voidptr {
[unsafe]
fn (mut dl Dlmalloc) tmalloc_large(size usize) voidptr {
unsafe {
mut v := &TreeChunk(voidptr(0))
mut v := &TreeChunk(unsafe { nil })
mut rsize := ~size + 1
idx := dl.compute_tree_index(size)
mut t := *dl.treebin_at(idx)
if !isnil(t) {
mut sizebits := size << leftshift_for_tree_index(idx)
mut rst := voidptr(0)
mut rst := unsafe { nil }
for {
csize := t.chunk().size()
if csize >= size && csize - size < rsize {
@ -1232,7 +1232,7 @@ fn (mut dl Dlmalloc) tmalloc_large(size usize) voidptr {
}
if isnil(v) || (dl.dvsize >= size && !(rsize < dl.dvsize - size)) {
return voidptr(0)
return unsafe { nil }
}
mut vc := v.chunk()
@ -1362,7 +1362,7 @@ fn (mut dl Dlmalloc) segment_holding(ptr voidptr) &Segment {
[unsafe]
pub fn (mut dl Dlmalloc) realloc(oldmem voidptr, bytes usize) voidptr {
if bytes >= dl.max_request {
return voidptr(0)
return unsafe { nil }
}
unsafe {
nb := request_2_size(bytes)
@ -1393,7 +1393,7 @@ pub fn (mut dl Dlmalloc) memalign(alignment_ usize, bytes usize) voidptr {
}
if bytes >= max_request() - alignment {
return voidptr(0)
return unsafe { nil }
}
unsafe {
nb := request_2_size(bytes)
@ -1412,7 +1412,7 @@ pub fn (mut dl Dlmalloc) memalign(alignment_ usize, bytes usize) voidptr {
// we've allocated enough total room so that this is always possible
br_ := (usize(mem) + alignment - 1) & (~alignment + 1)
br := chunk_from_mem(voidptr(br_))
mut pos := voidptr(0)
mut pos := unsafe { nil }
if usize(br) - usize(p) > min_chunk_size() {
pos = voidptr(br)
} else {
@ -1469,7 +1469,7 @@ fn (mut dl Dlmalloc) try_realloc_chunk(p_ &Chunk, nb usize, can_move bool) &Chun
return p
} else if voidptr(next) == voidptr(dl.top) {
if oldsize + dl.topsize <= nb {
return voidptr(0)
return unsafe { nil }
}
newsize := oldsize + dl.topsize
@ -1483,7 +1483,7 @@ fn (mut dl Dlmalloc) try_realloc_chunk(p_ &Chunk, nb usize, can_move bool) &Chun
} else if voidptr(next) == voidptr(dl.dv) {
dvs := dl.dvsize
if oldsize + dvs < nb {
return voidptr(0)
return unsafe { nil }
}
dsize := oldsize + dvs - nb
@ -1499,13 +1499,13 @@ fn (mut dl Dlmalloc) try_realloc_chunk(p_ &Chunk, nb usize, can_move bool) &Chun
newsize := oldsize + dvs
p.set_inuse(newsize)
dl.dvsize = 0
dl.dv = voidptr(0)
dl.dv = unsafe { nil }
}
return p
} else if !next.cinuse() {
nextsize := next.size()
if oldsize + nextsize < nb {
return voidptr(0)
return unsafe { nil }
}
rsize := oldsize + nextsize - nb
dl.unlink_chunk(next, nextsize)
@ -1520,7 +1520,7 @@ fn (mut dl Dlmalloc) try_realloc_chunk(p_ &Chunk, nb usize, can_move bool) &Chun
}
return p
} else {
return voidptr(0)
return unsafe { nil }
}
}
}
@ -1530,7 +1530,7 @@ fn (mut dl Dlmalloc) mmap_resize(oldp_ &Chunk, nb usize, can_move bool) &Chunk {
mut oldp := unsafe { oldp_ }
oldsize := oldp.size()
if is_small(nb) {
return voidptr(0)
return unsafe { nil }
}
// Keep the old chunk if it's big enough but not too big
if oldsize >= nb + sizeof(usize) && (oldsize - nb) <= (default_granularity() << 1) {
@ -1544,7 +1544,7 @@ fn (mut dl Dlmalloc) mmap_resize(oldp_ &Chunk, nb usize, can_move bool) &Chunk {
ptr := dl.system_allocator.remap(dl.system_allocator.data, voidptr(usize(oldp) - offset),
oldmmsize, newmmsize, can_move)
if isnil(ptr) {
return voidptr(0)
return unsafe { nil }
}
mut newp := &Chunk(voidptr(usize(ptr) + offset))
@ -1604,7 +1604,7 @@ fn (mut dl Dlmalloc) dispose_chunk(p_ &Chunk, psize_ usize) {
dl.top = p
p.head = tsize | dlmalloc.pinuse
if voidptr(p) == voidptr(dl.dv) {
dl.dv = voidptr(0)
dl.dv = unsafe { nil }
dl.dvsize = 0
}
return