From af73e195da94cb2af8224b451187808669972d36 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 15 Apr 2022 15:55:39 +0300 Subject: [PATCH] net: byte fixes --- examples/sokol/sounds/wav_player.v | 8 ++++---- vlib/builtin/linux_bare/old/string_bare.v | 2 +- vlib/json/json_primitives.v | 11 ----------- vlib/net/address.v | 14 +++++++------- vlib/net/address_android.c.v | 6 +++--- vlib/net/address_darwin.c.v | 8 ++++---- vlib/net/address_dragonfly.c.v | 8 ++++---- vlib/net/address_freebsd.c.v | 8 ++++---- vlib/net/address_linux.c.v | 6 +++--- vlib/net/address_netbsd.c.v | 8 ++++---- vlib/net/address_openbsd.c.v | 8 ++++---- vlib/net/address_windows.c.v | 6 +++--- vlib/net/http/cookie.v | 8 ++++---- vlib/net/websocket/message.v | 2 +- vlib/orm/orm.v | 4 ++-- vlib/pg/orm.v | 6 +++--- vlib/v/ast/table.v | 2 +- vlib/v/tests/alias_fixed_array_test.v | 4 ++-- 18 files changed, 54 insertions(+), 65 deletions(-) diff --git a/examples/sokol/sounds/wav_player.v b/examples/sokol/sounds/wav_player.v index 303553333a..143769faf9 100644 --- a/examples/sokol/sounds/wav_player.v +++ b/examples/sokol/sounds/wav_player.v @@ -92,13 +92,13 @@ fn (mut p Player) free() { // > MUST be placed before the Sound data chunk (but not necessarily // > contiguous to the Sound data chunk). struct RIFFHeader { - riff [4]byte + riff [4]u8 file_size u32 - form_type [4]byte + form_type [4]u8 } struct RIFFChunkHeader { - chunk_type [4]byte + chunk_type [4]u8 chunk_size u32 chunk_data voidptr } @@ -113,7 +113,7 @@ struct RIFFFormat { cbsize u16 // Size of the extension: 22 valid_bits_per_sample u16 // at most 8*M channel_mask u32 // Speaker position mask - sub_format [16]byte // GUID + sub_format [16]u8 // GUID } fn read_wav_file_samples(fpath string) ?[]f32 { diff --git a/vlib/builtin/linux_bare/old/string_bare.v b/vlib/builtin/linux_bare/old/string_bare.v index 5be89f2474..da4e117b6d 100644 --- a/vlib/builtin/linux_bare/old/string_bare.v +++ b/vlib/builtin/linux_bare/old/string_bare.v @@ -133,7 +133,7 @@ pub fn i64_str(n0 i64, base int) string { } pub fn ptr_str(ptr voidptr) string { - buf := [16]byte{} + buf := [16]u8{} hex := i64_tos(buf, 15, i64(ptr), 16) res := '0x' + hex return res diff --git a/vlib/json/json_primitives.v b/vlib/json/json_primitives.v index 05689d6304..f8868b67e1 100644 --- a/vlib/json/json_primitives.v +++ b/vlib/json/json_primitives.v @@ -71,13 +71,6 @@ fn decode_i64(root &C.cJSON) i64 { return i64(root.valuedouble) // i64 is double in C } -fn decode_u8(root &C.cJSON) byte { - if isnil(root) { - return u8(0) - } - return u8(root.valueint) -} - fn decode_u8(root &C.cJSON) u8 { if isnil(root) { return u8(0) @@ -168,10 +161,6 @@ fn encode_i64(val i64) &C.cJSON { return C.cJSON_CreateNumber(val) } -fn encode_u8(val byte) &C.cJSON { - return C.cJSON_CreateNumber(val) -} - fn encode_u8(val u8) &C.cJSON { return C.cJSON_CreateNumber(val) } diff --git a/vlib/net/address.v b/vlib/net/address.v index 1513fd38d5..d8ab22fb6a 100644 --- a/vlib/net/address.v +++ b/vlib/net/address.v @@ -10,13 +10,13 @@ union AddrData { } const ( - addr_ip6_any = [16]byte{init: u8(0)} - addr_ip_any = [4]byte{init: u8(0)} + addr_ip6_any = [16]u8{init: u8(0)} + addr_ip_any = [4]u8{init: u8(0)} ) -fn new_ip6(port u16, addr [16]byte) Addr { +fn new_ip6(port u16, addr [16]u8) Addr { a := Addr{ - f: u16(AddrFamily.ip6) + f: u8(AddrFamily.ip6) addr: AddrData{ Ip6: Ip6{ port: u16(C.htons(port)) @@ -29,9 +29,9 @@ fn new_ip6(port u16, addr [16]byte) Addr { return a } -fn new_ip(port u16, addr [4]byte) Addr { +fn new_ip(port u16, addr [4]u8) Addr { a := Addr{ - f: u16(AddrFamily.ip) + f: u8(AddrFamily.ip) addr: AddrData{ Ip: Ip{ port: u16(C.htons(port)) @@ -133,7 +133,7 @@ pub fn resolve_addrs(addr string, family AddrFamily, @type SocketType) ?[]Addr { return [ Addr{ - f: u16(AddrFamily.unix) + f: u8(AddrFamily.unix) addr: AddrData{ Unix: resolved } diff --git a/vlib/net/address_android.c.v b/vlib/net/address_android.c.v index 7f4149fcbc..38825cb2fd 100644 --- a/vlib/net/address_android.c.v +++ b/vlib/net/address_android.c.v @@ -38,20 +38,20 @@ mut: struct Ip6 { port u16 flow_info u32 - addr [16]byte + addr [16]u8 scope_id u32 } [_pack: '1'] struct Ip { port u16 - addr [4]byte + addr [4]u8 // Pad to size so that socket functions // dont complain to us (see in.h and bind()) // TODO(emily): I would really like to use // some constant calculations here // so that this doesnt have to be hardcoded - sin_pad [8]byte + sin_pad [8]u8 } struct Unix { diff --git a/vlib/net/address_darwin.c.v b/vlib/net/address_darwin.c.v index 041ccf2e2c..1bae1deb5d 100644 --- a/vlib/net/address_darwin.c.v +++ b/vlib/net/address_darwin.c.v @@ -21,7 +21,7 @@ mut: sin6_family byte // 1 sin6_port u16 // 2 sin6_flowinfo u32 // 4 - sin6_addr [16]byte // 16 + sin6_addr [16]u8 // 16 sin6_scope_id u32 // 4 } @@ -45,20 +45,20 @@ mut: struct Ip6 { port u16 flow_info u32 - addr [16]byte + addr [16]u8 scope_id u32 } [_pack: '1'] struct Ip { port u16 - addr [4]byte + addr [4]u8 // Pad to size so that socket functions // dont complain to us (see in.h and bind()) // TODO(emily): I would really like to use // some constant calculations here // so that this doesnt have to be hardcoded - sin_pad [8]byte + sin_pad [8]u8 } struct Unix { diff --git a/vlib/net/address_dragonfly.c.v b/vlib/net/address_dragonfly.c.v index a2ce22e354..3bb200ed33 100644 --- a/vlib/net/address_dragonfly.c.v +++ b/vlib/net/address_dragonfly.c.v @@ -26,7 +26,7 @@ mut: sin6_family byte // 1 sin6_port u16 // 2 sin6_flowinfo u32 // 4 - sin6_addr [16]byte // 16 + sin6_addr [16]u8 // 16 sin6_scope_id u32 // 4 } @@ -50,20 +50,20 @@ mut: struct Ip6 { port u16 flow_info u32 - addr [16]byte + addr [16]u8 scope_id u32 } [_pack: '1'] struct Ip { port u16 - addr [4]byte + addr [4]u8 // Pad to size so that socket functions // dont complain to us (see in.h and bind()) // TODO(emily): I would really like to use // some constant calculations here // so that this doesnt have to be hardcoded - sin_pad [8]byte + sin_pad [8]u8 } struct Unix { diff --git a/vlib/net/address_freebsd.c.v b/vlib/net/address_freebsd.c.v index bc84665a0f..72ad8b712a 100644 --- a/vlib/net/address_freebsd.c.v +++ b/vlib/net/address_freebsd.c.v @@ -24,7 +24,7 @@ mut: sin6_family byte // 1 sin6_port u16 // 2 sin6_flowinfo u32 // 4 - sin6_addr [16]byte // 16 + sin6_addr [16]u8 // 16 sin6_scope_id u32 // 4 } @@ -48,20 +48,20 @@ mut: struct Ip6 { port u16 flow_info u32 - addr [16]byte + addr [16]u8 scope_id u32 } [_pack: '1'] struct Ip { port u16 - addr [4]byte + addr [4]u8 // Pad to size so that socket functions // dont complain to us (see in.h and bind()) // TODO(emily): I would really like to use // some constant calculations here // so that this doesnt have to be hardcoded - sin_pad [8]byte + sin_pad [8]u8 } struct Unix { diff --git a/vlib/net/address_linux.c.v b/vlib/net/address_linux.c.v index 7f4149fcbc..38825cb2fd 100644 --- a/vlib/net/address_linux.c.v +++ b/vlib/net/address_linux.c.v @@ -38,20 +38,20 @@ mut: struct Ip6 { port u16 flow_info u32 - addr [16]byte + addr [16]u8 scope_id u32 } [_pack: '1'] struct Ip { port u16 - addr [4]byte + addr [4]u8 // Pad to size so that socket functions // dont complain to us (see in.h and bind()) // TODO(emily): I would really like to use // some constant calculations here // so that this doesnt have to be hardcoded - sin_pad [8]byte + sin_pad [8]u8 } struct Unix { diff --git a/vlib/net/address_netbsd.c.v b/vlib/net/address_netbsd.c.v index 8013bd35b8..6b85d8224a 100644 --- a/vlib/net/address_netbsd.c.v +++ b/vlib/net/address_netbsd.c.v @@ -26,7 +26,7 @@ mut: sin6_family byte // 1 sin6_port u16 // 2 sin6_flowinfo u32 // 4 - sin6_addr [16]byte // 16 + sin6_addr [16]u8 // 16 sin6_scope_id u32 // 4 } @@ -50,20 +50,20 @@ mut: struct Ip6 { port u16 flow_info u32 - addr [16]byte + addr [16]u8 scope_id u32 } [_pack: '1'] struct Ip { port u16 - addr [4]byte + addr [4]u8 // Pad to size so that socket functions // dont complain to us (see in.h and bind()) // TODO(emily): I would really like to use // some constant calculations here // so that this doesnt have to be hardcoded - sin_pad [8]byte + sin_pad [8]u8 } struct Unix { diff --git a/vlib/net/address_openbsd.c.v b/vlib/net/address_openbsd.c.v index bc84665a0f..72ad8b712a 100644 --- a/vlib/net/address_openbsd.c.v +++ b/vlib/net/address_openbsd.c.v @@ -24,7 +24,7 @@ mut: sin6_family byte // 1 sin6_port u16 // 2 sin6_flowinfo u32 // 4 - sin6_addr [16]byte // 16 + sin6_addr [16]u8 // 16 sin6_scope_id u32 // 4 } @@ -48,20 +48,20 @@ mut: struct Ip6 { port u16 flow_info u32 - addr [16]byte + addr [16]u8 scope_id u32 } [_pack: '1'] struct Ip { port u16 - addr [4]byte + addr [4]u8 // Pad to size so that socket functions // dont complain to us (see in.h and bind()) // TODO(emily): I would really like to use // some constant calculations here // so that this doesnt have to be hardcoded - sin_pad [8]byte + sin_pad [8]u8 } struct Unix { diff --git a/vlib/net/address_windows.c.v b/vlib/net/address_windows.c.v index aa3bdcc4a1..0b060ae209 100644 --- a/vlib/net/address_windows.c.v +++ b/vlib/net/address_windows.c.v @@ -38,15 +38,15 @@ mut: struct Ip6 { port u16 flow_info u32 - addr [16]byte + addr [16]u8 scope_id u32 } [_pack: '1'] struct Ip { port u16 - addr [4]byte - sin_pad [8]byte + addr [4]u8 + sin_pad [8]u8 } struct Unix { diff --git a/vlib/net/http/cookie.v b/vlib/net/http/cookie.v index a0569c5579..e9536cd920 100644 --- a/vlib/net/http/cookie.v +++ b/vlib/net/http/cookie.v @@ -177,7 +177,7 @@ pub fn (c &Cookie) str() string { return b.str() } -fn sanitize(valid fn (byte) bool, v string) string { +fn sanitize(valid fn (u8) bool, v string) string { mut ok := true for i in 0 .. v.len { if valid(v[i]) { @@ -222,11 +222,11 @@ fn sanitize_cookie_path(v string) string { return sanitize(valid_cookie_path_byte, v) } -fn valid_cookie_value_u8(b byte) bool { +fn valid_cookie_value_byte(b u8) bool { return 0x20 <= b && b < 0x7f && b != `"` && b != `;` && b != `\\` } -fn valid_cookie_path_u8(b byte) bool { +fn valid_cookie_path_byte(b u8) bool { return 0x20 <= b && b < 0x7f && b != `!` } @@ -300,7 +300,7 @@ fn parse_cookie_value(_raw string, allow_double_quote bool) ?string { raw = raw.substr(1, raw.len - 1) } for i in 0 .. raw.len { - if !valid_cookie_value_u8(raw[i]) { + if !valid_cookie_value_byte(raw[i]) { return error('http.cookie: invalid cookie value') } } diff --git a/vlib/net/websocket/message.v b/vlib/net/websocket/message.v index f19ea06fa5..237a1784e2 100644 --- a/vlib/net/websocket/message.v +++ b/vlib/net/websocket/message.v @@ -29,7 +29,7 @@ mut: opcode OPCode // interpretation of the payload data has_mask bool // true if the payload data is masked payload_len int // payload length - masking_key [4]byte // all frames from client to server is masked with this key + masking_key [4]u8 // all frames from client to server is masked with this key } const ( diff --git a/vlib/orm/orm.v b/vlib/orm/orm.v index d65fe1cfcb..77823e823d 100644 --- a/vlib/orm/orm.v +++ b/vlib/orm/orm.v @@ -39,7 +39,6 @@ pub const ( pub type Primitive = InfixType | bool - | byte | f32 | f64 | i16 @@ -51,6 +50,7 @@ pub type Primitive = InfixType | u16 | u32 | u64 + | u8 pub enum OperationKind { neq // != @@ -467,7 +467,7 @@ pub fn i64_to_primitive(b i64) Primitive { return Primitive(b) } -pub fn byte_to_primitive(b byte) Primitive { +pub fn u8_to_primitive(b u8) Primitive { return Primitive(b) } diff --git a/vlib/pg/orm.v b/vlib/pg/orm.v index 681e0025c7..37ff39e5d0 100644 --- a/vlib/pg/orm.v +++ b/vlib/pg/orm.v @@ -92,10 +92,10 @@ fn pg_stmt_match(mut types []u32, mut vals []&char, mut lens []int, mut formats lens << int(sizeof(bool)) formats << 1 } - byte { + u8 { types << u32(Oid.t_char) - vals << &char(&(d as byte)) - lens << int(sizeof(byte)) + vals << &char(&(d as u8)) + lens << int(sizeof(u8)) formats << 1 } u16 { diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 818840703c..39e1f94dae 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -1405,7 +1405,7 @@ pub fn (mut t Table) complete_interface_check() { // // `123 > panic()` // -// `128 > [16]byte` +// `128 > [16]u8` // // `608 > [76]byte` pub fn (mut t Table) bitsize_to_type(bit_size int) Type { diff --git a/vlib/v/tests/alias_fixed_array_test.v b/vlib/v/tests/alias_fixed_array_test.v index f2acb606f3..9cc3c9c052 100644 --- a/vlib/v/tests/alias_fixed_array_test.v +++ b/vlib/v/tests/alias_fixed_array_test.v @@ -1,7 +1,7 @@ -type Block = [8]byte +type Block = [8]u8 fn test_alias_fixed_array() { - a := [8]byte{init: 22} + a := [8]u8{init: 22} ret := get(Block(a)) println(ret) assert ret == 'Block([22, 22, 22, 22, 22, 22, 22, 22])'