[elephant-cvs] CVS elephant/src/db-bdb
ieslick
ieslick at common-lisp.net
Mon Jan 22 16:17:43 UTC 2007
Update of /project/elephant/cvsroot/elephant/src/db-bdb
In directory clnet:/tmp/cvs-serv25298/src/db-bdb
Modified Files:
libberkeley-db.c
Log Message:
0.6.1 Working HEAD is limping again. All tests pass on Allegro 8.0/Mac OS X
--- /project/elephant/cvsroot/elephant/src/db-bdb/libberkeley-db.c 2007/01/20 22:12:17 1.5
+++ /project/elephant/cvsroot/elephant/src/db-bdb/libberkeley-db.c 2007/01/22 16:17:43 1.6
@@ -265,889 +265,1055 @@
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);
-}
+/* Accessors */
+/* We manage our own buffers (DB_DBT_USERMEM). */
-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);
+int db_get_raw(DB *db, DB_TXN *txnid,
+ char *key, u_int32_t key_size,
+ char *buffer, u_int32_t buffer_length,
+ u_int32_t flags, u_int32_t *result_size) {
+ DBT DBTKey, DBTValue;
+ int ret;
+
+ memset(&DBTKey, 0, sizeof(DBT));
+ memset(&DBTValue, 0, sizeof(DBT));
+ DBTKey.data = key;
+ DBTKey.size = key_size;
+ DBTValue.data = buffer;
+ DBTValue.ulen = buffer_length;
+ DBTValue.flags |= DB_DBT_USERMEM;
+
+ ret = db->get(db, txnid, &DBTKey, &DBTValue, flags);
+ *result_size = DBTValue.size;
+
+ return ret;
}
-#define type_numeric1(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 wcs_cmp(const wchar_t *a, int32_t length1, const wchar_t *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 db_put_raw(DB *db, DB_TXN *txnid,
+ char *key, u_int32_t key_size,
+ char *value, u_int32_t value_size,
+ u_int32_t flags) {
+ DBT DBTKey, DBTValue;
+
+ memset(&DBTKey, 0, sizeof(DBT));
+ memset(&DBTValue, 0, sizeof(DBT));
+ DBTKey.data = key;
+ DBTKey.size = key_size;
+ DBTValue.data = value;
+ DBTValue.size = value_size;
+
+ return db->put(db, txnid, &DBTKey, &DBTValue, flags);
+}
-/* Original serializer */
-int lisp_compare1(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;
+int db_del(DB *db, DB_TXN *txnid,
+ char *key, u_int32_t key_size,
+ u_int32_t flags) {
+ DBT DBTKey;
+
+ memset(&DBTKey, 0, sizeof(DBT));
+ DBTKey.data = key;
+ DBTKey.size = key_size;
+ return db->del(db, txnid, &DBTKey, flags);
+}
- /* Compare OIDs. */
- difference = read_int(ad, 0) - read_int(bd, 0);
- if (difference) return difference;
+int db_compact(DB *db, DB_TXN *txnid,
+ char *start, u_int32_t start_size,
+ char *stop, u_int32_t stop_size,
+ u_int32_t flags,
+ char *end, u_int32_t end_length,
+ u_int32_t *end_size) {
+ DBT DBTStart, DBTStop, DBTEnd;
+ int errno;
- /* Have a type tag? */
- if (a->size == 4)
- if (b->size == 4)
- return 0;
- else
- return -1;
- else if (b->size == 4)
- return 1;
+ memset(&DBTStart, 0, sizeof(DBT));
+ DBTStart.data = start;
+ DBTStart.size = start_size;
- at = ad[4]; bt = bd[4];
+ memset(&DBTStop, 0, sizeof(DBT));
+ DBTStop.data = stop;
+ DBTStop.size = stop_size;
- /* Compare numerics. */
- if (type_numeric1(at) && type_numeric1(bt)) {
- ddifference = read_num(ad+4) - read_num(bd+4);
- if (ddifference > 0) return 1;
- else if (ddifference < 0) return -1;
- return 0;
- }
+ memset(&DBTEnd, 0, sizeof(DBT));
+ DBTEnd.data = end;
+ DBTEnd.ulen = end_length;
+ DBTEnd.flags |= DB_DBT_USERMEM;
- /* Compare types. */
- /* ISE: need extra conditional here...forget why, so research it */
- difference = at - bt;
- if (difference) return difference;
+ errno = db->compact(db, txnid,
+ &DBTStart,
+ &DBTStop,
+ NULL,
+ flags,
+ &DBTEnd);
+ *end_size = DBTEnd.size;
- /* 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((wchar_t*)ad+9, read_int(ad, 5), (wchar_t*)bd+9, read_int(bd, 5));
- default:
- return lex_cmp(ad+5, (a->size)-5, bd+5, (b->size)-5);
- }
+ return errno;
}
-
-#define type_numeric2(c) ((c)<9)
-
-/* New serializer */
-int lisp_compare2(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: OIDs are limited by native integer width */
- 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_numeric2(at) && type_numeric2(bt)) {
- /* ddifference = read_num2(ad+4) - read_num2(bd+4); */
- ddifference = read_num(ad+4) - read_num(bd+4);
- if (ddifference > 0) return 1;
- else if (ddifference < 0) return -1;
- return 0;
- }
-
- /* Compare types. */
- /* ISE: need extra conditional here...forget why, so research it */
- difference = at - bt;
- if (difference) return difference;
+/* Cursors */
- /* TODO: compare strings of different sizes? */
- /* TODO: compare symbol-ids? */
-
- /* Same type! */
- switch (at) {
- case 0x3F: /* nil */
- return 0;
- case 9: /* 8-bit string */
- return case_cmp(ad+9, read_int32(ad, 5), bd+9, read_int32(bd, 5));
- /* ISE: Why did I do this?
- if( bt == 9 )
- return case_cmp(ad+9, read_int32(ad, 5), bd+9, read_int32(bd, 5));
- else
- return full_cmp(ad+9, read_int32(ad, 5), bd+9, read_int32(bd, 5))
- */
- case 10: /* 16-bit string */
- return utf16_cmp(ad+9, read_int32(ad, 5), bd+9, read_int32(bd, 5));
- case 11:
- return wcs_cmp((wchar_t*)ad+9, read_int32(ad, 5), (wchar_t*)bd+9, read_int32(bd, 5));
- default:
- return lex_cmp(ad+5, (a->size)-5, bd+5, (b->size)-5);
- }
+DBC * db_cursor(DB *db, DB_TXN *txnid, u_int32_t flags, int *errno) {
+ DBC *cursor;
+ *errno = db->cursor(db, txnid, &cursor, flags);
+ return cursor;
}
-int db_set_lisp_compare(DB *db, int version) {
- switch (version) {
- case 1:
- return db->set_bt_compare(db, &lisp_compare1);
- default:
- return db->set_bt_compare(db, &lisp_compare2);
- }
+int db_cursor_close(DBC *cursor) {
+ return cursor->c_close(cursor);
}
-int db_set_lisp_dup_compare(DB *db, int version) {
- switch (version) {
- case 1:
- return db->set_dup_compare(db, &lisp_compare1);
- default:
- return db->set_dup_compare(db, &lisp_compare2);
- }
+int db_cursor_del(DBC *cursor, u_int32_t flags) {
+ return cursor->c_del(cursor, flags);
}
-#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;
- }
- }
+DBC * db_cursor_dup(DBC *cursor, u_int32_t flags, int *errno) {
+ DBC *dup;
+ *errno = cursor->c_dup(cursor, &dup, flags);
+ return dup;
}
-#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 db_cursor_get_raw(DBC *cursor,
+ char *keybuf, u_int32_t keybuf_size,
+ u_int32_t keybuf_length,
+ char *buffer, u_int32_t buffer_size,
+ u_int32_t buffer_length,
+ u_int32_t flags, u_int32_t *ret_key_size,
+ u_int32_t *result_size) {
+ DBT DBTKey, DBTValue;
+ int ret;
+
+ memset(&DBTKey, 0, sizeof(DBT));
+ memset(&DBTValue, 0, sizeof(DBT));
+ DBTKey.data = keybuf;
+ DBTKey.size = keybuf_size;
+ DBTKey.ulen = keybuf_length;
+ DBTKey.flags |= DB_DBT_USERMEM;
+ DBTValue.data = buffer;
+ DBTValue.size = buffer_size;
+ DBTValue.ulen = buffer_length;
+ DBTValue.flags |= DB_DBT_USERMEM;
+
+ ret = cursor->c_get(cursor, &DBTKey, &DBTValue, flags);
+ *ret_key_size = DBTKey.size;
+ *result_size = DBTValue.size;
+
+ return ret;
}
-int wcs_cmp(const wchar_t *a, int32_t length1,
- const wchar_t *b, int32_t length2) {
- int min, sizediff, diff;
- sizediff = length1 - length2;
- min = sizediff > 0 ? length2 : length1;
- diff = wcsncmp(a, b, min /4);
- if (diff == 0) return sizediff;
- return diff;
+int db_cursor_pget_raw(DBC *cursor,
+ char *keybuf, u_int32_t keybuf_size,
+ u_int32_t keybuf_length,
+ char *pkeybuf, u_int32_t pkeybuf_size,
+ u_int32_t pkeybuf_length,
+ char *buffer, u_int32_t buffer_size,
+ u_int32_t buffer_length,
+ u_int32_t flags,
+ u_int32_t *ret_key_size,
+ u_int32_t *ret_pkey_size,
+ u_int32_t *result_size) {
+ DBT DBTKey, DBTPKey, DBTValue;
+ int ret;
+
+ memset(&DBTKey, 0, sizeof(DBT));
+ memset(&DBTPKey, 0, sizeof(DBT));
[1387 lines skipped]
More information about the Elephant-cvs
mailing list