sellout / cl-dispatch

CFFI bindings to Grand Central Dispatch.
7 stars 2 forks source link

Doesn’t load with current CCL, Quicklisp, and dispatch #1

Open eschaton opened 7 years ago

eschaton commented 7 years ago

I put a symlink to cl-dispatch in my Quicklisp local-projects directory, launched the CCL IDE (Clozure CL64.app, built from CCL trunk r16809, the latest current), and ran (ql:quickload :dispatch) in the Listener.

That resulted in the following error:

Read error between positions 927 and 1051 in «path»/cl-dispatch/grovel.processed-grovel-file.
> Error: The value :POINTER is not of the expected type (MEMBER :UNSIGNED-CHAR :UNSIGNED-SHORT :UNSIGNED-INT :UNSIGNED-LONG :UNSIGNED-LONG-LONG :CHAR :SHORT :INT :LONG :LONG-LONG).
> While executing: CFFI-GROVEL::CONVERT-INTMAX-CONSTANT, in process Listener(4).

I suspect that grovel.lisp may need to be adjusted for the very different dispatch type declarations present in a more modern operating system than the one for which this was originally written; I’m using the macOS Sierra 10.12 SDK.

It might also be possible to greatly simplify some of the definitions, and redesign grovel.lisp around the shape of the API definition rather than the declarations in the headers.

eschaton commented 7 years ago

The issue is definitely with the definition of source-type using cenum, which doesn’t appear to handle pointer values. These values actually should be looked up at run time, just like DISPATCH_QUEUE_SERIAL maps to +serial-queue-address+ which maps to *serial-queue* which maps to :serial.

It might make sense to have CFFI-level support for the "enum-like" pattern since dispatch—and many other libraries & frameworks—use it in several places, something like:

(cenumlike (queue-concurrency :base-type :pointer)
              ((:serial "DISPATCH_QUEUE_SERIAL"))
              ((:concurrent "DISPATCH_QUEUE_CONCURRENT")))

Then the import definition of dispatch_queue_create could be something like

(defcfun "dispatch_queue_create" queue (label :string) (attr (or queue-attribute queue-concurrency))

and the make-queue wrapper could avoid the ecase.

eschaton commented 7 years ago

I filed https://bugs.launchpad.net/cffi/+bug/1660084 against CFFI to cover supporting this kind of "enum-like global."