[Openmcl-devel] An unfortunate interaction between CFFI and open-shared-library

Ron Garret ron at flownet.com
Sun Sep 19 14:22:04 PDT 2010


I suggest something like this:

(defun open-shared-library (name &optional (process #+darwin-target :initial
                                                    #-darwin-target :current))
  "If the library denoted by name can be loaded by the operating system,
return an object of type SHLIB that describes the library; if the library
is already open, increment a reference count. If the library can't be
loaded, signal a SIMPLE-ERROR which contains an often-cryptic message from
the operating system."
  (if (or (eq process :current)
          (eq process *current-process*)
          (and (eq process :initial)
               (eq *current-process* *initial-process*)))
    (open-shared-library-internal name)
    (multiple-value-bind (result error)
                         (call-in-process (lambda () (ignore-errors
                                                      (open-shared-library name)))
                                          (if (eq process :initial)
                                            *initial-process*
                                            process))
      (if error (error error) result))))

Or maybe:

(defmacro safely-call-in-process (fn process)
  `(multiple-value-bind (result error)
                        (call-in-process (lambda () (ignore-errors (funcall ,fn)))
                                         ,process)
     (if error (error error) result)))

(defun open-shared-library (name &optional (process #+darwin-target :initial
                                                    #-darwin-target :current))
  (if (and (eq process :initial) (not (eq *current-process* *initial-process*)))
    (safely-call-in-process (lambda () (open-shared-library-internal name))
                            *initial-process*)
    (open-shared-library-internal name)))

rg




More information about the Openmcl-devel mailing list