The branch, master has been updated
       via  7a59c90 pytdb: Make filename argument optional.
       via  4c72655 pytdb: Add support for tdb_freelist_size()
       via  b3314d6 pytdb: Add support for tdb_transaction_prepare_commit()
       via  b826ef9 pytdb: Add support for tdb_enable_seqnum, tdb_get_seqnum 
and tdb_increment_seqnum_nonblock
       via  a262103 pytdb: Update open flags to match those for tdb_open() in 
tdb.h
       via  277a1b2 pytdb: Fix repr segfault for internal db
       via  c4b1971 pytdb: Add support for tdb_add_flags() & tdb_remove_flags()
      from  92eccf8 waf: add a '+' to the git hash if the working tree isn't 
clean

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 7a59c90189b3b129c4cf9826a45ac5678e66d95b
Author: Jelmer Vernooij <[email protected]>
Date:   Sun Sep 19 10:42:29 2010 -0700

    pytdb: Make filename argument optional.

commit 4c726556784643a3c5860ec716e30cc1c7b99ce1
Author: Kirill Smelkov <[email protected]>
Date:   Sun Sep 19 13:53:29 2010 +0400

    pytdb: Add support for tdb_freelist_size()
    
    Cc: [email protected]
    Signed-off-by: Kirill Smelkov <[email protected]>
    Signed-off-by: Jelmer Vernooij <[email protected]>

commit b3314d6ad8de732f563f095ea538c7b95c667d73
Author: Kirill Smelkov <[email protected]>
Date:   Sun Sep 19 13:53:32 2010 +0400

    pytdb: Add support for tdb_transaction_prepare_commit()
    
    Cc: [email protected]
    Signed-off-by: Kirill Smelkov <[email protected]>
    Signed-off-by: Jelmer Vernooij <[email protected]>

commit b826ef9697c4bd236b6d861712fa1e450157bc6f
Author: Kirill Smelkov <[email protected]>
Date:   Sun Sep 19 09:34:33 2010 -0700

    pytdb: Add support for tdb_enable_seqnum, tdb_get_seqnum and 
tdb_increment_seqnum_nonblock
    
    Cc: [email protected]
    Signed-off-by: Kirill Smelkov <[email protected]>
    Signed-off-by: Jelmer Vernooij <[email protected]>

commit a2621034e985c87f87f7b196b75da56ffe8948dc
Author: Kirill Smelkov <[email protected]>
Date:   Sun Sep 19 13:53:19 2010 +0400

    pytdb: Update open flags to match those for tdb_open() in tdb.h
    
    Namely TDB_NOSYNC, TDB_SEQNUM, TDB_VOLATILE, TDB_ALLOW_NESTING and
    TDB_DISALLOW_NESTING were missing.
    
    Cc: [email protected]
    Signed-off-by: Kirill Smelkov <[email protected]>
    Signed-off-by: Jelmer Vernooij <[email protected]>

commit 277a1b229cf1b456560a50d021e2eaf2158e5134
Author: Kirill Smelkov <[email protected]>
Date:   Sun Sep 19 13:53:21 2010 +0400

    pytdb: Fix repr segfault for internal db
    
    The problem was tdb->name is NULL for TDB_INTERNAL databases, and
    so it was crashing ...
    
        #0  0xb76944f3 in strlen () from /lib/i686/cmov/libc.so.6
        #1  0x0809862b in PyString_FromFormatV (format=0xb72b6a26 "Tdb('%s')", 
vargs=0xbfc26a94 "")
            at ../Objects/stringobject.c:211
        #2  0x08098888 in PyString_FromFormat (format=0xb72b6a26 "Tdb('%s')") 
at ../Objects/stringobject.c:358
        #3  0xb72b65f2 in tdb_object_repr (self=0xb759e060) at ./pytdb.c:439
    
    Cc: [email protected]
    Signed-off-by: Kirill Smelkov <[email protected]>
    Signed-off-by: Jelmer Vernooij <[email protected]>

