[Ecls-list] using ECL with C programs, a test

Robert Lehr bozzio at the-lehrs.com
Wed Oct 15 18:07:08 UTC 2003


First, since I am asking for help, I should say that I will appreciate
any help in making this work.  Thanks.

Also, I think that, aside from the difficulty of actually embedding it
applications, I expect that ECL looks very promising for all of the features
that it offers as an embeddable ANSI-compliant Common Lisp.  I am very much
looking forward to making it work for me on my current project.

Now for my query.

So, I have studied the info pages along with some mailing-list threads
in response to queries from Mike Hannemann and Moshe Goldstein.

I want to use ECL inside a pre-existing C program, with its current main().
That immediately implies, AFAIK, that 'c:build-program' cannot be used for my
task.  I expect that I will be using the 'c:build-shared-library' function,
though, after my work has advanced.

I have developed a test-case that uses the model that (I think) is
described in the info pages where the C functions for the
ECL-interface are in a separate file, test.[ch] here.

When executed, I receive the following errors:

    $ ./ecl-test 1 "(x y) (princ '(x y))" 5 6 2>&1 | more
    MARK 1
    MARK 2
    MARK 3
    LAMBDA: Illegal lambda list X.
    0 is an illegal frs index.
              ^
              |
              +-- displayed 172 times
    Bind stack overflow.
    0 is an illegal frs index.
    Bind stack overflow.
    Bind stack overflow.
    0 is an illegal frs index.
    
    Unrecoverable error: bind stack overflow.

I "correct" the "Illegal lambda list X" error by wrapping more more
parens around the arg-list, although that should not be necessary.  It
definitely differs from the example in the "Bytecodes" section.

I then get this error.

    $ ./ecl-test 1 "((x y)) (princ '(x y))" 5 6 2>&1 | head
    MARK 1
    MARK 2
    MARK 3
    MARK 4
    MARK 5
    NIL is not of type FIXNUM.
    0 is an illegal frs index.
              ^
              |
              +-- displayed 172 times
    Bind stack overflow.
    0 is an illegal frs index.
    Bind stack overflow.
    Bind stack overflow.
    0 is an illegal frs index.
    
    Unrecoverable error: bind stack overflow.

The errors occur in the call to 'make_lambda()', as you can see in the
code below.  When I use a pre-defined function, e.g.,

    def= c_string_to_object("+");

the program works perfectly.

Why is this happening?  How can I fix it?  Is it a bug or an error in
my code/comprehension?

The code and build commands follow.n

    ecl-test.c:
        #include <ecl.h>
        #include <stdio.h>
        
        int do_with_xy( char* fxn, int x, int y, char* arg)
        {
          cl_object def;
          cl_object name;
          cl_object fun;
          cl_object result;
          int a=atoi(arg);
        
          fprintf(stderr,"MARK %d\n", a++);
        
          def=    c_string_to_object(fxn);
        
          fprintf(stderr,"MARK %d\n", a++);
        
          name=   _intern("foo",system_package);
        
          fprintf(stderr,"MARK %d\n", a++);
        
          fun=    make_lambda(name, def);
        
          fprintf(stderr,"MARK %d\n", a++);
        
          result= cl_funcall(3,fun, MAKE_FIXNUM(x), MAKE_FIXNUM(y));
        
          fprintf(stderr,"MARK %d\n", a++);
        
          return( fixint(result));
        }

    Built with

        $ gcc -c -g `ecl-config --cflags` ecl-test.c
        <command line>: warning: ISO C requires whitespace after the macro name
        $ gcc --shared -o ecl-test.so `ecl-config --ldflags` ecl-test.o

    main.c:
        #include <stdio.h>
        #include "ecl-test.h"
        
        int main( int argc, char** argv)
        {
          cl_fixnum x,y;
          char *fxn, *arg;
        
          arg= argv[1];
          fxn= argv[2];        // e.g., "(x y) (+ x y)"
          x=   atoi(argv[3]);
          y=   atoi(argv[4]);
        
          cl_boot(argc,argv);
          printf( "do_with_xy(\"%s\",%d,%d,%d)=%d\n",
            fxn, x, y, arg,
              do_with_xy(fxn,x,y,arg));
          return(1);
        }

    ecl-test.h:
        #include <ecl.h>
        int do_with_xy( char*, cl_fixnum, cl_fixnum, char*);

    Build with

        $ gcc -o ecl-test ecl-test.so main.o `ecl-config --ldflags`

-- 

Robert Lehr




More information about the ecl-devel mailing list