From: Benjamin Tovar
Subject: ffi automatic type translations
Date: 
Message-ID: <878wlwd150.fsf@the.google.mail.thing>
In cffi I can use something like

(cffi::define-foreign-type float-foreign () 
  ()
  (:actual-type :double)
  (:simple-parser float-foreign))

and

(defmethod cffi:translate-to-foreign (value (type float-foreign))
  (coerce value 'double-float))

to automatically convert the arguments of a foreign function call (i.e.,
to pass an integer when a C function expected a double).

How can I achieve this using only the Allegro FFI?

Thanks!


-- 
Benjamin Tovar

From: Pascal J. Bourguignon
Subject: Re: ffi automatic type translations
Date: 
Message-ID: <87ws9gef6w.fsf@galatea.local>
Benjamin Tovar <······················@the.google.mail.thing> writes:

> In cffi I can use something like
>
> (cffi::define-foreign-type float-foreign () 
>   ()
>   (:actual-type :double)
>   (:simple-parser float-foreign))
>
> and
>
> (defmethod cffi:translate-to-foreign (value (type float-foreign))
>   (coerce value 'double-float))
>
> to automatically convert the arguments of a foreign function call (i.e.,
> to pass an integer when a C function expected a double).
>
> How can I achieve this using only the Allegro FFI?

Allegro Common Lisp is compatible with CFFI, so you just use CFFI.
http://www.cl-user.net/asp/fZ$5/sdataQvZkCuxTZrc1DQ3KMHpX8yBX8yBXnMq=/sdataQu3F$sSHnB==


If you really want to know, then you may just macroexpand the above forms.


-- 
__Pascal Bourguignon__
From: Madhu
Subject: Re: ffi automatic type translations
Date: 
Message-ID: <m3bpqsq8d3.fsf@moon.robolove.meer.net>
* (Pascal J. Bourguignon) <··············@galatea.local> :
Wrote on Sun, 19 Apr 2009 19:17:11 +0200:

| Benjamin Tovar <······················@the.google.mail.thing> writes:
|
|> In cffi I can use something like
|>
|> (cffi::define-foreign-type float-foreign () 
|>   ()
|>   (:actual-type :double)
|>   (:simple-parser float-foreign))
|>
|> and
|>
|> (defmethod cffi:translate-to-foreign (value (type float-foreign))
|>   (coerce value 'double-float))
|>
|> to automatically convert the arguments of a foreign function call (i.e.,
|> to pass an integer when a C function expected a double).
|>
|> How can I achieve this using only the Allegro FFI?

(To the O.P.)

[AFAIK there is no documented way yet, so I hesitate to answer.
 HOPEFULLY I WILL BE CORRECTED IF THE INFORMATION BELOW IS INCORRECT.
 You have better chances of getting an answer from franz support if you
 posted your question on franz's `allegro-cl' mailing list.]

Briefly, you would use the as yet undocumented `user-conversion' feature
mentioned in Section 3.2.1, "def-foreign-call syntax" of
`doc/foreign-functions.htm'.

Something like:
	(defun my-convert-foo-arg (mode arg type lisp-type)
	    (case mode (:convert (coerce arg 'double-float))))

And if your function declaration was (say):  void foo (double)
You'd use: (ff:def-foreign-call foo ((arg :double double-float my-convert-foo-arg)))

(to Pascal)

| Allegro Common Lisp is compatible with CFFI, so you just use CFFI.

There may be good reasons to avoid CFFI.  I have several personal resons
after examining the CFFI code.

| If you really want to know, then you may just macroexpand the above forms.

And following the paths in that maze might possibly show you why CFFI is
more of an "Application" (which depends on a bunch of arbitrary
common-lisp.net libraries) and not a standalone "Library"

--
Madhu
From: Benjamin Tovar
Subject: Re: ffi automatic type translations
Date: 
Message-ID: <87eivn5nwj.fsf@the.google.mail.thing>
Madhu <·······@meer.net> writes:


> Briefly, you would use the as yet undocumented `user-conversion' feature
> mentioned in Section 3.2.1, "def-foreign-call syntax" of
> `doc/foreign-functions.htm'.
>
> Something like:
> 	(defun my-convert-foo-arg (mode arg type lisp-type)
> 	    (case mode (:convert (coerce arg 'double-float))))
>
> And if your function declaration was (say):  void foo (double)
> You'd use: (ff:def-foreign-call foo ((arg :double double-float
> my-convert-foo-arg)))

Thanks!, I will try this.

> And following the paths in that maze might possibly show you why CFFI is
> more of an "Application" (which depends on a bunch of arbitrary
> common-lisp.net libraries) and not a standalone "Library"

I want something to work that has the least number of dependencies, and
since I already have an allegro license...

-- 
From: Stelian Ionescu
Subject: Re: ffi automatic type translations
Date: 
Message-ID: <pan.2009.04.20.13.38.53@poste.it>
On Mon, 20 Apr 2009 09:33:52 +0530, Madhu wrote:
> | Allegro Common Lisp is compatible with CFFI, so you just use CFFI.
> 
> There may be good reasons to avoid CFFI.  I have several personal resons
> after examining the CFFI code.

such as ?
 
> | If you really want to know, then you may just macroexpand the above
> forms.
> 
> And following the paths in that maze might possibly show you why CFFI is
> more of an "Application" (which depends on a bunch of arbitrary
> common-lisp.net libraries) and not a standalone "Library"

3 deps are "a lot" ??

-- 
Stelian Ionescu a.k.a. fe[nl]ix
Quidquid latine dictum sit, altum videtur.
From: Madhu
Subject: Re: ffi automatic type translations
Date: 
Message-ID: <m34owjqtar.fsf@moon.robolove.meer.net>
* Stelian Ionescu <·······················@poste.it> :
Wrote on Mon, 20 Apr 2009 13:38:22 +0000 (UTC):
| On Mon, 20 Apr 2009 09:33:52 +0530, Madhu wrote:
|> | Allegro Common Lisp is compatible with CFFI, so you just use CFFI.
|> There may be good reasons to avoid CFFI.  I have several personal resons
|> after examining the CFFI code.
| such as ?

I stated "personal" reasons, so that I did not have to spend time in
discussing or debating them in public.[1], but the claim remains.

|> | If you really want to know, then you may just macroexpand the above
|> forms.
|> 
|> And following the paths in that maze might possibly show you why CFFI is
|> more of an "Application" (which depends on a bunch of arbitrary
|> common-lisp.net libraries) and not a standalone "Library"
|
| 3 deps are "a lot" ??

"a lot" or "a little", is not relevant to the point under consideration
which I am making here.

--
Madhu


[1] I suspect they would not be of interest to the CFFI community at
large (average common-lisp.net users, who do not care because their
needs are being met, or CFFI developers, because then its your design
choices and we obviously cannot see eye to eye over the impact of the
`problems' from your choices).  If you are not in those two categories,
and are still interested, (I cannot imagine why!), send me email