Date: 15 Jul 1996 15:41:05 GMT
I've been playing with the C-interface of scheme48 (and scsh), and I'm
running into a small wall. Specifically, I'd like the C-function to
return multiple values.
I've been using scsh's CIG which works well for simple return values
and for moderate multiple return values, but for functions that
return, for example, a 32-member array of integers, it's possible but
terribly cumbersome to collect all of them as scheme_value's.
If I were to use CIG's interface to catch all 32 integers, I'd need a
declaration similar to this:
(to-scheme integer "getInt1")
(to-scheme integer "getInt2")
(to-scheme integer "getInt3")
(to-scheme integer "getInt31")
(to-scheme integer "getInt32")))
Yes, it is possible to not have to define all 32 auxiliary functions,
but this is not the point -- I'd like to not have to type in that line
Is it possible to just return a `list' of scheme_values instead of
individual items? I've been messing around with some of how CIG works
with it, but I keep getting core dumps, which are painful on my *slow*
(I'm also applying this type of approach to struct disassembly, but I
understand that due to its heterogenous composition, this is more
Any help would be appreciated.
You could arrange for your Scheme function to pass a 32-elt vector into
the C function, who would then stuff the answers (in the proper Scheme
representation) into the vector.
The big, big problem with Cig (actually with any Scheme 48 C interface) is
returning aggregate data structures, such as strings, arrays, or structs.
The problem is that there is no provision in S48 for allocating on the Scheme
heap from C code. So you have to do all allocation on the Scheme side. You
can always pass data structures into C, which is allowed to mutate them,
but it can't allocate new ones. Playing by these rules gets complicated
when you want your C function to return a vector whose size is not known
ahead of time. For example, scsh has a function that returns all the files
in a directory as a vector of strings. It's a pain to do this in scsh.