mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-15 23:54:07 +00:00
more manual type carryover
This commit is contained in:
@@ -182,7 +182,7 @@ parse_ip6_address :: proc(address_and_maybe_port: string) -> (addr: IP6_Address,
|
||||
|
||||
for ch, i in address {
|
||||
switch ch {
|
||||
case '0'..'9', 'a'..'f', 'A'..'F':
|
||||
case '0'..='9', 'a'..='f', 'A'..='F':
|
||||
piece_end += 1
|
||||
|
||||
case ':':
|
||||
@@ -522,7 +522,7 @@ join_port :: proc(address_or_host: string, port: int, allocator := context.alloc
|
||||
addr_or_host, _, ok := split_port(address_or_host)
|
||||
if !ok do return addr_or_host
|
||||
|
||||
b := strings.make_builder(allocator)
|
||||
b := strings.builder_make(allocator)
|
||||
|
||||
addr := parse_address(addr_or_host)
|
||||
if addr == nil {
|
||||
@@ -560,7 +560,7 @@ map_to_ip6 :: proc(addr: Address) -> Address {
|
||||
See RFC 5952 section 4 for IPv6 representation recommendations.
|
||||
*/
|
||||
address_to_string :: proc(addr: Address, allocator := context.temp_allocator) -> string {
|
||||
b := strings.make_builder(allocator)
|
||||
b := strings.builder_make(allocator)
|
||||
switch v in addr {
|
||||
case IP4_Address:
|
||||
fmt.sbprintf(&b, "%v.%v.%v.%v", v[0], v[1], v[2], v[3])
|
||||
@@ -657,7 +657,7 @@ endpoint_to_string :: proc(ep: Endpoint, allocator := context.temp_allocator) ->
|
||||
return address_to_string(ep.address, allocator)
|
||||
} else {
|
||||
s := address_to_string(ep.address, context.temp_allocator)
|
||||
b := strings.make_builder(allocator)
|
||||
b := strings.builder_make(allocator)
|
||||
switch a in ep.address {
|
||||
case IP4_Address: fmt.sbprintf(&b, "%v:%v", s, ep.port)
|
||||
case IP6_Address: fmt.sbprintf(&b, "[%v]:%v", s, ep.port)
|
||||
@@ -751,11 +751,11 @@ parse_ip_component :: proc(input: string, max_value := u64(max(u32)), bases := D
|
||||
|
||||
parse_loop: for ch in input {
|
||||
switch ch {
|
||||
case '0'..'7':
|
||||
case '0'..='7':
|
||||
digit_bytes += 1
|
||||
value = value * base + u64(ch - '0')
|
||||
|
||||
case '8'..'9':
|
||||
case '8'..='9':
|
||||
digit_bytes += 1
|
||||
|
||||
if base == 8 {
|
||||
@@ -766,7 +766,7 @@ parse_ip_component :: proc(input: string, max_value := u64(max(u32)), bases := D
|
||||
}
|
||||
value = value * base + u64(ch - '0')
|
||||
|
||||
case 'a'..'f':
|
||||
case 'a'..='f':
|
||||
digit_bytes += 1
|
||||
|
||||
if base == 8 || base == 10 {
|
||||
@@ -777,7 +777,7 @@ parse_ip_component :: proc(input: string, max_value := u64(max(u32)), bases := D
|
||||
}
|
||||
value = value * base + (u64(ch - 'a') + 10)
|
||||
|
||||
case 'A'..'F':
|
||||
case 'A'..='F':
|
||||
digit_bytes += 1
|
||||
|
||||
if base == 8 || base == 10 {
|
||||
@@ -815,4 +815,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.
|
||||
*/
|
||||
return value, digit_bytes + prefix_bytes, digit_bytes >= 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -612,7 +612,7 @@ validate_hostname :: proc(hostname: string) -> (ok: bool) {
|
||||
switch ch {
|
||||
case:
|
||||
return
|
||||
case 'a'..'z', 'A'..'Z', '0'..'9', '-':
|
||||
case 'a'..='z', 'A'..='Z', '0'..='9', '-':
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ split_url :: proc(url: string, allocator := context.allocator) -> (scheme, host,
|
||||
join_url :: proc(scheme, host, path: string, queries: map[string]string, allocator := context.allocator) -> string {
|
||||
using strings
|
||||
|
||||
b := make_builder(allocator)
|
||||
grow_builder(&b, len(scheme) + 3 + len(host) + 1 + len(path))
|
||||
b := builder_make(allocator)
|
||||
builder_grow(&b, len(scheme) + 3 + len(host) + 1 + len(path))
|
||||
|
||||
write_string(&b, scheme)
|
||||
write_string(&b, "://")
|
||||
@@ -91,19 +91,19 @@ join_url :: proc(scheme, host, path: string, queries: map[string]string, allocat
|
||||
percent_encode :: proc(s: string, allocator := context.allocator) -> string {
|
||||
using strings
|
||||
|
||||
b := make_builder(allocator)
|
||||
grow_builder(&b, len(s) + 16) // NOTE(tetra): A reasonable number to allow for the number of things we need to escape.
|
||||
b := builder_make(allocator)
|
||||
builder_grow(&b, len(s) + 16) // NOTE(tetra): A reasonable number to allow for the number of things we need to escape.
|
||||
|
||||
for ch in s {
|
||||
switch ch {
|
||||
case 'A'..='Z', 'a'..='z', '0'..='9', '-', '_', '.', '~':
|
||||
write_rune_builder(&b, ch)
|
||||
write_rune(&b, ch)
|
||||
case:
|
||||
bytes, n := utf8.encode_rune(ch)
|
||||
for byte in bytes[:n] {
|
||||
buf: [2]u8 = ---
|
||||
t := strconv.append_int(buf[:], i64(byte), 16)
|
||||
write_rune_builder(&b, '%')
|
||||
write_rune(&b, '%')
|
||||
write_string(&b, t)
|
||||
}
|
||||
}
|
||||
@@ -115,8 +115,8 @@ percent_encode :: proc(s: string, allocator := context.allocator) -> string {
|
||||
percent_decode :: proc(encoded_string: string, allocator := context.allocator) -> (decoded_string: string, ok: bool) {
|
||||
using strings
|
||||
|
||||
b := make_builder(allocator)
|
||||
grow_builder(&b, len(encoded_string))
|
||||
b := builder_make(allocator)
|
||||
builder_grow(&b, len(encoded_string))
|
||||
defer if !ok do destroy_builder(&b)
|
||||
|
||||
stack_buf: [4]u8
|
||||
@@ -137,7 +137,7 @@ percent_decode :: proc(encoded_string: string, allocator := context.allocator) -
|
||||
s = s[1:]
|
||||
|
||||
if s[0] == '%' {
|
||||
write_rune_builder(&b, '%')
|
||||
write_rune(&b, '%')
|
||||
s = s[1:]
|
||||
continue
|
||||
}
|
||||
@@ -147,26 +147,26 @@ percent_decode :: proc(encoded_string: string, allocator := context.allocator) -
|
||||
n: int
|
||||
n, _ = strconv.parse_int(s[:2], 16)
|
||||
switch n {
|
||||
case 0x20: write_rune_builder(&b, ' ')
|
||||
case 0x21: write_rune_builder(&b, '!')
|
||||
case 0x23: write_rune_builder(&b, '#')
|
||||
case 0x24: write_rune_builder(&b, '$')
|
||||
case 0x25: write_rune_builder(&b, '%')
|
||||
case 0x26: write_rune_builder(&b, '&')
|
||||
case 0x27: write_rune_builder(&b, '\'')
|
||||
case 0x28: write_rune_builder(&b, '(')
|
||||
case 0x29: write_rune_builder(&b, ')')
|
||||
case 0x2A: write_rune_builder(&b, '*')
|
||||
case 0x2B: write_rune_builder(&b, '+')
|
||||
case 0x2C: write_rune_builder(&b, ',')
|
||||
case 0x2F: write_rune_builder(&b, '/')
|
||||
case 0x3A: write_rune_builder(&b, ':')
|
||||
case 0x3B: write_rune_builder(&b, ';')
|
||||
case 0x3D: write_rune_builder(&b, '=')
|
||||
case 0x3F: write_rune_builder(&b, '?')
|
||||
case 0x40: write_rune_builder(&b, '@')
|
||||
case 0x5B: write_rune_builder(&b, '[')
|
||||
case 0x5D: write_rune_builder(&b, ']')
|
||||
case 0x20: write_rune(&b, ' ')
|
||||
case 0x21: write_rune(&b, '!')
|
||||
case 0x23: write_rune(&b, '#')
|
||||
case 0x24: write_rune(&b, '$')
|
||||
case 0x25: write_rune(&b, '%')
|
||||
case 0x26: write_rune(&b, '&')
|
||||
case 0x27: write_rune(&b, '\'')
|
||||
case 0x28: write_rune(&b, '(')
|
||||
case 0x29: write_rune(&b, ')')
|
||||
case 0x2A: write_rune(&b, '*')
|
||||
case 0x2B: write_rune(&b, '+')
|
||||
case 0x2C: write_rune(&b, ',')
|
||||
case 0x2F: write_rune(&b, '/')
|
||||
case 0x3A: write_rune(&b, ':')
|
||||
case 0x3B: write_rune(&b, ';')
|
||||
case 0x3D: write_rune(&b, '=')
|
||||
case 0x3F: write_rune(&b, '?')
|
||||
case 0x40: write_rune(&b, '@')
|
||||
case 0x5B: write_rune(&b, '[')
|
||||
case 0x5D: write_rune(&b, ']')
|
||||
case:
|
||||
// utf-8 bytes
|
||||
// TODO(tetra): Audit this - 4 bytes???
|
||||
@@ -174,7 +174,7 @@ percent_decode :: proc(encoded_string: string, allocator := context.allocator) -
|
||||
append(&pending, s[1])
|
||||
if len(pending) == 4 {
|
||||
r, _ := utf8.decode_rune(pending[:])
|
||||
write_rune_builder(&b, r)
|
||||
write_rune(&b, r)
|
||||
clear(&pending)
|
||||
}
|
||||
}
|
||||
@@ -232,4 +232,4 @@ base64url_decode :: proc(s: string, allocator := context.allocator) -> []byte {
|
||||
|
||||
return base64.decode(string(temp), base64.DEC_TABLE, allocator);
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
@@ -67,6 +67,7 @@ ENOPROTOOPT: Errno : 42 /* Protocol not available */
|
||||
EPROTONOSUPPORT: Errno : 43 /* Protocol not supported */
|
||||
ESOCKTNOSUPPORT: Errno : 44 /* Socket type not supported */
|
||||
ENOTSUP: Errno : 45 /* Operation not supported */
|
||||
EOPNOTSUPP:: ENOTSUP
|
||||
EPFNOSUPPORT: Errno : 46 /* Protocol family not supported */
|
||||
EAFNOSUPPORT: Errno : 47 /* Address family not supported by protocol family */
|
||||
EADDRINUSE: Errno : 48 /* Address already in use */
|
||||
|
||||
@@ -14,6 +14,7 @@ Handle :: distinct i32
|
||||
Pid :: distinct i32
|
||||
File_Time :: distinct u64
|
||||
Errno :: distinct i32
|
||||
Socket :: distinct int
|
||||
|
||||
INVALID_HANDLE :: ~Handle(0)
|
||||
|
||||
@@ -231,6 +232,13 @@ RTLD_NOW :: 0x002
|
||||
RTLD_BINDING_MASK :: 0x3
|
||||
RTLD_GLOBAL :: 0x100
|
||||
|
||||
socklen_t :: c.int
|
||||
|
||||
Timeval :: struct {
|
||||
seconds: i64,
|
||||
nanoseconds: int,
|
||||
}
|
||||
|
||||
// "Argv" arguments converted to Odin strings
|
||||
args := _alloc_command_line_arguments()
|
||||
|
||||
|
||||
@@ -1518,6 +1518,7 @@ when ODIN_ARCH == .amd64 {
|
||||
#panic("Unsupported architecture")
|
||||
}
|
||||
|
||||
|
||||
// syscall related constants
|
||||
AT_FDCWD :: ~uintptr(99)
|
||||
AT_REMOVEDIR :: uintptr(0x200)
|
||||
@@ -2012,7 +2013,7 @@ sys_socket :: proc "contextless" (domain: int, type: int, protocol: int) -> int
|
||||
return int(intrinsics.syscall(unix.SYS_socket, uintptr(domain), uintptr(type), uintptr(protocol)))
|
||||
}
|
||||
|
||||
sys_connect :: proc "contextless" (sd: int, addr: rawptr, len: socklen_t) -> int {
|
||||
sys_connect :: proc "contextless" (sd: int, addr: rawptr, len: i32) -> int {
|
||||
return int(intrinsics.syscall(unix.SYS_connect, uintptr(sd), uintptr(addr), uintptr(len)))
|
||||
}
|
||||
|
||||
@@ -2024,11 +2025,11 @@ sys_listen :: proc "contextless" (sd: int, backlog: int) -> int {
|
||||
return int(intrinsics.syscall(unix.SYS_listen, uintptr(sd), uintptr(backlog)))
|
||||
}
|
||||
|
||||
sys_bind :: proc "contextless" (sd: int, addr: rawptr, len: socklen_t) -> int {
|
||||
sys_bind :: proc "contextless" (sd: int, addr: rawptr, len: i32) -> int {
|
||||
return int(intrinsics.syscall(unix.SYS_bind, uintptr(sd), uintptr(addr), uintptr(len)))
|
||||
}
|
||||
|
||||
sys_setsockopt :: proc "contextless" (sd: int, level: int, optname: int, optval: rawptr, optlen: socklen_t) -> int {
|
||||
sys_setsockopt :: proc "contextless" (sd: int, level: int, optname: int, optval: rawptr, optlen: i32) -> int {
|
||||
return int(intrinsics.syscall(unix.SYS_setsockopt, uintptr(sd), uintptr(level), uintptr(optname), uintptr(optval), uintptr(optlen)))
|
||||
}
|
||||
|
||||
@@ -2036,7 +2037,7 @@ sys_recvfrom :: proc "contextless" (sd: int, buf: rawptr, len: uint, flags: int,
|
||||
return i64(intrinsics.syscall(unix.SYS_recvfrom, uintptr(sd), uintptr(buf), uintptr(len), uintptr(flags), uintptr(addr), uintptr(alen)))
|
||||
}
|
||||
|
||||
sys_sendto :: proc "contextless" (sd: int, buf: rawptr, len: uint, flags: int, addr: rawptr, alen: socklen_t) -> i64 {
|
||||
sys_sendto :: proc "contextless" (sd: int, buf: rawptr, len: uint, flags: int, addr: rawptr, alen: i32) -> i64 {
|
||||
return i64(intrinsics.syscall(unix.SYS_sendto, uintptr(sd), uintptr(buf), uintptr(len), uintptr(flags), uintptr(addr), uintptr(alen)))
|
||||
}
|
||||
|
||||
|
||||
@@ -2425,6 +2425,27 @@ FILE_ATTRIBUTE_TAG_INFO :: struct {
|
||||
ReparseTag: DWORD,
|
||||
}
|
||||
|
||||
PADDRINFOEXW :: ^ADDRINFOEXW
|
||||
LPADDRINFOEXW :: ^ADDRINFOEXW
|
||||
ADDRINFOEXW :: struct {
|
||||
ai_flags: c_int,
|
||||
ai_family: c_int,
|
||||
ai_socktype: c_int,
|
||||
ai_protocol: c_int,
|
||||
ai_addrlen: size_t,
|
||||
ai_canonname: wstring,
|
||||
ai_addr: ^sockaddr,
|
||||
ai_blob: rawptr,
|
||||
ai_bloblen: size_t,
|
||||
ai_provider: LPGUID,
|
||||
ai_next: ^ADDRINFOEXW,
|
||||
}
|
||||
|
||||
LPLOOKUPSERVICE_COMPLETION_ROUTINE :: #type proc "stdcall" (
|
||||
dwErrorCode: DWORD,
|
||||
dwNumberOfBytesTransfered: DWORD,
|
||||
lpOverlapped: LPOVERLAPPED,
|
||||
)
|
||||
|
||||
|
||||
// https://docs.microsoft.com/en-gb/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info
|
||||
|
||||
Reference in New Issue
Block a user