Support "enum-like" pointers using cenum with :base-type :pointer
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
CFFI |
New
|
Undecided
|
Unassigned |
Bug Description
It's common in some systems to have "enum-like" pointers. For example, in Apple's libdispatch (Grand Central Dispatch) there's a dispatch_
You can see all of the latest /usr/local/dispatch headers here, dispatch_
What I'd like to do is use something like cenum to define these values in a way that results in loads of the global variables at runtime. For example:
(in-package :dispatch)
(import "dispatch/
(cenum (source-type :base-type :pointer "dispatch_
((proc "DISPATCH_
((read "DISPATCH_
((signal "DISPATCH_
((timer "DISPATCH_
((vnode "DISPATCH_
((write "DISPATCH_
The important aspect is that instances of source-type need to be global variables of a pointer type whose values comes from libdispatch at dynamic load time, rather than integer constants whose value is truly fixed.
I think I could achieve this right now with CFFI by using global variables, but that wouldn't express that these are all members of a particular type. (Of course, I could also annotate that, but it'd be nice to have it all be concise.)
I'm fine with using a new construct like "cenumlike" for this, since it's not technically a C enum.
Apple introduced a similar "enum-like string global" concept with macOS 10.12 and iOS 10 for better type system and IDE support in Objective-C and Swift interoperability, because of the pervasiveness of this sort of "global pointer used as enum" concept in its APIs.
(Disclosure: I work at Apple on developer tools and contributed to the design of ObjC/Swift string enums. I'm in no way representing my employer here though, I'm just an interested spare time hobbyist user of Lisp and CFFI, on Apple platforms and others as well.)