- (let (dlerror)
- (cond ((and objp (shared-object-handle obj))
- (setf dlerror (if (freelibrary (shared-object-handle obj))
- nil
- (getlasterror))
- (shared-object-handle obj) nil)))
- (when dlerror
- (cerror "Ignore the error and continue anyway" "dlerror returned an error: ~S" dlerror))))
-
-(defun load-shared-object (file)
- "Load a shared library/dynamic shared object file/general dlopenable
-alien container, such as a .so on an ELF platform.
-
-Reloading the same shared object will replace the old definitions; if
-a symbol was previously referenced thru the object and is not present
-in the reloaded version an error will be signalled. Sameness is
-determined using the library filename. Reloading may not work as
-expected if user or library-code has called dlopen on FILE.
-
-References to foreign symbols in loaded shared objects do not survive
-intact through SB-EXT:SAVE-LISP-AND-DIE on all platforms. See
-SB-EXT:SAVE-LISP-AND-DIE for details."
- ;; FIXME: 1. This is copy-paste from foreign-load.lisp.
- ;; FIXME: 2. Once windows gets threads, this is going to need a lock.
- ;; FIXME: 3. No linkage table on windows?
- (let* ((filename (or (unix-namestring file) file))
- (old (find filename *shared-objects* :key #'shared-object-file :test #'equal))
- (obj (or old (make-shared-object :file filename))))
- (unless old
- (dlopen-or-lose obj))
- (setf *shared-objects* (append (remove obj *shared-objects*)
- (list obj)))
- (pathname filename)))
-
-(defun try-reopen-shared-object (obj)
- (declare (type shared-object obj))
- (tagbody :dlopen
- (restart-case
- (dlopen-or-lose obj)
- (continue ()
- :report "Skip this shared object and continue."
- (setf (shared-object-handle obj) nil))
- (retry ()
- :report "Retry loading this shared object."
- (go :dlopen))
- (load-other ()
- :report "Specify an alternate shared object file to load."
- (setf (shared-object-file obj)
- (tagbody :query
- (format *query-io* "~&Enter pathname (evaluated):~%")
- (force-output *query-io*)
- (let ((pathname (ignore-errors (pathname (read *query-io*)))))
- (unless (pathnamep pathname)
- (format *query-io* "~&Error: invalid pathname.~%")
- (go :query))
- (unix-namestring pathname)))))))
- obj)
-
-;;; Open libraries in *SHARED-OBJECTS* and the runtime. Called during
-;;; initialization.
-;;; Note that, so long as we don't have linkage-table, this is braindead.
-(defun reopen-shared-objects ()
- (setf *shared-objects* (mapcar #'try-reopen-shared-object *shared-objects*)))
-
-;;; Close all dlopened libraries and clear out sap entries in
-;;; *SHARED-OBJECTS*.
-(defun close-shared-objects ()
- (mapc #'dlclose-or-lose (reverse *shared-objects*)))