[gambit-list] Returning a symbol to scheme from C

Alex Young alex at blackkettle.org
Tue Feb 19 05:38:57 EST 2013


On 18/02/2013 17:28, Mikael wrote:
>
> Symbols don't gc by default and they don't move, so their ___SCMOBJ
> representations remain constant across GC:s.
>
> Does this solve your problem? (of course you modify get-sy to not be a
> function of an input argument but to perform your desired function and
> return the symbol return value based on the result reached.)
>
> (c-declare "___SCMOBJ alex_symbols[123];")
> (define upload-sy! (c-lambda (int scheme-object) void
> "alex_symbols[___arg1] = ___arg2;"))
> (define get-sy (c-lambda (int) scheme-object "___result =
> alex_symbols[___arg1];"))

Ah, that's workable.  I hadn't thought of that.  It does seem like a 
duplication of effort, though - is there no way of usefully using the 
___S_foo symbols from C?

-- 
Alex


>
> Mikael
>
> 2013/2/18 Alex Young <alex at blackkettle.org <mailto:alex at blackkettle.org>>
>
>     Hi there,
>
>     I asked this question over on StackOverflow yesterday, but it's not had
>     any joy so far.
>
>     I've got a C function behind a c-lambda which needs to do some grubbing
>     around with a select(2) call and decide on a scheme symbol to return as
>     an indication of what it did, and whether an error condition occurred.
>     Basically I want to use that symbol as a signal to drive a transition in
>     a state machine.
>
>     How one gets hold of a named symbol as a ___SCMOBJ (or anything more
>     appropriate) from C isn't explained in the docs, and the wiki seems to
>     have fallen over. It's also not immediately obvious from gambit.h
>     whether there's a macro for this purpose.
>
>     I've tried doing this:
>
>         (define (foo) 'bar)
>
>     and taking a look at the C it generates, but it looks to me like
>     following this pattern only works if you know the offset into the symbol
>     table in advance.
>
>     Is this possible out of the box?  My workaround at the moment is to pass
>     in returnable symbols as arguments to the function, but with a larger
>     set of symbols I want to be able to return, that's going to get very
>     unwieldy very quickly.
>
>     Thanks,
>     --
>     Alex
>     _______________________________________________
>     Gambit-list mailing list
>     Gambit-list at iro.umontreal.ca <mailto:Gambit-list at iro.umontreal.ca>
>     https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
>
>




More information about the Gambit-list mailing list