Re: How CLSQL finds and loads foreign libraries
Edi Weitz <[email protected]> Wed, 08 Jun 2005 03:24:10 +0200
| Newsgroups | gmane.lisp.clsql.devel,gmane.lisp.uffi.devel |
|---|---|
| Message-ID | <[email protected]> |
--=-=-= On Tue, 7 Jun 2005 12:38:00 -0600, Kevin Rosenberg <kevin-HJRc7zDS/[email protected]> wrote: > That's my understanding of your proposal. Sounds like a good win, > Edi. Sure, send me a patch when you are ready, I'll be glad to > review it. OK, here's my first attempt. With these patches I was able to load successfully the following combinations: SQLite3, Windows, LispWorks SQLite3, Windows, AllegroCL Oracle, Windows, LispWorks Oracle, Windows, AllegroCL PostgreSQL, Windows, LispWorks PostgreSQL, Windows, AllegroCL PostgreSQL, Linux, LispWorks PostgreSQL, Linux, AllegroCL PostgreSQL, Linux, CMUCL MySQL, Linux, LispWorks MySQL, Linux, AllegroCL MySQL, Linux, CMUCL That's about all I have installed. I tried with various locations for the foreign libs and it seems to work fine. Let me know what you think. Cheers, Edi. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=uffi.diff diff -ur uffi-1.4.37/doc/ref_func_libr.xml uffi-1.4.37.new/doc/ref_func_libr.xml --- uffi-1.4.37/doc/ref_func_libr.xml 2004-09-15 18:45:03.000000000 +0200 +++ uffi-1.4.37.new/doc/ref_func_libr.xml 2005-06-08 01:07:24.000000000 +0200 @@ -103,7 +103,10 @@ <listitem> <para>A string or pathname specifying the library location in the filesystem. At least one implementation (&lw;) can not -accept a logical pathname. +accept a logical pathname. If this parameter denotes a pathname without a +directory component then most of the supported Lisp implementations will be +able to find the library themselves if it is located in one of the standard +locations as defined by the underlying operating system. </para> </listitem> </varlistentry> diff -ur uffi-1.4.37/src/libraries.lisp uffi-1.4.37.new/src/libraries.lisp --- uffi-1.4.37/src/libraries.lisp 2004-09-15 18:45:01.000000000 +0200 +++ uffi-1.4.37.new/src/libraries.lisp 2005-06-08 02:55:36.000000000 +0200 @@ -81,10 +81,13 @@ force-load) #+(or allegro mcl) (declare (ignore module supporting-libraries)) #+(or cmu scl sbcl) (declare (ignore module)) - - (when (and filename (probe-file filename)) - (if (pathnamep filename) ;; ensure filename is a string to check if - (setq filename (namestring filename))) ; already loaded + #+lispworks (declare (ignore supporting-libraries)) + + (when (and filename (or (null (pathname-directory filename)) + (probe-file filename))) + (if (pathnamep filename) ;; ensure filename is a string to check if already loaded + (setq filename (namestring (if (null (pathname-directory filename)) + filename (truename filename))))) (if (and (not force-load) (find filename *loaded-libraries* :test #'string-equal)) @@ -111,7 +114,8 @@ (funcall (intern "LOAD-SHARED-OBJECT" :sb-alien) filename) (error c)))) - #+lispworks (fli:register-module module :real-name filename) + #+lispworks (fli:register-module module :real-name filename + :connection-style :immediate) #+allegro (load filename) #+openmcl (ccl:open-shared-library filename) #+(and mcl (not openmcl)) (ccl:add-to-shared-library-search-path filename t) diff -ur uffi-1.4.37/src/package.lisp uffi-1.4.37.new/src/package.lisp --- uffi-1.4.37/src/package.lisp 2004-10-07 21:37:35.000000000 +0200 +++ uffi-1.4.37.new/src/package.lisp 2005-06-08 01:45:24.000000000 +0200 @@ -75,6 +75,7 @@ #:find-foreign-library #:load-foreign-library #:default-foreign-library-type + #:foreign-library-types ;; OS #:run-shell-command --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=clsql.diff diff -ur clsql-3.1.15/db-db2/db2-loader.lisp clsql-3.1.15.new/db-db2/db2-loader.lisp --- clsql-3.1.15/db-db2/db2-loader.lisp 2004-09-15 18:45:20.000000000 +0200 +++ clsql-3.1.15.new/db-db2/db2-loader.lisp 2005-06-08 02:01:48.000000000 +0200 @@ -23,16 +23,13 @@ (append (pathname-directory (parse-namestring (concatenate 'string db2-home "/"))) - (list "lib")))))) + (list "lib")))))) -(defparameter *db2-client-library-path* - (uffi:find-foreign-library - "libdb2" - `(,@(when *load-truename* (list (make-pathname :directory (pathname-directory *load-truename*)))) - ,@(when *db2-lib-path* (list *db2-lib-path*)) - #+64bit "/opt/IBM/db2/V8.1/lib64/" - "/opt/IBM/db2/V8.1/lib/") - :drive-letters '("C"))) +(defparameter *db2-library-filenames* + (if *db2-lib-path* + (list (merge-pathnames "libdb2" *db2-lib-path*) + "libdb2") + "libdb2")) (defvar *db2-supporting-libraries* '("c") "Used only by CMU. List of library flags needed to be passed to ld to @@ -46,14 +43,11 @@ *db2-library-loaded*) (defmethod clsql-sys:database-type-load-foreign ((database-type (eql :db2))) - (if (pathnamep *db2-client-library-path*) - (progn - (uffi:load-foreign-library *db2-client-library-path* - :module "clsql-db2" - :supporting-libraries - *db2-supporting-libraries*) - (setq *db2-library-loaded* t)) - (warn "Unable to load db2 client library."))) + (clsql-uffi:find-and-load-foreign-library *db2-library-filenames* + :module "clsql-db2" + :supporting-libraries + *db2-supporting-libraries*) + (setq *db2-library-loaded* t)) (clsql-sys:database-type-load-foreign :db2) diff -ur clsql-3.1.15/db-mysql/mysql-loader.lisp clsql-3.1.15.new/db-mysql/mysql-loader.lisp --- clsql-3.1.15/db-mysql/mysql-loader.lisp 2005-01-29 01:37:45.000000000 +0100 +++ clsql-3.1.15.new/db-mysql/mysql-loader.lisp 2005-06-08 02:33:22.000000000 +0200 @@ -18,24 +18,16 @@ (in-package #:mysql) -(defparameter *clsql-mysql-library-path* - (uffi:find-foreign-library - '(#+(or 64bit x86-64) "mysql64" "mysql") - `(,clsql-mysql-system::*library-file-dir* - "/usr/lib/clsql/" - "/sw/lib/clsql/") - :drive-letters '("C"))) +(defparameter *clsql-mysql-library-candidate-names* + (list #+(or 64bit x86-64) (make-pathname :name "mysql64" + :directory (pathname-directory *load-truename*)) + #+(or 64bit x86-64) "mysql64" + (make-pathname :name "mysql" + :directory (pathname-directory *load-truename*)) + "mysql64")) (defvar *mysql-library-candidate-names* - '("libmysqlclient" "libmysql")) - -(defparameter *mysql-library-candidate-directories* - `(,(pathname-directory *load-pathname*) - #+(or 64bit x86-64) "/usr/lib64/" #+(or 64bit x86-64) "/usr/local/lib64/mysql/" - "/opt/mysql/lib/mysql/" "/usr/local/lib/" - "/usr/lib/" "/usr/local/lib/mysql/" "/usr/lib/mysql/" "/mysql/lib/opt/" "/sw/lib/mysql/" "/opt/local/lib/mysql/")) - -(defvar *mysql-library-candidate-drive-letters* '("C" "D" "E")) + '("libmysqlclient" "libmysql")) (defvar *mysql-supporting-libraries* '("c") "Used only by CMU. List of library flags needed to be passed to ld to @@ -49,21 +41,12 @@ *mysql-library-loaded*) (defmethod clsql-sys:database-type-load-foreign ((database-type (eql :mysql))) - (let ((mysql-path - (uffi:find-foreign-library *mysql-library-candidate-names* - *mysql-library-candidate-directories* - :drive-letters - *mysql-library-candidate-drive-letters*))) - (unless (probe-file mysql-path) - (error "Can't find mysql client library to load")) - (uffi:load-foreign-library mysql-path - :module "mysql" - :supporting-libraries - *mysql-supporting-libraries*) - (uffi:load-foreign-library *clsql-mysql-library-path* - :module "clsql-mysql" - :supporting-libraries - (append *mysql-supporting-libraries*))) + (clsql-uffi:find-and-load-foreign-library *mysql-library-candidate-names* + :module "mysql" + :supporting-libraries *mysql-supporting-libraries*) + (clsql-uffi:find-and-load-foreign-library *clsql-mysql-library-candidate-names* + :module "clsql-mysql" + :supporting-libraries *mysql-supporting-libraries*) (setq *mysql-library-loaded* t)) diff -ur clsql-3.1.15/db-odbc/odbc-loader.lisp clsql-3.1.15.new/db-odbc/odbc-loader.lisp --- clsql-3.1.15/db-odbc/odbc-loader.lisp 2004-09-15 18:45:21.000000000 +0200 +++ clsql-3.1.15.new/db-odbc/odbc-loader.lisp 2005-06-08 02:09:16.000000000 +0200 @@ -18,19 +18,8 @@ (in-package #:odbc) -(defparameter *odbc-library-path* - (uffi:find-foreign-library - '("odbc32" "libodbc" "libiodbc") - `(,(make-pathname :directory (pathname-directory *load-truename*)) - #+64bit "/usr/lib64/" - "/usr/lib/" - "/sw/lib/" - "/usr/local/lib/" - "/home/kevin/debian/src/clsql/db-odbc/" - "/windows/system32/" - "/winnt/system32/" - "/odbc/lib/opt/") - :drive-letters '("C"))) +(defparameter *odbc-library-filenames* + '("odbc32" "libodbc" "libiodbc")) (defvar *odbc-supporting-libraries* '("c") "Used only by CMU. List of library flags needed to be passed to ld to @@ -44,8 +33,8 @@ *odbc-library-loaded*) (defmethod clsql-sys:database-type-load-foreign ((database-type (eql :odbc))) - (uffi:load-foreign-library *odbc-library-path* - :module "odbc") + (clsql-uffi:find-and-load-foreign-library *odbc-library-filenames* + :module "odbc") (setq *odbc-library-loaded* t)) (clsql-sys:database-type-load-foreign :odbc) diff -ur clsql-3.1.15/db-oracle/oracle-loader.lisp clsql-3.1.15.new/db-oracle/oracle-loader.lisp --- clsql-3.1.15/db-oracle/oracle-loader.lisp 2004-09-24 19:11:47.000000000 +0200 +++ clsql-3.1.15.new/db-oracle/oracle-loader.lisp 2005-06-08 03:07:42.000000000 +0200 @@ -22,24 +22,14 @@ (parse-namestring (concatenate 'string oracle-home "/")))) "Pathname of ORACLE_HOME as set in user environment.") -(defparameter *oracle-client-library-path* - (uffi:find-foreign-library - '("libclntsh" "oci") - `(,@(when *load-truename* - (list (make-pathname - :directory (pathname-directory *load-truename*)))) - ,@(when *oracle-home* - (list - (make-pathname :defaults *oracle-home* - :directory - (append (pathname-directory *oracle-home*) - (list "lib"))) - (make-pathname :defaults *oracle-home* - :directory - (append (pathname-directory *oracle-home*) - (list "bin"))))) - "/usr/lib/oracle/10.1.0.2/client/lib/") - :drive-letters '("C"))) +(defparameter *oracle-client-library-filenames* + (list* "libclntsh" "oci" + (when *oracle-home* + (loop for dir-name in '("lib" "bin") + nconc (loop for lib-name in '("libclntsh" "oci") + collect (make-pathname :defaults lib-name + :directory (append (pathname-directory *oracle-home*) + (list dir-name)))))))) (defvar *oracle-supporting-libraries* '("c") "Used only by CMU. List of library flags needed to be passed to ld to @@ -53,14 +43,10 @@ *oracle-library-loaded*) (defmethod clsql-sys:database-type-load-foreign ((database-type (eql :oracle))) - (if (pathnamep *oracle-client-library-path*) - (progn - (uffi:load-foreign-library *oracle-client-library-path* - :module "clsql-oracle" - :supporting-libraries - *oracle-supporting-libraries*) - (setq *oracle-library-loaded* t)) - (warn "Unable to load oracle client library."))) + (clsql-uffi:find-and-load-foreign-library *oracle-client-library-filenames* + :module "clsql-oracle" + :supporting-libraries *oracle-supporting-libraries*) + (setq *oracle-library-loaded* t)) (clsql-sys:database-type-load-foreign :oracle) diff -ur clsql-3.1.15/db-postgresql/postgresql-loader.lisp clsql-3.1.15.new/db-postgresql/postgresql-loader.lisp --- clsql-3.1.15/db-postgresql/postgresql-loader.lisp 2005-04-27 17:37:04.000000000 +0200 +++ clsql-3.1.15.new/db-postgresql/postgresql-loader.lisp 2005-06-08 02:14:20.000000000 +0200 @@ -33,24 +33,10 @@ (defmethod clsql-sys:database-type-load-foreign ((database-type (eql :postgresql))) - (let ((libpath (uffi:find-foreign-library - "libpq" - '("/opt/postgresql/lib/" "/usr/local/lib/" - #+(or 64bit x86-64) "/usr/lib64/" - "/usr/lib/" "/postgresql/lib/" - "/usr/local/pgsql/lib/" "/usr/lib/pgsql/" - "/opt/pgsql/lib/pgsql" "/sw/lib/pgsql/" "/sw/lib/" - "/windows/system32/") - :drive-letters '("C" "D" "E") - #+(or macosx darwin ccl-5.0) :types - #+(or macosx darwin ccl-5.0) '("so" "dylib") - ))) - (if (uffi:load-foreign-library libpath - :module "postgresql" - :supporting-libraries - *postgresql-supporting-libraries*) - (setq *postgresql-library-loaded* t) - (warn "Can't load PostgreSQL client library ~A" libpath)))) + (clsql-uffi:find-and-load-foreign-library "libpq" + :module "postgresql" + :supporting-libraries *postgresql-supporting-libraries*) + (setq *postgresql-library-loaded* t)) (clsql-sys:database-type-load-foreign :postgresql) diff -ur clsql-3.1.15/db-sqlite/sqlite-loader.lisp clsql-3.1.15.new/db-sqlite/sqlite-loader.lisp --- clsql-3.1.15/db-sqlite/sqlite-loader.lisp 2004-09-15 18:45:21.000000000 +0200 +++ clsql-3.1.15.new/db-sqlite/sqlite-loader.lisp 2005-06-08 02:15:26.000000000 +0200 @@ -31,17 +31,10 @@ *sqlite-library-loaded*) (defmethod database-type-load-foreign ((database-type (eql :sqlite))) - (let ((libpath (uffi:find-foreign-library - '("libsqlite" "sqlite") - '(#+64bit "/usr/lib64/" - "/usr/lib/" "/usr/local/lib/" "/bin/") - :drive-letters '("C" "D" "E")))) - (if (uffi:load-foreign-library libpath - :module "sqlite" - :supporting-libraries - *sqlite-supporting-libraries*) - (setq *sqlite-library-loaded* t) - (warn "Can't load SQLite library ~A" libpath)))) + (clsql-uffi:find-and-load-foreign-library '("libsqlite" "sqlite") + :module "sqlite" + :supporting-libraries *sqlite-supporting-libraries*) + (setq *sqlite-library-loaded* t)) (clsql-sys:database-type-load-foreign :sqlite) diff -ur clsql-3.1.15/db-sqlite3/sqlite3-loader.lisp clsql-3.1.15.new/db-sqlite3/sqlite3-loader.lisp --- clsql-3.1.15/db-sqlite3/sqlite3-loader.lisp 2004-12-21 08:24:58.000000000 +0100 +++ clsql-3.1.15.new/db-sqlite3/sqlite3-loader.lisp 2005-06-08 02:16:04.000000000 +0200 @@ -31,16 +31,9 @@ *sqlite3-library-loaded*) (defmethod database-type-load-foreign ((database-type (eql :sqlite3))) - (let ((libpath (uffi:find-foreign-library - '("libsqlite3" "sqlite3") - '(#+64bit "/usr/lib64/" - "/usr/lib/" "/usr/local/lib/" "/bin/") - :drive-letters '("C" "D" "E")))) - (if (uffi:load-foreign-library libpath - :module "sqlite3" - :supporting-libraries - *sqlite3-supporting-libraries*) - (setq *sqlite3-library-loaded* t) - (warn "Can't load Sqlite3 library ~A" libpath)))) + (clsql-uffi:find-and-load-foreign-library '("libsqlite3" "sqlite3") + :module "sqlite3" + :supporting-libraries *sqlite3-supporting-libraries*) + (setq *sqlite3-library-loaded* t)) (clsql-sys:database-type-load-foreign :sqlite3) diff -ur clsql-3.1.15/uffi/clsql-uffi-loader.lisp clsql-3.1.15.new/uffi/clsql-uffi-loader.lisp --- clsql-3.1.15/uffi/clsql-uffi-loader.lisp 2005-01-29 01:37:45.000000000 +0100 +++ clsql-3.1.15.new/uffi/clsql-uffi-loader.lisp 2005-06-08 03:05:16.000000000 +0200 @@ -18,12 +18,29 @@ (in-package #:clsql-uffi) -(defvar *clsql-uffi-library-filename* - (uffi:find-foreign-library - '(#+(or 64bit x86-64) "uffi64" "uffi") - `(,clsql-uffi-system::*library-file-dir* - "/usr/lib/clsql/") - :drive-letters '("C"))) +(defun find-and-load-foreign-library (filenames &key module supporting-libraries (errorp t)) + (setq filenames (if (listp filenames) filenames (list filenames))) + (or (loop for type in (uffi:foreign-library-types) + for suffix = (make-pathname :type type) + thereis (loop for filename in filenames + thereis (handler-case + (uffi:load-foreign-library (merge-pathnames filename suffix) + :module module + :supporting-libraries supporting-libraries) + (error (c) + (warn "~A" c) + nil)))) + (when errorp + (error "Couldn't load foreign librar~@P ~{~S~^, ~}." + (length filenames) filenames)))) + +(defvar *clsql-uffi-library-filenames* + (list #+(or 64bit x86-64) (make-pathname :name "uffi64" + :directory clsql-uffi-system::*library-file-dir*) + #+(or 64bit x86-64) "uffi64" + (make-pathname :name "uffi" + :directory clsql-uffi-system::*library-file-dir*) + "uffi")) (defvar *clsql-uffi-supporting-libraries* '("c") "Used only by CMU. List of library flags needed to be passed to ld to @@ -34,15 +51,11 @@ "T if foreign library was able to be loaded successfully") (defun load-uffi-foreign-library () - (unless (probe-file *clsql-uffi-library-filename*) - (error "Unable to find uffi.so")) - - (if (uffi:load-foreign-library *clsql-uffi-library-filename* - :module "clsql-uffi" - :supporting-libraries - *clsql-uffi-supporting-libraries*) - (setq *uffi-library-loaded* t) - (error "Unable to load helper library ~A" *clsql-uffi-library-filename*))) + (find-and-load-foreign-library *clsql-uffi-library-filenames* + :module "clsql-uffi" + :supporting-libraries + *clsql-uffi-supporting-libraries*) + (setq *uffi-library-loaded* t)) (load-uffi-foreign-library) diff -ur clsql-3.1.15/uffi/clsql-uffi-package.lisp clsql-3.1.15.new/uffi/clsql-uffi-package.lisp --- clsql-3.1.15/uffi/clsql-uffi-package.lisp 2004-09-15 18:45:20.000000000 +0200 +++ clsql-3.1.15.new/uffi/clsql-uffi-package.lisp 2005-06-08 01:51:26.000000000 +0200 @@ -21,6 +21,7 @@ (defpackage #:clsql-uffi (:use #:cl #:uffi) (:export + #:find-and-load-foreign-library #:canonicalize-type-list #:convert-raw-field #:atoi --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ CLSQL-Devel mailing list [email protected] http://lists.b9.com/mailman/listinfo/clsql-devel --=-=-=--