Add samba3.samba3badnameblob test to check regressions in bug #9215.
[Samba/gbeck.git] / lib / tdb / pytdb.c
blobae0e6f808d74da94450f7441ded0d3ef05fafffb
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 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
168 Py_RETURN_NONE;
171 static PyObject *obj_lockall(PyTdbObject *self)
173 int ret;
174 PyErr_TDB_RAISE_IF_CLOSED(self);
175 ret = tdb_lockall(self->ctx);
176 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
177 Py_RETURN_NONE;
180 static PyObject *obj_unlockall(PyTdbObject *self)
182 int ret;
183 PyErr_TDB_RAISE_IF_CLOSED(self);
184 ret = tdb_unlockall(self->ctx);
185 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
186 Py_RETURN_NONE;
189 static PyObject *obj_lockall_read(PyTdbObject *self)
191 int ret;
192 PyErr_TDB_RAISE_IF_CLOSED(self);
193 ret = tdb_lockall_read(self->ctx);
194 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
195 Py_RETURN_NONE;
198 static PyObject *obj_unlockall_read(PyTdbObject *self)
200 int ret = tdb_unlockall_read(self->ctx);
201 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
202 Py_RETURN_NONE;
205 static PyObject *obj_close(PyTdbObject *self)
207 int ret;
208 if (self->closed)
209 Py_RETURN_NONE;
210 ret = tdb_close(self->ctx);
211 self->closed = true;
212 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
213 Py_RETURN_NONE;
216 static PyObject *obj_get(PyTdbObject *self, PyObject *args)
218 TDB_DATA key;
219 PyObject *py_key;
221 PyErr_TDB_RAISE_IF_CLOSED(self);
223 if (!PyArg_ParseTuple(args, "O", &py_key))
224 return NULL;
226 key = PyString_AsTDB_DATA(py_key);
227 if (!key.dptr)
228 return NULL;
230 return PyString_FromTDB_DATA(tdb_fetch(self->ctx, key));
233 static PyObject *obj_append(PyTdbObject *self, PyObject *args)
235 TDB_DATA key, data;
236 PyObject *py_key, *py_data;
237 int ret;
239 PyErr_TDB_RAISE_IF_CLOSED(self);
241 if (!PyArg_ParseTuple(args, "OO", &py_key, &py_data))
242 return NULL;
244 key = PyString_AsTDB_DATA(py_key);
245 if (!key.dptr)
246 return NULL;
247 data = PyString_AsTDB_DATA(py_data);
248 if (!data.dptr)
249 return NULL;
251 ret = tdb_append(self->ctx, key, data);
252 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
253 Py_RETURN_NONE;
256 static PyObject *obj_firstkey(PyTdbObject *self)
258 PyErr_TDB_RAISE_IF_CLOSED(self);
260 return PyString_FromTDB_DATA(tdb_firstkey(self->ctx));
263 static PyObject *obj_nextkey(PyTdbObject *self, PyObject *args)
265 TDB_DATA key;
266 PyObject *py_key;
267 PyErr_TDB_RAISE_IF_CLOSED(self);
269 if (!PyArg_ParseTuple(args, "O", &py_key))
270 return NULL;
272 key = PyString_AsTDB_DATA(py_key);
273 if (!key.dptr)
274 return NULL;
276 return PyString_FromTDB_DATA(tdb_nextkey(self->ctx, key));
279 static PyObject *obj_delete(PyTdbObject *self, PyObject *args)
281 TDB_DATA key;
282 PyObject *py_key;
283 int ret;
284 PyErr_TDB_RAISE_IF_CLOSED(self);
286 if (!PyArg_ParseTuple(args, "O", &py_key))
287 return NULL;
289 key = PyString_AsTDB_DATA(py_key);
290 if (!key.dptr)
291 return NULL;
292 ret = tdb_delete(self->ctx, key);
293 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
294 Py_RETURN_NONE;
297 static PyObject *obj_has_key(PyTdbObject *self, PyObject *args)
299 TDB_DATA key;
300 int ret;
301 PyObject *py_key;
302 PyErr_TDB_RAISE_IF_CLOSED(self);
304 if (!PyArg_ParseTuple(args, "O", &py_key))
305 return NULL;
307 key = PyString_AsTDB_DATA(py_key);
308 if (!key.dptr)
309 return NULL;
310 ret = tdb_exists(self->ctx, key);
311 if (ret != TDB_ERR_NOEXIST) {
312 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
315 return (ret == TDB_ERR_NOEXIST)?Py_False:Py_True;
318 static PyObject *obj_store(PyTdbObject *self, PyObject *args)
320 TDB_DATA key, value;
321 int ret;
322 int flag = TDB_REPLACE;
323 PyObject *py_key, *py_value;
325 PyErr_TDB_RAISE_IF_CLOSED(self);
327 if (!PyArg_ParseTuple(args, "OO|i", &py_key, &py_value, &flag))
328 return NULL;
330 key = PyString_AsTDB_DATA(py_key);
331 if (!key.dptr)
332 return NULL;
333 value = PyString_AsTDB_DATA(py_value);
334 if (!value.dptr)
335 return NULL;
337 ret = tdb_store(self->ctx, key, value, flag);
338 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
339 Py_RETURN_NONE;
342 static PyObject *obj_add_flags(PyTdbObject *self, PyObject *args)
344 unsigned flags;
346 PyErr_TDB_RAISE_IF_CLOSED(self);
348 if (!PyArg_ParseTuple(args, "I", &flags))
349 return NULL;
351 tdb_add_flags(self->ctx, flags);
352 Py_RETURN_NONE;
355 static PyObject *obj_remove_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_remove_flags(self->ctx, flags);
365 Py_RETURN_NONE;
368 typedef struct {
369 PyObject_HEAD
370 TDB_DATA current;
371 PyTdbObject *iteratee;
372 } PyTdbIteratorObject;
374 static PyObject *tdb_iter_next(PyTdbIteratorObject *self)
376 TDB_DATA current;
377 PyObject *ret;
378 if (self->current.dptr == NULL && self->current.dsize == 0)
379 return NULL;
380 current = self->current;
381 self->current = tdb_nextkey(self->iteratee->ctx, self->current);
382 ret = PyString_FromTDB_DATA(current);
383 return ret;
386 static void tdb_iter_dealloc(PyTdbIteratorObject *self)
388 Py_DECREF(self->iteratee);
389 PyObject_Del(self);
392 PyTypeObject PyTdbIterator = {
393 .tp_name = "Iterator",
394 .tp_basicsize = sizeof(PyTdbIteratorObject),
395 .tp_iternext = (iternextfunc)tdb_iter_next,
396 .tp_dealloc = (destructor)tdb_iter_dealloc,
397 .tp_flags = Py_TPFLAGS_DEFAULT,
398 .tp_iter = PyObject_SelfIter,
401 static PyObject *tdb_object_iter(PyTdbObject *self)
403 PyTdbIteratorObject *ret;
405 PyErr_TDB_RAISE_IF_CLOSED(self);
407 ret = PyObject_New(PyTdbIteratorObject, &PyTdbIterator);
408 if (!ret)
409 return NULL;
410 ret->current = tdb_firstkey(self->ctx);
411 ret->iteratee = self;
412 Py_INCREF(self);
413 return (PyObject *)ret;
416 static PyObject *obj_clear(PyTdbObject *self)
418 int ret;
419 PyErr_TDB_RAISE_IF_CLOSED(self);
420 ret = tdb_wipe_all(self->ctx);
421 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
422 Py_RETURN_NONE;
425 static PyObject *obj_repack(PyTdbObject *self)
427 int ret;
428 PyErr_TDB_RAISE_IF_CLOSED(self);
429 ret = tdb_repack(self->ctx);
430 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
431 Py_RETURN_NONE;
434 static PyObject *obj_enable_seqnum(PyTdbObject *self)
436 PyErr_TDB_RAISE_IF_CLOSED(self);
437 tdb_enable_seqnum(self->ctx);
438 Py_RETURN_NONE;
441 static PyObject *obj_increment_seqnum_nonblock(PyTdbObject *self)
443 PyErr_TDB_RAISE_IF_CLOSED(self);
444 tdb_increment_seqnum_nonblock(self->ctx);
445 Py_RETURN_NONE;
448 static PyMethodDef tdb_object_methods[] = {
449 { "transaction_cancel", (PyCFunction)obj_transaction_cancel, METH_NOARGS,
450 "S.transaction_cancel() -> None\n"
451 "Cancel the currently active transaction." },
452 { "transaction_commit", (PyCFunction)obj_transaction_commit, METH_NOARGS,
453 "S.transaction_commit() -> None\n"
454 "Commit the currently active transaction." },
455 { "transaction_prepare_commit", (PyCFunction)obj_transaction_prepare_commit, METH_NOARGS,
456 "S.transaction_prepare_commit() -> None\n"
457 "Prepare to commit the currently active transaction" },
458 { "transaction_start", (PyCFunction)obj_transaction_start, METH_NOARGS,
459 "S.transaction_start() -> None\n"
460 "Start a new transaction." },
461 { "reopen", (PyCFunction)obj_reopen, METH_NOARGS, "Reopen this file." },
462 { "lock_all", (PyCFunction)obj_lockall, METH_NOARGS, NULL },
463 { "unlock_all", (PyCFunction)obj_unlockall, METH_NOARGS, NULL },
464 { "read_lock_all", (PyCFunction)obj_lockall_read, METH_NOARGS, NULL },
465 { "read_unlock_all", (PyCFunction)obj_unlockall_read, METH_NOARGS, NULL },
466 { "close", (PyCFunction)obj_close, METH_NOARGS, NULL },
467 { "get", (PyCFunction)obj_get, METH_VARARGS, "S.get(key) -> value\n"
468 "Fetch a value." },
469 { "append", (PyCFunction)obj_append, METH_VARARGS, "S.append(key, value) -> None\n"
470 "Append data to an existing key." },
471 { "firstkey", (PyCFunction)obj_firstkey, METH_NOARGS, "S.firstkey() -> data\n"
472 "Return the first key in this database." },
473 { "nextkey", (PyCFunction)obj_nextkey, METH_NOARGS, "S.nextkey(key) -> data\n"
474 "Return the next key in this database." },
475 { "delete", (PyCFunction)obj_delete, METH_VARARGS, "S.delete(key) -> None\n"
476 "Delete an entry." },
477 { "has_key", (PyCFunction)obj_has_key, METH_VARARGS, "S.has_key(key) -> None\n"
478 "Check whether key exists in this database." },
479 { "store", (PyCFunction)obj_store, METH_VARARGS, "S.store(key, data, flag=REPLACE) -> None"
480 "Store data." },
481 { "add_flags", (PyCFunction)obj_add_flags, METH_VARARGS, "S.add_flags(flags) -> None" },
482 { "remove_flags", (PyCFunction)obj_remove_flags, METH_VARARGS, "S.remove_flags(flags) -> None" },
483 { "iterkeys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() -> iterator" },
484 { "clear", (PyCFunction)obj_clear, METH_NOARGS, "S.clear() -> None\n"
485 "Wipe the entire database." },
486 { "repack", (PyCFunction)obj_repack, METH_NOARGS, "S.repack() -> None\n"
487 "Repack the entire database." },
488 { "enable_seqnum", (PyCFunction)obj_enable_seqnum, METH_NOARGS,
489 "S.enable_seqnum() -> None" },
490 { "increment_seqnum_nonblock", (PyCFunction)obj_increment_seqnum_nonblock, METH_NOARGS,
491 "S.increment_seqnum_nonblock() -> None" },
492 { NULL }
495 static PyObject *obj_get_hash_size(PyTdbObject *self, void *closure)
497 PyErr_TDB_RAISE_IF_CLOSED(self);
498 return PyInt_FromLong(tdb_hash_size(self->ctx));
501 static int obj_set_max_dead(PyTdbObject *self, PyObject *max_dead, void *closure)
503 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
504 if (!PyInt_Check(max_dead))
505 return -1;
506 tdb_set_max_dead(self->ctx, PyInt_AsLong(max_dead));
507 return 0;
510 static PyObject *obj_get_map_size(PyTdbObject *self, void *closure)
512 PyErr_TDB_RAISE_IF_CLOSED(self);
513 return PyInt_FromLong(tdb_map_size(self->ctx));
516 static PyObject *obj_get_freelist_size(PyTdbObject *self, void *closure)
518 PyErr_TDB_RAISE_IF_CLOSED(self);
519 return PyInt_FromLong(tdb_freelist_size(self->ctx));
522 static PyObject *obj_get_flags(PyTdbObject *self, void *closure)
524 PyErr_TDB_RAISE_IF_CLOSED(self);
525 return PyInt_FromLong(tdb_get_flags(self->ctx));
528 static PyObject *obj_get_filename(PyTdbObject *self, void *closure)
530 PyErr_TDB_RAISE_IF_CLOSED(self);
531 return PyString_FromString(tdb_name(self->ctx));
534 static PyObject *obj_get_seqnum(PyTdbObject *self, void *closure)
536 PyErr_TDB_RAISE_IF_CLOSED(self);
537 return PyInt_FromLong(tdb_get_seqnum(self->ctx));
541 static PyGetSetDef tdb_object_getsetters[] = {
542 { (char *)"hash_size", (getter)obj_get_hash_size, NULL, NULL },
543 { (char *)"map_size", (getter)obj_get_map_size, NULL, NULL },
544 { (char *)"freelist_size", (getter)obj_get_freelist_size, NULL, NULL },
545 { (char *)"flags", (getter)obj_get_flags, NULL, NULL },
546 { (char *)"max_dead", NULL, (setter)obj_set_max_dead, NULL },
547 { (char *)"filename", (getter)obj_get_filename, NULL, (char *)"The filename of this TDB file."},
548 { (char *)"seqnum", (getter)obj_get_seqnum, NULL, NULL },
549 { NULL }
552 static PyObject *tdb_object_repr(PyTdbObject *self)
554 PyErr_TDB_RAISE_IF_CLOSED(self);
555 if (tdb_get_flags(self->ctx) & TDB_INTERNAL) {
556 return PyString_FromString("Tdb(<internal>)");
557 } else {
558 return PyString_FromFormat("Tdb('%s')", tdb_name(self->ctx));
562 static void tdb_object_dealloc(PyTdbObject *self)
564 if (!self->closed)
565 tdb_close(self->ctx);
566 self->ob_type->tp_free(self);
569 static PyObject *obj_getitem(PyTdbObject *self, PyObject *key)
571 TDB_DATA tkey, val;
572 PyErr_TDB_RAISE_IF_CLOSED(self);
573 if (!PyString_Check(key)) {
574 PyErr_SetString(PyExc_TypeError, "Expected string as key");
575 return NULL;
578 tkey.dptr = (unsigned char *)PyString_AsString(key);
579 tkey.dsize = PyString_Size(key);
581 val = tdb_fetch(self->ctx, tkey);
582 if (val.dptr == NULL) {
583 PyErr_SetString(PyExc_KeyError, "No such TDB entry");
584 return NULL;
585 } else {
586 return PyString_FromTDB_DATA(val);
590 static int obj_setitem(PyTdbObject *self, PyObject *key, PyObject *value)
592 TDB_DATA tkey, tval;
593 int ret;
594 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
595 if (!PyString_Check(key)) {
596 PyErr_SetString(PyExc_TypeError, "Expected string as key");
597 return -1;
600 tkey = PyString_AsTDB_DATA(key);
602 if (value == NULL) {
603 ret = tdb_delete(self->ctx, tkey);
604 } else {
605 if (!PyString_Check(value)) {
606 PyErr_SetString(PyExc_TypeError, "Expected string as value");
607 return -1;
610 tval = PyString_AsTDB_DATA(value);
612 ret = tdb_store(self->ctx, tkey, tval, TDB_REPLACE);
615 if (ret != 0) {
616 PyErr_SetTDBError(self->ctx);
617 return -1;
620 return ret;
623 static PyMappingMethods tdb_object_mapping = {
624 .mp_subscript = (binaryfunc)obj_getitem,
625 .mp_ass_subscript = (objobjargproc)obj_setitem,
627 static PyTypeObject PyTdb = {
628 .tp_name = "tdb.Tdb",
629 .tp_basicsize = sizeof(PyTdbObject),
630 .tp_methods = tdb_object_methods,
631 .tp_getset = tdb_object_getsetters,
632 .tp_new = py_tdb_open,
633 .tp_doc = "A TDB file",
634 .tp_repr = (reprfunc)tdb_object_repr,
635 .tp_dealloc = (destructor)tdb_object_dealloc,
636 .tp_as_mapping = &tdb_object_mapping,
637 .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_ITER,
638 .tp_iter = (getiterfunc)tdb_object_iter,
641 static PyMethodDef tdb_methods[] = {
642 { "open", (PyCFunction)py_tdb_open, METH_VARARGS|METH_KEYWORDS, "open(name, hash_size=0, tdb_flags=TDB_DEFAULT, flags=O_RDWR, mode=0600)\n"
643 "Open a TDB file." },
644 { NULL }
647 void inittdb(void);
648 void inittdb(void)
650 PyObject *m;
652 if (PyType_Ready(&PyTdb) < 0)
653 return;
655 if (PyType_Ready(&PyTdbIterator) < 0)
656 return;
658 m = Py_InitModule3("tdb", tdb_methods,
659 "simple key-value database that supports multiple writers.");
660 if (m == NULL)
661 return;
663 PyModule_AddObject(m, "REPLACE", PyInt_FromLong(TDB_REPLACE));
664 PyModule_AddObject(m, "INSERT", PyInt_FromLong(TDB_INSERT));
665 PyModule_AddObject(m, "MODIFY", PyInt_FromLong(TDB_MODIFY));
667 PyModule_AddObject(m, "DEFAULT", PyInt_FromLong(TDB_DEFAULT));
668 PyModule_AddObject(m, "CLEAR_IF_FIRST", PyInt_FromLong(TDB_CLEAR_IF_FIRST));
669 PyModule_AddObject(m, "INTERNAL", PyInt_FromLong(TDB_INTERNAL));
670 PyModule_AddObject(m, "NOLOCK", PyInt_FromLong(TDB_NOLOCK));
671 PyModule_AddObject(m, "NOMMAP", PyInt_FromLong(TDB_NOMMAP));
672 PyModule_AddObject(m, "CONVERT", PyInt_FromLong(TDB_CONVERT));
673 PyModule_AddObject(m, "BIGENDIAN", PyInt_FromLong(TDB_BIGENDIAN));
674 PyModule_AddObject(m, "NOSYNC", PyInt_FromLong(TDB_NOSYNC));
675 PyModule_AddObject(m, "SEQNUM", PyInt_FromLong(TDB_SEQNUM));
676 PyModule_AddObject(m, "VOLATILE", PyInt_FromLong(TDB_VOLATILE));
677 PyModule_AddObject(m, "ALLOW_NESTING", PyInt_FromLong(TDB_ALLOW_NESTING));
678 PyModule_AddObject(m, "DISALLOW_NESTING", PyInt_FromLong(TDB_DISALLOW_NESTING));
679 PyModule_AddObject(m, "INCOMPATIBLE_HASH", PyInt_FromLong(TDB_INCOMPATIBLE_HASH));
681 PyModule_AddObject(m, "__docformat__", PyString_FromString("restructuredText"));
683 PyModule_AddObject(m, "__version__", PyString_FromString(PACKAGE_VERSION));
685 Py_INCREF(&PyTdb);
686 PyModule_AddObject(m, "Tdb", (PyObject *)&PyTdb);
688 Py_INCREF(&PyTdbIterator);