[plt-scheme] embedding - crash after scheme_basic_env

From: Dave Griffiths (dave at pawfal.org)
Date: Mon Mar 1 08:41:27 EST 2010

Hi all,

I've found a problem which manifests itself in 4.2.4. 

Using scheme_main_stack_setup I create a new interpreter using
scheme_basic_env, and everything works as expected. However, after
creating a new interpreter, and passing a string with an error such as
"(modulo 1 2 3)" I get a crash inside the error logger.

I suspect something needs to happen to the new Scheme_Env after it's
been created. Here is some code which reproduces the crash:

#define MZ_PRECISE_GC

#include "scheme.h"
#include "base.c"
#include <iostream>
using namespace std;

static Scheme_Env *e;

void register_interpreter()
{
    MZ_GC_DECL_REG(0);
    MZ_GC_REG();
    MZ_REGISTER_STATIC(e);
    MZ_GC_UNREG();  
}

void make_interpreter()
{
   Scheme_Object *v = NULL;
    
   MZ_GC_DECL_REG(1);
   MZ_GC_VAR_IN_REG(0, v);
   MZ_GC_REG();
    
   e=scheme_basic_env();
    
   declare_modules(e);
   v = scheme_intern_symbol("scheme/base");
   scheme_namespace_require(v);    
   MZ_GC_UNREG();
}

void interpret(const char *code)
{  
    mz_jmp_buf * volatile save = NULL, fresh;
    
    MZ_GC_DECL_REG(1);
    MZ_GC_VAR_IN_REG(0, save);
    MZ_GC_REG();
    
    save = scheme_current_thread->error_buf;
    scheme_current_thread->error_buf = &fresh;
    if (scheme_setjmp(scheme_error_buf)) {
        scheme_current_thread->error_buf = save;
        MZ_GC_UNREG();
        return; /* There was an error */
    } else {
        scheme_eval_string(code, e);       
    }   
    
    MZ_GC_UNREG();
}

static int run(void *data)
{
    register_interpreter();
    
    make_interpreter();
    interpret("(modulo 1 2 3)"); // <- returns error as expected
    make_interpreter();
    interpret("(modulo 1 2 3)"); // <- crash!
    
    return 0;
}

int main(int argc, char *argv[])
{
    return scheme_main_stack_setup(1, run, NULL);
}




Posted on the users mailing list.