* support DBEnv.log_stat() method on BerkeleyDB >= 4.0 [patch #1494885]
diff --git a/Lib/bsddb/dbobj.py b/Lib/bsddb/dbobj.py
index 5bcf84b..b06106e 100644
--- a/Lib/bsddb/dbobj.py
+++ b/Lib/bsddb/dbobj.py
@@ -91,6 +91,9 @@
return apply(self._cobj.lock_stat, args, kwargs)
def log_archive(self, *args, **kwargs):
return apply(self._cobj.log_archive, args, kwargs)
+ if db.version() >= (4,0):
+ def log_stat(self, *args, **kwargs):
+ return apply(self._cobj.log_stat, args, kwargs)
def set_get_returns_none(self, *args, **kwargs):
return apply(self._cobj.set_get_returns_none, args, kwargs)
diff --git a/Lib/bsddb/test/test_basics.py b/Lib/bsddb/test/test_basics.py
index 92cad06..0ae8732 100644
--- a/Lib/bsddb/test/test_basics.py
+++ b/Lib/bsddb/test/test_basics.py
@@ -659,6 +659,13 @@
except db.DBIncompleteError:
pass
+ if db.version() >= (4,0):
+ statDict = self.env.log_stat(0);
+ assert statDict.has_key('magic')
+ assert statDict.has_key('version')
+ assert statDict.has_key('cur_file')
+ assert statDict.has_key('region_nowait')
+
# must have at least one log file present:
logs = self.env.log_archive(db.DB_ARCH_ABS | db.DB_ARCH_LOG)
assert logs != None
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index aad4d1f..3c50a39 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -4294,6 +4294,71 @@
RETURN_NONE();
}
+#if (DBVER >= 40)
+static PyObject*
+DBEnv_log_stat(DBEnvObject* self, PyObject* args)
+{
+ int err;
+ DB_LOG_STAT* statp = NULL;
+ PyObject* d = NULL;
+ u_int32_t flags = 0;
+
+ if (!PyArg_ParseTuple(args, "|i:log_stat", &flags))
+ return NULL;
+ CHECK_ENV_NOT_CLOSED(self);
+
+ MYDB_BEGIN_ALLOW_THREADS;
+ err = self->db_env->log_stat(self->db_env, &statp, flags);
+ MYDB_END_ALLOW_THREADS;
+ RETURN_IF_ERR();
+
+ /* Turn the stat structure into a dictionary */
+ d = PyDict_New();
+ if (d == NULL) {
+ if (statp)
+ free(statp);
+ return NULL;
+ }
+
+#define MAKE_ENTRY(name) _addIntToDict(d, #name, statp->st_##name)
+
+ MAKE_ENTRY(magic);
+ MAKE_ENTRY(version);
+ MAKE_ENTRY(mode);
+ MAKE_ENTRY(lg_bsize);
+#if (DBVER >= 44)
+ MAKE_ENTRY(lg_size);
+ MAKE_ENTRY(record);
+#endif
+#if (DBVER <= 40)
+ MAKE_ENTRY(lg_max);
+#endif
+ MAKE_ENTRY(w_mbytes);
+ MAKE_ENTRY(w_bytes);
+ MAKE_ENTRY(wc_mbytes);
+ MAKE_ENTRY(wc_bytes);
+ MAKE_ENTRY(wcount);
+ MAKE_ENTRY(wcount_fill);
+#if (DBVER >= 44)
+ MAKE_ENTRY(rcount);
+#endif
+ MAKE_ENTRY(scount);
+ MAKE_ENTRY(cur_file);
+ MAKE_ENTRY(cur_offset);
+ MAKE_ENTRY(disk_file);
+ MAKE_ENTRY(disk_offset);
+ MAKE_ENTRY(maxcommitperflush);
+ MAKE_ENTRY(mincommitperflush);
+ MAKE_ENTRY(regsize);
+ MAKE_ENTRY(region_wait);
+ MAKE_ENTRY(region_nowait);
+
+#undef MAKE_ENTRY
+ free(statp);
+ return d;
+} /* DBEnv_log_stat */
+#endif /* DBVER >= 4.0 for log_stat method */
+
static PyObject*
DBEnv_lock_stat(DBEnvObject* self, PyObject* args)
@@ -4781,6 +4846,9 @@
{"lock_put", (PyCFunction)DBEnv_lock_put, METH_VARARGS},
{"lock_stat", (PyCFunction)DBEnv_lock_stat, METH_VARARGS},
{"log_archive", (PyCFunction)DBEnv_log_archive, METH_VARARGS},
+#if (DBVER >= 40)
+ {"log_stat", (PyCFunction)DBEnv_log_stat, METH_VARARGS},
+#endif
{"set_get_returns_none",(PyCFunction)DBEnv_set_get_returns_none, METH_VARARGS},
{NULL, NULL} /* sentinel */
};