[elephant-cvs] CVS elephant/src/db-bdb

ieslick ieslick at common-lisp.net
Sat Nov 11 18:41:10 UTC 2006


Update of /project/elephant/cvsroot/elephant/src/db-bdb
In directory clnet:/tmp/cvs-serv20360/src/db-bdb

Modified Files:
	bdb-collections.lisp bdb-controller.lisp bdb-transactions.lisp 
	package.lisp 
Added Files:
	libberkeley-db.c libberkeley-db.def 
Removed Files:
	libsleepycat.c libsleepycat.def sleepycat.lisp 
Log Message:

Remove all references to sleepycat; change to bdb db-bdb or 
berkeley-db; passes all test for BDB and SQLite on Allegro/Mac OS/32-bit



--- /project/elephant/cvsroot/elephant/src/db-bdb/bdb-collections.lisp	2006/09/04 04:56:50	1.9
+++ /project/elephant/cvsroot/elephant/src/db-bdb/bdb-collections.lisp	2006/11/11 18:41:10	1.10
@@ -17,7 +17,7 @@
 ;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;
 
-(in-package "SLEEPYCAT")
+(in-package :db-bdb)
 
 (defclass bdb-btree (btree) ()
   (:documentation "A BerkleyDB implementation of a BTree"))
--- /project/elephant/cvsroot/elephant/src/db-bdb/bdb-controller.lisp	2006/09/05 03:23:16	1.12
+++ /project/elephant/cvsroot/elephant/src/db-bdb/bdb-controller.lisp	2006/11/11 18:41:10	1.13
@@ -17,7 +17,7 @@
 ;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;
 
-(in-package "SLEEPYCAT")
+(in-package :db-bdb)
 
 (defclass bdb-store-controller (store-controller)
   ((db :type (or null pointer-void) :accessor controller-db :initform '())
@@ -78,24 +78,24 @@
 	       :auto-commit t :type DB-BTREE :create t :thread thread)
 
       (setf (controller-btrees sc) btrees)
-      (sleepycat::db-set-lisp-compare btrees)
+      (db-bdb::db-set-lisp-compare btrees)
       (db-open btrees :file "%ELEPHANT" :database "%ELEPHANTBTREES" 
 	       :auto-commit t :type DB-BTREE :create t :thread thread)
 
       (setf (controller-indices sc) indices)
-      (sleepycat::db-set-lisp-compare indices)
-      (sleepycat::db-set-lisp-dup-compare indices)
+      (db-bdb::db-set-lisp-compare indices)
+      (db-bdb::db-set-lisp-dup-compare indices)
       (db-set-flags indices :dup-sort t)
       (db-open indices :file "%ELEPHANT" :database "%ELEPHANTINDICES" 
 	       :auto-commit t :type DB-BTREE :create t :thread thread)
 
       (setf (controller-indices-assoc sc) indices-assoc)
-      (sleepycat::db-set-lisp-compare indices-assoc)
-      (sleepycat::db-set-lisp-dup-compare indices-assoc)
+      (db-bdb::db-set-lisp-compare indices-assoc)
+      (db-bdb::db-set-lisp-dup-compare indices-assoc)
       (db-set-flags indices-assoc :dup-sort t)
       (db-open indices-assoc :file "%ELEPHANT" :database "%ELEPHANTINDICES" 
 	       :auto-commit t :type DB-UNKNOWN :thread thread :rdonly t)
-      (sleepycat::db-fake-associate btrees indices-assoc :auto-commit t)
+      (db-bdb::db-fake-associate btrees indices-assoc :auto-commit t)
       
       (let ((db (db-create env)))
 	(setf (controller-oid-db sc) db)
--- /project/elephant/cvsroot/elephant/src/db-bdb/bdb-transactions.lisp	2006/04/26 19:19:12	1.3
+++ /project/elephant/cvsroot/elephant/src/db-bdb/bdb-transactions.lisp	2006/11/11 18:41:10	1.4
@@ -17,7 +17,7 @@
 ;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;
 
-(in-package "SLEEPYCAT")
+(in-package :db-bdb)
 
 (defmethod execute-transaction ((sc bdb-store-controller) txn-fn
 				&key 
@@ -60,7 +60,7 @@
 	     (return result))))
        finally (error "Too many retries in transaction"))))
     
