From: Kevin M. Rosenberg Date: Wed, 8 Jun 2005 19:25:26 +0000 (+0000) Subject: r10575: 09 Jun 2005 Kevin Rosenberg X-Git-Tag: v3.8.6~142 X-Git-Url: http://git.kpe.io/?p=clsql.git;a=commitdiff_plain;h=e3924d6e872f06dce33c923b15c5d30baa31460c r10575: 09 Jun 2005 Kevin Rosenberg * clsql-mysql.asd: Renamed uffi/mysql interface library from mysql to uffi_mysql * db-mysql/uffi_mysql.c: Renamed from mysql.c * db-mysql/Makefile, db-mysql/mysql-loader.lisp: Rename shared library * db-*/*-loader.lisp: Commit big patch from Edi Weitz to remove absolute pathnames when searching for foreign libraries. * uffi/clsql-uffi-loader: New file from Edi Weitz for support foreign library loading. --- diff --git a/ChangeLog b/ChangeLog index b3df41b..42b193d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +09 Jun 2005 Kevin Rosenberg + * clsql-mysql.asd: Renamed uffi/mysql interface library from + mysql to uffi_mysql + * db-mysql/uffi_mysql.c: Renamed from mysql.c + * db-mysql/Makefile, db-mysql/mysql-loader.lisp: Rename shared library + * db-*/*-loader.lisp: Commit big patch from Edi Weitz to remove + absolute pathnames when searching for foreign libraries. + * uffi/clsql-uffi-loader: New file from Edi Weitz for support + foreign library loading. + 07 Jun 2005 Kevin Rosenberg * Version 3.1.16 * db-mysql/mysql-api.lisp: Commit patch from Espen Wiborn diff --git a/clsql-mysql.asd b/clsql-mysql.asd index 3780827..0092175 100644 --- a/clsql-mysql.asd +++ b/clsql-mysql.asd @@ -64,7 +64,7 @@ (error 'operation-error :component c :operation o)))) (defmethod operation-done-p ((o compile-op) (c clsql-mysql-source-file)) - (or (and (probe-file #p"/usr/lib/clsql/mysql.so") t) + (or (and (probe-file #p"/usr/lib/clsql/clsql_mysql.so") t) (let ((lib (make-pathname :defaults (component-pathname c) :type (uffi:default-foreign-library-type)))) (and (probe-file lib) diff --git a/db-db2/db2-loader.lisp b/db-db2/db2-loader.lisp index 70be078..8faf9e3 100644 --- a/db-db2/db2-loader.lisp +++ b/db-db2/db2-loader.lisp @@ -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 @@ set to the right path before compiling or loading the system.") *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 --git a/db-mysql/Makefile b/db-mysql/Makefile index dd47bc5..bd3cfd2 100644 --- a/db-mysql/Makefile +++ b/db-mysql/Makefile @@ -17,10 +17,11 @@ SUBDIRS= include ../Makefile.common -base=uffi_mysql +base=clsql_mysql source=$(base).c object=$(base).o -shared_lib=uffi_mysql.so +shared_lib=$(base).so + .PHONY: all all: $(shared_lib) diff --git a/db-mysql/clsql_mysql.c b/db-mysql/clsql_mysql.c new file mode 100644 index 0000000..d1bb084 --- /dev/null +++ b/db-mysql/clsql_mysql.c @@ -0,0 +1,153 @@ +/**************************************************************************** + * FILE IDENTIFICATION + * + * Name: clsql-mysql.c + * Purpose: Helper functions for mysql.cl to handle 64-bit parts of API + * Programmer: Kevin M. Rosenberg + * Date Started: Mar 2002 + * + * $Id$ + * + * This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg + * + * CLSQL users are granted the rights to distribute and use this software + * as governed by the terms of the Lisp Lesser GNU Public License + * (http://opensource.franz.com/preamble.html), also known as the LLGPL. + ***************************************************************************/ + +#ifdef WIN32 +#include + +BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll, DWORD fdwReason, + LPVOID lpvReserved) +{ + return 1; +} + +#define DLLEXPORT __declspec(dllexport) + +#else +#define DLLEXPORT +#endif + + +#include + +/* Need to assemble a 64-bit integer to send to MySQL */ +DLLEXPORT +void +clsql_mysql_data_seek (MYSQL_RES* res, unsigned int offset_high32, + unsigned int offset_low32) +{ + my_ulonglong offset; + + offset = offset_high32; + offset = offset << 32; + offset += offset_low32; + + mysql_data_seek (res, offset); +} + +/* The following functions are used to return 64-bit integers to Lisp. + They return the 32-bit low part and store in upper 32-bits in a + located sent via a pointer */ + +static const unsigned int bitmask_32bits = 0xFFFFFFFF; +#define lower_32bits(int64) ((unsigned int) int64 & bitmask_32bits) +#define upper_32bits(int64) ((unsigned int) (int64 >> 32)) + +DLLEXPORT +unsigned int +clsql_mysql_num_rows (MYSQL_RES* res, unsigned int* pHigh32) +{ + my_ulonglong nRows = mysql_num_rows (res); + *pHigh32 = upper_32bits(nRows); + return lower_32bits(nRows); +} + +DLLEXPORT +unsigned int +clsql_mysql_affected_rows (MYSQL* res, unsigned int* pHigh32) +{ + my_ulonglong nAffected = mysql_affected_rows (res); + *pHigh32 = upper_32bits(nAffected); + return lower_32bits(nAffected); +} + +DLLEXPORT +unsigned int +clsql_mysql_insert_id (MYSQL* mysql, unsigned int* pHigh32) +{ + my_ulonglong insert_id = mysql_insert_id (mysql); + *pHigh32 = upper_32bits(insert_id); + return lower_32bits(insert_id); +} + + +/* Accessor functions to hide the differences across MySQL versions */ + +DLLEXPORT +short int +clsql_mysql_field_type (MYSQL_FIELD* field) +{ + return field->type; +} + +DLLEXPORT +char* +clsql_mysql_field_name (MYSQL_FIELD* field) +{ + return field->name; +} + +DLLEXPORT +unsigned long +clsql_mysql_field_length (MYSQL_FIELD* field) +{ + return field->length; +} + +DLLEXPORT +unsigned long +clsql_mysql_field_max_length (MYSQL_FIELD* field) +{ + return field->max_length; +} + + +#if MYSQL_VERSION_ID >= 40102 +#include + +DLLEXPORT +MYSQL_BIND* +allocate_bind (unsigned int n) +{ + return (MYSQL_BIND*) malloc (n * sizeof(MYSQL_BIND)); +} + +DLLEXPORT +void +bind_param (MYSQL_BIND bind[], unsigned int n, unsigned long length, unsigned short is_null, + void* buffer, unsigned short buffer_type, unsigned long buffer_length) +{ + *bind[n].length = length; + *bind[n].is_null = is_null; + bind[n].buffer = buffer; + bind[n].buffer_type = buffer_type; + bind[n].buffer_length = buffer_length; +} + + +DLLEXPORT +DLLEXPORT +unsigned int +clsql_mysql_stmt_affected_rows (MYSQL_STMT* stmt, unsigned int* pHigh32) +{ + my_ulonglong nAffected = mysql_stmt_affected_rows (stmt); + *pHigh32 = upper_32bits(nAffected); + return lower_32bits(nAffected); +} + + +#endif + diff --git a/db-mysql/uffi_mysql.c b/db-mysql/uffi_mysql.c deleted file mode 100644 index d1bb084..0000000 --- a/db-mysql/uffi_mysql.c +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************************** - * FILE IDENTIFICATION - * - * Name: clsql-mysql.c - * Purpose: Helper functions for mysql.cl to handle 64-bit parts of API - * Programmer: Kevin M. Rosenberg - * Date Started: Mar 2002 - * - * $Id$ - * - * This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg - * - * CLSQL users are granted the rights to distribute and use this software - * as governed by the terms of the Lisp Lesser GNU Public License - * (http://opensource.franz.com/preamble.html), also known as the LLGPL. - ***************************************************************************/ - -#ifdef WIN32 -#include - -BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll, DWORD fdwReason, - LPVOID lpvReserved) -{ - return 1; -} - -#define DLLEXPORT __declspec(dllexport) - -#else -#define DLLEXPORT -#endif - - -#include - -/* Need to assemble a 64-bit integer to send to MySQL */ -DLLEXPORT -void -clsql_mysql_data_seek (MYSQL_RES* res, unsigned int offset_high32, - unsigned int offset_low32) -{ - my_ulonglong offset; - - offset = offset_high32; - offset = offset << 32; - offset += offset_low32; - - mysql_data_seek (res, offset); -} - -/* The following functions are used to return 64-bit integers to Lisp. - They return the 32-bit low part and store in upper 32-bits in a - located sent via a pointer */ - -static const unsigned int bitmask_32bits = 0xFFFFFFFF; -#define lower_32bits(int64) ((unsigned int) int64 & bitmask_32bits) -#define upper_32bits(int64) ((unsigned int) (int64 >> 32)) - -DLLEXPORT -unsigned int -clsql_mysql_num_rows (MYSQL_RES* res, unsigned int* pHigh32) -{ - my_ulonglong nRows = mysql_num_rows (res); - *pHigh32 = upper_32bits(nRows); - return lower_32bits(nRows); -} - -DLLEXPORT -unsigned int -clsql_mysql_affected_rows (MYSQL* res, unsigned int* pHigh32) -{ - my_ulonglong nAffected = mysql_affected_rows (res); - *pHigh32 = upper_32bits(nAffected); - return lower_32bits(nAffected); -} - -DLLEXPORT -unsigned int -clsql_mysql_insert_id (MYSQL* mysql, unsigned int* pHigh32) -{ - my_ulonglong insert_id = mysql_insert_id (mysql); - *pHigh32 = upper_32bits(insert_id); - return lower_32bits(insert_id); -} - - -/* Accessor functions to hide the differences across MySQL versions */ - -DLLEXPORT -short int -clsql_mysql_field_type (MYSQL_FIELD* field) -{ - return field->type; -} - -DLLEXPORT -char* -clsql_mysql_field_name (MYSQL_FIELD* field) -{ - return field->name; -} - -DLLEXPORT -unsigned long -clsql_mysql_field_length (MYSQL_FIELD* field) -{ - return field->length; -} - -DLLEXPORT -unsigned long -clsql_mysql_field_max_length (MYSQL_FIELD* field) -{ - return field->max_length; -} - - -#if MYSQL_VERSION_ID >= 40102 -#include - -DLLEXPORT -MYSQL_BIND* -allocate_bind (unsigned int n) -{ - return (MYSQL_BIND*) malloc (n * sizeof(MYSQL_BIND)); -} - -DLLEXPORT -void -bind_param (MYSQL_BIND bind[], unsigned int n, unsigned long length, unsigned short is_null, - void* buffer, unsigned short buffer_type, unsigned long buffer_length) -{ - *bind[n].length = length; - *bind[n].is_null = is_null; - bind[n].buffer = buffer; - bind[n].buffer_type = buffer_type; - bind[n].buffer_length = buffer_length; -} - - -DLLEXPORT -DLLEXPORT -unsigned int -clsql_mysql_stmt_affected_rows (MYSQL_STMT* stmt, unsigned int* pHigh32) -{ - my_ulonglong nAffected = mysql_stmt_affected_rows (stmt); - *pHigh32 = upper_32bits(nAffected); - return lower_32bits(nAffected); -} - - -#endif - diff --git a/db-odbc/odbc-loader.lisp b/db-odbc/odbc-loader.lisp index 07c77b0..b63a25a 100644 --- a/db-odbc/odbc-loader.lisp +++ b/db-odbc/odbc-loader.lisp @@ -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 @@ set to the right path before compiling or loading the system.") *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 --git a/db-oracle/oracle-loader.lisp b/db-oracle/oracle-loader.lisp index 7241402..9a970d3 100644 --- a/db-oracle/oracle-loader.lisp +++ b/db-oracle/oracle-loader.lisp @@ -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 @@ set to the right path before compiling or loading the system.") *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 --git a/db-postgresql/postgresql-loader.lisp b/db-postgresql/postgresql-loader.lisp index a7fefa9..8124bb9 100644 --- a/db-postgresql/postgresql-loader.lisp +++ b/db-postgresql/postgresql-loader.lisp @@ -33,24 +33,10 @@ set to the right path before compiling or loading the system.") (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 --git a/db-sqlite/sqlite-loader.lisp b/db-sqlite/sqlite-loader.lisp index 59baaee..27bea20 100644 --- a/db-sqlite/sqlite-loader.lisp +++ b/db-sqlite/sqlite-loader.lisp @@ -31,17 +31,10 @@ set to the right path before compiling or loading the system.") *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 --git a/db-sqlite3/sqlite3-loader.lisp b/db-sqlite3/sqlite3-loader.lisp index 9efaf1f..a3b26b8 100644 --- a/db-sqlite3/sqlite3-loader.lisp +++ b/db-sqlite3/sqlite3-loader.lisp @@ -31,16 +31,9 @@ set to the right path before compiling or loading the system.") *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 --git a/debian/changelog b/debian/changelog index 3abdab6..015d7a2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +cl-sql (3.1.17-1) unstable; urgency=low + + * New upstream + + -- Kevin M. Rosenberg Wed, 08 Jun 2005 13:25:06 -0600 + cl-sql (3.1.16-1) unstable; urgency=low * New upstream diff --git a/uffi/clsql-uffi-loader.lisp b/uffi/clsql-uffi-loader.lisp index 8b9efb7..05eee3f 100644 --- a/uffi/clsql-uffi-loader.lisp +++ b/uffi/clsql-uffi-loader.lisp @@ -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 @@ set to the right path before compiling or loading the system.") "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 --git a/uffi/clsql-uffi-package.lisp b/uffi/clsql-uffi-package.lisp index e5837a0..be5abf5 100644 --- a/uffi/clsql-uffi-package.lisp +++ b/uffi/clsql-uffi-package.lisp @@ -21,6 +21,7 @@ (defpackage #:clsql-uffi (:use #:cl #:uffi) (:export + #:find-and-load-foreign-library #:canonicalize-type-list #:convert-raw-field #:atoi