Skip to content

Commit

Permalink
dlopen fasl lib on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-s committed Dec 5, 2024
1 parent b808664 commit 3a16c86
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/fasl-lib.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ symbols defined in SYSTEMS. The C functions to perform
:when (typep system 'asdf:require-system)
:do (format stream "~v@{ ~}lisp_require(\"~A\");~%" indent-size system-name))))
(with-open-file (stream (uiop:merge-pathnames* *fasl-loader-filename* directory) :direction :output :if-exists :supersede)
#+linux
(format stream "#include <dlfcn.h>~%")
#+win32
(format stream "#include <Windows.h>~%")
(format stream "#include \<~A.h\>~%" *base-library-name*)
Expand All @@ -105,6 +107,11 @@ symbols defined in SYSTEMS. The C functions to perform
(progn
(let ((function-name (fasl-library-load-function-name library)))
(format stream "__attribute__((constructor))~%static void ~A(void) {~%" function-name)
#+linux
(progn
(format stream " Dl_info info;~%")
(format stream " dladdr(~A_fasl, &info);~%" (system-c-name (first systems)))
(format stream " dlopen(info.dli_fname, RTLD_NOW | RTLD_GLOBAL);~%"))
#+win32
(let ((buf-size 1024))
(format stream " char dll_path[~D];~%" buf-size)
Expand Down

0 comments on commit 3a16c86

Please sign in to comment.