struct by value doesn't work without runtime translation
Bug #1528719 reported by
Attila Lendvai
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
CFFI |
New
|
Undecided
|
Unassigned |
Bug Description
the issue:
(progn
(asdf:test-system :cffi-tests)
(in-package :cffi-tests))
(with-foreign-
(convert-
(sumpair arg))
=> a runtime error because the current fsbv assumes that everything goes through runtime translators.
description: | updated |
To post a comment you must log in.
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::TRANSLATA BLE-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.