]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
- Bug #1493322: bsddb: the __len__ method of a DB object has been fixed to
authorGregory P. Smith <greg@mad-scientist.com>
Tue, 6 Jun 2006 00:23:21 +0000 (00:23 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Tue, 6 Jun 2006 00:23:21 +0000 (00:23 +0000)
  return correct results.  It could previously incorrectly return 0 in some
  cases.  Fixes SF bug 1493322 (pybsddb bug 1184012).

Misc/NEWS
Modules/_bsddb.c

index 93d16279166a6fc3c74db1655ea7f19407124e84..1cf9e65bae3324dc77805fb1ab7de2f38c0be216 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -35,6 +35,11 @@ Extension Modules
 - Bug #1117761: bsddb.*open() no longer raises an exception when using
   the cachesize parameter.
 
+- Bug #1493322: bsddb: the __len__ method of a DB object has been fixed to
+  return correct results.  It could previously incorrectly return 0 in some
+  cases.  Fixes SF bug 1493322 (pybsddb bug 1184012).
+
+
 Library
 -------
 
index 3684bfdce3ce284f41df3a914e65d89683393b55..b3707e91b66de7467bd48dfbee166d0822b61d7d 100644 (file)
@@ -2450,10 +2450,15 @@ int DB_length(DBObject* self)
 
     if (self->haveStat) {  /* Has the stat function been called recently?  If
                               so, we can use the cached value. */
+#if (DBVER <= 32)
         flags = DB_CACHED_COUNTS;
+#else
+        flags = DB_FAST_STAT;
+#endif
     }
 
     MYDB_BEGIN_ALLOW_THREADS;
+redo_stat_for_length:
 #if (DBVER >= 43)
     err = self->db->stat(self->db, /*txnid*/ NULL, &sp, flags);
 #elif (DBVER >= 33)
@@ -2461,6 +2466,20 @@ int DB_length(DBObject* self)
 #else
     err = self->db->stat(self->db, &sp, NULL, flags);
 #endif
+
+    /* All the stat structures have matching fields upto the ndata field,
+       so we can use any of them for the type cast */
+    size = ((DB_BTREE_STAT*)sp)->bt_ndata;
+
+    /* A size of 0 could mean that BerkeleyDB no longer had the stat values cached.
+     * redo a full stat to make sure.
+     *   Fixes SF python bug 1493322, pybsddb bug 1184012
+     */
+    if (size == 0 && (flags & DB_FAST_STAT)) {
+        flags = 0;
+        goto redo_stat_for_length;
+    }
+
     MYDB_END_ALLOW_THREADS;
 
     if (err)
@@ -2468,9 +2487,6 @@ int DB_length(DBObject* self)
 
     self->haveStat = 1;
 
-    /* All the stat structures have matching fields upto the ndata field,
-       so we can use any of them for the type cast */
-    size = ((DB_BTREE_STAT*)sp)->bt_ndata;
     free(sp);
     return size;
 }