|
@@ -12,6 +12,11 @@ A handle to a dynamically loaded library.
|
|
*/
|
|
*/
|
|
Library :: distinct rawptr
|
|
Library :: distinct rawptr
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+The file extension for dynamic libraries on the target OS.
|
|
|
|
+*/
|
|
|
|
+LIBRARY_FILE_EXTENSION :: _LIBRARY_FILE_EXTENSION
|
|
|
|
+
|
|
/*
|
|
/*
|
|
Loads a dynamic library from the filesystem. The paramater `global_symbols` makes the symbols in the loaded
|
|
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.
|
|
library available to resolve references in subsequently loaded libraries.
|
|
@@ -123,31 +128,36 @@ initialize_symbols :: proc(
|
|
) -> (count: int = -1, ok: bool = false) where intrinsics.type_is_struct(T) {
|
|
) -> (count: int = -1, ok: bool = false) where intrinsics.type_is_struct(T) {
|
|
assert(symbol_table != nil)
|
|
assert(symbol_table != nil)
|
|
|
|
|
|
- handle := load_library(library_path) or_return
|
|
|
|
-
|
|
|
|
- // Buffer to concatenate the prefix + symbol name.
|
|
|
|
- prefixed_symbol_buf: [2048]u8 = ---
|
|
|
|
-
|
|
|
|
- count = 0
|
|
|
|
|
|
+ // First, (re)load the library.
|
|
|
|
+ handle: Library
|
|
for field in reflect.struct_fields_zipped(T) {
|
|
for field in reflect.struct_fields_zipped(T) {
|
|
- // Calculate address of struct member
|
|
|
|
- field_ptr := rawptr(uintptr(symbol_table) + field.offset)
|
|
|
|
-
|
|
|
|
- // If we've come across the struct member for the handle, store it and continue scanning for other symbols.
|
|
|
|
if field.name == handle_field_name {
|
|
if field.name == handle_field_name {
|
|
|
|
+ field_ptr := rawptr(uintptr(symbol_table) + field.offset)
|
|
|
|
+
|
|
// We appear to be hot reloading. Unload previous incarnation of the library.
|
|
// We appear to be hot reloading. Unload previous incarnation of the library.
|
|
if old_handle := (^Library)(field_ptr)^; old_handle != nil {
|
|
if old_handle := (^Library)(field_ptr)^; old_handle != nil {
|
|
unload_library(old_handle) or_return
|
|
unload_library(old_handle) or_return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ handle = load_library(library_path) or_return
|
|
(^Library)(field_ptr)^ = handle
|
|
(^Library)(field_ptr)^ = handle
|
|
- continue
|
|
|
|
|
|
+ break
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Buffer to concatenate the prefix + symbol name.
|
|
|
|
+ prefixed_symbol_buf: [2048]u8 = ---
|
|
|
|
|
|
- // We're not the library handle, so the field needs to be a pointer type, be it a procedure pointer or an exported global.
|
|
|
|
- if !(reflect.is_procedure(field.type) || reflect.is_pointer(field.type)) {
|
|
|
|
|
|
+ count = 0
|
|
|
|
+ for field in reflect.struct_fields_zipped(T) {
|
|
|
|
+ // If we're not the library handle, the field needs to be a pointer type, be it a procedure pointer or an exported global.
|
|
|
|
+ if field.name == handle_field_name || !(reflect.is_procedure(field.type) || reflect.is_pointer(field.type)) {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Calculate address of struct member
|
|
|
|
+ field_ptr := rawptr(uintptr(symbol_table) + field.offset)
|
|
|
|
+
|
|
// Let's look up or construct the symbol name to find in the library
|
|
// Let's look up or construct the symbol name to find in the library
|
|
prefixed_name: string
|
|
prefixed_name: string
|
|
|
|
|