build: Remove unused install-sh
[Samba/id10ts.git] / lib / tdb / pytdb.c
blobcf77a2527466ae8ad7440c5b216240bf36314143
1 /*
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
11 ** under the LGPL
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/>.
27 #include <Python.h>
28 #include "replace.h"
29 #include "system/filesys.h"
31 #ifndef Py_RETURN_NONE
32 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
33 #endif
35 /* Include tdb headers */
36 #include <tdb.h>
38 typedef struct {
39 PyObject_HEAD
40 TDB_CONTEXT *ctx;
41 bool closed;
42 } PyTdbObject;
44 staticforward PyTypeObject PyTdb;
46 static void PyErr_SetTDBError(TDB_CONTEXT *tdb)
48 PyErr_SetObject(PyExc_RuntimeError,
49 Py_BuildValue("(i,s)", tdb_error(tdb), tdb_errorstr(tdb)));
52 static TDB_DATA PyString_AsTDB_DATA(PyObject *data)
54 TDB_DATA ret;
55 ret.dptr = (unsigned char *)PyString_AsString(data);
56 ret.dsize = PyString_Size(data);
57 return ret;
60 static PyObject *PyString_FromTDB_DATA(TDB_DATA data)
62 if (data.dptr == NULL && data.dsize == 0) {
63 Py_RETURN_NONE;
64 } else {
65 PyObject *ret = PyString_FromStringAndSize((const char *)data.dptr,
66 data.dsize);
67 free(data.dptr);
68 return ret;
72 #define PyErr_TDB_ERROR_IS_ERR_RAISE(ret, tdb) \
73 if (ret != 0) { \
74 PyErr_SetTDBError(tdb); \
75 return NULL; \
78 #define PyErr_TDB_RAISE_IF_CLOSED(self) \
79 if (self->closed) { \
80 PyErr_SetObject(PyExc_RuntimeError, \
81 Py_BuildValue("(i,s)", TDB_ERR_IO, "Database is already closed")); \
82 return NULL; \
85 #define PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self) \
86 if (self->closed) { \
87 PyErr_SetObject(PyExc_RuntimeError, \
88 Py_BuildValue("(i,s)", TDB_ERR_IO, "Database is already closed")); \
89 return -1; \
92 static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject *kwargs)
94 char *name = NULL;
95 int hash_size = 0, tdb_flags = TDB_DEFAULT, flags = O_RDWR, mode = 0600;
96 TDB_CONTEXT *ctx;
97 PyTdbObject *ret;
98 const char *kwnames[] = { "name", "hash_size", "tdb_flags", "flags", "mode", NULL };
100 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|siiii", (char **)kwnames, &name, &hash_size, &tdb_flags, &flags, &mode))
101 return NULL;
103 if (name == NULL) {
104 tdb_flags |= TDB_INTERNAL;
107 ctx = tdb_open(name, hash_size, tdb_flags, flags, mode);
108 if (ctx == NULL) {
109 PyErr_SetFromErrno(PyExc_IOError);
110 return NULL;
113 ret = PyObject_New(PyTdbObject, &PyTdb);
114 if (!ret) {
115 tdb_close(ctx);
116 return NULL;
119 ret->ctx = ctx;
120 ret->closed = false;
121 return (PyObject *)ret;
124 static PyObject *obj_transaction_cancel(PyTdbObject *self)
126 int ret;
128 PyErr_TDB_RAISE_IF_CLOSED(self);
130 ret = tdb_transaction_cancel(self->ctx);
131 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
132 Py_RETURN_NONE;
135 static PyObject *obj_transaction_commit(PyTdbObject *self)
137 int ret;
138 PyErr_TDB_RAISE_IF_CLOSED(self);
139 ret = tdb_transaction_commit(self->ctx);
140 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
141 Py_RETURN_NONE;
144 static PyObject *obj_transaction_prepare_commit(PyTdbObject *self)
146 int ret;
147 PyErr_TDB_RAISE_IF_CLOSED(self);
148 ret = tdb_transaction_prepare_commit(self->ctx);
149 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
150 Py_RETURN_NONE;
153 static PyObject *obj_transaction_start(PyTdbObject *self)
155 int ret;
156 PyErr_TDB_RAISE_IF_CLOSED(self);
157 ret = tdb_transaction_start(self->ctx);
158 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
159 Py_RETURN_NONE;
162 static PyObject *obj_reopen(PyTdbObject *self)
164 int ret;
165 PyErr_TDB_RAISE_IF_CLOSED(self);
166 ret = tdb_reopen(self->ctx);
167 if (ret != 0) {
168 self->closed = true;
169 PyErr_SetObject(PyExc_RuntimeError,
170 Py_BuildValue("(i,s)",
171 TDB_ERR_IO,
172 "Failed to reopen database"));
173 return NULL;
175 Py_RETURN_NONE;
178 static PyObject *obj_lockall(PyTdbObject *self)
180 int ret;
181 PyErr_TDB_RAISE_IF_CLOSED(self);
182 ret = tdb_lockall(self->ctx);
183 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
184 Py_RETURN_NONE;
187 static PyObject *obj_unlockall(PyTdbObject *self)
189 int ret;
190 PyErr_TDB_RAISE_IF_CLOSED(self);
191 ret = tdb_unlockall(self->ctx);
192 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
193 Py_RETURN_NONE;
196 static PyObject *obj_lockall_read(PyTdbObject *self)
198 int ret;
199 PyErr_TDB_RAISE_IF_CLOSED(self);
200 ret = tdb_lockall_read(self->ctx);
201 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
202 Py_RETURN_NONE;
205 static PyObject *obj_unlockall_read(PyTdbObject *self)
207 int ret = tdb_unlockall_read(self->ctx);
208 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
209 Py_RETURN_NONE;
212 static PyObject *obj_close(PyTdbObject *self)
214 int ret;
215 if (self->closed)
216 Py_RETURN_NONE;
217 ret = tdb_close(self->ctx);
218 self->closed = true;
219 if (ret != 0) {
220 PyErr_SetObject(PyExc_RuntimeError,
221 Py_BuildValue("(i,s)",
222 TDB_ERR_IO,
223 "Failed to close database"));
224 return NULL;
226 Py_RETURN_NONE;
229 static PyObject *obj_get(PyTdbObject *self, PyObject *args)
231 TDB_DATA key;
232 PyObject *py_key;
234 PyErr_TDB_RAISE_IF_CLOSED(self);
236 if (!PyArg_ParseTuple(args, "O", &py_key))
237 return NULL;
239 key = PyString_AsTDB_DATA(py_key);
240 if (!key.dptr)
241 return NULL;
243 return PyString_FromTDB_DATA(tdb_fetch(self->ctx, key));
246 static PyObject *obj_append(PyTdbObject *self, PyObject *args)
248 TDB_DATA key, data;
249 PyObject *py_key, *py_data;
250 int ret;
252 PyErr_TDB_RAISE_IF_CLOSED(self);
254 if (!PyArg_ParseTuple(args, "OO", &py_key, &py_data))
255 return NULL;
257 key = PyString_AsTDB_DATA(py_key);
258 if (!key.dptr)
259 return NULL;
260 data = PyString_AsTDB_DATA(py_data);
261 if (!data.dptr)
262 return NULL;
264 ret = tdb_append(self->ctx, key, data);
265 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
266 Py_RETURN_NONE;
269 static PyObject *obj_firstkey(PyTdbObject *self)
271 PyErr_TDB_RAISE_IF_CLOSED(self);
273 return PyString_FromTDB_DATA(tdb_firstkey(self->ctx));
276 static PyObject *obj_nextkey(PyTdbObject *self, PyObject *args)
278 TDB_DATA key;
279 PyObject *py_key;
280 PyErr_TDB_RAISE_IF_CLOSED(self);
282 if (!PyArg_ParseTuple(args, "O", &py_key))
283 return NULL;
285 key = PyString_AsTDB_DATA(py_key);
286 if (!key.dptr)
287 return NULL;
289 return PyString_FromTDB_DATA(tdb_nextkey(self->ctx, key));
292 static PyObject *obj_delete(PyTdbObject *self, PyObject *args)
294 TDB_DATA key;
295 PyObject *py_key;
296 int ret;
297 PyErr_TDB_RAISE_IF_CLOSED(self);
299 if (!PyArg_ParseTuple(args, "O", &py_key))
300 return NULL;
302 key = PyString_AsTDB_DATA(py_key);
303 if (!key.dptr)
304 return NULL;
305 ret = tdb_delete(self->ctx, key);
306 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
307 Py_RETURN_NONE;
310 static PyObject *obj_has_key(PyTdbObject *self, PyObject *args)
312 TDB_DATA key;
313 int ret;
314 PyObject *py_key;
315 PyErr_TDB_RAISE_IF_CLOSED(self);
317 if (!PyArg_ParseTuple(args, "O", &py_key))
318 return NULL;
320 key = PyString_AsTDB_DATA(py_key);
321 if (!key.dptr)
322 return NULL;
323 ret = tdb_exists(self->ctx, key);
324 if (ret != TDB_ERR_NOEXIST) {
325 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
328 return (ret == TDB_ERR_NOEXIST)?Py_False:Py_True;
331 static PyObject *obj_store(PyTdbObject *self, PyObject *args)
333 TDB_DATA key, value;
334 int ret;
335 int flag = TDB_REPLACE;
336 PyObject *py_key, *py_value;
338 PyErr_TDB_RAISE_IF_CLOSED(self);
340 if (!PyArg_ParseTuple(args, "OO|i", &py_key, &py_value, &flag))
341 return NULL;
343 key = PyString_AsTDB_DATA(py_key);
344 if (!key.dptr)
345 return NULL;
346 value = PyString_AsTDB_DATA(py_value);
347 if (!value.dptr)
348 return NULL;
350 ret = tdb_store(self->ctx, key, value, flag);
351 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
352 Py_RETURN_NONE;
355 static PyObject *obj_add_flags(PyTdbObject *self, PyObject *args)
357 unsigned flags;
359 PyErr_TDB_RAISE_IF_CLOSED(self);
361 if (!PyArg_ParseTuple(args, "I", &flags))
362 return NULL;
364 tdb_add_flags(self->ctx, flags);
365 Py_RETURN_NONE;
368 static PyObject *obj_remove_flags(PyTdbObject *self, PyObject *args)
370 unsigned flags;
372 PyErr_TDB_RAISE_IF_CLOSED(self);
374 if (!PyArg_ParseTuple(args, "I", &flags))
375 return NULL;
377 tdb_remove_flags(self->ctx, flags);
378 Py_RETURN_NONE;
381 typedef struct {
382 PyObject_HEAD
383 TDB_DATA current;
384 PyTdbObject *iteratee;
385 } PyTdbIteratorObject;
387 static PyObject *tdb_iter_next(PyTdbIteratorObject *self)
389 TDB_DATA current;
390 PyObject *ret;
391 if (self->current.dptr == NULL && self->current.dsize == 0)
392 return NULL;
393 current = self->current;
394 self->current = tdb_nextkey(self->iteratee->ctx, self->current);
395 ret = PyString_FromTDB_DATA(current);
396 return ret;
399 static void tdb_iter_dealloc(PyTdbIteratorObject *self)
401 Py_DECREF(self->iteratee);
402 PyObject_Del(self);
405 PyTypeObject PyTdbIterator = {
406 .tp_name = "Iterator",
407 .tp_basicsize = sizeof(PyTdbIteratorObject),
408 .tp_iternext = (iternextfunc)tdb_iter_next,
409 .tp_dealloc = (destructor)tdb_iter_dealloc,
410 .tp_flags = Py_TPFLAGS_DEFAULT,
411 .tp_iter = PyObject_SelfIter,
414 static PyObject *tdb_object_iter(PyTdbObject *self)
416 PyTdbIteratorObject *ret;
418 PyErr_TDB_RAISE_IF_CLOSED(self);
420 ret = PyObject_New(PyTdbIteratorObject, &PyTdbIterator);
421 if (!ret)
422 return NULL;
423 ret->current = tdb_firstkey(self->ctx);
424 ret->iteratee = self;
425 Py_INCREF(self);
426 return (PyObject *)ret;
429 static PyObject *obj_clear(PyTdbObject *self)
431 int ret;
432 PyErr_TDB_RAISE_IF_CLOSED(self);
433 ret = tdb_wipe_all(self->ctx);
434 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
435 Py_RETURN_NONE;
438 static PyObject *obj_repack(PyTdbObject *self)
440 int ret;
441 PyErr_TDB_RAISE_IF_CLOSED(self);
442 ret = tdb_repack(self->ctx);
443 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
444 Py_RETURN_NONE;
447 static PyObject *obj_enable_seqnum(PyTdbObject *self)
449 PyErr_TDB_RAISE_IF_CLOSED(self);
450 tdb_enable_seqnum(self->ctx);
451 Py_RETURN_NONE;
454 static PyObject *obj_increment_seqnum_nonblock(PyTdbObject *self)
456 PyErr_TDB_RAISE_IF_CLOSED(self);
457 tdb_increment_seqnum_nonblock(self->ctx);
458 Py_RETURN_NONE;
461 static PyMethodDef tdb_object_methods[] = {
462 { "transaction_cancel", (PyCFunction)obj_transaction_cancel, METH_NOARGS,
463 "S.transaction_cancel() -> None\n"
464 "Cancel the currently active transaction." },
465 { "transaction_commit", (PyCFunction)obj_transaction_commit, METH_NOARGS,
466 "S.transaction_commit() -> None\n"
467 "Commit the currently active transaction." },
468 { "transaction_prepare_commit", (PyCFunction)obj_transaction_prepare_commit, METH_NOARGS,
469 "S.transaction_prepare_commit() -> None\n"
470 "Prepare to commit the currently active transaction" },
471 { "transaction_start", (PyCFunction)obj_transaction_start, METH_NOARGS,
472 "S.transaction_start() -> None\n"
473 "Start a new transaction." },
474 { "reopen", (PyCFunction)obj_reopen, METH_NOARGS, "Reopen this file." },
475 { "lock_all", (PyCFunction)obj_lockall, METH_NOARGS, NULL },
476 { "unlock_all", (PyCFunction)obj_unlockall, METH_NOARGS, NULL },
477 { "read_lock_all", (PyCFunction)obj_lockall_read, METH_NOARGS, NULL },
478 { "read_unlock_all", (PyCFunction)obj_unlockall_read, METH_NOARGS, NULL },
479 { "close", (PyCFunction)obj_close, METH_NOARGS, NULL },
480 { "get", (PyCFunction)obj_get, METH_VARARGS, "S.get(key) -> value\n"
481 "Fetch a value." },
482 { "append", (PyCFunction)obj_append, METH_VARARGS, "S.append(key, value) -> None\n"
483 "Append data to an existing key." },
484 { "firstkey", (PyCFunction)obj_firstkey, METH_NOARGS, "S.firstkey() -> data\n"
485 "Return the first key in this database." },
486 { "nextkey", (PyCFunction)obj_nextkey, METH_NOARGS, "S.nextkey(key) -> data\n"
487 "Return the next key in this database." },
488 { "delete", (PyCFunction)obj_delete, METH_VARARGS, "S.delete(key) -> None\n"
489 "Delete an entry." },
490 { "has_key", (PyCFunction)obj_has_key, METH_VARARGS, "S.has_key(key) -> None\n"
491 "Check whether key exists in this database." },
492 { "store", (PyCFunction)obj_store, METH_VARARGS, "S.store(key, data, flag=REPLACE) -> None"
493 "Store data." },
494 { "add_flags", (PyCFunction)obj_add_flags, METH_VARARGS, "S.add_flags(flags) -> None" },
495 { "remove_flags", (PyCFunction)obj_remove_flags, METH_VARARGS, "S.remove_flags(flags) -> None" },
496 { "iterkeys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() -> iterator" },
497 { "clear", (PyCFunction)obj_clear, METH_NOARGS, "S.clear() -> None\n"
498 "Wipe the entire database." },
499 { "repack", (PyCFunction)obj_repack, METH_NOARGS, "S.repack() -> None\n"
500 "Repack the entire database." },
501 { "enable_seqnum", (PyCFunction)obj_enable_seqnum, METH_NOARGS,
502 "S.enable_seqnum() -> None" },
503 { "increment_seqnum_nonblock", (PyCFunction)obj_increment_seqnum_nonblock, METH_NOARGS,
504 "S.increment_seqnum_nonblock() -> None" },
505 { NULL }
508 static PyObject *obj_get_hash_size(PyTdbObject *self, void *closure)
510 PyErr_TDB_RAISE_IF_CLOSED(self);
511 return PyInt_FromLong(tdb_hash_size(self->ctx));
514 static int obj_set_max_dead(PyTdbObject *self, PyObject *max_dead, void *closure)
516 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
517 if (!PyInt_Check(max_dead))
518 return -1;
519 tdb_set_max_dead(self->ctx, PyInt_AsLong(max_dead));
520 return 0;
523 static PyObject *obj_get_map_size(PyTdbObject *self, void *closure)
525 PyErr_TDB_RAISE_IF_CLOSED(self);
526 return PyInt_FromLong(tdb_map_size(self->ctx));
529 static PyObject *obj_get_freelist_size(PyTdbObject *self, void *closure)
531 PyErr_TDB_RAISE_IF_CLOSED(self);
532 return PyInt_FromLong(tdb_freelist_size(self->ctx));
535 static PyObject *obj_get_flags(PyTdbObject *self, void *closure)
537 PyErr_TDB_RAISE_IF_CLOSED(self);
538 return PyInt_FromLong(tdb_get_flags(self->ctx));
541 static PyObject *obj_get_filename(PyTdbObject *self, void *closure)
543 PyErr_TDB_RAISE_IF_CLOSED(self);
544 return PyString_FromString(tdb_name(self->ctx));
547 static PyObject *obj_get_seqnum(PyTdbObject *self, void *closure)
549 PyErr_TDB_RAISE_IF_CLOSED(self);
550 return PyInt_FromLong(tdb_get_seqnum(self->ctx));
554 static PyGetSetDef tdb_object_getsetters[] = {
555 { (char *)"hash_size", (getter)obj_get_hash_size, NULL, NULL },
556 { (char *)"map_size", (getter)obj_get_map_size, NULL, NULL },
557 { (char *)"freelist_size", (getter)obj_get_freelist_size, NULL, NULL },
558 { (char *)"flags", (getter)obj_get_flags, NULL, NULL },
559 { (char *)"max_dead", NULL, (setter)obj_set_max_dead, NULL },
560 { (char *)"filename", (getter)obj_get_filename, NULL, (char *)"The filename of this TDB file."},
561 { (char *)"seqnum", (getter)obj_get_seqnum, NULL, NULL },
562 { NULL }
565 static PyObject *tdb_object_repr(PyTdbObject *self)
567 PyErr_TDB_RAISE_IF_CLOSED(self);
568 if (tdb_get_flags(self->ctx) & TDB_INTERNAL) {
569 return PyString_FromString("Tdb(<internal>)");
570 } else {
571 return PyString_FromFormat("Tdb('%s')", tdb_name(self->ctx));
575 static void tdb_object_dealloc(PyTdbObject *self)
577 if (!self->closed)
578 tdb_close(self->ctx);
579 self->ob_type->tp_free(self);
582 static PyObject *obj_getitem(PyTdbObject *self, PyObject *key)
584 TDB_DATA tkey, val;
585 PyErr_TDB_RAISE_IF_CLOSED(self);
586 if (!PyString_Check(key)) {
587 PyErr_SetString(PyExc_TypeError, "Expected string as key");
588 return NULL;
591 tkey.dptr = (unsigned char *)PyString_AsString(key);
592 tkey.dsize = PyString_Size(key);
594 val = tdb_fetch(self->ctx, tkey);
595 if (val.dptr == NULL) {
596 PyErr_SetString(PyExc_KeyError, "No such TDB entry");
597 return NULL;
598 } else {
599 return PyString_FromTDB_DATA(val);
603 static int obj_setitem(PyTdbObject *self, PyObject *key, PyObject *value)
605 TDB_DATA tkey, tval;
606 int ret;
607 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
608 if (!PyString_Check(key)) {
609 PyErr_SetString(PyExc_TypeError, "Expected string as key");
610 return -1;
613 tkey = PyString_AsTDB_DATA(key);
615 if (value == NULL) {
616 ret = tdb_delete(self->ctx, tkey);
617 } else {
618 if (!PyString_Check(value)) {
619 PyErr_SetString(PyExc_TypeError, "Expected string as value");
620 return -1;
623 tval = PyString_AsTDB_DATA(value);
625 ret = tdb_store(self->ctx, tkey, tval, TDB_REPLACE);
628 if (ret != 0) {
629 PyErr_SetTDBError(self->ctx);
630 return -1;
633 return ret;
636 static PyMappingMethods tdb_object_mapping = {
637 .mp_subscript = (binaryfunc)obj_getitem,
638 .mp_ass_subscript = (objobjargproc)obj_setitem,
640 static PyTypeObject PyTdb = {
641 .tp_name = "tdb.Tdb",
642 .tp_basicsize = sizeof(PyTdbObject),
643 .tp_methods = tdb_object_methods,
644 .tp_getset = tdb_object_getsetters,
645 .tp_new = py_tdb_open,
646 .tp_doc = "A TDB file",
647 .tp_repr = (reprfunc)tdb_object_repr,
648 .tp_dealloc = (destructor)tdb_object_dealloc,
649 .tp_as_mapping = &tdb_object_mapping,
650 .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_ITER,
651 .tp_iter = (getiterfunc)tdb_object_iter,
654 static PyMethodDef tdb_methods[] = {
655 { "open", (PyCFunction)py_tdb_open, METH_VARARGS|METH_KEYWORDS, "open(name, hash_size=0, tdb_flags=TDB_DEFAULT, flags=O_RDWR, mode=0600)\n"
656 "Open a TDB file." },
657 { NULL }
660 void inittdb(void);
661 void inittdb(void)
663 PyObject *m;
665 if (PyType_Ready(&PyTdb) < 0)
666 return;
668 if (PyType_Ready(&PyTdbIterator) < 0)
669 return;
671 m = Py_InitModule3("tdb", tdb_methods,
672 "simple key-value database that supports multiple writers.");
673 if (m == NULL)
674 return;
676 PyModule_AddObject(m, "REPLACE", PyInt_FromLong(TDB_REPLACE));
677 PyModule_AddObject(m, "INSERT", PyInt_FromLong(TDB_INSERT));
678 PyModule_AddObject(m, "MODIFY", PyInt_FromLong(TDB_MODIFY));
680 PyModule_AddObject(m, "DEFAULT", PyInt_FromLong(TDB_DEFAULT));
681 PyModule_AddObject(m, "CLEAR_IF_FIRST", PyInt_FromLong(TDB_CLEAR_IF_FIRST));
682 PyModule_AddObject(m, "INTERNAL", PyInt_FromLong(TDB_INTERNAL));
683 PyModule_AddObject(m, "NOLOCK", PyInt_FromLong(TDB_NOLOCK));
684 PyModule_AddObject(m, "NOMMAP", PyInt_FromLong(TDB_NOMMAP));
685 PyModule_AddObject(m, "CONVERT", PyInt_FromLong(TDB_CONVERT));
686 PyModule_AddObject(m, "BIGENDIAN", PyInt_FromLong(TDB_BIGENDIAN));
687 PyModule_AddObject(m, "NOSYNC", PyInt_FromLong(TDB_NOSYNC));
688 PyModule_AddObject(m, "SEQNUM", PyInt_FromLong(TDB_SEQNUM));
689 PyModule_AddObject(m, "VOLATILE", PyInt_FromLong(TDB_VOLATILE));
690 PyModule_AddObject(m, "ALLOW_NESTING", PyInt_FromLong(TDB_ALLOW_NESTING));
691 PyModule_AddObject(m, "DISALLOW_NESTING", PyInt_FromLong(TDB_DISALLOW_NESTING));
692 PyModule_AddObject(m, "INCOMPATIBLE_HASH", PyInt_FromLong(TDB_INCOMPATIBLE_HASH));
694 PyModule_AddObject(m, "__docformat__", PyString_FromString("restructuredText"));
696 PyModule_AddObject(m, "__version__", PyString_FromString(PACKAGE_VERSION));
698 Py_INCREF(&PyTdb);
699 PyModule_AddObject(m, "Tdb", (PyObject *)&PyTdb);
701 Py_INCREF(&PyTdbIterator);