summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2006-06-06 00:23:21 +0000
committerGregory P. Smith <greg@mad-scientist.com>2006-06-06 00:23:21 +0000
commit2e56541d457b7fe19bf17d07848981ee43383197 (patch)
treec39bfeeb9d51da78d8efe226ba8249b27ba17187 /Modules
parent89d862360cc15c20783f4aa0775a3d2450f1bd7b (diff)
downloadcpython-git-2e56541d457b7fe19bf17d07848981ee43383197.tar.gz
- 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).
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_bsddb.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index 3684bfdce3..b3707e91b6 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -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;
}