Alignment + unnecessary allocator param.

This commit is contained in:
Jeroen van Rijn
2023-03-03 12:04:36 +01:00
parent 38d58e818c
commit 96ac405952
6 changed files with 24 additions and 24 deletions
+1 -1
View File
@@ -738,4 +738,4 @@ parse_ip_component :: proc(input: string, max_value := u64(max(u32)), bases := D
// If we consumed at least 1 digit byte, `value` *should* continue a valid number in an appropriate base in the allowable range. // If we consumed at least 1 digit byte, `value` *should* continue a valid number in an appropriate base in the allowable range.
return value, digit_bytes + prefix_bytes, digit_bytes >= 1 return value, digit_bytes + prefix_bytes, digit_bytes >= 1
} }
+1 -1
View File
@@ -68,4 +68,4 @@ sockaddr_to_endpoint :: proc(native_addr: ^os.SOCKADDR_STORAGE_LH) -> (ep: Endpo
panic("native_addr is neither IP4 or IP6 address") panic("native_addr is neither IP4 or IP6 address")
} }
return return
} }
+7 -7
View File
@@ -348,7 +348,7 @@ unpack_dns_header :: proc(id: u16be, bits: u16be) -> (hdr: DNS_Header) {
hdr.is_truncated = (bits & (1 << 9)) != 0 hdr.is_truncated = (bits & (1 << 9)) != 0
hdr.is_recursion_desired = (bits & (1 << 8)) != 0 hdr.is_recursion_desired = (bits & (1 << 8)) != 0
hdr.is_recursion_available = (bits & (1 << 7)) != 0 hdr.is_recursion_available = (bits & (1 << 7)) != 0
hdr.response_code = DNS_Response_Code(bits & 0xF) hdr.response_code = DNS_Response_Code(bits & 0xF)
return hdr return hdr
} }
@@ -422,7 +422,7 @@ load_hosts :: proc(hosts_file_path: string, allocator := context.allocator) -> (
} }
// www.google.com -> 3www6google3com0 // www.google.com -> 3www6google3com0
encode_hostname :: proc(b: ^strings.Builder, hostname: string, allocator := context.allocator) -> (ok: bool) { encode_hostname :: proc(b: ^strings.Builder, hostname: string) -> (ok: bool) {
_hostname := hostname _hostname := hostname
for section in strings.split_iterator(&_hostname, ".") { for section in strings.split_iterator(&_hostname, ".") {
if len(section) > LABEL_MAX { if len(section) > LABEL_MAX {
@@ -437,7 +437,7 @@ encode_hostname :: proc(b: ^strings.Builder, hostname: string, allocator := cont
return true return true
} }
skip_hostname :: proc(packet: []u8, start_idx: int, allocator := context.allocator) -> (encode_size: int, ok: bool) { skip_hostname :: proc(packet: []u8, start_idx: int) -> (encode_size: int, ok: bool) {
out_size := 0 out_size := 0
cur_idx := start_idx cur_idx := start_idx
@@ -690,9 +690,9 @@ parse_record :: proc(packet: []u8, cur_off: ^int, filter: DNS_Record_Type = nil)
return return
} }
priority: u16be = mem.slice_data_cast([]u16be, data)[0] _data := mem.slice_data_cast([]u16be, data)
weight: u16be = mem.slice_data_cast([]u16be, data)[1]
port: u16be = mem.slice_data_cast([]u16be, data)[2] priority, weight, port := _data[0], _data[1], _data[2]
target, _ := decode_hostname(packet, data_off + (size_of(u16be) * 3)) or_return target, _ := decode_hostname(packet, data_off + (size_of(u16be) * 3)) or_return
// NOTE(tetra): Srv record name should be of the form '_servicename._protocol.hostname' // NOTE(tetra): Srv record name should be of the form '_servicename._protocol.hostname'
@@ -800,7 +800,7 @@ parse_response :: proc(response: []u8, filter: DNS_Record_Type = nil, allocator
} }
dq_sz :: 4 dq_sz :: 4
hn_sz := skip_hostname(response, cur_idx, context.temp_allocator) or_return hn_sz := skip_hostname(response, cur_idx) or_return
dns_query := mem.slice_data_cast([]u16be, response[cur_idx+hn_sz:cur_idx+hn_sz+dq_sz]) dns_query := mem.slice_data_cast([]u16be, response[cur_idx+hn_sz:cur_idx+hn_sz+dq_sz])
cur_idx += hn_sz + dq_sz cur_idx += hn_sz + dq_sz
+5 -5
View File
@@ -328,12 +328,12 @@ set_option :: proc(s: Any_Socket, option: Socket_Option, value: any, loc := #cal
.Send_Buffer_Size: .Send_Buffer_Size:
// TODO: check for out of range values and return .Value_Out_Of_Range? // TODO: check for out of range values and return .Value_Out_Of_Range?
switch i in value { switch i in value {
case i8, u8: i2 := i; int_value = os.socklen_t((^u8)(&i2)^) case i8, u8: i2 := i; int_value = os.socklen_t((^u8)(&i2)^)
case i16, u16: i2 := i; int_value = os.socklen_t((^u16)(&i2)^) case i16, u16: i2 := i; int_value = os.socklen_t((^u16)(&i2)^)
case i32, u32: i2 := i; int_value = os.socklen_t((^u32)(&i2)^) case i32, u32: i2 := i; int_value = os.socklen_t((^u32)(&i2)^)
case i64, u64: i2 := i; int_value = os.socklen_t((^u64)(&i2)^) case i64, u64: i2 := i; int_value = os.socklen_t((^u64)(&i2)^)
case i128, u128: i2 := i; int_value = os.socklen_t((^u128)(&i2)^) case i128, u128: i2 := i; int_value = os.socklen_t((^u128)(&i2)^)
case int, uint: i2 := i; int_value = os.socklen_t((^uint)(&i2)^) case int, uint: i2 := i; int_value = os.socklen_t((^uint)(&i2)^)
case: case:
panic("set_option() value must be an integer here", loc) panic("set_option() value must be an integer here", loc)
} }
+5 -5
View File
@@ -308,12 +308,12 @@ set_option :: proc(s: Any_Socket, option: Socket_Option, value: any, loc := #cal
.Send_Buffer_Size: .Send_Buffer_Size:
// TODO: check for out of range values and return .Value_Out_Of_Range? // TODO: check for out of range values and return .Value_Out_Of_Range?
switch i in value { switch i in value {
case i8, u8: i2 := i; int_value = os.socklen_t((^u8)(&i2)^) case i8, u8: i2 := i; int_value = os.socklen_t((^u8)(&i2)^)
case i16, u16: i2 := i; int_value = os.socklen_t((^u16)(&i2)^) case i16, u16: i2 := i; int_value = os.socklen_t((^u16)(&i2)^)
case i32, u32: i2 := i; int_value = os.socklen_t((^u32)(&i2)^) case i32, u32: i2 := i; int_value = os.socklen_t((^u32)(&i2)^)
case i64, u64: i2 := i; int_value = os.socklen_t((^u64)(&i2)^) case i64, u64: i2 := i; int_value = os.socklen_t((^u64)(&i2)^)
case i128, u128: i2 := i; int_value = os.socklen_t((^u128)(&i2)^) case i128, u128: i2 := i; int_value = os.socklen_t((^u128)(&i2)^)
case int, uint: i2 := i; int_value = os.socklen_t((^uint)(&i2)^) case int, uint: i2 := i; int_value = os.socklen_t((^uint)(&i2)^)
case: case:
panic("set_option() value must be an integer here", loc) panic("set_option() value must be an integer here", loc)
} }
+5 -5
View File
@@ -317,12 +317,12 @@ set_option :: proc(s: Any_Socket, option: Socket_Option, value: any, loc := #cal
.Receive_Buffer_Size, .Receive_Buffer_Size,
.Send_Buffer_Size: .Send_Buffer_Size:
switch i in value { switch i in value {
case i8, u8: i2 := i; int_value = c.int((^u8)(&i2)^) case i8, u8: i2 := i; int_value = c.int((^u8)(&i2)^)
case i16, u16: i2 := i; int_value = c.int((^u16)(&i2)^) case i16, u16: i2 := i; int_value = c.int((^u16)(&i2)^)
case i32, u32: i2 := i; int_value = c.int((^u32)(&i2)^) case i32, u32: i2 := i; int_value = c.int((^u32)(&i2)^)
case i64, u64: i2 := i; int_value = c.int((^u64)(&i2)^) case i64, u64: i2 := i; int_value = c.int((^u64)(&i2)^)
case i128, u128: i2 := i; int_value = c.int((^u128)(&i2)^) case i128, u128: i2 := i; int_value = c.int((^u128)(&i2)^)
case int, uint: i2 := i; int_value = c.int((^uint)(&i2)^) case int, uint: i2 := i; int_value = c.int((^uint)(&i2)^)
case: case:
panic("set_option() value must be an integer here", loc) panic("set_option() value must be an integer here", loc)
} }