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 PyInt_AsLong PyLong_AsLong
37 #define Py_TPFLAGS_HAVE_ITER 0
40 /* discard signature of 'func' in favour of 'target_sig' */
41 #define PY_DISCARD_FUNC_SIG(target_sig, func) (target_sig)(void(*)(void))func
49 static PyTypeObject PyTdb;
51 static void PyErr_SetTDBError(TDB_CONTEXT *tdb)
53 PyErr_SetObject(PyExc_RuntimeError,
54 Py_BuildValue("(i,s)", tdb_error(tdb), tdb_errorstr(tdb)));
57 static TDB_DATA PyBytes_AsTDB_DATA(PyObject *data)
60 ret.dptr = (unsigned char *)PyBytes_AsString(data);
61 ret.dsize = PyBytes_Size(data);
65 static PyObject *PyBytes_FromTDB_DATA(TDB_DATA data)
67 if (data.dptr == NULL && data.dsize == 0) {
70 PyObject *ret = PyBytes_FromStringAndSize((const char *)data.dptr,
77 #define PyErr_TDB_ERROR_IS_ERR_RAISE(ret, tdb) \
79 PyErr_SetTDBError(tdb); \
83 #define PyErr_TDB_RAISE_IF_CLOSED(self) \
85 PyErr_SetObject(PyExc_RuntimeError, \
86 Py_BuildValue("(i,s)", TDB_ERR_IO, "Database is already closed")); \
90 #define PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self) \
92 PyErr_SetObject(PyExc_RuntimeError, \
93 Py_BuildValue("(i,s)", TDB_ERR_IO, "Database is already closed")); \
97 static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject *kwargs)
100 int hash_size = 0, tdb_flags = TDB_DEFAULT, flags = O_RDWR, mode = 0600;
103 const char *_kwnames[] = { "name", "hash_size", "tdb_flags", "flags", "mode", NULL };
104 char **kwnames = discard_const_p(char *, _kwnames);
106 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|siiii", kwnames, &name, &hash_size, &tdb_flags, &flags, &mode))
110 tdb_flags |= TDB_INTERNAL;
113 ctx = tdb_open(name, hash_size, tdb_flags, flags, mode);
115 PyErr_SetFromErrno(PyExc_IOError);
119 ret = PyObject_New(PyTdbObject, &PyTdb);
127 return (PyObject *)ret;
130 static PyObject *obj_transaction_cancel(PyTdbObject *self,
131 PyObject *Py_UNUSED(ignored))
135 PyErr_TDB_RAISE_IF_CLOSED(self);
137 ret = tdb_transaction_cancel(self->ctx);
138 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
142 static PyObject *obj_transaction_commit(PyTdbObject *self,
143 PyObject *Py_UNUSED(ignored))
146 PyErr_TDB_RAISE_IF_CLOSED(self);
147 ret = tdb_transaction_commit(self->ctx);
148 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
152 static PyObject *obj_transaction_prepare_commit(PyTdbObject *self,
153 PyObject *Py_UNUSED(ignored))
156 PyErr_TDB_RAISE_IF_CLOSED(self);
157 ret = tdb_transaction_prepare_commit(self->ctx);
158 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
162 static PyObject *obj_transaction_start(PyTdbObject *self,
163 PyObject *Py_UNUSED(ignored))
166 PyErr_TDB_RAISE_IF_CLOSED(self);
167 ret = tdb_transaction_start(self->ctx);
168 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
172 static PyObject *obj_reopen(PyTdbObject *self,
173 PyObject *Py_UNUSED(ignored))
176 PyErr_TDB_RAISE_IF_CLOSED(self);
177 ret = tdb_reopen(self->ctx);
180 PyErr_SetObject(PyExc_RuntimeError,
181 Py_BuildValue("(i,s)",
183 "Failed to reopen database"));
189 static PyObject *obj_lockall(PyTdbObject *self,
190 PyObject *Py_UNUSED(ignored))
193 PyErr_TDB_RAISE_IF_CLOSED(self);
194 ret = tdb_lockall(self->ctx);
195 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
199 static PyObject *obj_unlockall(PyTdbObject *self,
200 PyObject *Py_UNUSED(ignored))
203 PyErr_TDB_RAISE_IF_CLOSED(self);
204 ret = tdb_unlockall(self->ctx);
205 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
209 static PyObject *obj_lockall_read(PyTdbObject *self,
210 PyObject *Py_UNUSED(ignored))
213 PyErr_TDB_RAISE_IF_CLOSED(self);
214 ret = tdb_lockall_read(self->ctx);
215 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
219 static PyObject *obj_unlockall_read(PyTdbObject *self,
220 PyObject *Py_UNUSED(ignored))
222 int ret = tdb_unlockall_read(self->ctx);
223 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
227 static PyObject *obj_close(PyTdbObject *self, PyObject *Py_UNUSED(ignored))
232 ret = tdb_close(self->ctx);
235 PyErr_SetObject(PyExc_RuntimeError,
236 Py_BuildValue("(i,s)",
238 "Failed to close database"));
244 static PyObject *obj_get(PyTdbObject *self, PyObject *args)
249 PyErr_TDB_RAISE_IF_CLOSED(self);
251 if (!PyArg_ParseTuple(args, "O", &py_key))
254 key = PyBytes_AsTDB_DATA(py_key);
258 return PyBytes_FromTDB_DATA(tdb_fetch(self->ctx, key));
261 static PyObject *obj_append(PyTdbObject *self, PyObject *args)
264 PyObject *py_key, *py_data;
267 PyErr_TDB_RAISE_IF_CLOSED(self);
269 if (!PyArg_ParseTuple(args, "OO", &py_key, &py_data))
272 key = PyBytes_AsTDB_DATA(py_key);
275 data = PyBytes_AsTDB_DATA(py_data);
279 ret = tdb_append(self->ctx, key, data);
280 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
284 static PyObject *obj_firstkey(PyTdbObject *self, PyObject *Py_UNUSED(ignored))
286 PyErr_TDB_RAISE_IF_CLOSED(self);
288 return PyBytes_FromTDB_DATA(tdb_firstkey(self->ctx));
291 static PyObject *obj_nextkey(PyTdbObject *self, PyObject *args)
295 PyErr_TDB_RAISE_IF_CLOSED(self);
297 if (!PyArg_ParseTuple(args, "O", &py_key))
300 key = PyBytes_AsTDB_DATA(py_key);
304 return PyBytes_FromTDB_DATA(tdb_nextkey(self->ctx, key));
307 static PyObject *obj_delete(PyTdbObject *self, PyObject *args)
312 PyErr_TDB_RAISE_IF_CLOSED(self);
314 if (!PyArg_ParseTuple(args, "O", &py_key))
317 key = PyBytes_AsTDB_DATA(py_key);
320 ret = tdb_delete(self->ctx, key);
321 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
325 static int obj_contains(PyTdbObject *self, PyObject *py_key)
329 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
331 key = PyBytes_AsTDB_DATA(py_key);
336 ret = tdb_exists(self->ctx, key);
342 #if PY_MAJOR_VERSION < 3
343 static PyObject *obj_has_key(PyTdbObject *self, PyObject *args)
347 PyErr_TDB_RAISE_IF_CLOSED(self);
349 if (!PyArg_ParseTuple(args, "O", &py_key))
352 ret = obj_contains(self, py_key);
362 static PyObject *obj_store(PyTdbObject *self, PyObject *args)
366 int flag = TDB_REPLACE;
367 PyObject *py_key, *py_value;
369 PyErr_TDB_RAISE_IF_CLOSED(self);
371 if (!PyArg_ParseTuple(args, "OO|i", &py_key, &py_value, &flag))
374 key = PyBytes_AsTDB_DATA(py_key);
377 value = PyBytes_AsTDB_DATA(py_value);
381 ret = tdb_store(self->ctx, key, value, flag);
382 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
386 static PyObject *obj_add_flags(PyTdbObject *self, PyObject *args)
390 PyErr_TDB_RAISE_IF_CLOSED(self);
392 if (!PyArg_ParseTuple(args, "I", &flags))
395 tdb_add_flags(self->ctx, flags);
399 static PyObject *obj_remove_flags(PyTdbObject *self, PyObject *args)
403 PyErr_TDB_RAISE_IF_CLOSED(self);
405 if (!PyArg_ParseTuple(args, "I", &flags))
408 tdb_remove_flags(self->ctx, flags);
415 PyTdbObject *iteratee;
416 } PyTdbIteratorObject;
418 static PyObject *tdb_iter_next(PyTdbIteratorObject *self)
422 if (self->current.dptr == NULL && self->current.dsize == 0)
424 current = self->current;
425 self->current = tdb_nextkey(self->iteratee->ctx, self->current);
426 ret = PyBytes_FromTDB_DATA(current);
430 static void tdb_iter_dealloc(PyTdbIteratorObject *self)
432 Py_DECREF(self->iteratee);
436 PyTypeObject PyTdbIterator = {
437 .tp_name = "Iterator",
438 .tp_basicsize = sizeof(PyTdbIteratorObject),
439 .tp_iternext = (iternextfunc)tdb_iter_next,
440 .tp_dealloc = (destructor)tdb_iter_dealloc,
441 .tp_flags = Py_TPFLAGS_DEFAULT,
442 .tp_iter = PyObject_SelfIter,
445 static PyObject *tdb_object_iter(PyTdbObject *self,
446 PyObject *Py_UNUSED(ignored))
448 PyTdbIteratorObject *ret;
450 PyErr_TDB_RAISE_IF_CLOSED(self);
452 ret = PyObject_New(PyTdbIteratorObject, &PyTdbIterator);
455 ret->current = tdb_firstkey(self->ctx);
456 ret->iteratee = self;
458 return (PyObject *)ret;
461 static PyObject *obj_clear(PyTdbObject *self, PyObject *Py_UNUSED(ignored))
464 PyErr_TDB_RAISE_IF_CLOSED(self);
465 ret = tdb_wipe_all(self->ctx);
466 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
470 static PyObject *obj_repack(PyTdbObject *self, PyObject *Py_UNUSED(ignored))
473 PyErr_TDB_RAISE_IF_CLOSED(self);
474 ret = tdb_repack(self->ctx);
475 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
479 static PyObject *obj_enable_seqnum(PyTdbObject *self,
480 PyObject *Py_UNUSED(ignored))
482 PyErr_TDB_RAISE_IF_CLOSED(self);
483 tdb_enable_seqnum(self->ctx);
487 static PyObject *obj_increment_seqnum_nonblock(PyTdbObject *self,
488 PyObject *Py_UNUSED(ignored))
490 PyErr_TDB_RAISE_IF_CLOSED(self);
491 tdb_increment_seqnum_nonblock(self->ctx);
495 static PyMethodDef tdb_object_methods[] = {
496 { "transaction_cancel", (PyCFunction)obj_transaction_cancel, METH_NOARGS,
497 "S.transaction_cancel() -> None\n"
498 "Cancel the currently active transaction." },
499 { "transaction_commit", (PyCFunction)obj_transaction_commit, METH_NOARGS,
500 "S.transaction_commit() -> None\n"
501 "Commit the currently active transaction." },
502 { "transaction_prepare_commit", (PyCFunction)obj_transaction_prepare_commit, METH_NOARGS,
503 "S.transaction_prepare_commit() -> None\n"
504 "Prepare to commit the currently active transaction" },
505 { "transaction_start", (PyCFunction)obj_transaction_start, METH_NOARGS,
506 "S.transaction_start() -> None\n"
507 "Start a new transaction." },
508 { "reopen", (PyCFunction)obj_reopen, METH_NOARGS, "Reopen this file." },
509 { "lock_all", (PyCFunction)obj_lockall, METH_NOARGS, NULL },
510 { "unlock_all", (PyCFunction)obj_unlockall, METH_NOARGS, NULL },
511 { "read_lock_all", (PyCFunction)obj_lockall_read, METH_NOARGS, NULL },
512 { "read_unlock_all", (PyCFunction)obj_unlockall_read, METH_NOARGS, NULL },
513 { "close", (PyCFunction)obj_close, METH_NOARGS, NULL },
514 { "get", (PyCFunction)obj_get, METH_VARARGS, "S.get(key) -> value\n"
516 { "append", (PyCFunction)obj_append, METH_VARARGS, "S.append(key, value) -> None\n"
517 "Append data to an existing key." },
518 { "firstkey", (PyCFunction)obj_firstkey, METH_NOARGS, "S.firstkey() -> data\n"
519 "Return the first key in this database." },
520 { "nextkey", (PyCFunction)obj_nextkey, METH_VARARGS, "S.nextkey(key) -> data\n"
521 "Return the next key in this database." },
522 { "delete", (PyCFunction)obj_delete, METH_VARARGS, "S.delete(key) -> None\n"
523 "Delete an entry." },
524 #if PY_MAJOR_VERSION < 3
525 { "has_key", (PyCFunction)obj_has_key, METH_VARARGS, "S.has_key(key) -> None\n"
526 "Check whether key exists in this database." },
528 { "store", (PyCFunction)obj_store, METH_VARARGS, "S.store(key, data, flag=REPLACE) -> None"
530 { "add_flags", (PyCFunction)obj_add_flags, METH_VARARGS, "S.add_flags(flags) -> None" },
531 { "remove_flags", (PyCFunction)obj_remove_flags, METH_VARARGS, "S.remove_flags(flags) -> None" },
532 #if PY_MAJOR_VERSION >= 3
533 { "keys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() -> iterator" },
535 { "iterkeys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() -> iterator" },
537 { "clear", (PyCFunction)obj_clear, METH_NOARGS, "S.clear() -> None\n"
538 "Wipe the entire database." },
539 { "repack", (PyCFunction)obj_repack, METH_NOARGS, "S.repack() -> None\n"
540 "Repack the entire database." },
541 { "enable_seqnum", (PyCFunction)obj_enable_seqnum, METH_NOARGS,
542 "S.enable_seqnum() -> None" },
543 { "increment_seqnum_nonblock", (PyCFunction)obj_increment_seqnum_nonblock, METH_NOARGS,
544 "S.increment_seqnum_nonblock() -> None" },
548 static PyObject *obj_get_hash_size(PyTdbObject *self, void *closure)
550 PyErr_TDB_RAISE_IF_CLOSED(self);
551 return PyInt_FromLong(tdb_hash_size(self->ctx));
554 static int obj_set_max_dead(PyTdbObject *self, PyObject *max_dead, void *closure)
556 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
557 if (!PyLong_Check(max_dead))
559 tdb_set_max_dead(self->ctx, PyInt_AsLong(max_dead));
563 static PyObject *obj_get_map_size(PyTdbObject *self, void *closure)
565 PyErr_TDB_RAISE_IF_CLOSED(self);
566 return PyInt_FromLong(tdb_map_size(self->ctx));
569 static PyObject *obj_get_freelist_size(PyTdbObject *self, void *closure)
571 PyErr_TDB_RAISE_IF_CLOSED(self);
572 return PyInt_FromLong(tdb_freelist_size(self->ctx));
575 static PyObject *obj_get_flags(PyTdbObject *self, void *closure)
577 PyErr_TDB_RAISE_IF_CLOSED(self);
578 return PyInt_FromLong(tdb_get_flags(self->ctx));
581 static PyObject *obj_get_filename(PyTdbObject *self, void *closure)
583 PyErr_TDB_RAISE_IF_CLOSED(self);
584 return PyBytes_FromString(tdb_name(self->ctx));
587 static PyObject *obj_get_seqnum(PyTdbObject *self, void *closure)
589 PyErr_TDB_RAISE_IF_CLOSED(self);
590 return PyInt_FromLong(tdb_get_seqnum(self->ctx));
593 static PyObject *obj_get_text(PyTdbObject *self, void *closure)
595 PyObject *mod, *cls, *inst;
596 mod = PyImport_ImportModule("_tdb_text");
599 cls = PyObject_GetAttrString(mod, "TdbTextWrapper");
604 inst = PyObject_CallFunction(cls, discard_const_p(char, "O"), self);
610 static PyGetSetDef tdb_object_getsetters[] = {
612 .name = discard_const_p(char, "hash_size"),
613 .get = (getter)obj_get_hash_size,
616 .name = discard_const_p(char, "map_size"),
617 .get = (getter)obj_get_map_size,
620 .name = discard_const_p(char, "freelist_size"),
621 .get = (getter)obj_get_freelist_size,
624 .name = discard_const_p(char, "flags"),
625 .get = (getter)obj_get_flags,
628 .name = discard_const_p(char, "max_dead"),
629 .set = (setter)obj_set_max_dead,
632 .name = discard_const_p(char, "filename"),
633 .get = (getter)obj_get_filename,
634 .doc = discard_const_p(char, "The filename of this TDB file."),
637 .name = discard_const_p(char, "seqnum"),
638 .get = (getter)obj_get_seqnum,
641 .name = discard_const_p(char, "text"),
642 .get = (getter)obj_get_text,
647 static PyObject *tdb_object_repr(PyTdbObject *self)
649 PyErr_TDB_RAISE_IF_CLOSED(self);
650 if (tdb_get_flags(self->ctx) & TDB_INTERNAL) {
651 return PyUnicode_FromString("Tdb(<internal>)");
653 return PyUnicode_FromFormat("Tdb('%s')", tdb_name(self->ctx));
657 static void tdb_object_dealloc(PyTdbObject *self)
660 tdb_close(self->ctx);
661 Py_TYPE(self)->tp_free(self);
664 static PyObject *obj_getitem(PyTdbObject *self, PyObject *key)
667 PyErr_TDB_RAISE_IF_CLOSED(self);
668 if (!PyBytes_Check(key)) {
669 PyErr_SetString(PyExc_TypeError, "Expected bytestring as key");
673 tkey.dptr = (unsigned char *)PyBytes_AsString(key);
674 tkey.dsize = PyBytes_Size(key);
676 val = tdb_fetch(self->ctx, tkey);
677 if (val.dptr == NULL) {
679 * if the key doesn't exist raise KeyError(key) to be
680 * consistent with python dict
682 PyErr_SetObject(PyExc_KeyError, key);
685 return PyBytes_FromTDB_DATA(val);
689 static int obj_setitem(PyTdbObject *self, PyObject *key, PyObject *value)
693 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
694 if (!PyBytes_Check(key)) {
695 PyErr_SetString(PyExc_TypeError, "Expected bytestring as key");
699 tkey = PyBytes_AsTDB_DATA(key);
702 ret = tdb_delete(self->ctx, tkey);
704 if (!PyBytes_Check(value)) {
705 PyErr_SetString(PyExc_TypeError, "Expected string as value");
709 tval = PyBytes_AsTDB_DATA(value);
711 ret = tdb_store(self->ctx, tkey, tval, TDB_REPLACE);
715 PyErr_SetTDBError(self->ctx);
722 static PyMappingMethods tdb_object_mapping = {
723 .mp_subscript = (binaryfunc)obj_getitem,
724 .mp_ass_subscript = (objobjargproc)obj_setitem,
726 static PySequenceMethods tdb_object_seq = {
727 .sq_contains = (objobjproc)obj_contains,
729 static PyTypeObject PyTdb = {
730 .tp_name = "tdb.Tdb",
731 .tp_basicsize = sizeof(PyTdbObject),
732 .tp_methods = tdb_object_methods,
733 .tp_getset = tdb_object_getsetters,
734 .tp_new = py_tdb_open,
735 .tp_doc = "A TDB file",
736 .tp_repr = (reprfunc)tdb_object_repr,
737 .tp_dealloc = (destructor)tdb_object_dealloc,
738 .tp_as_mapping = &tdb_object_mapping,
739 .tp_as_sequence = &tdb_object_seq,
740 .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_ITER,
741 .tp_iter = PY_DISCARD_FUNC_SIG(getiterfunc,tdb_object_iter),
744 static PyMethodDef tdb_methods[] = {
747 .ml_meth = PY_DISCARD_FUNC_SIG(PyCFunction, py_tdb_open),
748 .ml_flags = METH_VARARGS|METH_KEYWORDS,
749 .ml_doc = "open(name, hash_size=0, tdb_flags=TDB_DEFAULT, "
750 "flags=O_RDWR, mode=0600)\nOpen a TDB file."
755 #define MODULE_DOC "simple key-value database that supports multiple writers."
757 #if PY_MAJOR_VERSION >= 3
758 static struct PyModuleDef moduledef = {
759 PyModuleDef_HEAD_INIT,
763 .m_methods = tdb_methods,
767 PyObject* module_init(void);
768 PyObject* module_init(void)
772 if (PyType_Ready(&PyTdb) < 0)
775 if (PyType_Ready(&PyTdbIterator) < 0)
778 #if PY_MAJOR_VERSION >= 3
779 m = PyModule_Create(&moduledef);
781 m = Py_InitModule3("tdb", tdb_methods, MODULE_DOC);
786 PyModule_AddIntConstant(m, "REPLACE", TDB_REPLACE);
787 PyModule_AddIntConstant(m, "INSERT", TDB_INSERT);
788 PyModule_AddIntConstant(m, "MODIFY", TDB_MODIFY);
790 PyModule_AddIntConstant(m, "DEFAULT", TDB_DEFAULT);
791 PyModule_AddIntConstant(m, "CLEAR_IF_FIRST", TDB_CLEAR_IF_FIRST);
792 PyModule_AddIntConstant(m, "INTERNAL", TDB_INTERNAL);
793 PyModule_AddIntConstant(m, "NOLOCK", TDB_NOLOCK);
794 PyModule_AddIntConstant(m, "NOMMAP", TDB_NOMMAP);
795 PyModule_AddIntConstant(m, "CONVERT", TDB_CONVERT);
796 PyModule_AddIntConstant(m, "BIGENDIAN", TDB_BIGENDIAN);
797 PyModule_AddIntConstant(m, "NOSYNC", TDB_NOSYNC);
798 PyModule_AddIntConstant(m, "SEQNUM", TDB_SEQNUM);
799 PyModule_AddIntConstant(m, "VOLATILE", TDB_VOLATILE);
800 PyModule_AddIntConstant(m, "ALLOW_NESTING", TDB_ALLOW_NESTING);
801 PyModule_AddIntConstant(m, "DISALLOW_NESTING", TDB_DISALLOW_NESTING);
802 PyModule_AddIntConstant(m, "INCOMPATIBLE_HASH", TDB_INCOMPATIBLE_HASH);
804 PyModule_AddStringConstant(m, "__docformat__", "restructuredText");
806 PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION);
809 PyModule_AddObject(m, "Tdb", (PyObject *)&PyTdb);
811 Py_INCREF(&PyTdbIterator);
817 #if PY_MAJOR_VERSION >= 3
818 PyMODINIT_FUNC PyInit_tdb(void);
819 PyMODINIT_FUNC PyInit_tdb(void)
821 return module_init();