aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2024-07-04 16:53:00 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2024-07-04 16:53:00 +0200
commit8bee73b08e68df67caad24fe309617d96f8ed47c (patch)
tree06bbdb85a2d669186bd613ba24eb2bdbbf8a6e50
parent1eb0bc1408735401a2ba6fdfbc2dd27726be5137 (diff)
Remove implicit allocator usage in core:dynlib
-rw-r--r--core/dynlib/lib.odin18
-rw-r--r--core/dynlib/lib_js.odin2
-rw-r--r--core/dynlib/lib_unix.odin2
-rw-r--r--core/dynlib/lib_windows.odin16
4 files changed, 14 insertions, 24 deletions
diff --git a/core/dynlib/lib.odin b/core/dynlib/lib.odin
index 3d41cbe2e..09e16002d 100644
--- a/core/dynlib/lib.odin
+++ b/core/dynlib/lib.odin
@@ -16,15 +16,12 @@ Library :: distinct rawptr
Loads a dynamic library from the filesystem. The paramater `global_symbols` makes the symbols in the loaded
library available to resolve references in subsequently loaded libraries.
-The paramater `global_symbols` is only used for the platforms `linux`, `darwin`, `freebsd` and `openbsd`.
+The parameter `global_symbols` is only used for the platforms `linux`, `darwin`, `freebsd` and `openbsd`.
On `windows` this paramater is ignored.
The underlying behaviour is platform specific.
On `linux`, `darwin`, `freebsd` and `openbsd` refer to `dlopen`.
-On `windows` refer to `LoadLibraryW`.
-
-**Implicit Allocators**
-`context.temp_allocator`
+On `windows` refer to `LoadLibraryW`. Also temporarily needs an allocator to convert a string.
Example:
import "core:dynlib"
@@ -79,10 +76,7 @@ Loads the address of a procedure/variable from a dynamic library.
The underlying behaviour is platform specific.
On `linux`, `darwin`, `freebsd` and `openbsd` refer to `dlsym`.
-On `windows` refer to `GetProcAddress`.
-
-**Implicit Allocators**
-`context.temp_allocator`
+On `windows` refer to `GetProcAddress`. Also temporarily needs an allocator to convert a string.
Example:
import "core:dynlib"
@@ -177,9 +171,7 @@ initialize_symbols :: proc(
return count, count > 0
}
-/*
-Returns an error message for the last failed procedure call.
-*/
+// Returns an error message for the last failed procedure call.
last_error :: proc() -> string {
return _last_error()
-}
+} \ No newline at end of file
diff --git a/core/dynlib/lib_js.odin b/core/dynlib/lib_js.odin
index 866874ee8..bfc724c12 100644
--- a/core/dynlib/lib_js.odin
+++ b/core/dynlib/lib_js.odin
@@ -16,4 +16,4 @@ _symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found
_last_error :: proc() -> string {
return ""
-}
+} \ No newline at end of file
diff --git a/core/dynlib/lib_unix.odin b/core/dynlib/lib_unix.odin
index fb0270ea3..8adaadb2d 100644
--- a/core/dynlib/lib_unix.odin
+++ b/core/dynlib/lib_unix.odin
@@ -26,4 +26,4 @@ _symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found
_last_error :: proc() -> string {
err := os.dlerror()
return "unknown" if err == "" else err
-}
+} \ No newline at end of file
diff --git a/core/dynlib/lib_windows.odin b/core/dynlib/lib_windows.odin
index c7bfe1537..b41abe3b2 100644
--- a/core/dynlib/lib_windows.odin
+++ b/core/dynlib/lib_windows.odin
@@ -4,14 +4,12 @@ package dynlib
import win32 "core:sys/windows"
import "core:strings"
-import "base:runtime"
import "core:reflect"
-_load_library :: proc(path: string, global_symbols := false) -> (Library, bool) {
+_load_library :: proc(path: string, global_symbols := false, allocator := context.temp_allocator) -> (Library, bool) {
// NOTE(bill): 'global_symbols' is here only for consistency with POSIX which has RTLD_GLOBAL
-
- runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
- wide_path := win32.utf8_to_wstring(path, context.temp_allocator)
+ wide_path := win32.utf8_to_wstring(path, allocator)
+ defer free(wide_path, allocator)
handle := cast(Library)win32.LoadLibraryW(wide_path)
return handle, handle != nil
}
@@ -21,9 +19,9 @@ _unload_library :: proc(library: Library) -> bool {
return bool(ok)
}
-_symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found: bool) {
- runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
- c_str := strings.clone_to_cstring(symbol, context.temp_allocator)
+_symbol_address :: proc(library: Library, symbol: string, allocator := context.temp_allocator) -> (ptr: rawptr, found: bool) {
+ c_str := strings.clone_to_cstring(symbol, allocator)
+ defer delete(c_str, allocator)
ptr = win32.GetProcAddress(cast(win32.HMODULE)library, c_str)
found = ptr != nil
return
@@ -33,4 +31,4 @@ _last_error :: proc() -> string {
err := win32.System_Error(win32.GetLastError())
err_msg := reflect.enum_string(err)
return "unknown" if err_msg == "" else err_msg
-}
+} \ No newline at end of file