[Top][All Lists]
[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 10:55:16 -0700 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
Well, what I've got is working, I was just wondering if ___out could
make it simpler. Since out doesn't work with strings, I guess not.
Anyways, here's the function:
http://doxygen.xmms2.xmms.se/clientlib/stable/xmmsclient/group__ResultValueRetrieval.html#gcabbd913954d7ad92b6d2179f1fb6a5d
-Robin
On Thu, Jul 05, 2007 at 12:25:12PM -0500, Zbigniew wrote:
> Hello,
>
> Could you post the actual function name, signature and description.
> It may be better to write a small wrapper here but we can't know that
> from just the signature. For example does this function malloc a
> string and return the pointer, expect you to malloc enough space for a
> string and pass -it- the pointer, return a static string pointer, do
> you have to free the returned pointer ... etc. Also, char** seems
> more appropriate so I'm confused.
>
> As an example, let's say your function is returning a pointer to a
> static string (into its argument) along with the return code. You
> might be able to write a little wrapper which returns the string
> directly, or #f if the return code was bad (or the pointer was null).
> This is self-contained code:
>
> #>!
> char *wrap_bar(void) {
> char *ptr;
> if (bar(&ptr) != 0)
> return NULL;
> else
> return ptr;
> }
> <#
>
> #>
> int bar(char **ptr) {
> static char baz[] = "hello";
> *ptr = (char *)baz;
> return 0; // failure code
> }
> <#
>
> Add ___discard to wrap_bar() if bar() expects you to free the string;
> also it's just as easy to use foreign-lambda* for the wrapper.
>
> On 7/5/07, Robin Lee Powell <address@hidden> wrote:
> >#>?
> >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))
>
>
> _______________________________________________
> Chicken-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/chicken-users
--
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/
Re: [Chicken-users] How to FFI?, Robin Lee Powell, 2007/07/03