[cffi-devel] Re: getting CFFI function signature

Stephen Compall s11 at member.fsf.org
Sun May 13 15:23:57 UTC 2007


On Sun, 2007-05-13 at 10:00 -0400, Tamas K Papp wrote:
> (cffi:defcfun ("cairo_line_to" cairo_line_to) :void
>   (cr :pointer)
>   (x :double)
>   (y :double))
> 
> I would like to generate wrapper functions that would take the first
> argument from a global variable and apply conversions for the rest.
> The problem is that there are many functions, and I want to automate
> this as much as possible.
> 
> Is there any way to get the signature of a function defined with
> cffi:defcfun?  In this case, I need something like (:void cr :pointer
> x :double y: double) (of course the syntax and the ordering can vary).
> With this, I could automate the generation of wrappers.

Sorry, this information is used in the macroexpansion, but not saved.
See src/functions.lisp.

If you're using SWIG's output unedited, there should be a pattern of
output.  In that case, you could pretty easily postprocess the output.

(defun wanted-signature-p (form)
  (and (eq (first form) 'cffi:defcfun)
       (cdddr form)
       (eq (second (fourth form)) :pointer)))

(defun save-signature (form)
  "Save CFFI:DEFCFUN signature in FORM."
  (destructuring-bind (macro-name (c-name lisp-name) &rest rettype-args)
      form
    (declare (ignore macro-name c-name))
    (put lisp-name 'defcfun-signature rettype-args)))

Alternatively, you could wipe out the cffi: prefix and wrap defcfun at
the top of that file.

-- 
;;; Stephen Compall ** http://scompall.nocandysw.com/blog **
Failure to imagine vast possibilities usually stems from a lack of
imagination, not a lack of possibility.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20070513/626ba520/attachment.sig>


More information about the cffi-devel mailing list