This is the mail archive of the guile@cygnus.com mailing list for the guile project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
I was almost going to send this to bug-guile, but I am not sure it is
entirely a bug, and perhaps what I really want is another way to do
what I'm thinking. I'd like to use continuations to jump back and
forth between Scheme and C code, with the Scheme code preferably being
evaluated from a string inside the C code. The problem is that this
explodes, because scm_eval_string, which is what ultimately gets
called to deal with evaluating a string file, closes the port it
internally creates when it exits, and can't deal if it is re-entered
via a continuation. A simple example program will show what I mean:
---- begin cont-test.c ---
#include <guile/gh.h>
void g_main(int argc, char **argv);
int main(int argc, char **argv) {
gh_enter(argc,argv,g_main);
}
void g_main(int argc, char **argv) {
SCM x;
x = gh_eval_str("(call-with-current-continuation (lambda (cont)"
"(lambda ()"
"(display 37)"
"(newline)"
"(cont cont))))");
gh_display(x);
gh_newline();
gh_call0(x);
}
---- end cont-test.c ----
The output I get is something like this:
#<procedure ()>
37
guile: Wrong type argument in position 1: #<closed: string 0>
having read the definition of scm_eval_string I am pretty sure that
what is happening is that scm_eval_string is getting re-entered and is
choking on the port that it closed. If people consider this a bug, the
only solution I can see is to use something like dynamic-wind from the
C side, the way call-with-input-port and such use it on the Scheme
side -- tricky to say the least. What I would really like is a
workaround that will allow me to get a similar effect. primitive-load
will not be any more helpful than eval-string; it suffers from the
same problem of closing its port the first time it returns. Can anyone
suggest what I can do?
- Maciej Stachowiak