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: Zbigniew
Subject: Re: [Chicken-users] How to FFI?
Date: Thu, 5 Jul 2007 12:25:12 -0500

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))




reply via email to

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