I am writing a CFFI tutorial, to be integrated into the manual when it is done if the maintainers will have it. You can get the first half or so in Texinfo format if you so desire at http://csserver.evansville.edu/~sc87/cffi/tutorial.texi . You can integrate it into cffi-manual.texi for building (if you want to see TeX, HTML, etc output) with a
@include tutorial.texi
For best results, put it where that comment about the manual needing a tutorial is. If you want curl.h and easy.h to follow along, they are in the same directory.
Stuff left to be written about:
* Dealing with memory allocation. The importance of the "Breaking the abstraction" section should become clearer here.
* define-foreign-type for bits to be LOGIORed, then using that to type the input to curl_global_init.
* Writing type translators. This will be used to restrict the :curl-easy-handle type.
* Callbacks. This of course will be a :writefunction.
* I think that error CURLcodes should "translate" to conditions. However, that is mostly macrology rather than new CFFI material, so I am not sure it should be included.
* Some other stuff I can't remember right now. It depends on what I can reasonably introduce in the context of the example I've chosen.
I may also consider disjoining the TYPEs in the :curl-option definition. After all, I'm breaking the abstraction, so I might as well make a better one.
Some notes may be confusing at the moment. If you see one, please tell me anyway, in case it is not one I am thinking of.
There is a stray TODO, and I don't yet know how I'm going to type curl_off_t portably. I will probably just remove :off-t for this tutorial.
Comments are of course welcome here, and especially on Freenode #lisp, where I am S11001001.
On 2005-dec-22, at 07:12, Stephen Compall wrote:
I am writing a CFFI tutorial, to be integrated into the manual when it is done if the maintainers will have it.
Looks great, you write very well!
A few minor notes:
- You suggest UFFI-COMPAT is not complete. Well, it should be complete (though likely not bug free). It passes all of the uffi- tests and is known to work with (and find bugs in) a couple of UFFI libraries.
- (defctype :curl-code :int) -- Hmm, using the keyword namespace for user-defined types. I'm not sure if it's a good idea. Some people have also suggested that using the keyword namespace for CFFI types isn't a good idea either.
- @sc{} looks gorgeous. :D
This tutorial shows the usefulness of foreign-funcall for C functions with varargs. Lispworks unfortunately doesn't export this functionality. Martin, I wonder if Lispworks will ever export something like this or if we could have some clues on how to use unexported functionality to implement cffi-sys:%foreign-funcall (and eventually cffi-sys:%foreign-funcall-pointer).
On Thu, 22 Dec 2005 10:14:38 +0000, =?ISO-8859-1?Q?Lu=EDs_Oliveira?= luismbo@gmail.com said:
Luís> This tutorial shows the usefulness of foreign-funcall for C functions Luís> with varargs. Lispworks unfortunately doesn't export this Luís> functionality. Martin, I wonder if Lispworks will ever export Luís> something like this or if we could have some clues on how to use Luís> unexported functionality to implement cffi-sys:%foreign-funcall (and Luís> eventually cffi-sys:%foreign-funcall-pointer).
No, LispWorks doesn't support that kind of call with random run-time types. The problem is that some of the low level calling conventions are very baroque in which registers they use to pass the arguments, so supporting a call pattern with run-time types is too complicated. Defining a small number of FLI:DEFINE-FOREIGN-FUNCTION wrappers for the same C function with specific types has sufficed so far in our cases.
You can get some of the functionality by using the :ONE-OF type in LispWorks, but you can't use it to mix float, non-float and aggregate types for the same value. LispWorks also has FLI:DEFINE-FOREIGN-FUNCALLABLE for creating specific "FUNCALL" functions to allow calling of function pointers.
On 2005-dec-22, at 13:15, Martin Simmons wrote:
No, LispWorks doesn't support that kind of call with random run- time types. The problem is that some of the low level calling conventions are very baroque in which registers they use to pass the arguments, so supporting a call pattern with run-time types is too complicated.
Actually, cffi:foreign-funcall's type arguments aren't evaluated. Does this help?
On Thu, 22 Dec 2005 13:30:20 +0000, =?ISO-8859-1?Q?Lu=EDs_Oliveira?= luismbo@gmail.com said:
Luís> DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
Luís> On 2005-dec-22, at 13:15, Martin Simmons wrote:
No, LispWorks doesn't support that kind of call with random run- time types. The problem is that some of the low level calling conventions are very baroque in which registers they use to pass the arguments, so supporting a call pattern with run-time types is too complicated.
Luís> Actually, cffi:foreign-funcall's type arguments aren't evaluated. Luís> Does this help?
Yes, that makes it much easier!
I saw the function curl-easy-setopt in the tutorial...
On Dec 22, 2005, at 5:14 AM, Luís Oliveira wrote:
On 2005-dec-22, at 07:12, Stephen Compall wrote:
I am writing a CFFI tutorial, to be integrated into the manual when it is done if the maintainers will have it.
Looks great, you write very well!
A few minor notes:
- You suggest UFFI-COMPAT is not complete. Well, it should be complete
(though likely not bug free). It passes all of the uffi-tests and is known to work with (and find bugs in) a couple of UFFI libraries.
- (defctype :curl-code :int) -- Hmm, using the keyword namespace for
user-defined types. I'm not sure if it's a good idea. Some people have also suggested that using the keyword namespace for CFFI types isn't a good idea either.
I am just a lurker here. But this is definitively something I feel strongly about. No abuses of the KEYWORD package should go unpunished. :)
Please export the relevant symbols from the CFFI package.
Cheers
-- Marco Antoniotti http://bioinformatics.nyu.edu/~marcoxa NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488 715 Broadway 10th FL fax. +1 - 212 - 998 3484 New York, NY, 10003, U.S.A.
The first draft is now available. See inline comments below about obtaining, and notes about changes since the previous announcement.
On Thu, 2005-12-22 at 01:12 -0600, Stephen Compall wrote:
I am writing a CFFI tutorial, to be integrated into the manual when it is done if the maintainers will have it. You can get the first half or so in Texinfo format if you so desire at http://csserver.evansville.edu/~sc87/cffi/tutorial.texi . You can integrate it into cffi-manual.texi for building (if you want to see TeX, HTML, etc output) with a
@include tutorial.texi
For best results, put it where that comment about the manual needing a tutorial is. If you want curl.h and easy.h to follow along, they are in the same directory.
Available at the same address. Differences in tutorial-r1-r2.diff; current (hopefully loadable) final source at tutorial-source.lisp.
Stuff left out:
- define-foreign-type for bits to be LOGIORed, then using that to type
the input to curl_global_init.
Callbacks. This of course will be a :writefunction.
Some other stuff I can't remember right now. It depends on what I can
reasonably introduce in the context of the example I've chosen.
I may also consider disjoining the TYPEs in the :curl-option definition. After all, I'm breaking the abstraction, so I might as well make a better one.
Didn't do this.
There is a stray TODO, and I don't yet know how I'm going to type curl_off_t portably. I will probably just remove :off-t for this tutorial.
Left off-t in there, but didn't use it. It's not very useful anyway, so hardly anyone would miss it.
Comments are of course welcome here, and especially on Freenode #lisp, where I am S11001001.
On Mon, 2006-01-09 at 21:14 -0600, Stephen Compall wrote:
The first draft is now available. See inline comments below about obtaining, and notes about changes since the previous announcement.
Darcs patch now at http://csserver.evansville.edu/~sc87/cffi/cffi-tutorial-r3.darcs.patch
Stephen Compall s11@member.fsf.org writes:
Darcs patch now at http://csserver.evansville.edu/~sc87/cffi/cffi-tutorial-r3.darcs.patch
Thanks! I've pushed this patch to the tree and updated the documentation in the website.