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

Mikael mikael.rcv at gmail.com
Mon Feb 18 12:28:04 EST 2013


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];"))

Mikael

2013/2/18 Alex Young <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
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20130218/3e4c8408/attachment.htm>


More information about the Gambit-list mailing list