[plt-scheme] Adding primitive c procedure
At Thu, 24 Jul 2008 17:50:22 +0200, "Erlend Lorentzen" wrote:
> I'm trying to add a primitive c procedure to MzScheme. I can't show all the
> code, but I'm basically doing something like this:
Are you embedding the CGC or 3m variant of MzScheme?
>From the crash dump fragment, it looks like 3m --- but that's an
indirect guess, based on "scheme_add_global + 98" as a call to
scheme_do_add_global_symbol().
The C code you showed, meanwhile, didn't cooperate with the garbage
collector as required for 3m.
So that's my guess about that problem.
If you want to MzScheme to substitute for Guile, and if your
application has a wide interface with Scheme, then you probably want
the CGC variant. If the interface is narrow enough (e.g., just setting
up a few callback functions), then 3m could work, and you'll need to
help the GC see local and static variables when you call into Scheme.
I agree with the suggestions to use the FFI when possible. That
approach may insulate you from some 3m versus CGC issues, though you
still have to deal with the difference when calling into Scheme to get
things started.
Matthew