Hello,
I'm experimenting with Gambit as an embedded scripting engine (to replace a Lua-based one) inside a large application written in C. For the most part, the scm<->c interop is working well for my use-case.
I would now like to add a remote REPL for debugging and changing application logic on the fly. I added examples//web-repl.scm into my app and exposed start-repl-server within a c-define.
Surprisingly it works, but I notice that if I do ,q or ,qt the application segfaults. gdb bt is no help #0 0x00007ffff742c2b8 in siglongjmp () from /lib/libc.so.6 #1 0x00000000004c0f3c in ___call () #2 0x00000000004bff3e in start_repltest () #3 0x00000000004c0060 in main ()
Also, the application no longer responds to ctrl-c. Furthermore, as soon as I hit ctrl-c, the app starts eating up massive amount of cpu and ram. ram usage rapidly increase and segfaults when it runs out (goes from few megabytes to 8GB in less than a minute).
I've attached a small 30 line c file + web-repl based scm combo that reproduces this on my machine
Linux 2.6.33-ARCH #1 SMP PREEMPT Mon Apr 26 19:31:00 CEST 2010 x86_64 Intel(R) Xeon(R) CPU E5410 @ 2.33GHz GenuineIntel GNU/Linux
Gambit v4.6.0
Any suggestions would be much appreciated.
-Emit
Afficher les réponses par date
On 2010-05-25, at 2:14 PM, Emit Sorrels wrote:
Hello,
I'm experimenting with Gambit as an embedded scripting engine (to replace a Lua-based one) inside a large application written in C. For the most part, the scm<->c interop is working well for my use-case.
I would now like to add a remote REPL for debugging and changing application logic on the fly. I added examples//web-repl.scm into my app and exposed start-repl-server within a c-define.
Surprisingly it works, but I notice that if I do ,q or ,qt the application segfaults. gdb bt is no help #0 0x00007ffff742c2b8 in siglongjmp () from /lib/libc.so.6 #1 0x00000000004c0f3c in ___call () #2 0x00000000004bff3e in start_repltest () #3 0x00000000004c0060 in main ()
How exactly do you start the Scheme code? Ideally you should model your main program along the lines of lib/_setup.c . The important part is to delimit the C code which calls Scheme code inside a ___BEGIN_TRY and ___END_TRY pair so that exceptions (such as the one which is used to terminate the process when you enter ,q) will be caught, i.e.:
___BEGIN_TRY scheme_proc(1,2,3); // call Scheme procedure (defined using c-define) ___END_TRY
Moreover, if you want to catch Scheme exceptions in all REPL threads created, then you should set the right flags in setup_params.debug_settings . So the main function of your program will be:
int main (int argc, char **argv) { ___setup_params_struct setup_params; ___setup_params_reset (&setup_params);
setup_params.version = ___VERSION; setup_params.linker = SCHEME_LIBRARY_LINKER; setup_params.debug_settings = (___DEBUG_SETTINGS_UNCAUGHT_ALL << ___DEBUG_SETTINGS_UNCAUGHT_SHIFT) | (___DEBUG_SETTINGS_ERROR_REPL << ___DEBUG_SETTINGS_ERROR_SHIFT);
___setup (&setup_params);
{ ___SCMOBJ ___err; ___processor_state ___ps = ___PSTATE;
___BEGIN_TRY
start_repltest();
___END_TRY }
___cleanup ();
return 0; }
Also, the application no longer responds to ctrl-c.
It turns out that there were a few bugs in the implementation of the telnet protocol in example/web-repl.scm . I've attached a corrected repltest.scm file which fixes the problem. Now each REPL created will have its own thread-group and a CTRL-C at a REPL will interrupt all threads in that thread group.
Let me know if that works out for you.
Marc
On Thu, Jun 03, 2010 at 10:01:36PM -0400, Marc Feeley wrote:
It turns out that there were a few bugs in the implementation of the telnet protocol in example/web-repl.scm . I've attached a corrected repltest.scm file which fixes the problem. Now each REPL created will have its own thread-group and a CTRL-C at a REPL will interrupt all threads in that thread group.
Let me know if that works out for you.
Marc
Thank you Marc, the files you sent fixed the problem(s). I will have to study them more carefully to truly understand what they're doing, but for the time being I packaged up the code and uploaded it to the "Dumping Grounds" section of the wiki for anyone else who may wish to do something similar in the future.