Subject: [clisp-list] dynamic loading of shared libraries/objects

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Thu Apr 4 23:51:02 2002

Silly me,

withholding dynload.d because of the low-level error reporting bug shouldn't prevent you from trying to compile the files on the various platforms (Linux, Solaris, HP, Mac etc.).

So I'll be happy to receive feedback on:
1. how dynload.d and especially sysdll.c (from XEmacs) compiles on all CLISP systems.
2. the various comments in dynload.d

You have to get sysdll.[ch] from:
http://xarch.tu-graz.ac.at/autocad/lsp_tools/ntemacs/emodules/dynaload/

>and it doesn't seem to be a package issue this time.
It was. Damn' PACKAGE-LOCK. Of course, "*TERMINAL-IO* was not a stream" didn't help point at the right location :-(

Enjoy,
	Jorg Hohle
PS: don't forget to add
MODULE(dynload)
to modules.h and recompile lisp.{run,exe}

For MS-Windows, I had to add #include "windows.h" to sysdll.c
My makefile.msvc6: look at -D stuff
################################ Joerg's dynload+regexp playground
REGEXDYNMODOBJECTS = \
dynload.obj \
sysdll.obj \
..\modules\regexp\regexp.obj \
..\modules\regexp\regexi.obj \
..\modules\regexp\regex.obj

dynload.c : dynload.d # comment5.exe ansidecl.exe varbrace.exe
	$(COMMENT5) dynload.d | $(ANSIDECL) | $(VARBRACE) > dynload.c
dynload.obj : dynload.c sysdll.h # clisp.h
	$(CPP) $(CFLAGS) dynload.c > dynload.i.c
	$(CC) $(CFLAGS) -c dynload.i.c
	$(RM) dynload.obj
	$(MV) dynload.i.obj dynload.obj
	$(RM) dynload.i.c
# don't -DUNICODE sysdll.c via CFLAGS or you'll get LoadLibraryW(), not -A
sysdll.obj : sysdll.c sysdll.h
	$(CC) -DCONST=const -DHAVE_SHLIB -DWIN32 $(CFLAGS) -UUNICODE -c sysdll.c

lispd.exe : $(REGEXDYNMODOBJECTS) $(OBJECTS) modules.obj avcall.lib callback.lib iconv.lib sigsegv.lib data
	$(RM) lisp.ilk
	$(CC) $(CFLAGS) $(CLFLAGS) $(REGEXDYNMODOBJECTS) $(OBJECTS) modules.obj $(LIBS) /link /out:lispd.exe
	editbin /stack:3145728 lispd.exe

---

From: Peter Wood <[email-masked]>
Date: Fri Apr 5 20:45:17 2002

Hi,

> 2. the various comments in dynload.d

THANKS!

On:

Linux localhost.localdomain 2.4.5 #1 Fri Jun 22 23:12:44 CEST 2001 i586 unknown
with a CVS clisp (about 10 days old).

bash-2.04$ ./base/lisp.run -B . -q -norc -M base/lispinit.mem 

[1]> (load "dynex.lisp")
;; Loading file dynex.lisp ...

#<FOREIGN-POINTER #x082927D0> is a foreign pointer

#<FOREIGN-ADDRESS #x08062624> is a foreign address

#<FOREIGN-FUNCTION "compress" #x08062624> is a foreign function of foreign 
type 
(FFI:C-FUNCTION
 (:ARGUMENTS
  ((:|arg1| (FFI:C-PTR (FFI:C-ARRAY FFI:UINT8 23)) :OUT :ALLOCA)
   (:|arg2| (FFI:C-PTR FFI:ULONG) :IN-OUT :ALLOCA)
   (:|arg3| (FFI:C-PTR (FFI:C-ARRAY FFI:UINT8 9)) :IN :ALLOCA)
   (:|arg4| FFI:ULONG :IN :NONE)))
 (:RETURN-TYPE FFI:INT :NONE) (:LANGUAGE :STDC)).
;; Loading of file dynex.lisp is finished.
T
[2]> 

This is extremely cool.

I didn't compile it together with regex.

I needed to add -DHAVE_DLOPEN to the CFLAGS for compiling sysdll.c,
(otherwise, although  it compiled fine,  #'foreign-library would not
work.).

Also, I commented out the #else #error comments in dynload.d, since
gcc didn't like them :-) Maybe I was forgetting something with cpp.

Thanks again.

(Joerg, I will be trying your mini-module in the bug report at
sourceforge on an old version of Clisp.  I will send you the results.)

Regards,
Peter