From: Damien Kick
Subject: Clisp FFI
Date: 
Message-ID: <m3vg3d3slm.fsf@IL27-5850.cig.mot.com>
I sent the following to the clist-list but thought I would see if I
could get some help here, too.

I'm having problems with attempting build my own FFI example based on
the example in the FFI implementation notes
<http://clisp.cons.org/impnotes/dffi.html> and would appreciate any
help.

    [····@login0 ~/tmp]% $DIR/clisp-link create-module-set f00f f00f-code.c
    [····@login0 ~/tmp]% gcc -c f00f-code.c 
    [····@login0 ~/tmp]% lf
    call-f00f.lisp	f00f/  f00f-code.c  f00f-code.o
    [····@login0 ~/tmp]% cd f00f
    [····@login0 tmp/f00f]% ln -s ../f00f-code.o
    [····@login0 tmp/f00f]% cd ..
    [····@login0 ~/tmp]% $DIR/base/lisp.run -M $DIR/base/lispinit.mem -c call-f00f.lisp 
      i i i i i i i       ooooo    o        ooooooo   ooooo   ooooo
      I I I I I I I      8     8   8           8     8     o  8    8
      I  \ `+' /  I      8         8           8     8        8    8
       \  `-+-'  /       8         8           8      ooooo   8oooo
        `-__|__-'        8         8           8           8  8
            |            8     o   8           8     o     8  8
      ------+------       ooooo    8oooooo  ooo8ooo   ooooo   8

    Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
    Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
    Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
    Copyright (c) Bruno Haible, Sam Steingold 1999-2002


    Compiling file /home/kick/tmp/call-f00f.lisp ...
    WARNING:
    SETQ(FFI::*FOREIGN-LANGUAGE*): #<PACKAGE FFI> is locked
    Ignore the lock and proceed
    WARNING in (DEFAULT-FOREIGN-LANGUAGE :STDC)-4 in line 4 :
    SETQ: assignment to the internal special symbol FFI::*FOREIGN-LANGUAGE*

    Wrote file /home/kick/tmp/call-f00f.fas
    Wrote file /home/kick/tmp/call-f00f.c
    0 errors, 1 warning
    Bye.
    [····@login0 ~/tmp]% $DIR/clisp-link add-module-set f00f $DIR/base base+f00f
    make: Warning: File `Makefile' has modification time 44 s in the future
    make: Nothing to be done for `clisp-module'.
    make: warning:  Clock skew detected.  Your build may be incomplete.
    /usr/test/npaero/local/sparc-sun-solaris2.6/bin/gcc -W -Wswitch -Wcomment -Wpointer-arith -Wimplicit -Wreturn-type -fomit-frame-pointer -Wno-sign-compare -O2 -fno-schedule-insns -fno-gcse -DUNIX_BINARY_DISTRIB -DUNICODE -DDYNAMIC_FFI -DNO_GETTEXT -DNO_SIGSEGV -I. -I/usr/test/awo/user_work/kick/sparc-sun-solaris2.6/lib/clisp/linkkit -c modules.c
    In file included from modules.d:11:
    /usr/test/awo/user_work/kick/sparc-sun-solaris2.6/lib/clisp/linkkit/clisp.h:2855: warning: call-clobbered register used for global register variable
    /usr/test/npaero/local/sparc-sun-solaris2.6/bin/gcc -W -Wswitch -Wcomment -Wpointer-arith -Wimplicit -Wreturn-type -fomit-frame-pointer -Wno-sign-compare -O2 -fno-schedule-insns -fno-gcse -DUNIX_BINARY_DISTRIB -DUNICODE -DDYNAMIC_FFI -DNO_GETTEXT -DNO_SIGSEGV -I. -x none modules.o f00f-code.o lisp.a libcharset.a libavcall.a libcallback.a -ltermcap -lnsl -lsocket -o lisp.run
    modules.o(.data+0x30): undefined reference to `module__f00f_code__subr_tab'
    modules.o(.data+0x34): undefined reference to `module__f00f_code__subr_tab_size'
    modules.o(.data+0x38): undefined reference to `module__f00f_code__object_tab'
    modules.o(.data+0x3c): undefined reference to `module__f00f_code__object_tab_size'
    modules.o(.data+0x44): undefined reference to `module__f00f_code__subr_tab_initdata'
    modules.o(.data+0x48): undefined reference to `module__f00f_code__object_tab_initdata'
    modules.o(.data+0x4c): undefined reference to `module__f00f_code__init_function_1'
    modules.o(.data+0x50): undefined reference to `module__f00f_code__init_function_2'
    collect2: ld returned 1 exit status
    [····@login0 ~/tmp]% lf
    base+f00f/   call-f00f.fas  call-f00f.lisp  f00f-code.c
    call-f00f.c  call-f00f.lib  f00f/	    f00f-code.o
    [····@login0 ~/tmp]% cat f00f-code.c
    #include <stdio.h>

    struct X { int i; };

    void f(struct X* p)
    {
        printf("p->i => %d\n", p->i);
    }
    [····@login0 ~/tmp]% cat call-f00f.lisp 
    (defpackage "CALL-F00F" (:use "LISP" "FFI"))
    (in-package "CALL-F00F")
    (def-c-struct X (i int))
    (default-foreign-language :stdc)
    (def-call-out f
        (:arguments (p (c-ptr X) :in :alloca))
      (:return-type nil))
    (defun call-f ()
      (f (make-X :i 5)))
    [····@login0 ~/tmp]% cat f00f/link.sh 
    file_list=''
    mod_list=''
    if test -r f00f-code.c; then
      file_list="$file_list"' f00f-code.o'
      mod_list="$mod_list"' f00f_code'
    fi
    make clisp-module CC="${CC}" CFLAGS="${CFLAGS}" INCLUDES="$absolute_linkkitdir"
    NEW_FILES="$file_list"
    NEW_LIBS="$file_list"
    NEW_MODULES="$mod_list"
    TO_LOAD=''
    [····@login0 ~/tmp]% cat call-f00f.c
    #include "clisp.h"

    extern object module__call_f00f__object_tab[];

    subr_t module__call_f00f__subr_tab[1];
    uintC module__call_f00f__subr_tab_size = 0;
    subr_initdata_t module__call_f00f__subr_tab_initdata[1];

    object module__call_f00f__object_tab[1];
    object_initdata_t module__call_f00f__object_tab_initdata[1];
    uintC module__call_f00f__object_tab_size = 0;

    extern void (f)();

    void module__call_f00f__init_function_1(module)
      var module_t* module;
    { }

    void module__call_f00f__init_function_2(module)
      var module_t* module;
    {
      register_foreign_function(&f,"f",1024);
    }
    [····@login0 ~/tmp]% 

Why is "call-f00f.c" not being included in the build?
From: Damien Kick
Subject: Re: Clisp FFI
Date: 
Message-ID: <m3pttl3rqh.fsf@IL27-5850.cig.mot.com>
Damien Kick <······@email.mot.com> writes:

> I'm having problems with attempting build my own FFI example [...]

I probably should've mentioned the following information in the first
post.

[····@login0 ~/tmp]% clisp --version
GNU CLISP 2.30 (released 2002-09-15) (built on login2 [10.17.192.178])
Features: 
(CLOS LOOP COMPILER CLISP ANSI-CL COMMON-LISP LISP=CL INTERPRETER SOCKETS
 GENERIC-STREAMS LOGICAL-PATHNAMES SCREEN FFI UNICODE BASE-CHAR=CHARACTER UNIX)
[····@login0 ~/tmp]% gcc --version
gcc (GCC) 3.1.1
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[····@login0 ~/tmp]% uname -a
SunOS login0 5.6 Generic_105181-29 sun4u sparc SUNW,Ultra-Enterprise Solaris
[····@login0 ~/tmp]%