+ (let ((sap (shared-object-sap obj)))
+ (when sap
+ (setf result (sap-int (dlsym sap extern))
+ err (dlerror))
+ (when (or (not (zerop result)) (not err))
+ (return result))))))))
+
+(let ((symbols (make-hash-table :test #'equal))
+ (undefineds (make-hash-table :test #'equal)))
+ (defun ensure-dynamic-foreign-symbol-address (symbol &optional datap)
+ "Returns the address of the foreign symbol as an integer. On linkage-table
+ports if the symbols isn't found a special guard address is returned instead,
+accesses to which will result in an UNDEFINED-ALIEN-ERROR. On other ports an
+error is immediately signalled if the symbol isn't found. The returned address
+is never in the linkage-table."
+ (declare (ignorable datap))
+ (let ((addr (find-dynamic-foreign-symbol-address symbol)))
+ (cond #!-linkage-table
+ ((not addr)
+ (error 'undefined-alien-error :name symbol))
+ #!+linkage-table
+ ((not addr)
+ (style-warn "Undefined alien: ~S" symbol)
+ (setf (gethash symbol undefineds) t)
+ (remhash symbol symbols)
+ (if datap
+ undefined-alien-address
+ (foreign-symbol-address "undefined_alien_function")))
+ (addr
+ (setf (gethash symbol symbols) t)
+ (remhash symbol undefineds)
+ addr))))
+ (defun undefined-foreign-symbols-p ()
+ (plusp (hash-table-count undefineds)))
+ (defun dynamic-foreign-symbols-p ()
+ (plusp (hash-table-count symbols)))
+ (defun list-dynamic-foreign-symbols ()
+ (loop for symbol being each hash-key in symbols
+ collect symbol)))
+