Skip to content

Commit 5c12375

Browse files
authored
cleanup: replace C.NULL with unsafe { nil } (#28916)
1 parent 4c434ac commit 5c12375

26 files changed

Lines changed: 53 additions & 53 deletions

‎examples/1brc/solution/main.v‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ fn mmap_file(path string) MemoryMappedFile {
1919
mut mf := MemoryMappedFile{
2020
file: os.open_file(path, 'r', 0) or { panic('fail') }
2121
size: usize(os.file_size(path))
22-
data: C.NULL
22+
data: unsafe { nil }
2323
}
2424

2525
// `mmap` returns an untyped mapping pointer; reinterpret it as `&u8` to read the file
2626
// bytes. The mapping is owned by this `MemoryMappedFile` and stays valid until `unmap`
2727
// calls `munmap`, so the pointer is live for as long as the struct is used.
28-
mf.data = unsafe { &u8(C.mmap(C.NULL, mf.size, C.PROT_READ, C.MAP_SHARED, mf.file.fd, 0)) }
28+
mf.data = unsafe { &u8(C.mmap(nil, mf.size, C.PROT_READ, C.MAP_SHARED, mf.file.fd, 0)) }
2929
return mf
3030
}
3131

‎vlib/clipboard/clipboard_darwin.c.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn new_clipboard() &Clipboard {
3131

3232
// check_availability returns true if the clipboard is ready to be used.
3333
pub fn (cb &Clipboard) check_availability() bool {
34-
return cb.pb != C.NULL
34+
return cb.pb != unsafe { nil }
3535
}
3636

3737
// clear empties the clipboard contents.

‎vlib/clipboard/clipboard_windows.c.v‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn new_clipboard() &Clipboard {
103103
println('Failed registering class.')
104104
}
105105
hwnd := C.CreateWindowEx(0, wndclass.lpsz_class_name, wndclass.lpsz_class_name, 0, 0, 0, 0, 0,
106-
C.HWND_MESSAGE, C.NULL, C.NULL, C.NULL)
106+
C.HWND_MESSAGE, unsafe { nil }, unsafe { nil }, unsafe { nil })
107107
if hwnd == unsafe { nil } {
108108
println('Error creating window!')
109109
}
@@ -143,7 +143,7 @@ const cp_utf8 = 65001
143143
fn to_wide(text string) C.HGLOBAL {
144144
len_required := C.MultiByteToWideChar(cp_utf8, C.MB_ERR_INVALID_CHARS, voidptr(text.str),
145145

146-
text.len + 1, C.NULL, 0)
146+
text.len + 1, unsafe { nil }, 0)
147147
buf := C.GlobalAlloc(C.GMEM_MOVEABLE, i64(sizeof(u16)) * len_required)
148148
if buf != unsafe { nil } {
149149
mut locked := &u16(C.GlobalLock(buf))

‎vlib/clipboard/x11/clipboard.c.v‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ fn new_x11_clipboard(selection AtomType) &Clipboard {
205205

206206
display := new_display()
207207

208-
if display == C.NULL {
208+
if display == unsafe { nil } {
209209
println('ERROR: No X Server running. Clipboard cannot be used.')
210210
return &Clipboard{
211211
display: unsafe { nil }
@@ -228,7 +228,7 @@ fn new_x11_clipboard(selection AtomType) &Clipboard {
228228

229229
// check_availability returns `true` if the clipboard is available for use.
230230
pub fn (cb &Clipboard) check_availability() bool {
231-
return cb.display != C.NULL
231+
return cb.display != unsafe { nil }
232232
}
233233

234234
// free releases the clipboard resources.
@@ -520,7 +520,7 @@ fn create_xwindow(display &C.Display) Window {
520520
}
521521

522522
fn new_display() &C.Display {
523-
return C.XOpenDisplay(C.NULL)
523+
return C.XOpenDisplay(unsafe { nil })
524524
}
525525

526526
// new_primary returns a new X11 `PRIMARY` type `Clipboard` instance allocated on the heap.

‎vlib/fasthttp/fasthttp_linux.c.v‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ fn sendfile_without_sigpipe(out_fd i32, in_fd i32, offset &i64, count usize) i32
8484
// Consume only the SIGPIPE generated by sendfile before restoring an unblocked mask.
8585
timeout := C.timespec{}
8686
for {
87-
wait_result := C.sigtimedwait(&sigpipe_set, C.NULL, &timeout)
87+
wait_result := C.sigtimedwait(&sigpipe_set, unsafe { nil }, &timeout)
8888
if wait_result == C.SIGPIPE || C.errno != C.EINTR {
8989
break
9090
}
9191
}
9292
}
9393

94-
restore_result := C.pthread_sigmask(C.SIG_SETMASK, &previous_mask, C.NULL)
94+
restore_result := C.pthread_sigmask(C.SIG_SETMASK, &previous_mask, unsafe { nil })
9595
if restore_result != 0 {
9696
C.errno = restore_result
9797
return -1

‎vlib/fasthttp/fasthttp_linux.v‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ fn mod_fd_in_epoll(epoll_fd int, fd int, events u32) int {
232232

233233
// remove_fd_from_epoll removes a file descriptor from the epoll instance
234234
fn remove_fd_from_epoll(epoll_fd int, fd int) bool {
235-
ret := C.epoll_ctl(epoll_fd, C.EPOLL_CTL_DEL, fd, C.NULL)
235+
ret := C.epoll_ctl(epoll_fd, C.EPOLL_CTL_DEL, fd, unsafe { nil })
236236
if ret == -1 {
237237
eprintln('ERROR: epoll_ctl(DEL, fd=${fd}) failed with errno=${C.errno}')
238238
return false
@@ -924,7 +924,7 @@ fn handle_writable(mut w Worker, fd int) {
924924
// registers each with this worker's epoll for readability.
925925
fn handle_accept_loop(mut w Worker) {
926926
for {
927-
client_fd := C.accept4(w.listen_fd, C.NULL, C.NULL, C.SOCK_NONBLOCK)
927+
client_fd := C.accept4(w.listen_fd, unsafe { nil }, unsafe { nil }, C.SOCK_NONBLOCK)
928928
if client_fd < 0 {
929929
if C.errno == C.EAGAIN {
930930
break // no more incoming connections

‎vlib/fasthttp/fasthttp_linux_regression_test.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ fn record_sigpipe_handler(_ os.Signal) {
523523

524524
fn current_thread_blocks_sigpipe() bool {
525525
mut current_mask := C.sigset_t{}
526-
if C.pthread_sigmask(C.SIG_SETMASK, C.NULL, &current_mask) != 0 {
526+
if C.pthread_sigmask(C.SIG_SETMASK, unsafe { nil }, &current_mask) != 0 {
527527
return true
528528
}
529529
return C.sigismember(&current_mask, C.SIGPIPE) == 1

‎vlib/net/common.c.v‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ fn select(handle int, test Select, timeout time.Duration) !bool {
116116
if timeout == infinite_timeout {
117117
match test {
118118
.read {
119-
socket_error(C.select(handle + 1, &set, C.NULL, C.NULL, &C.timeval(unsafe { nil })))!
119+
socket_error(C.select(handle + 1, &set, unsafe { nil }, unsafe { nil }, &C.timeval(unsafe { nil })))!
120120
}
121121
.write {
122-
socket_error(C.select(handle + 1, C.NULL, &set, C.NULL, &C.timeval(unsafe { nil })))!
122+
socket_error(C.select(handle + 1, unsafe { nil }, &set, unsafe { nil }, &C.timeval(unsafe { nil })))!
123123
}
124124
.except {
125-
socket_error(C.select(handle + 1, C.NULL, C.NULL, &set, &C.timeval(unsafe { nil })))!
125+
socket_error(C.select(handle + 1, unsafe { nil }, unsafe { nil }, &set, &C.timeval(unsafe { nil })))!
126126
}
127127
}
128128
} else {
@@ -134,13 +134,13 @@ fn select(handle int, test Select, timeout time.Duration) !bool {
134134
}
135135
match test {
136136
.read {
137-
socket_error(C.select(handle + 1, &set, C.NULL, C.NULL, &tt))!
137+
socket_error(C.select(handle + 1, &set, unsafe { nil }, unsafe { nil }, &tt))!
138138
}
139139
.write {
140-
socket_error(C.select(handle + 1, C.NULL, &set, C.NULL, &tt))!
140+
socket_error(C.select(handle + 1, unsafe { nil }, &set, unsafe { nil }, &tt))!
141141
}
142142
.except {
143-
socket_error(C.select(handle + 1, C.NULL, C.NULL, &set, &tt))!
143+
socket_error(C.select(handle + 1, unsafe { nil }, unsafe { nil }, &set, &tt))!
144144
}
145145
}
146146
}

‎vlib/net/mbedtls/ssl_connection.c.v‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,13 +1021,13 @@ fn select(handle int, test Select, timeout time.Duration) !bool {
10211021
mut res := -1
10221022
match test {
10231023
.read {
1024-
res = C.select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout)
1024+
res = C.select(handle + 1, &set, unsafe { nil }, unsafe { nil }, timeval_timeout)
10251025
}
10261026
.write {
1027-
res = C.select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout)
1027+
res = C.select(handle + 1, unsafe { nil }, &set, unsafe { nil }, timeval_timeout)
10281028
}
10291029
.except {
1030-
res = C.select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout)
1030+
res = C.select(handle + 1, unsafe { nil }, unsafe { nil }, &set, timeval_timeout)
10311031
}
10321032
}
10331033

‎vlib/net/openssl/ssl_connection.c.v‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,13 +602,13 @@ fn select(handle int, test Select, timeout time.Duration) !bool {
602602
mut res := -1
603603
match test {
604604
.read {
605-
res = C.select(handle + 1, &set, C.NULL, C.NULL, timeval_timeout)
605+
res = C.select(handle + 1, &set, unsafe { nil }, unsafe { nil }, timeval_timeout)
606606
}
607607
.write {
608-
res = C.select(handle + 1, C.NULL, &set, C.NULL, timeval_timeout)
608+
res = C.select(handle + 1, unsafe { nil }, &set, unsafe { nil }, timeval_timeout)
609609
}
610610
.except {
611-
res = C.select(handle + 1, C.NULL, C.NULL, &set, timeval_timeout)
611+
res = C.select(handle + 1, unsafe { nil }, unsafe { nil }, &set, timeval_timeout)
612612
}
613613
}
614614

0 commit comments

Comments
 (0)