convert-from-foreign doesn't translate struct typedefs

Bug #1473506 reported by 3b
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
CFFI
New
Undecided
Unassigned

Bug Description

(cffi:defcstruct foo
  (f :unsigned-int))
(cffi:defctype foo (:struct foo))

(cffi:with-foreign-object (p 'foo)
  (cffi:convert-from-foreign p '(:struct foo)))
=>
(F 871732)

(cffi:with-foreign-object (p 'foo)
  (cffi:convert-from-foreign p 'foo))
=>
#.(SB-SYS:INT-SAP #X7FFFD68CFFF0)
;; expected (F ...) as with (:struct foo)

tested on sbcl 1.2.13.x, linux/windows x8664, cffi from dec 2014 and a bit past 0.15

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

using ENSURE-PARSED-BASE-TYPE instead of PARSE-TYPE fixes it:

(defun convert-from-foreign (value type)
  (translate-from-foreign value (ensure-parsed-base-type type)))

(define-compiler-macro convert-from-foreign (value type)
  (if (constantp type)
      (expand-from-foreign value (ensure-parsed-base-type (eval type)))
      `(translate-from-foreign ,value (parse-type ,type))))

but also breaks some other tests.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.