[elephant-cvs] CVS update: elephant/src/libsleepycat.c

blee at common-lisp.net blee at common-lisp.net
Thu Feb 24 01:04:17 UTC 2005


Update of /project/elephant/cvsroot/elephant/src
In directory common-lisp.net:/tmp/cvs-serv4315/src

Modified Files:
	libsleepycat.c 
Log Message:
updates for wide char strings, etc

Date: Thu Feb 24 02:04:14 2005
Author: blee

Index: elephant/src/libsleepycat.c
diff -u elephant/src/libsleepycat.c:1.10 elephant/src/libsleepycat.c:1.11
--- elephant/src/libsleepycat.c:1.10	Fri Oct  8 02:53:04 2004
+++ elephant/src/libsleepycat.c	Thu Feb 24 02:04:13 2005
@@ -56,6 +56,7 @@
 */
 
 #include <string.h>
+#include <wchar.h>
 
 /* Pointer arithmetic utility functions */
 /* should these be in network-byte order? probably not..... */
@@ -227,9 +228,9 @@
 
 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);
-int lex_cmp(const char *a, int32_t length1, const char *b, int32_t length2);
 
 /* Inspired by the Sleepycat docs.  We have to memcpy to
    insure memory alignment. */
@@ -279,6 +280,10 @@
   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);
   }
@@ -387,6 +392,16 @@
   return diff;
 }
 
+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 lex_cmp(const char *a, int32_t length1, const char *b, int32_t length2) {
   int min, sizediff, diff;
   sizediff = length1 - length2;
@@ -724,6 +739,99 @@
 int db_txnp_begin(DB_ENV *env, DB_TXN *parent, DB_TXN **txnp,
 		 u_int32_t flags) {
   return env->txn_begin(env, parent, txnp, flags);
+}
+
+/* Sequences */
+
+DB_SEQUENCE * db_sequence_create2(DB *db, u_int32_t flags, int *errno) {
+  DB_SEQUENCE * seq;
+  *errno = db_sequence_create(&seq, db, flags);
+  return seq;
+}
+
+int db_sequence_open(DB_SEQUENCE *seq, 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 seq->open(seq, txnid, &DBTKey, flags);
+}
+
+int db_sequence_close(DB_SEQUENCE *seq, u_int32_t flags) {
+  return seq->close(seq, flags);
+}
+
+/* db_seq_t = int64_t */
+const unsigned int bitmask_32bits = 0xFFFFFFFF;
+#define lower_u32bits(int64) ((unsigned int) int64 & bitmask_32bits)
+#define upper_u32bits(int64) ((unsigned int) (int64 >> 32))
+#define UUto64(low, high) ((((u_int64_t)high) << 32) | (u_int64_t)low)
+#define lower_32bits(int64) ((int) int64 & bitmask_32bits)
+#define upper_32bits(int64) ((int) (int64 >> 32))
+#define USto64(low, high) ((((int64_t)high) << 32) | (u_int64_t)low)
+  
+int db_sequence_get(DB_SEQUENCE *seq, DB_TXN *txnid, int32_t delta,
+		    u_int32_t *lowp, int32_t *highp, u_int32_t flags) {
+  db_seq_t next;
+  int ret;
+
+  ret = seq->get(seq, txnid, delta, &next, flags);
+  *lowp = lower_u32bits(next);
+  *highp = upper_32bits(next);
+  return ret;
+}
+
+int db_sequence_get_lower(DB_SEQUENCE *seq, DB_TXN *txnid, int32_t delta,
+			  int32_t *lowp, u_int32_t flags) {
+  db_seq_t next;
+  int ret;
+
+  ret = seq->get(seq, txnid, delta, &next, flags);
+  *lowp = (int)lower_32bits(next);
+  return ret;
+}
+
+/* Typo in the sleepycat docs! */
+int db_sequence_initial_value(DB_SEQUENCE *seq, u_int32_t low, 
+			      int32_t high) {
+  return seq->initial_value(seq, USto64(low, high));
+}
+
+int db_sequence_remove(DB_SEQUENCE *seq, DB_TXN *txnid, u_int32_t flags) {
+  return seq->remove(seq, txnid, flags);
+}
+
+int db_sequence_set_cachesize(DB_SEQUENCE *seq, int32_t size) {
+  return seq->set_cachesize(seq, size);
+}
+
+int db_sequence_get_cachesize(DB_SEQUENCE *seq, int32_t *sizep) {
+  return seq->get_cachesize(seq, sizep);
+}
+
+int db_sequence_set_flags(DB_SEQUENCE *seq, u_int32_t flags) {
+  return seq->set_flags(seq, flags);
+}
+
+int db_sequence_set_range(DB_SEQUENCE *seq, u_int32_t minlow, 
+			  int32_t minhigh, u_int32_t maxlow, 
+			  int32_t maxhigh) {
+  return seq->set_range(seq, USto64(minlow, minhigh), USto64(maxlow, maxhigh));
+}
+
+int db_sequence_get_range(DB_SEQUENCE *seq, u_int32_t *minlowp, 
+			  int32_t *minhighp, u_int32_t *maxlowp, 
+			  int32_t *maxhighp) {
+  int64_t min, max;
+  int errno;
+  errno = seq->get_range(seq, &min, &max);
+  *minlowp = lower_u32bits(min);
+  *minhighp = upper_32bits(min);
+  *maxlowp = lower_u32bits(max);
+  *maxhighp = upper_32bits(max);
+  return errno;
 }
 
 /* Locks and timeouts */




More information about the Elephant-cvs mailing list