vlib: add unsafe{} wrappers to C. fn calls, to allow compiling with -prod again
parent
6dbc143d67
commit
0af415fa28
|
@ -187,7 +187,7 @@ fn json_parse(s string) &C.cJSON {
|
|||
// json_string := json_print(encode_User(user))
|
||||
fn json_print(json &C.cJSON) string {
|
||||
s := C.cJSON_PrintUnformatted(json)
|
||||
return tos(s, C.strlen(s))
|
||||
return unsafe { tos(s, C.strlen(s)) }
|
||||
}
|
||||
|
||||
// / cjson wrappers
|
||||
|
|
|
@ -20,7 +20,7 @@ fn htonl64(payload_len u64) byteptr {
|
|||
fn create_masking_key() []byte {
|
||||
mask_bit := byte(rand.intn(255))
|
||||
buf := [`0`].repeat(4)
|
||||
C.memcpy(buf.data, &mask_bit, 4)
|
||||
unsafe { C.memcpy(buf.data, &mask_bit, 4) }
|
||||
return buf
|
||||
}
|
||||
|
||||
|
|
|
@ -430,7 +430,7 @@ pub fn (mut ws Client) read() int {
|
|||
if payload == 0 {
|
||||
l.f('out of memory')
|
||||
}
|
||||
C.memcpy(payload, &data[header_len], payload_len)
|
||||
unsafe { C.memcpy(payload, &data[header_len], payload_len) }
|
||||
if frame.fin {
|
||||
if ws.fragments.len > 0 {
|
||||
// join fragments
|
||||
|
@ -522,7 +522,7 @@ pub fn (mut ws Client) read() int {
|
|||
mut payload := []byte{}
|
||||
if payload_len > 0 {
|
||||
payload = [`0`].repeat(int(payload_len))
|
||||
C.memcpy(payload.data, &data[header_len], payload_len)
|
||||
unsafe { C.memcpy(payload.data, &data[header_len], payload_len) }
|
||||
}
|
||||
unsafe {
|
||||
free(data)
|
||||
|
@ -601,7 +601,7 @@ fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []b
|
|||
if code == .close {
|
||||
if payload.len > 2 {
|
||||
mut parsed_payload := [`0`].repeat(payload.len + 1)
|
||||
C.memcpy(parsed_payload.data, &payload[0], payload.len)
|
||||
unsafe { C.memcpy(parsed_payload.data, &payload[0], payload.len) }
|
||||
parsed_payload[payload.len] = `\0`
|
||||
for i in 0 .. payload.len {
|
||||
control_frame[6 + i] = (parsed_payload[i] ^ masking_key[i % 4]) & 0xff
|
||||
|
|
|
@ -46,7 +46,7 @@ pub fn (mut r SysRNG) seed(seed_data []u32) {
|
|||
exit(1)
|
||||
}
|
||||
r.seed = seed_data[0]
|
||||
C.srand(int(r.seed))
|
||||
unsafe { C.srand(int(r.seed)) }
|
||||
}
|
||||
|
||||
// r.default_rand() exposes the default behavior of the system's RNG
|
||||
|
|
|
@ -114,7 +114,7 @@ pub fn new_semaphore() Semaphore {
|
|||
s := Semaphore{
|
||||
sem: &PosixSemaphore{}
|
||||
}
|
||||
C.sem_init(&&PosixSemaphore(s.sem).sem, 0, 0)
|
||||
unsafe { C.sem_init(&&PosixSemaphore(s.sem).sem, 0, 0) }
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ pub fn (s Semaphore) post() {
|
|||
C.pthread_cond_signal(&&MacOSX_Semaphore(s.sem).cond)
|
||||
C.pthread_mutex_unlock(&&MacOSX_Semaphore(s.sem).mtx)
|
||||
} $else {
|
||||
C.sem_post(&&PosixSemaphore(s.sem).sem)
|
||||
unsafe { C.sem_post(&&PosixSemaphore(s.sem).sem) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ pub fn (s Semaphore) wait() {
|
|||
(&MacOSX_Semaphore(s.sem)).count--
|
||||
C.pthread_mutex_unlock(&&MacOSX_Semaphore(s.sem).mtx)
|
||||
} $else {
|
||||
C.sem_wait(&&PosixSemaphore(s.sem).sem)
|
||||
unsafe { C.sem_wait(&&PosixSemaphore(s.sem).sem) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ pub fn (s Semaphore) try_wait() bool {
|
|||
C.pthread_mutex_unlock(&&MacOSX_Semaphore(s.sem).mtx)
|
||||
return res
|
||||
} $else {
|
||||
return C.sem_trywait(&&PosixSemaphore(s.sem).sem) == 0
|
||||
return unsafe { C.sem_trywait(&&PosixSemaphore(s.sem).sem) == 0 }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,6 +183,6 @@ pub fn (s Semaphore) timed_wait(timeout time.Duration) bool {
|
|||
C.pthread_mutex_unlock(&&MacOSX_Semaphore(s.sem).mtx)
|
||||
return res
|
||||
} $else {
|
||||
return C.sem_timedwait(&&PosixSemaphore(s.sem).sem, &t_spec) == 0
|
||||
return unsafe { C.sem_timedwait(&&PosixSemaphore(s.sem).sem, &t_spec) == 0 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
fn test_cstring() {
|
||||
w := c'world'
|
||||
hlen := C.strlen(c'hello')
|
||||
hlen2 := C.strlen('hello')
|
||||
wlen := C.strlen(w)
|
||||
hlen := unsafe{ C.strlen(c'hello') }
|
||||
hlen2 := unsafe{ C.strlen('hello') }
|
||||
wlen := unsafe{ C.strlen(w) }
|
||||
assert hlen == 5
|
||||
assert hlen2 == 5
|
||||
assert wlen == 5
|
||||
|
|
Loading…
Reference in New Issue