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

builtin: x.vstring() instead of string(x) (#6102)

This commit is contained in:
Delyan Angelov
2020-08-10 19:05:26 +03:00
committed by GitHub
parent eba413853f
commit 36eae1c175
30 changed files with 143 additions and 72 deletions

View File

@@ -32,12 +32,8 @@ fn create_key_challenge_response(seckey string) string {
guid := '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
sha1buf := seckey + guid
hash := sha1.sum(sha1buf.bytes())
hashstr := string(byteptr(hash.data))
hashstr := hash.bytestr()
b64 := base64.encode(hashstr)
unsafe {
sha1buf.free()
hash.free()
}
return b64
}

View File

@@ -294,7 +294,7 @@ pub fn (mut ws Client) write(payload byteptr, payload_len int, code OPCode) int
}
bytes_written = ws.write_to_server(fbdata, frame_len)
if bytes_written == -1 {
err := string(byteptr(C.strerror(C.errno)))
err := unsafe { byteptr(C.strerror(C.errno)).vstring() }
ws.log.error('write: there was an error writing data: $err')
ws.send_error_event('Error writing data')
goto free_data
@@ -344,7 +344,7 @@ pub fn (mut ws Client) read() int {
return -1
}
-1 {
err := string(byteptr(C.strerror(C.errno)))
err := unsafe { byteptr(C.strerror(C.errno)).vstring() }
ws.log.error('read: error reading frame. $err')
ws.send_error_event('error reading frame')
goto free_data
@@ -564,7 +564,7 @@ pub fn (mut ws Client) read() int {
code = (int(unsafe {data[header_len]}) << 8) + int(unsafe {data[header_len + 1]})
header_len += 2
payload_len -= 2
reason = unsafe {string(&data[header_len])}
reason = unsafe { byteptr(&data[header_len]).vstring() }
ws.log.info('Closing with reason: $reason & code: $code')
if reason.len > 1 && !utf8.validate(reason.str, reason.len) {
ws.log.error('malformed utf8 payload')
@@ -654,4 +654,4 @@ fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []b
return bytes_written
}
}
}
}