From: Kirill Smelkov <[email protected]>

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]>
---
 lib/tdb/pytdb.c                |   23 +++++++++++++++++++++++
 lib/tdb/python/tests/simple.py |    4 ++++
 2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/lib/tdb/pytdb.c b/lib/tdb/pytdb.c
index 58b6d93..f6fb8ab 100644
--- a/lib/tdb/pytdb.c
+++ b/lib/tdb/pytdb.c
@@ -259,6 +259,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
@@ -341,6 +362,8 @@ 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." },
diff --git a/lib/tdb/python/tests/simple.py b/lib/tdb/python/tests/simple.py
index 6b1e840..5db8247 100644
--- a/lib/tdb/python/tests/simple.py
+++ b/lib/tdb/python/tests/simple.py
@@ -132,6 +132,10 @@ class SimpleTdbTests(TestCase):
         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
-- 
1.7.3.rc2



-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to