2 Unix SMB/CIFS implementation.
4 Python interface to tdb.
6 Copyright (C) 2004-2006 Tim Potter <tpot@samba.org>
7 Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org>
9 ** NOTE! The following LGPL license applies to the tdb
10 ** library. This does NOT imply that all of Samba is released
13 This library is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, see <http://www.gnu.org/licenses/>.
29 #include "system/filesys.h"
31 /* Include tdb headers */
34 #if PY_MAJOR_VERSION >= 3
35 #define PyInt_FromLong PyLong_FromLong
36 #define Py_TPFLAGS_HAVE_ITER 0
39 /* discard signature of 'func' in favour of 'target_sig' */
40 #define PY_DISCARD_FUNC_SIG(target_sig, func) (target_sig)(void(*)(void))func
48 static PyTypeObject PyTdb;
50 static void PyErr_SetTDBError(TDB_CONTEXT *tdb)
52 PyErr_SetObject(PyExc_RuntimeError,
53 Py_BuildValue("(i,s)", tdb_error(tdb), tdb_errorstr(tdb)));
56 static TDB_DATA PyBytes_AsTDB_DATA(PyObject *data)
59 ret.dptr = (unsigned char *)PyBytes_AsString(data);
60 ret.dsize = PyBytes_Size(data);
64 static PyObject *PyBytes_FromTDB_DATA(TDB_DATA data)
66 if (data.dptr == NULL && data.dsize == 0) {
69 PyObject *ret = PyBytes_FromStringAndSize((const char *)data.dptr,
76 #define PyErr_TDB_ERROR_IS_ERR_RAISE(ret, tdb) \
78 PyErr_SetTDBError(tdb); \
82 #define PyErr_TDB_RAISE_IF_CLOSED(self) \
84 PyErr_SetObject(PyExc_RuntimeError, \
85 Py_BuildValue("(i,s)", TDB_ERR_IO, "Database is already closed")); \
89 #define PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self) \
91 PyErr_SetObject(PyExc_RuntimeError, \
92 Py_BuildValue("(i,s)", TDB_ERR_IO, "Database is already closed")); \
96 static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject *kwargs)
99 int hash_size = 0, tdb_flags = TDB_DEFAULT, flags = O_RDWR, mode = 0600;
102 const char *_kwnames[] = { "name", "hash_size", "tdb_flags", "flags", "mode", NULL };
103 char **kwnames = discard_const_p(char *, _kwnames);
105 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|siiii", kwnames, &name, &hash_size, &tdb_flags, &flags, &mode))
109 tdb_flags |= TDB_INTERNAL;
112 ctx = tdb_open(name, hash_size, tdb_flags, flags, mode);
114 PyErr_SetFromErrno(PyExc_IOError);
118 ret = PyObject_New(PyTdbObject, &PyTdb);
126 return (PyObject *)ret;
129 static PyObject *obj_transaction_cancel(PyTdbObject *self,
130 PyObject *Py_UNUSED(ignored))
134 PyErr_TDB_RAISE_IF_CLOSED(self);
136 ret = tdb_transaction_cancel(self->ctx);
137 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
141 static PyObject *obj_transaction_commit(PyTdbObject *self,
142 PyObject *Py_UNUSED(ignored))
145 PyErr_TDB_RAISE_IF_CLOSED(self);
146 ret = tdb_transaction_commit(self->ctx);
147 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
151 static PyObject *obj_transaction_prepare_commit(PyTdbObject *self,
152 PyObject *Py_UNUSED(ignored))
155 PyErr_TDB_RAISE_IF_CLOSED(self);
156 ret = tdb_transaction_prepare_commit(self->ctx);
157 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
161 static PyObject *obj_transaction_start(PyTdbObject *self,
162 PyObject *Py_UNUSED(ignored))
165 PyErr_TDB_RAISE_IF_CLOSED(self);
166 ret = tdb_transaction_start(self->ctx);
167 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
171 static PyObject *obj_reopen(PyTdbObject *self,
172 PyObject *Py_UNUSED(ignored))
175 PyErr_TDB_RAISE_IF_CLOSED(self);
176 ret = tdb_reopen(self->ctx);
179 PyErr_SetObject(PyExc_RuntimeError,
180 Py_BuildValue("(i,s)",
182 "Failed to reopen database"));
188 static PyObject *obj_lockall(PyTdbObject *self,
189 PyObject *Py_UNUSED(ignored))
192 PyErr_TDB_RAISE_IF_CLOSED(self);
193 ret = tdb_lockall(self->ctx);
194 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
198 static PyObject *obj_unlockall(PyTdbObject *self,
199 PyObject *Py_UNUSED(ignored))
202 PyErr_TDB_RAISE_IF_CLOSED(self);
203 ret = tdb_unlockall(self->ctx);
204 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
208 static PyObject *obj_lockall_read(PyTdbObject *self,
209 PyObject *Py_UNUSED(ignored))
212 PyErr_TDB_RAISE_IF_CLOSED(self);
213 ret = tdb_lockall_read(self->ctx);
214 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
218 static PyObject *obj_unlockall_read(PyTdbObject *self,
219 PyObject *Py_UNUSED(ignored))
221 int ret = tdb_unlockall_read(self->ctx);
222 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
226 static PyObject *obj_close(PyTdbObject *self, PyObject *Py_UNUSED(ignored))
231 ret = tdb_close(self->ctx);
234 PyErr_SetObject(PyExc_RuntimeError,
235 Py_BuildValue("(i,s)",
237 "Failed to close database"));
243 static PyObject *obj_get(PyTdbObject *self, PyObject *args)
248 PyErr_TDB_RAISE_IF_CLOSED(self);
250 if (!PyArg_ParseTuple(args, "O", &py_key))
253 key = PyBytes_AsTDB_DATA(py_key);
257 return PyBytes_FromTDB_DATA(tdb_fetch(self->ctx, key));
260 static PyObject *obj_append(PyTdbObject *self, PyObject *args)
263 PyObject *py_key, *py_data;
266 PyErr_TDB_RAISE_IF_CLOSED(self);
268 if (!PyArg_ParseTuple(args, "OO", &py_key, &py_data))
271 key = PyBytes_AsTDB_DATA(py_key);
274 data = PyBytes_AsTDB_DATA(py_data);
278 ret = tdb_append(self->ctx, key, data);
279 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
283 static PyObject *obj_firstkey(PyTdbObject *self, PyObject *Py_UNUSED(ignored))
285 PyErr_TDB_RAISE_IF_CLOSED(self);
287 return PyBytes_FromTDB_DATA(tdb_firstkey(self->ctx));
290 static PyObject *obj_nextkey(PyTdbObject *self, PyObject *args)
294 PyErr_TDB_RAISE_IF_CLOSED(self);
296 if (!PyArg_ParseTuple(args, "O", &py_key))
299 key = PyBytes_AsTDB_DATA(py_key);
303 return PyBytes_FromTDB_DATA(tdb_nextkey(self->ctx, key));
306 static PyObject *obj_delete(PyTdbObject *self, PyObject *args)
311 PyErr_TDB_RAISE_IF_CLOSED(self);
313 if (!PyArg_ParseTuple(args, "O", &py_key))
316 key = PyBytes_AsTDB_DATA(py_key);
319 ret = tdb_delete(self->ctx, key);
320 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
324 static int obj_contains(PyTdbObject *self, PyObject *py_key)
328 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
330 key = PyBytes_AsTDB_DATA(py_key);
335 ret = tdb_exists(self->ctx, key);
341 #if PY_MAJOR_VERSION < 3
342 static PyObject *obj_has_key(PyTdbObject *self, PyObject *args)
346 PyErr_TDB_RAISE_IF_CLOSED(self);
348 if (!PyArg_ParseTuple(args, "O", &py_key))
351 ret = obj_contains(self, py_key);
361 static PyObject *obj_store(PyTdbObject *self, PyObject *args)
365 int flag = TDB_REPLACE;
366 PyObject *py_key, *py_value;
368 PyErr_TDB_RAISE_IF_CLOSED(self);
370 if (!PyArg_ParseTuple(args, "OO|i", &py_key, &py_value, &flag))
373 key = PyBytes_AsTDB_DATA(py_key);
376 value = PyBytes_AsTDB_DATA(py_value);
380 ret = tdb_store(self->ctx, key, value, flag);
381 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
385 static PyObject *obj_add_flags(PyTdbObject *self, PyObject *args)
389 PyErr_TDB_RAISE_IF_CLOSED(self);
391 if (!PyArg_ParseTuple(args, "I", &flags))
394 tdb_add_flags(self->ctx, flags);
398 static PyObject *obj_remove_flags(PyTdbObject *self, PyObject *args)
402 PyErr_TDB_RAISE_IF_CLOSED(self);
404 if (!PyArg_ParseTuple(args, "I", &flags))
407 tdb_remove_flags(self->ctx, flags);
414 PyTdbObject *iteratee;
415 } PyTdbIteratorObject;
417 static PyObject *tdb_iter_next(PyTdbIteratorObject *self)
421 if (self->current.dptr == NULL && self->current.dsize == 0)
423 current = self->current;
424 self->current = tdb_nextkey(self->iteratee->ctx, self->current);
425 ret = PyBytes_FromTDB_DATA(current);
429 static void tdb_iter_dealloc(PyTdbIteratorObject *self)
431 Py_DECREF(self->iteratee);
435 PyTypeObject PyTdbIterator = {
436 .tp_name = "Iterator",
437 .tp_basicsize = sizeof(PyTdbIteratorObject),
438 .tp_iternext = (iternextfunc)tdb_iter_next,
439 .tp_dealloc = (destructor)tdb_iter_dealloc,
440 .tp_flags = Py_TPFLAGS_DEFAULT,
441 .tp_iter = PyObject_SelfIter,
444 static PyObject *tdb_object_iter(PyTdbObject *self,
445 PyObject *Py_UNUSED(ignored))
447 PyTdbIteratorObject *ret;
449 PyErr_TDB_RAISE_IF_CLOSED(self);
451 ret = PyObject_New(PyTdbIteratorObject, &PyTdbIterator);
454 ret->current = tdb_firstkey(self->ctx);
455 ret->iteratee = self;
457 return (PyObject *)ret;
460 static PyObject *obj_clear(PyTdbObject *self, PyObject *Py_UNUSED(ignored))
463 PyErr_TDB_RAISE_IF_CLOSED(self);
464 ret = tdb_wipe_all(self->ctx);
465 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
469 static PyObject *obj_repack(PyTdbObject *self, PyObject *Py_UNUSED(ignored))
472 PyErr_TDB_RAISE_IF_CLOSED(self);
473 ret = tdb_repack(self->ctx);
474 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
478 static PyObject *obj_enable_seqnum(PyTdbObject *self,
479 PyObject *Py_UNUSED(ignored))
481 PyErr_TDB_RAISE_IF_CLOSED(self);
482 tdb_enable_seqnum(self->ctx);
486 static PyObject *obj_increment_seqnum_nonblock(PyTdbObject *self,
487 PyObject *Py_UNUSED(ignored))
489 PyErr_TDB_RAISE_IF_CLOSED(self);
490 tdb_increment_seqnum_nonblock(self->ctx);
494 static PyMethodDef tdb_object_methods[] = {
495 { "transaction_cancel", (PyCFunction)obj_transaction_cancel, METH_NOARGS,
496 "S.transaction_cancel() -> None\n"
497 "Cancel the currently active transaction." },
498 { "transaction_commit", (PyCFunction)obj_transaction_commit, METH_NOARGS,
499 "S.transaction_commit() -> None\n"
500 "Commit the currently active transaction." },
501 { "transaction_prepare_commit", (PyCFunction)obj_transaction_prepare_commit, METH_NOARGS,
502 "S.transaction_prepare_commit() -> None\n"
503 "Prepare to commit the currently active transaction" },
504 { "transaction_start", (PyCFunction)obj_transaction_start, METH_NOARGS,
505 "S.transaction_start() -> None\n"
506 "Start a new transaction." },
507 { "reopen", (PyCFunction)obj_reopen, METH_NOARGS, "Reopen this file." },
508 { "lock_all", (PyCFunction)obj_lockall, METH_NOARGS, NULL },
509 { "unlock_all", (PyCFunction)obj_unlockall, METH_NOARGS, NULL },
510 { "read_lock_all", (PyCFunction)obj_lockall_read, METH_NOARGS, NULL },
511 { "read_unlock_all", (PyCFunction)obj_unlockall_read, METH_NOARGS, NULL },
512 { "close", (PyCFunction)obj_close, METH_NOARGS, NULL },
513 { "get", (PyCFunction)obj_get, METH_VARARGS, "S.get(key) -> value\n"
515 { "append", (PyCFunction)obj_append, METH_VARARGS, "S.append(key, value) -> None\n"
516 "Append data to an existing key." },
517 { "firstkey", (PyCFunction)obj_firstkey, METH_NOARGS, "S.firstkey() -> data\n"
518 "Return the first key in this database." },
519 { "nextkey", (PyCFunction)obj_nextkey, METH_VARARGS, "S.nextkey(key) -> data\n"
520 "Return the next key in this database." },
521 { "delete", (PyCFunction)obj_delete, METH_VARARGS, "S.delete(key) -> None\n"
522 "Delete an entry." },
523 #if PY_MAJOR_VERSION < 3
524 { "has_key", (PyCFunction)obj_has_key, METH_VARARGS, "S.has_key(key) -> None\n"
525 "Check whether key exists in this database." },
527 { "store", (PyCFunction)obj_store, METH_VARARGS, "S.store(key, data, flag=REPLACE) -> None"
529 { "add_flags", (PyCFunction)obj_add_flags, METH_VARARGS, "S.add_flags(flags) -> None" },
530 { "remove_flags", (PyCFunction)obj_remove_flags, METH_VARARGS, "S.remove_flags(flags) -> None" },
531 #if PY_MAJOR_VERSION >= 3
532 { "keys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() -> iterator" },
534 { "iterkeys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() -> iterator" },
536 { "clear", (PyCFunction)obj_clear, METH_NOARGS, "S.clear() -> None\n"
537 "Wipe the entire database." },
538 { "repack", (PyCFunction)obj_repack, METH_NOARGS, "S.repack() -> None\n"
539 "Repack the entire database." },
540 { "enable_seqnum", (PyCFunction)obj_enable_seqnum, METH_NOARGS,
541 "S.enable_seqnum() -> None" },
542 { "increment_seqnum_nonblock", (PyCFunction)obj_increment_seqnum_nonblock, METH_NOARGS,
543 "S.increment_seqnum_nonblock() -> None" },
547 static PyObject *obj_get_hash_size(PyTdbObject *self, void *closure)
549 PyErr_TDB_RAISE_IF_CLOSED(self);
550 return PyInt_FromLong(tdb_hash_size(self->ctx));
553 static int obj_set_max_dead(PyTdbObject *self, PyObject *max_dead, void *closure)
555 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
556 if (!PyLong_Check(max_dead))
558 tdb_set_max_dead(self->ctx, PyLong_AsLong(max_dead));
562 static PyObject *obj_get_map_size(PyTdbObject *self, void *closure)
564 PyErr_TDB_RAISE_IF_CLOSED(self);
565 return PyInt_FromLong(tdb_map_size(self->ctx));
568 static PyObject *obj_get_freelist_size(PyTdbObject *self, void *closure)
570 PyErr_TDB_RAISE_IF_CLOSED(self);
571 return PyInt_FromLong(tdb_freelist_size(self->ctx));
574 static PyObject *obj_get_flags(PyTdbObject *self, void *closure)
576 PyErr_TDB_RAISE_IF_CLOSED(self);
577 return PyInt_FromLong(tdb_get_flags(self->ctx));
580 static PyObject *obj_get_filename(PyTdbObject *self, void *closure)
582 PyErr_TDB_RAISE_IF_CLOSED(self);
583 return PyBytes_FromString(tdb_name(self->ctx));
586 static PyObject *obj_get_seqnum(PyTdbObject *self, void *closure)
588 PyErr_TDB_RAISE_IF_CLOSED(self);
589 return PyInt_FromLong(tdb_get_seqnum(self->ctx));
592 static PyObject *obj_get_text(PyTdbObject *self, void *closure)
594 PyObject *mod, *cls, *inst;
595 mod = PyImport_ImportModule("_tdb_text");
598 cls = PyObject_GetAttrString(mod, "TdbTextWrapper");
603 inst = PyObject_CallFunction(cls, discard_const_p(char, "O"), self);
609 static PyGetSetDef tdb_object_getsetters[] = {
611 .name = discard_const_p(char, "hash_size"),
612 .get = (getter)obj_get_hash_size,
615 .name = discard_const_p(char, "map_size"),
616 .get = (getter)obj_get_map_size,
619 .name = discard_const_p(char, "freelist_size"),
620 .get = (getter)obj_get_freelist_size,
623 .name = discard_const_p(char, "flags"),
624 .get = (getter)obj_get_flags,
627 .name = discard_const_p(char, "max_dead"),
628 .set = (setter)obj_set_max_dead,
631 .name = discard_const_p(char, "filename"),
632 .get = (getter)obj_get_filename,
633 .doc = discard_const_p(char, "The filename of this TDB file."),
636 .name = discard_const_p(char, "seqnum"),
637 .get = (getter)obj_get_seqnum,
640 .name = discard_const_p(char, "text"),
641 .get = (getter)obj_get_text,
646 static PyObject *tdb_object_repr(PyTdbObject *self)
648 PyErr_TDB_RAISE_IF_CLOSED(self);
649 if (tdb_get_flags(self->ctx) & TDB_INTERNAL) {
650 return PyUnicode_FromString("Tdb(<internal>)");
652 return PyUnicode_FromFormat("Tdb('%s')", tdb_name(self->ctx));
656 static void tdb_object_dealloc(PyTdbObject *self)
659 tdb_close(self->ctx);
660 Py_TYPE(self)->tp_free(self);
663 static PyObject *obj_getitem(PyTdbObject *self, PyObject *key)
666 PyErr_TDB_RAISE_IF_CLOSED(self);
667 if (!PyBytes_Check(key)) {
668 PyErr_SetString(PyExc_TypeError, "Expected bytestring as key");
672 tkey.dptr = (unsigned char *)PyBytes_AsString(key);
673 tkey.dsize = PyBytes_Size(key);
675 val = tdb_fetch(self->ctx, tkey);
676 if (val.dptr == NULL) {
678 * if the key doesn't exist raise KeyError(key) to be
679 * consistent with python dict
681 PyErr_SetObject(PyExc_KeyError, key);
684 return PyBytes_FromTDB_DATA(val);
688 static int obj_setitem(PyTdbObject *self, PyObject *key, PyObject *value)
692 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
693 if (!PyBytes_Check(key)) {
694 PyErr_SetString(PyExc_TypeError, "Expected bytestring as key");
698 tkey = PyBytes_AsTDB_DATA(key);
701 ret = tdb_delete(self->ctx, tkey);
703 if (!PyBytes_Check(value)) {
704 PyErr_SetString(PyExc_TypeError, "Expected string as value");
708 tval = PyBytes_AsTDB_DATA(value);
710 ret = tdb_store(self->ctx, tkey, tval, TDB_REPLACE);
714 PyErr_SetTDBError(self->ctx);
721 static PyMappingMethods tdb_object_mapping = {
722 .mp_subscript = (binaryfunc)obj_getitem,
723 .mp_ass_subscript = (objobjargproc)obj_setitem,
725 static PySequenceMethods tdb_object_seq = {
726 .sq_contains = (objobjproc)obj_contains,
728 static PyTypeObject PyTdb = {
729 .tp_name = "tdb.Tdb",
730 .tp_basicsize = sizeof(PyTdbObject),
731 .tp_methods = tdb_object_methods,
732 .tp_getset = tdb_object_getsetters,
733 .tp_new = py_tdb_open,
734 .tp_doc = "A TDB file",
735 .tp_repr = (reprfunc)tdb_object_repr,
736 .tp_dealloc = (destructor)tdb_object_dealloc,
737 .tp_as_mapping = &tdb_object_mapping,
738 .tp_as_sequence = &tdb_object_seq,
739 .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_ITER,
740 .tp_iter = PY_DISCARD_FUNC_SIG(getiterfunc,tdb_object_iter),
743 static PyMethodDef tdb_methods[] = {
746 .ml_meth = PY_DISCARD_FUNC_SIG(PyCFunction, py_tdb_open),
747 .ml_flags = METH_VARARGS|METH_KEYWORDS,
748 .ml_doc = "open(name, hash_size=0, tdb_flags=TDB_DEFAULT, "
749 "flags=O_RDWR, mode=0600)\nOpen a TDB file."
754 #define MODULE_DOC "simple key-value database that supports multiple writers."
756 #if PY_MAJOR_VERSION >= 3
757 static struct PyModuleDef moduledef = {
758 PyModuleDef_HEAD_INIT,
762 .m_methods = tdb_methods,
766 PyObject* module_init(void);
767 PyObject* module_init(void)
771 if (PyType_Ready(&PyTdb) < 0)
774 if (PyType_Ready(&PyTdbIterator) < 0)
777 #if PY_MAJOR_VERSION >= 3
778 m = PyModule_Create(&moduledef);
780 m = Py_InitModule3("tdb", tdb_methods, MODULE_DOC);
785 PyModule_AddIntConstant(m, "REPLACE", TDB_REPLACE);
786 PyModule_AddIntConstant(m, "INSERT", TDB_INSERT);
787 PyModule_AddIntConstant(m, "MODIFY", TDB_MODIFY);
789 PyModule_AddIntConstant(m, "DEFAULT", TDB_DEFAULT);
790 PyModule_AddIntConstant(m, "CLEAR_IF_FIRST", TDB_CLEAR_IF_FIRST);
791 PyModule_AddIntConstant(m, "INTERNAL", TDB_INTERNAL);
792 PyModule_AddIntConstant(m, "NOLOCK", TDB_NOLOCK);
793 PyModule_AddIntConstant(m, "NOMMAP", TDB_NOMMAP);
794 PyModule_AddIntConstant(m, "CONVERT", TDB_CONVERT);
795 PyModule_AddIntConstant(m, "BIGENDIAN", TDB_BIGENDIAN);
796 PyModule_AddIntConstant(m, "NOSYNC", TDB_NOSYNC);
797 PyModule_AddIntConstant(m, "SEQNUM", TDB_SEQNUM);
798 PyModule_AddIntConstant(m, "VOLATILE", TDB_VOLATILE);
799 PyModule_AddIntConstant(m, "ALLOW_NESTING", TDB_ALLOW_NESTING);
800 PyModule_AddIntConstant(m, "DISALLOW_NESTING", TDB_DISALLOW_NESTING);
801 PyModule_AddIntConstant(m, "INCOMPATIBLE_HASH", TDB_INCOMPATIBLE_HASH);
803 PyModule_AddStringConstant(m, "__docformat__", "restructuredText");
805 PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION);
808 PyModule_AddObject(m, "Tdb", (PyObject *)&PyTdb);
810 Py_INCREF(&PyTdbIterator);
816 #if PY_MAJOR_VERSION >= 3
817 PyMODINIT_FUNC PyInit_tdb(void);
818 PyMODINIT_FUNC PyInit_tdb(void)
820 return module_init();