commit c4b1971259638875317aa991b6a119b668ac03a8
Author: Kirill Smelkov <[email protected]>
Date:   Sun Sep 19 13:53:20 2010 +0400

    pytdb: Add support for tdb_add_flags() & tdb_remove_flags()
    
    Note, unlike tdb_open where flags is `int', tdb_{add,remove}_flags want
    flags as `unsigned', so instead of "i" I used "I" in PyArg_ParseTuple.
    
    Cc: [email protected]
    Signed-off-by: Kirill Smelkov <[email protected]>
    Signed-off-by: Jelmer Vernooij <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 lib/tdb/pytdb.c                |   82 ++++++++++++++++++++++++++++++++++++++-
 lib/tdb/python/tests/simple.py |   34 ++++++++++++++--
 2 files changed, 109 insertions(+), 7 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/tdb/pytdb.c b/lib/tdb/pytdb.c
index 7a9205b..f2638db 100644
--- a/lib/tdb/pytdb.c
+++ b/lib/tdb/pytdb.c
@@ -77,15 +77,19 @@ static PyObject *PyString_FromTDB_DATA(TDB_DATA data)
 
 static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject 
*kwargs)
 {
-       char *name;
+       char *name = NULL;
        int hash_size = 0, tdb_flags = TDB_DEFAULT, flags = O_RDWR, mode = 0600;
        TDB_CONTEXT *ctx;
        PyTdbObject *ret;
        const char *kwnames[] = { "name", "hash_size", "tdb_flags", "flags", 
"mode", NULL };
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiii", (char 
**)kwnames, &name, &hash_size, &tdb_flags, &flags, &mode))
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|siiii", (char 
**)kwnames, &name, &hash_size, &tdb_flags, &flags, &mode))
                return NULL;
 
+       if (name == NULL) {
+               tdb_flags |= TDB_INTERNAL;
+       }
+
        ctx = tdb_open(name, hash_size, tdb_flags, flags, mode);
        if (ctx == NULL) {
                PyErr_SetFromErrno(PyExc_IOError);
@@ -112,6 +116,13 @@ static PyObject *obj_transaction_commit(PyTdbObject *self)
        Py_RETURN_NONE;
 }
 
+static PyObject *obj_transaction_prepare_commit(PyTdbObject *self)
+{
+       int ret = tdb_transaction_prepare_commit(self->ctx);
+       PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
+       Py_RETURN_NONE;
+}
+
 static PyObject *obj_transaction_start(PyTdbObject *self)
 {
        int ret = tdb_transaction_start(self->ctx);
@@ -259,6 +270,27 @@ static PyObject *obj_store(PyTdbObject *self, PyObject 
*args)
        Py_RETURN_NONE;
 }
 
+static PyObject *obj_add_flags(PyTdbObject *self, PyObject *args)
+{
+       unsigned flags;
+
+       if (!PyArg_ParseTuple(args, "I", &flags))
+               return NULL;
+
+       tdb_add_flags(self->ctx, flags);
+       Py_RETURN_NONE;
+}
+
+static PyObject *obj_remove_flags(PyTdbObject *self, PyObject *args)
+{
+       unsigned flags;
+
+       if (!PyArg_ParseTuple(args, "I", &flags))
+               return NULL;
+
+       tdb_remove_flags(self->ctx, flags);
+       Py_RETURN_NONE;
+}
 
 typedef struct {
        PyObject_HEAD
@@ -311,6 +343,18 @@ static PyObject *obj_clear(PyTdbObject *self)
        Py_RETURN_NONE;
 }
 
