chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] How to FFI?


From: Robin Lee Powell
Subject: Re: [Chicken-users] How to FFI?
Date: Thu, 5 Jul 2007 08:48:35 -0700
User-agent: Mutt/1.5.13 (2006-08-11)

On Thu, Jul 05, 2007 at 09:35:26AM +0200, felix winkelmann wrote:
> On 7/4/07, Robin Lee Powell <address@hidden> wrote:
> >As a related question, something I ran across in libxmmsclient
> >that seems particularily tricky: a function with an int return
> >value, but an int32_t *foo argument where the *actual* data is
> >returned.
> >
> >In whichever method(s) you reccomend, how would I set up the
> >32-bit integer pointer, and then read data out of it after the
> >call?
> 
> ; manually:
> 
> (define foo (foreign-lambda int "foo" (c-pointer int)))
> 
> (let-location ((n int 0)) (my-function n) n)
> 
> or:
> 
> ; easyffi:
> 
> #>?
> int foo(___in int *x);
> <#
> 
> (foo 123)

I can't really follow the first version, but the second version
seems the opposite of what I was looking for; I don't care what I
pass in, I care about reading what gets written to *x.

I first tried:

#>?
int foo(int *x);
<#

(define-external val unsigned-int32)

(foo val)

But easyffi complained that the type wasn't u32vector, so I ended up
with:

(define intval (s32vector 999999))

(foo val)

which seems to work.

I have a similar function:

#>?
int bar(char *x);
<#

Which I'm handling like so:

(define-external vstring c-string "N/A")

(bar (location vstring))

Could I drop the (location ...) call by using ___out?

I guess it would just be:

(define vstring (bar))

, huh?

Oh, but http://chicken.wiki.br/easyffi says you can't do that with
strings; nevermind.

-Robin, still struggling with FFI, obviously.

-- 
http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/
Reason #237 To Learn Lojban: "Homonyms: Their Grate!"
Proud Supporter of the Singularity Institute - http://singinst.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]