From 2e56541d457b7fe19bf17d07848981ee43383197 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Tue, 6 Jun 2006 00:23:21 +0000 Subject: - 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). --- Misc/NEWS | 5 +++++ Modules/_bsddb.c | 22 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 93d1627..1cf9e65 100644 --- 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 ------- diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c index 3684bfd..b3707e9 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; } -- cgit v0.12