can't access array of enums in struct slot

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

Bug Description

(cffi:defcenum (foo :unsigned-int))
(cffi:defcstruct bar
  (f :unsigned-int :count 2)
  (f2 foo :count 2))

(cffi:with-foreign-object (p '(:struct bar))
  (print (cffi:foreign-slot-value p '(:struct bar) 'f)))
=>
#.(SB-SYS:INT-SAP #X7FFFD68CFFE8)

(cffi:with-foreign-object (p '(:struct bar))
  (print (cffi:foreign-slot-value p '(:struct bar) 'f2)))
=>

The value of CFFI::VALUE is #.(SB-SYS:INT-SAP #X7FFFD68CFFF0), which is not of type INTEGER.

Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {1003B765A3}>
0: (SB-KERNEL:CHECK-TYPE-ERROR CFFI::VALUE #.(SB-SYS:INT-SAP #X7FFFD68CFFF0) INTEGER NIL)
1: (CFFI::%FOREIGN-ENUM-KEYWORD #<CFFI::FOREIGN-ENUM FOO> #<unavailable argument> :ERRORP T)
2: ((LAMBDA ()))

expected a pointer or sequence of enum keywords

tested on sbcl 1.2.13.2 linux x8664, cffi from dec 2014, and sbcl 1.2.13.48 windows x8664, cffi a bit past v0.15

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

shouldn't it be written something like:

(cffi:with-foreign-object (p '(:struct bar))
              (print (mem-ref p 'foo (foreign-slot-offset '(:struct bar) 'f2))))

i think the given example is a violation of the CFFI API... or is it not?

Changed in cffi:
status: New → Incomplete
Revision history for this message
Attila Lendvai (attila-lendvai) wrote :

although, on a second thought... even if it's a violation of the API, the original test case should still return with a SAP to the enum array, right?

Changed in cffi:
status: Incomplete → New
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.