[cffi-devel] using defcenum keywords in function call

Johan Ur Riise johan at riise-data.no
Sat Sep 26 02:09:37 UTC 2009


I have some enums defined, a defcfun and I use the keywords of the enum when I
call the function.

The documentation says:	
Keywords will be automatically converted to values and vice-versa when being passed as
arguments to or returned from foreign functions, respectively.

But this does not seem to be the case, I get a type error. 

The following should be a minimalistic runnable example. What am I doing wrong?

CL-USER> (require 'cffi)
; loading system definition from C:/prg/libcl/babel/babel.asd into #<Package "ASDF0">
; registering #<SYSTEM BABEL #x14DE5106> as BABEL
; loading system definition from C:/prg/libcl/alexandria/alexandria.asd into #<Package "ASDF0">
; registering #<SYSTEM :ALEXANDRIA #x14E038B6> as ALEXANDRIA
; loading system definition from C:/prg/libcl/trivial-features/trivial-features.asd into #<Package "ASDF0">
; registering #<SYSTEM TRIVIAL-FEATURES #x14E5DAE6> as TRIVIAL-FEATURES
CFFI
NIL
CL-USER> (in-package :cffi)
#<Package "CFFI">
CFFI> (defctype SOCKET :uint)
SOCKET
CFFI> (defcenum af
  :af-unspec
  :af-unix
  :af-inet)
AF
CFFI> (defcenum sock-type
  (:sock-stream 1)
  :sock-dgram
  :sock-raw)
SOCK-TYPE
CFFI> (defcenum pf
  :pf-unspec
  :pf-unix
  :pf-inet)
PF
CFFI> (defcfun ("socket" win-socket) socket
  "Creates a socket with the overlapped mode as default"
  (af :int32)
  (type :int)
  (protocol :int))
WIN-SOCKET
CFFI> (defun make-socket ()
  (win-socket :af-inet :sock-stream :pf-inet))
MAKE-SOCKET
CFFI> (make-socket)
; Evaluation aborted.
CFFI> ;->value :AF-INET is not of the expected type (SIGNED-BYTE 32).
   ;[Condition of type TYPE-ERROR]

; No value
CFFI> 







More information about the cffi-devel mailing list