mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
Work around BSD lack of core:net support
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
package flags
|
package flags
|
||||||
|
|
||||||
import "base:runtime"
|
|
||||||
import "core:net"
|
|
||||||
import "core:os"
|
import "core:os"
|
||||||
|
|
||||||
Parse_Error_Reason :: enum {
|
Parse_Error_Reason :: enum {
|
||||||
@@ -20,12 +18,6 @@ Parse_Error_Reason :: enum {
|
|||||||
Unsupported_Type,
|
Unsupported_Type,
|
||||||
}
|
}
|
||||||
|
|
||||||
Unified_Parse_Error_Reason :: union #shared_nil {
|
|
||||||
Parse_Error_Reason,
|
|
||||||
runtime.Allocator_Error,
|
|
||||||
net.Parse_Endpoint_Error,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Raised during parsing, naturally.
|
// Raised during parsing, naturally.
|
||||||
Parse_Error :: struct {
|
Parse_Error :: struct {
|
||||||
reason: Unified_Parse_Error_Reason,
|
reason: Unified_Parse_Error_Reason,
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
//+build freebsd, netbsd, openbsd
|
||||||
|
package flags
|
||||||
|
|
||||||
|
import "base:runtime"
|
||||||
|
|
||||||
|
Unified_Parse_Error_Reason :: union #shared_nil {
|
||||||
|
Parse_Error_Reason,
|
||||||
|
runtime.Allocator_Error,
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
//+build !freebsd !netbsd !openbsd
|
||||||
|
package flags
|
||||||
|
|
||||||
|
import "base:runtime"
|
||||||
|
import "core:net"
|
||||||
|
|
||||||
|
Unified_Parse_Error_Reason :: union #shared_nil {
|
||||||
|
Parse_Error_Reason,
|
||||||
|
runtime.Allocator_Error,
|
||||||
|
net.Parse_Endpoint_Error,
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ import "base:intrinsics"
|
|||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:mem"
|
import "core:mem"
|
||||||
@require import "core:net"
|
|
||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:reflect"
|
import "core:reflect"
|
||||||
import "core:strconv"
|
import "core:strconv"
|
||||||
@@ -309,18 +308,7 @@ parse_and_set_pointer_by_named_type :: proc(ptr: rawptr, str: string, data_type:
|
|||||||
}
|
}
|
||||||
|
|
||||||
when IMPORTING_NET {
|
when IMPORTING_NET {
|
||||||
if data_type == net.Host_Or_Endpoint {
|
if try_net_parse_workaround(data_type, str, ptr, out_error) {
|
||||||
addr, net_error := net.parse_hostname_or_endpoint(str)
|
|
||||||
if net_error != nil {
|
|
||||||
// We pass along `net.Error` here.
|
|
||||||
out_error^ = Parse_Error {
|
|
||||||
net_error,
|
|
||||||
"Invalid Host/Endpoint.",
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
(cast(^net.Host_Or_Endpoint)ptr)^ = addr
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
//+private
|
||||||
|
//+build !freebsd !netbsd !openbsd
|
||||||
|
package flags
|
||||||
|
|
||||||
|
import "core:net"
|
||||||
|
|
||||||
|
// This proc exists purely as a workaround for import restrictions.
|
||||||
|
// Returns true if caller should return early.
|
||||||
|
try_net_parse_workaround :: #force_inline proc (
|
||||||
|
data_type: typeid,
|
||||||
|
str: string,
|
||||||
|
ptr: rawptr,
|
||||||
|
out_error: ^Error,
|
||||||
|
) -> bool {
|
||||||
|
if data_type == net.Host_Or_Endpoint {
|
||||||
|
addr, net_error := net.parse_hostname_or_endpoint(str)
|
||||||
|
if net_error != nil {
|
||||||
|
// We pass along `net.Error` here.
|
||||||
|
out_error^ = Parse_Error {
|
||||||
|
net_error,
|
||||||
|
"Invalid Host/Endpoint.",
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
(cast(^net.Host_Or_Endpoint)ptr)^ = addr
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user