+static PyObject *obj_enable_seqnum(PyTdbObject *self)
+{
+       tdb_enable_seqnum(self->ctx);
+       Py_RETURN_NONE;
+}
+
+static PyObject *obj_increment_seqnum_nonblock(PyTdbObject *self)
+{
+       tdb_increment_seqnum_nonblock(self->ctx);
+       Py_RETURN_NONE;
+}
+
 static PyMethodDef tdb_object_methods[] = {
        { "transaction_cancel", (PyCFunction)obj_transaction_cancel, 
METH_NOARGS, 
                "S.transaction_cancel() -> None\n"
@@ -318,6 +362,9 @@ static PyMethodDef tdb_object_methods[] = {
        { "transaction_commit", (PyCFunction)obj_transaction_commit, 
METH_NOARGS,
                "S.transaction_commit() -> None\n"
                "Commit the currently active transaction." },
+       { "transaction_prepare_commit", 
(PyCFunction)obj_transaction_prepare_commit, METH_NOARGS,
+               "S.transaction_prepare_commit() -> None\n"
+               "Prepare to commit the currently active transaction" },
        { "transaction_start", (PyCFunction)obj_transaction_start, METH_NOARGS,
                "S.transaction_start() -> None\n"
                "Start a new transaction." },
@@ -341,9 +388,15 @@ static PyMethodDef tdb_object_methods[] = {
                "Check whether key exists in this database." },
        { "store", (PyCFunction)obj_store, METH_VARARGS, "S.store(key, data, 
flag=REPLACE) -> None"
                "Store data." },
+       { "add_flags", (PyCFunction)obj_add_flags, METH_VARARGS, 
"S.add_flags(flags) -> None" },
+       { "remove_flags", (PyCFunction)obj_remove_flags, METH_VARARGS, 
"S.remove_flags(flags) -> None" },
        { "iterkeys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() 
-> iterator" },
        { "clear", (PyCFunction)obj_clear, METH_NOARGS, "S.clear() -> None\n"
                "Wipe the entire database." },
+       { "enable_seqnum", (PyCFunction)obj_enable_seqnum, METH_NOARGS,
+               "S.enable_seqnum() -> None" },
+       { "increment_seqnum_nonblock", 
(PyCFunction)obj_increment_seqnum_nonblock, METH_NOARGS,
+               "S.increment_seqnum_nonblock() -> None" },
        { NULL }
 };
 
@@ -365,6 +418,11 @@ static PyObject *obj_get_map_size(PyTdbObject *self, void 
*closure)
        return PyInt_FromLong(tdb_map_size(self->ctx));
 }
 
+static PyObject *obj_get_freelist_size(PyTdbObject *self, void *closure)
+{
+       return PyInt_FromLong(tdb_freelist_size(self->ctx));
+}
+
 static PyObject *obj_get_flags(PyTdbObject *self, void *closure)
 {
        return PyInt_FromLong(tdb_get_flags(self->ctx));
@@ -375,18 +433,30 @@ static PyObject *obj_get_filename(PyTdbObject *self, void 
*closure)
        return PyString_FromString(tdb_name(self->ctx));
 }
 
+static PyObject *obj_get_seqnum(PyTdbObject *self, void *closure)
+{
+       return PyInt_FromLong(tdb_get_seqnum(self->ctx));
+}
+
+
 static PyGetSetDef tdb_object_getsetters[] = {
        { (char *)"hash_size", (getter)obj_get_hash_size, NULL, NULL },
        { (char *)"map_size", (getter)obj_get_map_size, NULL, NULL },
+       { (char *)"freelist_size", (getter)obj_get_freelist_size, NULL, NULL },
        { (char *)"flags", (getter)obj_get_flags, NULL, NULL },
        { (char *)"max_dead", NULL, (setter)obj_set_max_dead, NULL },
        { (char *)"filename", (getter)obj_get_filename, NULL, (char *)"The 
filename of this TDB file."},
+       { (char *)"seqnum", (getter)obj_get_seqnum, NULL, NULL },
        { NULL }
 };
 
 static PyObject *tdb_object_repr(PyTdbObject *self)
 {
-       return PyString_FromFormat("Tdb('%s')", tdb_name(self->ctx));
+       if (tdb_get_flags(self->ctx) & TDB_INTERNAL) {
+               return PyString_FromString("Tdb(<internal>)");
+       } else {
+               return PyString_FromFormat("Tdb('%s')", tdb_name(self->ctx));
+       }
 }
 
 static void tdb_object_dealloc(PyTdbObject *self)
@@ -497,6 +567,12 @@ void inittdb(void)
        PyModule_AddObject(m, "NOMMAP", PyInt_FromLong(TDB_NOMMAP));
        PyModule_AddObject(m, "CONVERT", PyInt_FromLong(TDB_CONVERT));
        PyModule_AddObject(m, "BIGENDIAN", PyInt_FromLong(TDB_BIGENDIAN));
+       PyModule_AddObject(m, "NOSYNC", PyInt_FromLong(TDB_NOSYNC));
+       PyModule_AddObject(m, "SEQNUM", PyInt_FromLong(TDB_SEQNUM));
+       PyModule_AddObject(m, "VOLATILE", PyInt_FromLong(TDB_VOLATILE));
+       PyModule_AddObject(m, "ALLOW_NESTING", 
PyInt_FromLong(TDB_ALLOW_NESTING));
+       PyModule_AddObject(m, "DISALLOW_NESTING", 
PyInt_FromLong(TDB_DISALLOW_NESTING));
+
        PyModule_AddObject(m, "__docformat__", 
PyString_FromString("restructuredText"));
 
        Py_INCREF(&PyTdb);
diff --git a/lib/tdb/python/tests/simple.py b/lib/tdb/python/tests/simple.py
index 6b1e840..18180e1 100644
--- a/lib/tdb/python/tests/simple.py
+++ b/lib/tdb/python/tests/simple.py
@@ -18,6 +18,7 @@ class OpenTdbTests(TestCase):
                 tdb.DEFAULT, os.O_RDWR)
 
 class CloseTdbTests(TestCase):
+
     def test_double_close(self):
         self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT,
                 os.O_CREAT|os.O_RDWR)
