[Ecls-list] Segmentation faults/detected access to ...address

Seth Burleigh seth at tewebs.com
Sat Mar 13 16:08:49 UTC 2010


So, i decided that I would try to get a c REPL going which would also
catch any errors with incorrectly entered code (not go into the
debugger). Cool stuff , ecl:)
Anyways, I found that whenever I entered an statement which would
generate an error, like the letter a, the program exits with a
segmentation fault. Im not exactly sure why entering an invalid
statement would generate one. I was also wondering if ecl was supposed
to catch all segmentation faults which resuled from lisp code executing
inside of it? According to this:
http://ecls.sourceforge.net/new-manual/re41.html
SIGSEGV should be caught automatically? I noticed that if i used
cl_eval, everything would work, it would just go into the debugger.
Also, I noticed that if i uncommented the code below it would produce a
"Detected acccess to an invalid or protected memory address" and would
throw me into the lisp debugger. I know this has something to do with
'puts' expecting a constant char* while the statement obj==OBJNULL
returns an int, but I would like to understand what exactly is causing
this error.

Heres the code: 

#include <ecl/ecl.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char **argv)  {
  cl_boot(argc, argv);
  cl_env_ptr env = ecl_process_env();
  while (1) {
    printf(">>");
    int nbytes = 100;
    char *str = (char*)malloc(nbytes);
    getline(&str,&nbytes,stdin);
    if (strcmp(str,"exit\n")==0 ) {
      break;
    }    
    
    cl_object obj = c_string_to_object(str);

    //uncommented code below produced unprotected access error
    //puts(obj==OBJNULL);

    CL_CATCH_ALL_BEGIN(env) {
      cl_object evaled = cl_safe_eval(obj,(cl_object)env,Cnil);
      cl_pprint(1,evaled);
    } CL_CATCH_ALL_IF_CAUGHT {
      puts("ERROR");
    } CL_CATCH_ALL_END;
  }
  cl_shutdown();
}






More information about the ecl-devel mailing list