Merge branch 'master' into cargs2-dev

This commit is contained in:
Justin Ethier 2021-02-23 15:20:47 -05:00
commit 085860ac51
3 changed files with 20 additions and 8 deletions

View file

@ -5,6 +5,7 @@
Features Features
- Arthur Maciel added `opaque?` and `opaque-null?` predicates to `(cyclone foreign)`. - 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 Bug Fixes

View file

@ -6828,6 +6828,11 @@ void Cyc_import_shared_object(void *data, object cont, object filename, object e
} }
dlerror(); /* Clear any existing error */ dlerror(); /* Clear any existing error */
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)); entry_pt = (function_type) dlsym(handle, string_str(entry_pt_fnc));
if (entry_pt == NULL) { if (entry_pt == NULL) {
snprintf(buffer, 256, "%s, %s, %s", string_str(filename), string_str(entry_pt_fnc), dlerror()); snprintf(buffer, 256, "%s, %s, %s", string_str(filename), string_str(entry_pt_fnc), dlerror());
@ -6837,6 +6842,7 @@ void Cyc_import_shared_object(void *data, object cont, object filename, object e
mclosure1(clo, entry_pt, cont); mclosure1(clo, entry_pt, cont);
object buf[1] = {&clo}; object buf[1] = {&clo};
entry_pt(data, &clo, 1, buf); entry_pt(data, &clo, 1, buf);
}
} }
/** Read */ /** Read */

View file

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