From b34b26b6bf128faded4134ffbe7621ea401a1fd4 Mon Sep 17 00:00:00 2001 From: jgarcia Date: Mon, 23 Oct 2006 16:12:55 +0000 Subject: [PATCH] ECL now uses dlopen() in OS X so that shared libraries can be loaded. --- examples/ffi/uffi.lsp | 19 +++++++++++++++---- src/CHANGELOG | 3 +++ src/c/load.d | 20 +++++++++++--------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/examples/ffi/uffi.lsp b/examples/ffi/uffi.lsp index 85a34ecb5..a5d99b232 100644 --- a/examples/ffi/uffi.lsp +++ b/examples/ffi/uffi.lsp @@ -2,11 +2,22 @@ Build this module with (compile-file "uffi.lsp") Load it with (load "uffi.fas") |# - -(uffi:load-foreign-library "/usr/lib/libm.dylib") - +;; +;; This toplevel statement notifies the compiler that we will +;; need this shared library at runtime. We do not need this +;; statement in windows. +;; +#-windows +(uffi:load-foreign-library #+darwin "/usr/lib/libm.dylib" + #-darwin "/usr/lib/libm.so") +;; +;; With this other statement, we import the C function sin(), +;; which operates on IEEE doubles. +;; (uffi:def-function ("sin" c-sin) ((arg :double)) :returning :double) - +;; +;; We now use this function and compare with the lisp version. +;; (format t "~%Lisp sin:~t~d~%C sin:~t~d~%Difference:~t~d" (sin 1.0d0) (c-sin 1.0d0) (- (sin 1.0d0) (c-sin 1.0d0))) diff --git a/src/CHANGELOG b/src/CHANGELOG index 12f6a9848..5ad1b9fc1 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -96,6 +96,9 @@ ECL 1.0: - DESCRIBE was not prepare for the number range types returned by TYPE-OF. + - In OS X, ECL can now load shared libraries (Extension *.dylib) thanks + to using dlopen() instead of the obsolete NSLinkModule() function. + * Visible changes: - EXT:PROCESS-COMMAND-ARGS now allows for a default rule. diff --git a/src/c/load.d b/src/c/load.d index a2f02b9b6..163dad211 100644 --- a/src/c/load.d +++ b/src/c/load.d @@ -19,19 +19,21 @@ #include #ifdef ENABLE_DLOPEN -# ifdef HAVE_MACH_O_DYLD_H -# undef HAVE_DLFCN_H -# undef HAVE_LINK_H -# include -# define INIT_PREFIX "_init_" -# ifdef bool -# undef bool -# endif -# endif # ifdef HAVE_DLFCN_H # include # define INIT_PREFIX "init_" # endif +# ifdef HAVE_MACH_O_DYLD_H +# ifndef HAVE_DLFCN_H +# include +# define INIT_PREFIX "_init_" +# else +# undef HAVE_MACH_O_DYLD_H +# endif +# ifdef bool +# undef bool +# endif +# endif # ifdef HAVE_LINK_H # include # endif