2015-12-23 00:15:17 |
Attila Lendvai |
description |
the issue:
(progn
(asdf:test-system :cffi-tests)
(in-package :cffi-tests))
(with-foreign-object (arg '(:struct pair))
(convert-into-foreign-memory '(40 . 2) '(:struct pair) arg)
(sumpair arg))
=> a runtime error because the current fsbv assumes that everything goes through runtime translators.
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? |
the issue:
(progn
(asdf:test-system :cffi-tests)
(in-package :cffi-tests))
(with-foreign-object (arg '(:struct pair))
(convert-into-foreign-memory '(40 . 2) '(:struct pair) arg)
(sumpair arg))
=> a runtime error because the current fsbv assumes that everything goes through runtime translators. |
|