@@ -28,6 +29,15 @@ class CloseTdbTests(TestCase):
         self.tdb.close()
 
 
+class InternalTdbTests(TestCase):
+
+    def test_repr(self):
+        self.tdb = tdb.Tdb()
+
+        # repr used to crash on internal db
+        self.assertEquals(repr(self.tdb), "Tdb(<internal>)")
+
+
 class SimpleTdbTests(TestCase):
 
     def setUp(self):
@@ -86,6 +96,9 @@ class SimpleTdbTests(TestCase):
     def test_map_size(self):
         self.tdb.map_size
 
+    def test_freelist_size(self):
+        self.tdb.freelist_size
+
     def test_name(self):
         self.tdb.filename
 
@@ -108,11 +121,13 @@ class SimpleTdbTests(TestCase):
         self.tdb.transaction_commit()
         self.assertEquals("1", self.tdb["bloe"])
 
-    def test_iterator(self):
+    def test_transaction_prepare_commit(self):
         self.tdb["bloe"] = "2"
-        self.tdb["bla"] = "hoi"
-        i = iter(self.tdb)
-        self.assertEquals(set(["bloe", "bla"]), set([i.next(), i.next()]))
+        self.tdb.transaction_start()
+        self.tdb["bloe"] = "1"
+        self.tdb.transaction_prepare_commit()
+        self.tdb.transaction_commit()
+        self.assertEquals("1", self.tdb["bloe"])
 
     def test_iterkeys(self):
         self.tdb["bloe"] = "2"
@@ -127,11 +142,22 @@ class SimpleTdbTests(TestCase):
         self.tdb.clear()
         self.assertEquals(0, len(list(self.tdb)))
 
+    def test_seqnum(self):
+        self.tdb.enable_seqnum()
+        seq1 = self.tdb.seqnum
+        self.tdb.increment_seqnum_nonblock()
+        seq2 = self.tdb.seqnum
+        self.assertEquals(seq2-seq1, 1)
+
     def test_len(self):
         self.assertEquals(0, len(list(self.tdb)))
         self.tdb["entry"] = "value"
         self.assertEquals(1, len(list(self.tdb)))
 
+    def test_add_flags(self):
+        self.tdb.add_flags(tdb.NOMMAP)
+        self.tdb.remove_flags(tdb.NOMMAP)
+
 
 if __name__ == '__main__':
     import unittest


-- 
Samba Shared Repository

Reply via email to