-;;     (with-sleepycat-transaction (:transaction ,transaction
+;;     (with-bdb-transaction (:transaction ,transaction
 ;; 					      :environment env
 ;; 					      :parent ,parent
 ;; 					      :degree-2 ,degree-2
--- /project/elephant/cvsroot/elephant/src/db-bdb/package.lisp	2006/02/19 04:53:00	1.1
+++ /project/elephant/cvsroot/elephant/src/db-bdb/package.lisp	2006/11/11 18:41:10	1.2
@@ -19,13 +19,13 @@
 
 (in-package :cl-user)
 
-(defpackage sleepycat
-  (:documentation "A low-level UFFI-based interface to
-   Berkeley DB / Sleepycat to implement the elephant front-end
-   framework.  Uses the libsleepycat.c wrapper.  Partly intended 
-   to be usable outside Elephant, but with some magic for Elephant.  
-   In general there is a 1-1 mapping from functions here and 
-   functions in Sleepycat, so refer to their documentation for details.")
+(defpackage db-bdb
+  (:documentation "A low-level UFFI-based interface to Berkeley
+   DB to implement the elephant front-end framework.  Uses the
+   libelebdb.c wrapper.  Partly intended to be usable outside
+   Elephant, but with some magic for Elephant.  In general there
+   is a 1-1 mapping from functions here and functions in
+   Berkeley DB, so refer to their documentation for details.")
   (:use common-lisp uffi elephant-memutil elephant elephant-backend)
   #+cmu
   (:use alien)

--- /project/elephant/cvsroot/elephant/src/db-bdb/libberkeley-db.c	2006/11/11 18:41:10	NONE
+++ /project/elephant/cvsroot/elephant/src/db-bdb/libberkeley-db.c	2006/11/11 18:41:10	1.1
/*
;;;
;;; libsleepycat.c -- C wrappers for Sleepycat for FFI
;;; 
;;; Initial version 8/26/2004 by Ben Lee
;;; <blee at common-lisp.net>
;;; 
;;; part of
;;;
;;; Elephant: an object-oriented database for Common Lisp
;;;
;;; Copyright (c) 2004 by Andrew Blumberg and Ben Lee
;;; <ablumberg at common-lisp.net> <blee at common-lisp.net>
;;;
;;; This program is released under the following license
;;; ("GPL").  For differenct licensing terms, contact the
;;; copyright holders.
;;;
;;; This program is free software; you can redistribute it
;;; and/or modify it under the terms of the GNU General
;;; Public License as published by the Free Software
;;; Foundation; either version 2 of the License, or (at
;;; your option) any later version.
;;;
;;; This program is distributed in the hope that it will be
;;; useful, but WITHOUT ANY WARRANTY; without even the
;;; implied warranty of MERCHANTABILITY or FITNESS FOR A
;;; PARTICULAR PURPOSE. See the GNU General Public License
;;; for more details.
;;;
;;; The GNU General Public License can be found in the file
;;; LICENSE which should have been distributed with this
;;; code.  It can also be found at
;;;
;;; http://www.opensource.org/licenses/gpl-license.php
;;;
;;; You should have received a copy of the GNU General
;;; Public License along with this program; if not, write
;;; to the Free Software Foundation, Inc., 59 Temple Place,
;;; Suite 330, Boston, MA 02111-1307 USA
;;;
;;; Portions of this program (namely the C unicode string
;;; sorter) are derived from IBM's ICU:
;;;
;;; http://oss.software.ibm.com/icu/
;;;
;;; Copyright (c) 1995-2003 International Business Machines
;;; Corporation and others All rights reserved.
;;;
;;; ICU's copyright, license and warranty can be found at
;;;
;;; http://oss.software.ibm.com/cvs/icu/~checkout~/icu/license.html
;;;
;;; or in the file LICENSE.
;;;
*/

#include <string.h>
#include <wchar.h>

/* Some utility stuff used to be here but has been placed in
   libmemutil.c  */

/* Pointer arithmetic utility functions */
/* should these be in network-byte order? probably not..... */
/* Pointer arithmetic utility functions */
/* should these be in network-byte order? probably not..... */
int read_int(char *buf, int offset) {
  int i;
  memcpy(&i, buf+offset, sizeof(int));
  return i;
}

unsigned int read_uint(char *buf, int offset) {
  unsigned int ui; 
  memcpy(&ui, buf+offset, sizeof(unsigned int));
  return ui;
}

float read_float(char *buf, int offset) {
  float f;
  memcpy(&f, buf+offset, sizeof(float));
  return f;
}

double read_double(char *buf, int offset) {
  double d;
  memcpy(&d, buf+offset, sizeof(double));
  return d;
}

void write_int(char *buf, int num, int offset) {
  memcpy(buf+offset, &num, sizeof(int));
}

void write_uint(char *buf, unsigned int num, int offset) {
  memcpy(buf+offset, &num, sizeof(unsigned int));
}

void write_float(char *buf, float num, int offset) {
  memcpy(buf+offset, &num, sizeof(float));
}

void write_double(char *buf, double num, int offset) {
  memcpy(buf+offset, &num, sizeof(double));
}

char *offset_charp(char *p, int offset) {
  return p + offset;
}

void copy_buf(char *dest, int dest_offset, char *src, int src_offset, 
	      int length) {
  memcpy(dest + dest_offset, src + src_offset, length);
}


/* Berkeley DB stuff */

#include <db.h>

/* Environment */

/* All "creation" functions return the create object, not the errno.
   This simplifies FFI handling. */

/* These next two functions are also needed because in db42 these
   are #define macros */
DB_ENV *db_env_cr(u_int32_t flags, int *errno) {
  DB_ENV *envp;
  *errno = db_env_create(&envp, flags);
  return envp; 
}

char * db_strerr(int error) {
  return db_strerror(error);
}

int db_env_close(DB_ENV *env, u_int32_t flags) {
  return env->close(env, flags);
}

int db_env_open(DB_ENV *env, char *home, u_int32_t flags, int mode) {
  return env->open(env, home, flags, mode);
}

int db_env_dbremove(DB_ENV *env, DB_TXN *txnid, char *file, char *database,
		    u_int32_t flags) {
  return env->dbremove(env, txnid, file, database, flags);
}

int db_env_dbrename(DB_ENV *env, DB_TXN *txnid, char *file, char *database,
		    char *newname, u_int32_t flags) {
  return env->dbrename(env, txnid, file, database, newname, flags);
}

int db_env_remove(DB_ENV *env, char *home, u_int32_t flags) {
  return env->remove(env, home, flags);
}

int db_env_set_flags(DB_ENV *dbenv, u_int32_t flags, int onoff) {
  return dbenv->set_flags(dbenv, flags, onoff);
}

int db_env_get_flags(DB_ENV *dbenv, u_int32_t *flagsp) {
  return dbenv->get_flags(dbenv, flagsp);
}

/* Database */

DB *db_cr(DB_ENV *dbenv, u_int32_t flags, int *errno) {
  DB *dbp;
  *errno = db_create(&dbp, dbenv, flags);
  return dbp;
}

int db_close(DB *db, u_int32_t flags) {
  return db->close(db, flags);
}

int db_open(DB *db, DB_TXN *txnid, char *file, char *database, DBTYPE type,
	    u_int32_t flags, int mode) {
  return db->open(db, txnid, file, database, type, flags, mode);
}

int db_remove(DB *db, char *file, char *database, u_int32_t flags) {
  return db->remove(db, file, database, flags);
}

int db_rename(DB *db, char *file, char *database, char *newname,
	      u_int32_t flags) {
  return db->rename(db, file, database, newname, flags);
}

int db_sync(DB *db, u_int32_t flags) {
  return db->sync(db, flags);
}

int db_truncate(DB *db, DB_TXN *txnid, u_int32_t *countp, u_int32_t flags) {
  return db->truncate(db, txnid, countp, flags);
}

int db_set_flags(DB *db, u_int32_t flags) {
  return db->set_flags(db, flags);
}

int db_get_flags(DB *db, u_int32_t *flagsp) {
  return db->get_flags(db, flagsp);
}

int db_set_pagesize(DB *db, u_int32_t pagesize) {
  return db->set_pagesize(db, pagesize);
}

int db_get_pagesize(DB *db, u_int32_t *pagesizep) {
  return db->get_pagesize(db, pagesizep);
}

int db_set_bt_compare(DB *db,
		      int (*bt_compare_fcn)(DB *db, const DBT *dbt1, 
					    const DBT *dbt2)) {
  return db->set_bt_compare(db, bt_compare_fcn);
}

int db_set_dup_compare(DB *db,
		       int (*dup_compare_fcn)(DB *db, const DBT *dbt1, 
					      const DBT *dbt2)) {
  return db->set_dup_compare(db, dup_compare_fcn);
}

#define type_numeric(c) ((c)<8)
#include <math.h>

double read_num(char *buf);
int case_cmp(const char *a, int32_t length1, const char *b, int32_t length2);
int lex_cmp(const char *a, int32_t length1, const char *b, int32_t length2);
int utf16_cmp(const char *s1, int32_t length1, 
	      const char *s2, int32_t length2);

/* Inspired by the BDB docs.  We have to memcpy to
   insure memory alignment. */
int lisp_compare(DB *dbp, const DBT *a, const DBT *b) {
  int difference;
  double ddifference;
  char *ad, *bd, at, bt;
  ad = (char*)a->data;
  bd = (char*)b->data;

  /* Compare OIDs. */
  difference = read_int(ad, 0) - read_int(bd, 0);
  if (difference) return difference;
  
  /* Have a type tag? */
  if (a->size == 4) 
    if (b->size == 4) 
      return 0;
    else
      return -1;
  else if (b->size == 4) 
    return 1;

  at = ad[4]; bt = bd[4];

  /* Compare numerics. */
  if (type_numeric(at) && type_numeric(bt)) {
    ddifference = read_num(ad+4) - read_num(bd+4);
    if (ddifference > 0) return 1;
    else if (ddifference < 0) return -1;
    return 0;
  }

  /* Compare types. */
  difference = at - bt;
  if (difference) return difference;

  /* Same type! */
  switch (at) {
  case 8: /* nil */
    return 0;
  case 9: /* 8-bit symbol */
  case 10: /* 8-bit string */
  case 11: /* 8-bit pathname */
    return case_cmp(ad+9, read_int(ad, 5), bd+9, read_int(bd, 5));
  case 12: /* 16-bit symbol */
  case 13: /* 16-bit string */
  case 14: /* 16-bit pathname */
    return utf16_cmp(ad+9, read_int(ad, 5), bd+9, read_int(bd, 5));
  case 20:
  case 21:
  case 22:
    return wcs_cmp(ad+9, read_int(ad, 5), bd+9, read_int(bd, 5)); 
  default:
    return lex_cmp(ad+5, (a->size)-5, bd+5, (b->size)-5);
  }
}

int db_set_lisp_compare(DB *db) {
  return db->set_bt_compare(db, &lisp_compare);
}

int db_set_lisp_dup_compare(DB *db) {
  return db->set_dup_compare(db, &lisp_compare);
}

#ifndef exp2
#define exp2(c) (pow(2,(c)))
#endif

double read_num(char *buf) {
  char *limit;
  double i, result, denom;
  switch (buf[0]) {
  case 1:
  case 2:
    return (double)read_int(buf, 1);
  case 3:
    return (double)read_float(buf, 1);
  case 4:
    return read_double(buf, 1);
  case 5:
    result = 0;
    buf += 5;
    limit = buf + read_uint(buf, -4);
    for(i=0 ; buf < limit; i++, buf = buf+4) {
      result -= exp2(i*32) * read_uint(buf, 0);
    }
    return result;
  case 6:
    result = 0;
    buf += 5;
    limit = buf + read_uint(buf, -4);
    for(i=0 ; buf < limit; i++, buf = buf+4) {
      result += exp2(i*32) * read_uint(buf, 0);
    }
    return result;
  case 7:
  default:
    switch ((++buf)[0]) {
    case 1: 
      result = (double)read_int(++buf, 0);
      buf += 4;
      break;
    case 5:
      result = 0;
      buf += 5;
      limit = buf + read_uint(buf, -4);
      for(i=0 ; buf < limit; i++, buf = buf+4) {
	result -= exp2(i*32) - read_uint(buf, 0);
      }
      break;
    case 6:
    default:
      result = 0;
      buf += 5;
      limit = buf + read_uint(buf, -4);
      for(i=0 ; buf < limit; i++, buf = buf+4) {
	result += exp2(i*32) * read_uint(buf, 0);
      }
      break;
    }
    
    switch (buf[0]) {
    case 1: 
      return result / read_int(++buf, 0);
    case 5:
      denom = 0;
      buf += 5;
      limit = buf + read_uint(buf, -4);
      for(i=0 ; buf < limit; i++, buf = buf+4) {
	denom -= exp2(i*32) * read_uint(buf, 0);
      }
      return result / denom;
    case 6:
    default:
      denom = 0;
      buf += 5;
      limit = buf + read_uint(buf, -4);
      for(i=0 ; buf < limit; i++, buf = buf+4) {
	denom += exp2(i*32) * read_uint(buf, 0);
      }
      return result / denom;
    }    
  }
}

#ifdef WIN32
#define strncasecmp _strnicmp
typedef unsigned short uint16_t;
#endif

int case_cmp(const char *a, int32_t length1, const char *b, int32_t length2) {
  int min, sizediff, diff;
  sizediff = length1 - length2;
  min = sizediff > 0 ? length2 : length1;
  diff = strncasecmp(a, b, min);
  if (diff == 0) return sizediff;
  return diff;
}

int wcs_cmp(const wchar_t *a, int32_t length1, 

[627 lines skipped]
--- /project/elephant/cvsroot/elephant/src/db-bdb/libberkeley-db.def	2006/11/11 18:41:10	NONE
+++ /project/elephant/cvsroot/elephant/src/db-bdb/libberkeley-db.def	2006/11/11 18:41:10	1.1

[700 lines skipped]



More information about the Elephant-cvs mailing list