[cffi-devel] getting CFFI function signature
![](https://secure.gravatar.com/avatar/13663028cac36d0b9ff102354f298263.jpg?s=120&d=mm&r=g)
Hi, I have CFFI bindings generated by SWIG, which look like (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. Thanks, Tamas
![](https://secure.gravatar.com/avatar/51004fb1ed7a9faec361b6dd7787fc9f.jpg?s=120&d=mm&r=g)
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.
![](https://secure.gravatar.com/avatar/4fd19de0b3e4891247e0056c282337c4.jpg?s=120&d=mm&r=g)
I have CFFI bindings generated by SWIG, which look like
just a hint: by now verrazano generates much better bindings out of the box then swig and it has a pregenerated cairo binding. this won't solve your problem either, but if you are interested in such a change, then verrazano could easily be extended to support custom generators. yours would be the first though, so it would need some refactoring in verrazano, but its internal state has all the info that is needed. hth, -- attila
participants (3)
-
Attila Lendvai
-
Stephen Compall
-
Tamas K Papp