aboutsummaryrefslogtreecommitdiff
path: root/core/flags
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-15 01:32:28 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-15 01:32:48 -0400
commit51a013fcf142fd7fcfed370bdbaf9de6db19020e (patch)
tree57287638715c388ee5e4e64def41a54bcb5c9330 /core/flags
parentf28c6c3bbaf3e55c75340125a1244e42c3462385 (diff)
Work around BSD lack of `core:net` support
Diffstat (limited to 'core/flags')
-rw-r--r--core/flags/errors.odin8
-rw-r--r--core/flags/errors_bsd.odin9
-rw-r--r--core/flags/errors_nonbsd.odin11
-rw-r--r--core/flags/internal_rtti.odin14
-rw-r--r--core/flags/internal_rtti_nonbsd.odin31
5 files changed, 52 insertions, 21 deletions
diff --git a/core/flags/errors.odin b/core/flags/errors.odin
index 1862a7a00..21ea05477 100644
--- a/core/flags/errors.odin
+++ b/core/flags/errors.odin
@@ -1,7 +1,5 @@
package flags
-import "base:runtime"
-import "core:net"
import "core:os"
Parse_Error_Reason :: enum {
@@ -20,12 +18,6 @@ Parse_Error_Reason :: enum {
Unsupported_Type,
}
-Unified_Parse_Error_Reason :: union #shared_nil {
- Parse_Error_Reason,
- runtime.Allocator_Error,
- net.Parse_Endpoint_Error,
-}
-
// Raised during parsing, naturally.
Parse_Error :: struct {
reason: Unified_Parse_Error_Reason,
diff --git a/core/flags/errors_bsd.odin b/core/flags/errors_bsd.odin
new file mode 100644
index 000000000..10c04b506
--- /dev/null
+++ b/core/flags/errors_bsd.odin
@@ -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,
+}
diff --git a/core/flags/errors_nonbsd.odin b/core/flags/errors_nonbsd.odin
new file mode 100644
index 000000000..ff46f38ed
--- /dev/null
+++ b/core/flags/errors_nonbsd.odin
@@ -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,
+}
diff --git a/core/flags/internal_rtti.odin b/core/flags/internal_rtti.odin
index 8a11ebbc1..c9b1f59fd 100644
--- a/core/flags/internal_rtti.odin
+++ b/core/flags/internal_rtti.odin
@@ -5,7 +5,6 @@ import "base:intrinsics"
import "base:runtime"
import "core:fmt"
import "core:mem"
-@require import "core:net"
import "core:os"
import "core:reflect"
import "core:strconv"
@@ -309,18 +308,7 @@ parse_and_set_pointer_by_named_type :: proc(ptr: rawptr, str: string, data_type:
}
when IMPORTING_NET {
- 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
- }
-
- (cast(^net.Host_Or_Endpoint)ptr)^ = addr
+ if try_net_parse_workaround(data_type, str, ptr, out_error) {
return
}
}
diff --git a/core/flags/internal_rtti_nonbsd.odin b/core/flags/internal_rtti_nonbsd.odin
new file mode 100644
index 000000000..196c27ab8
--- /dev/null
+++ b/core/flags/internal_rtti_nonbsd.odin
@@ -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
+}