Changeset 740 for vendor/current/lib/tdb/pytdb.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified vendor/current/lib/tdb/pytdb.c ¶
r414 r740 10 10 ** library. This does NOT imply that all of Samba is released 11 11 ** under the LGPL 12 12 13 13 This library is free software; you can redistribute it and/or 14 14 modify it under the terms of the GNU Lesser General Public … … 25 25 */ 26 26 27 #include <Python.h> 27 28 #include "replace.h" 28 29 #include "system/filesys.h" 29 30 30 #include <Python.h>31 31 #ifndef Py_RETURN_NONE 32 32 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None … … 42 42 } PyTdbObject; 43 43 44 PyAPI_DATA(PyTypeObject)PyTdb;44 staticforward PyTypeObject PyTdb; 45 45 46 46 static void PyErr_SetTDBError(TDB_CONTEXT *tdb) … … 78 78 static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject *kwargs) 79 79 { 80 char *name ;80 char *name = NULL; 81 81 int hash_size = 0, tdb_flags = TDB_DEFAULT, flags = O_RDWR, mode = 0600; 82 82 TDB_CONTEXT *ctx; … … 84 84 const char *kwnames[] = { "name", "hash_size", "tdb_flags", "flags", "mode", NULL }; 85 85 86 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiii", (char **)kwnames, &name, &hash_size, &tdb_flags, &flags, &mode)) 87 return NULL; 86 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|siiii", (char **)kwnames, &name, &hash_size, &tdb_flags, &flags, &mode)) 87 return NULL; 88 89 if (name == NULL) { 90 tdb_flags |= TDB_INTERNAL; 91 } 88 92 89 93 ctx = tdb_open(name, hash_size, tdb_flags, flags, mode); … … 94 98 95 99 ret = PyObject_New(PyTdbObject, &PyTdb); 100 if (!ret) { 101 tdb_close(ctx); 102 return NULL; 103 } 104 96 105 ret->ctx = ctx; 97 106 ret->closed = false; … … 113 122 } 114 123 115 static PyObject *obj_transaction_ recover(PyTdbObject *self)116 { 117 int ret = tdb_transaction_ recover(self->ctx);124 static PyObject *obj_transaction_prepare_commit(PyTdbObject *self) 125 { 126 int ret = tdb_transaction_prepare_commit(self->ctx); 118 127 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); 119 128 Py_RETURN_NONE; … … 267 276 } 268 277 278 static PyObject *obj_add_flags(PyTdbObject *self, PyObject *args) 279 { 280 unsigned flags; 281 282 if (!PyArg_ParseTuple(args, "I", &flags)) 283 return NULL; 284 285 tdb_add_flags(self->ctx, flags); 286 Py_RETURN_NONE; 287 } 288 289 static PyObject *obj_remove_flags(PyTdbObject *self, PyObject *args) 290 { 291 unsigned flags; 292 293 if (!PyArg_ParseTuple(args, "I", &flags)) 294 return NULL; 295 296 tdb_remove_flags(self->ctx, flags); 297 Py_RETURN_NONE; 298 } 269 299 270 300 typedef struct { … … 306 336 307 337 ret = PyObject_New(PyTdbIteratorObject, &PyTdbIterator); 338 if (!ret) 339 return NULL; 308 340 ret->current = tdb_firstkey(self->ctx); 309 341 ret->iteratee = self; … … 316 348 int ret = tdb_wipe_all(self->ctx); 317 349 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); 350 Py_RETURN_NONE; 351 } 352 353 static PyObject *obj_repack(PyTdbObject *self) 354 { 355 int ret = tdb_repack(self->ctx); 356 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); 357 Py_RETURN_NONE; 358 } 359 360 static PyObject *obj_enable_seqnum(PyTdbObject *self) 361 { 362 tdb_enable_seqnum(self->ctx); 363 Py_RETURN_NONE; 364 } 365 366 static PyObject *obj_increment_seqnum_nonblock(PyTdbObject *self) 367 { 368 tdb_increment_seqnum_nonblock(self->ctx); 318 369 Py_RETURN_NONE; 319 370 } … … 326 377 "S.transaction_commit() -> None\n" 327 378 "Commit the currently active transaction." }, 328 { "transaction_ recover", (PyCFunction)obj_transaction_recover, METH_NOARGS,329 "S.transaction_ recover() -> None\n"330 " Recover the currently active transaction." },379 { "transaction_prepare_commit", (PyCFunction)obj_transaction_prepare_commit, METH_NOARGS, 380 "S.transaction_prepare_commit() -> None\n" 381 "Prepare to commit the currently active transaction" }, 331 382 { "transaction_start", (PyCFunction)obj_transaction_start, METH_NOARGS, 332 383 "S.transaction_start() -> None\n" … … 352 403 { "store", (PyCFunction)obj_store, METH_VARARGS, "S.store(key, data, flag=REPLACE) -> None" 353 404 "Store data." }, 405 { "add_flags", (PyCFunction)obj_add_flags, METH_VARARGS, "S.add_flags(flags) -> None" }, 406 { "remove_flags", (PyCFunction)obj_remove_flags, METH_VARARGS, "S.remove_flags(flags) -> None" }, 354 407 { "iterkeys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() -> iterator" }, 355 408 { "clear", (PyCFunction)obj_clear, METH_NOARGS, "S.clear() -> None\n" 356 409 "Wipe the entire database." }, 410 { "repack", (PyCFunction)obj_repack, METH_NOARGS, "S.repack() -> None\n" 411 "Repack the entire database." }, 412 { "enable_seqnum", (PyCFunction)obj_enable_seqnum, METH_NOARGS, 413 "S.enable_seqnum() -> None" }, 414 { "increment_seqnum_nonblock", (PyCFunction)obj_increment_seqnum_nonblock, METH_NOARGS, 415 "S.increment_seqnum_nonblock() -> None" }, 357 416 { NULL } 358 417 }; … … 376 435 } 377 436 437 static PyObject *obj_get_freelist_size(PyTdbObject *self, void *closure) 438 { 439 return PyInt_FromLong(tdb_freelist_size(self->ctx)); 440 } 441 378 442 static PyObject *obj_get_flags(PyTdbObject *self, void *closure) 379 443 { … … 385 449 return PyString_FromString(tdb_name(self->ctx)); 386 450 } 451 452 static PyObject *obj_get_seqnum(PyTdbObject *self, void *closure) 453 { 454 return PyInt_FromLong(tdb_get_seqnum(self->ctx)); 455 } 456 387 457 388 458 static PyGetSetDef tdb_object_getsetters[] = { 389 459 { (char *)"hash_size", (getter)obj_get_hash_size, NULL, NULL }, 390 460 { (char *)"map_size", (getter)obj_get_map_size, NULL, NULL }, 461 { (char *)"freelist_size", (getter)obj_get_freelist_size, NULL, NULL }, 391 462 { (char *)"flags", (getter)obj_get_flags, NULL, NULL }, 392 463 { (char *)"max_dead", NULL, (setter)obj_set_max_dead, NULL }, 393 464 { (char *)"filename", (getter)obj_get_filename, NULL, (char *)"The filename of this TDB file."}, 465 { (char *)"seqnum", (getter)obj_get_seqnum, NULL, NULL }, 394 466 { NULL } 395 467 }; … … 397 469 static PyObject *tdb_object_repr(PyTdbObject *self) 398 470 { 399 return PyString_FromFormat("Tdb('%s')", tdb_name(self->ctx)); 471 if (tdb_get_flags(self->ctx) & TDB_INTERNAL) { 472 return PyString_FromString("Tdb(<internal>)"); 473 } else { 474 return PyString_FromFormat("Tdb('%s')", tdb_name(self->ctx)); 475 } 400 476 } 401 477 … … 404 480 if (!self->closed) 405 481 tdb_close(self->ctx); 406 PyObject_Del(self);482 self->ob_type->tp_free(self); 407 483 } 408 484 … … 463 539 .mp_ass_subscript = (objobjargproc)obj_setitem, 464 540 }; 465 PyTypeObject PyTdb = {541 static PyTypeObject PyTdb = { 466 542 .tp_name = "Tdb", 467 543 .tp_basicsize = sizeof(PyTdbObject), … … 483 559 }; 484 560 561 void inittdb(void); 485 562 void inittdb(void) 486 563 { … … 508 585 PyModule_AddObject(m, "CONVERT", PyInt_FromLong(TDB_CONVERT)); 509 586 PyModule_AddObject(m, "BIGENDIAN", PyInt_FromLong(TDB_BIGENDIAN)); 587 PyModule_AddObject(m, "NOSYNC", PyInt_FromLong(TDB_NOSYNC)); 588 PyModule_AddObject(m, "SEQNUM", PyInt_FromLong(TDB_SEQNUM)); 589 PyModule_AddObject(m, "VOLATILE", PyInt_FromLong(TDB_VOLATILE)); 590 PyModule_AddObject(m, "ALLOW_NESTING", PyInt_FromLong(TDB_ALLOW_NESTING)); 591 PyModule_AddObject(m, "DISALLOW_NESTING", PyInt_FromLong(TDB_DISALLOW_NESTING)); 592 PyModule_AddObject(m, "INCOMPATIBLE_HASH", PyInt_FromLong(TDB_INCOMPATIBLE_HASH)); 593 510 594 PyModule_AddObject(m, "__docformat__", PyString_FromString("restructuredText")); 595 596 PyModule_AddObject(m, "__version__", PyString_FromString(PACKAGE_VERSION)); 511 597 512 598 Py_INCREF(&PyTdb);
Note:
See TracChangeset
for help on using the changeset viewer.