Comment 1 for bug 1528719

Revision history for this message
Attila Lendvai (attila-lendvai) wrote :

and a half-working solution:

defcstruct's define a lisp class to represent the struct type, and this lisp class inherits from both (CFFI::FOREIGN-STRUCT-TYPE CFFI::TRANSLATABLE-FOREIGN-TYPE).

after a long session of staring at trace output and letting my creativity loose in the forest of EXPAND-TO-FOREIGN-DYN, EXPAND-TO-FOREIGN-DYN-INDIRECT, TRANSLATE-TO-FOREIGN, TRANSLATE-INTO-FOREIGN-MEMORY, and friends... i've identified the magic 3 lines that fixes this:

(defmethod expand-to-foreign-dyn-indirect (value var body (type foreign-struct-type))
  `(let ((,var ,value))
     ,@body))

the problem is that this breaks type translation because it kicks in before the method specialized on TRANSLATABLE-FOREIGN-TYPE.

maybe there's someone with more insight into the cffi type internals who can come up with a fix for this?

unfortunately FOREIGN-POINTER is not a class, so we cannot dispatch on the value in CFFI::TRANSLATE-INTO-FOREIGN-MEMORY.