Added import-shared-object

This commit is contained in:
Justin Ethier 2021-02-23 15:18:38 -05:00
parent a259755037
commit c82e69a997
3 changed files with 19 additions and 7 deletions

View file

@ -5,6 +5,7 @@
Features
- Arthur Maciel added `opaque?` and `opaque-null?` predicates to `(cyclone foreign)`.
- Added `import-shared-object` to `(scheme eval)` to allow loading a third party C shared library.
Bug Fixes

View file

@ -6946,14 +6946,20 @@ void Cyc_import_shared_object(void *data, object cont, object filename, object e
}
dlerror(); /* Clear any existing error */
entry_pt = (function_type) dlsym(handle, string_str(entry_pt_fnc));
if (entry_pt == NULL) {
snprintf(buffer, 256, "%s, %s, %s", string_str(filename), string_str(entry_pt_fnc), dlerror());
make_utf8_string(data, s, buffer);
Cyc_rt_raise2(data, "Unable to load symbol", &s);
if (string_len(entry_pt_fnc) == 0) {
// No entry point so this is a third party library.
// Just call into our continuation
return_closcall1(data, cont, boolean_t);
} else {
entry_pt = (function_type) dlsym(handle, string_str(entry_pt_fnc));
if (entry_pt == NULL) {
snprintf(buffer, 256, "%s, %s, %s", string_str(filename), string_str(entry_pt_fnc), dlerror());
make_utf8_string(data, s, buffer);
Cyc_rt_raise2(data, "Unable to load symbol", &s);
}
mclosure1(clo, entry_pt, cont);
entry_pt(data, 0, &clo, &clo);
}
mclosure1(clo, entry_pt, cont);
entry_pt(data, 0, &clo, &clo);
}
/** Read */

View file

@ -26,6 +26,8 @@
%import
imported?
%set-import-dirs!
import-shared-object
;; Macros
*defined-macros*
get-macros
macro:macro?
@ -810,6 +812,9 @@
(define (imported? lis)
(c:lib-loaded? (lib:name->unique-string (lib:list->import-set lis))))
(define (import-shared-object filename)
(c:import-shared-obj filename ""))
;; Wrapper around the actual shared object import function
(define-c c:import-shared-obj
"(void *data, int argc, closure _, object k, object fn, object entry_fnc)"