Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1 | /*---------------------------------------------------------------------- |
| 2 | Copyright (c) 1999-2001, Digital Creations, Fredericksburg, VA, USA |
| 3 | and Andrew Kuchling. All rights reserved. |
| 4 | |
| 5 | Redistribution and use in source and binary forms, with or without |
| 6 | modification, are permitted provided that the following conditions are |
| 7 | met: |
| 8 | |
| 9 | o Redistributions of source code must retain the above copyright |
| 10 | notice, this list of conditions, and the disclaimer that follows. |
| 11 | |
| 12 | o Redistributions in binary form must reproduce the above copyright |
| 13 | notice, this list of conditions, and the following disclaimer in |
| 14 | the documentation and/or other materials provided with the |
| 15 | distribution. |
| 16 | |
| 17 | o Neither the name of Digital Creations nor the names of its |
| 18 | contributors may be used to endorse or promote products derived |
| 19 | from this software without specific prior written permission. |
| 20 | |
| 21 | THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS |
| 22 | IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 23 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 24 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL |
| 25 | CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 28 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 29 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 30 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 31 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 32 | DAMAGE. |
| 33 | ------------------------------------------------------------------------*/ |
| 34 | |
| 35 | |
| 36 | /* |
| 37 | * Handwritten code to wrap version 3.x of the Berkeley DB library, |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 38 | * written to replace a SWIG-generated file. It has since been updated |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 39 | * to compile with Berkeley DB versions 3.2 through 4.2. |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 40 | * |
| 41 | * This module was started by Andrew Kuchling to remove the dependency |
Gregory P. Smith | f805785 | 2007-09-09 20:25:00 +0000 | [diff] [blame] | 42 | * on SWIG in a package by Gregory P. Smith who based his work on a |
| 43 | * similar package by Robin Dunn <robin@alldunn.com> which wrapped |
| 44 | * Berkeley DB 2.7.x. |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 45 | * |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 46 | * Development of this module then returned full circle back to Robin Dunn |
| 47 | * who worked on behalf of Digital Creations to complete the wrapping of |
| 48 | * the DB 3.x API and to build a solid unit test suite. Robin has |
| 49 | * since gone onto other projects (wxPython). |
| 50 | * |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 51 | * Gregory P. Smith <greg@krypto.org> was once again the maintainer. |
| 52 | * |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 53 | * Since January 2008, new maintainer is Jesus Cea <jcea@jcea.es>. |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 54 | * Jesus Cea licenses this code to PSF under a Contributor Agreement. |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 55 | * |
| 56 | * Use the pybsddb-users@lists.sf.net mailing list for all questions. |
Barry Warsaw | c74e4a5 | 2003-04-24 14:28:08 +0000 | [diff] [blame] | 57 | * Things can change faster than the header of this file is updated. This |
| 58 | * file is shared with the PyBSDDB project at SourceForge: |
| 59 | * |
| 60 | * http://pybsddb.sf.net |
| 61 | * |
| 62 | * This file should remain backward compatible with Python 2.1, but see PEP |
| 63 | * 291 for the most current backward compatibility requirements: |
| 64 | * |
| 65 | * http://www.python.org/peps/pep-0291.html |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 66 | * |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 67 | * This module contains 7 types: |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 68 | * |
| 69 | * DB (Database) |
| 70 | * DBCursor (Database Cursor) |
| 71 | * DBEnv (database environment) |
| 72 | * DBTxn (An explicit database transaction) |
| 73 | * DBLock (A lock handle) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 74 | * DBSequence (Sequence) |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 75 | * DBSite (Site) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 76 | * |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 77 | * More datatypes added: |
| 78 | * |
| 79 | * DBLogCursor (Log Cursor) |
| 80 | * |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 81 | */ |
| 82 | |
| 83 | /* --------------------------------------------------------------------- */ |
| 84 | |
| 85 | /* |
| 86 | * Portions of this module, associated unit tests and build scripts are the |
| 87 | * result of a contract with The Written Word (http://thewrittenword.com/) |
| 88 | * Many thanks go out to them for causing me to raise the bar on quality and |
| 89 | * functionality, resulting in a better bsddb3 package for all of us to use. |
| 90 | * |
| 91 | * --Robin |
| 92 | */ |
| 93 | |
| 94 | /* --------------------------------------------------------------------- */ |
| 95 | |
Gregory P. Smith | a703a21 | 2003-11-03 01:04:41 +0000 | [diff] [blame] | 96 | #include <stddef.h> /* for offsetof() */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 97 | #include <Python.h> |
Gregory P. Smith | 3925053 | 2007-10-09 06:02:21 +0000 | [diff] [blame] | 98 | |
| 99 | #define COMPILING_BSDDB_C |
| 100 | #include "bsddb.h" |
| 101 | #undef COMPILING_BSDDB_C |
| 102 | |
| 103 | static char *rcs_id = "$Id$"; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 104 | |
| 105 | /* --------------------------------------------------------------------- */ |
| 106 | /* Various macro definitions */ |
| 107 | |
Gregory P. Smith | 7f5b6f4 | 2006-04-08 07:10:51 +0000 | [diff] [blame] | 108 | #if (PY_VERSION_HEX < 0x02050000) |
Neal Norwitz | 09a29fa | 2006-06-12 02:05:55 +0000 | [diff] [blame] | 109 | typedef int Py_ssize_t; |
Gregory P. Smith | 7f5b6f4 | 2006-04-08 07:10:51 +0000 | [diff] [blame] | 110 | #endif |
| 111 | |
Gregory P. Smith | 572226c | 2008-05-26 19:03:35 +0000 | [diff] [blame] | 112 | #if (PY_VERSION_HEX < 0x02060000) /* really: before python trunk r63675 */ |
| 113 | /* This code now uses PyBytes* API function names instead of PyString*. |
| 114 | * These #defines map to their equivalent on earlier python versions. */ |
| 115 | #define PyBytes_FromStringAndSize PyString_FromStringAndSize |
| 116 | #define PyBytes_FromString PyString_FromString |
| 117 | #define PyBytes_AsStringAndSize PyString_AsStringAndSize |
| 118 | #define PyBytes_Check PyString_Check |
| 119 | #define PyBytes_GET_SIZE PyString_GET_SIZE |
| 120 | #define PyBytes_AS_STRING PyString_AS_STRING |
| 121 | #endif |
| 122 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 123 | #if (PY_VERSION_HEX >= 0x03000000) |
| 124 | #define NUMBER_Check PyLong_Check |
| 125 | #define NUMBER_AsLong PyLong_AsLong |
| 126 | #define NUMBER_FromLong PyLong_FromLong |
| 127 | #else |
| 128 | #define NUMBER_Check PyInt_Check |
| 129 | #define NUMBER_AsLong PyInt_AsLong |
| 130 | #define NUMBER_FromLong PyInt_FromLong |
| 131 | #endif |
| 132 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 133 | #ifdef WITH_THREAD |
| 134 | |
| 135 | /* These are for when calling Python --> C */ |
| 136 | #define MYDB_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS; |
| 137 | #define MYDB_END_ALLOW_THREADS Py_END_ALLOW_THREADS; |
| 138 | |
| 139 | /* and these are for calling C --> Python */ |
Mark Hammond | a69d409 | 2003-04-22 23:13:27 +0000 | [diff] [blame] | 140 | #define MYDB_BEGIN_BLOCK_THREADS \ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 141 | PyGILState_STATE __savestate = PyGILState_Ensure(); |
Mark Hammond | a69d409 | 2003-04-22 23:13:27 +0000 | [diff] [blame] | 142 | #define MYDB_END_BLOCK_THREADS \ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 143 | PyGILState_Release(__savestate); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 144 | |
| 145 | #else |
Mark Hammond | a69d409 | 2003-04-22 23:13:27 +0000 | [diff] [blame] | 146 | /* Compiled without threads - avoid all this cruft */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 147 | #define MYDB_BEGIN_ALLOW_THREADS |
| 148 | #define MYDB_END_ALLOW_THREADS |
| 149 | #define MYDB_BEGIN_BLOCK_THREADS |
| 150 | #define MYDB_END_BLOCK_THREADS |
| 151 | |
| 152 | #endif |
| 153 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 154 | /* --------------------------------------------------------------------- */ |
| 155 | /* Exceptions */ |
| 156 | |
| 157 | static PyObject* DBError; /* Base class, all others derive from this */ |
Gregory P. Smith | e276717 | 2003-11-02 08:06:29 +0000 | [diff] [blame] | 158 | static PyObject* DBCursorClosedError; /* raised when trying to use a closed cursor object */ |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 159 | static PyObject* DBKeyEmptyError; /* DB_KEYEMPTY: also derives from KeyError */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 160 | static PyObject* DBKeyExistError; /* DB_KEYEXIST */ |
| 161 | static PyObject* DBLockDeadlockError; /* DB_LOCK_DEADLOCK */ |
| 162 | static PyObject* DBLockNotGrantedError; /* DB_LOCK_NOTGRANTED */ |
| 163 | static PyObject* DBNotFoundError; /* DB_NOTFOUND: also derives from KeyError */ |
| 164 | static PyObject* DBOldVersionError; /* DB_OLD_VERSION */ |
| 165 | static PyObject* DBRunRecoveryError; /* DB_RUNRECOVERY */ |
| 166 | static PyObject* DBVerifyBadError; /* DB_VERIFY_BAD */ |
| 167 | static PyObject* DBNoServerError; /* DB_NOSERVER */ |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 168 | #if (DBVER < 52) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 169 | static PyObject* DBNoServerHomeError; /* DB_NOSERVER_HOME */ |
| 170 | static PyObject* DBNoServerIDError; /* DB_NOSERVER_ID */ |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 171 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 172 | static PyObject* DBPageNotFoundError; /* DB_PAGE_NOTFOUND */ |
| 173 | static PyObject* DBSecondaryBadError; /* DB_SECONDARY_BAD */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 174 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 175 | static PyObject* DBInvalidArgError; /* EINVAL */ |
| 176 | static PyObject* DBAccessError; /* EACCES */ |
| 177 | static PyObject* DBNoSpaceError; /* ENOSPC */ |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 178 | static PyObject* DBNoMemoryError; /* DB_BUFFER_SMALL */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 179 | static PyObject* DBAgainError; /* EAGAIN */ |
| 180 | static PyObject* DBBusyError; /* EBUSY */ |
| 181 | static PyObject* DBFileExistsError; /* EEXIST */ |
| 182 | static PyObject* DBNoSuchFileError; /* ENOENT */ |
| 183 | static PyObject* DBPermissionsError; /* EPERM */ |
| 184 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 185 | static PyObject* DBRepHandleDeadError; /* DB_REP_HANDLE_DEAD */ |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 186 | #if (DBVER >= 44) |
| 187 | static PyObject* DBRepLockoutError; /* DB_REP_LOCKOUT */ |
| 188 | #endif |
| 189 | |
| 190 | #if (DBVER >= 46) |
| 191 | static PyObject* DBRepLeaseExpiredError; /* DB_REP_LEASE_EXPIRED */ |
| 192 | #endif |
| 193 | |
| 194 | #if (DBVER >= 47) |
| 195 | static PyObject* DBForeignConflictError; /* DB_FOREIGN_CONFLICT */ |
| 196 | #endif |
| 197 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 198 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 199 | static PyObject* DBRepUnavailError; /* DB_REP_UNAVAIL */ |
| 200 | |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 201 | #if (DBVER < 48) |
| 202 | #define DB_GID_SIZE DB_XIDDATASIZE |
| 203 | #endif |
| 204 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 205 | |
| 206 | /* --------------------------------------------------------------------- */ |
| 207 | /* Structure definitions */ |
| 208 | |
Gregory P. Smith | 3925053 | 2007-10-09 06:02:21 +0000 | [diff] [blame] | 209 | #if PYTHON_API_VERSION < 1010 |
| 210 | #error "Python 2.1 or later required" |
Gregory P. Smith | a703a21 | 2003-11-03 01:04:41 +0000 | [diff] [blame] | 211 | #endif |
| 212 | |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 213 | |
Gregory P. Smith | 3925053 | 2007-10-09 06:02:21 +0000 | [diff] [blame] | 214 | /* Defaults for moduleFlags in DBEnvObject and DBObject. */ |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 215 | #define DEFAULT_GET_RETURNS_NONE 1 |
Gregory P. Smith | a703a21 | 2003-11-03 01:04:41 +0000 | [diff] [blame] | 216 | #define DEFAULT_CURSOR_SET_RETURNS_NONE 1 /* 0 in pybsddb < 4.2, python < 2.4 */ |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 217 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 218 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 219 | /* See comment in Python 2.6 "object.h" */ |
| 220 | #ifndef staticforward |
| 221 | #define staticforward static |
| 222 | #endif |
| 223 | #ifndef statichere |
| 224 | #define statichere static |
| 225 | #endif |
| 226 | |
| 227 | staticforward PyTypeObject DB_Type, DBCursor_Type, DBEnv_Type, DBTxn_Type, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 228 | DBLock_Type, DBLogCursor_Type; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 229 | staticforward PyTypeObject DBSequence_Type; |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 230 | #if (DBVER >= 52) |
| 231 | staticforward PyTypeObject DBSite_Type; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 232 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 233 | |
Martin v. Löwis | 83c9201 | 2008-04-24 13:17:24 +0000 | [diff] [blame] | 234 | #ifndef Py_TYPE |
Gregory P. Smith | fc00669 | 2007-11-05 09:06:28 +0000 | [diff] [blame] | 235 | /* for compatibility with Python 2.5 and earlier */ |
Christian Heimes | e93237d | 2007-12-19 02:37:44 +0000 | [diff] [blame] | 236 | #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) |
Gregory P. Smith | fc00669 | 2007-11-05 09:06:28 +0000 | [diff] [blame] | 237 | #endif |
| 238 | |
Christian Heimes | e93237d | 2007-12-19 02:37:44 +0000 | [diff] [blame] | 239 | #define DBObject_Check(v) (Py_TYPE(v) == &DB_Type) |
| 240 | #define DBCursorObject_Check(v) (Py_TYPE(v) == &DBCursor_Type) |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 241 | #define DBLogCursorObject_Check(v) (Py_TYPE(v) == &DBLogCursor_Type) |
Christian Heimes | e93237d | 2007-12-19 02:37:44 +0000 | [diff] [blame] | 242 | #define DBEnvObject_Check(v) (Py_TYPE(v) == &DBEnv_Type) |
| 243 | #define DBTxnObject_Check(v) (Py_TYPE(v) == &DBTxn_Type) |
| 244 | #define DBLockObject_Check(v) (Py_TYPE(v) == &DBLock_Type) |
Christian Heimes | e93237d | 2007-12-19 02:37:44 +0000 | [diff] [blame] | 245 | #define DBSequenceObject_Check(v) (Py_TYPE(v) == &DBSequence_Type) |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 246 | #if (DBVER >= 52) |
| 247 | #define DBSiteObject_Check(v) (Py_TYPE(v) == &DBSite_Type) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 248 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 249 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 250 | #if (DBVER < 46) |
| 251 | #define _DBC_close(dbc) dbc->c_close(dbc) |
| 252 | #define _DBC_count(dbc,a,b) dbc->c_count(dbc,a,b) |
| 253 | #define _DBC_del(dbc,a) dbc->c_del(dbc,a) |
| 254 | #define _DBC_dup(dbc,a,b) dbc->c_dup(dbc,a,b) |
| 255 | #define _DBC_get(dbc,a,b,c) dbc->c_get(dbc,a,b,c) |
| 256 | #define _DBC_pget(dbc,a,b,c,d) dbc->c_pget(dbc,a,b,c,d) |
| 257 | #define _DBC_put(dbc,a,b,c) dbc->c_put(dbc,a,b,c) |
| 258 | #else |
| 259 | #define _DBC_close(dbc) dbc->close(dbc) |
| 260 | #define _DBC_count(dbc,a,b) dbc->count(dbc,a,b) |
| 261 | #define _DBC_del(dbc,a) dbc->del(dbc,a) |
| 262 | #define _DBC_dup(dbc,a,b) dbc->dup(dbc,a,b) |
| 263 | #define _DBC_get(dbc,a,b,c) dbc->get(dbc,a,b,c) |
| 264 | #define _DBC_pget(dbc,a,b,c,d) dbc->pget(dbc,a,b,c,d) |
| 265 | #define _DBC_put(dbc,a,b,c) dbc->put(dbc,a,b,c) |
| 266 | #endif |
| 267 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 268 | |
| 269 | /* --------------------------------------------------------------------- */ |
| 270 | /* Utility macros and functions */ |
| 271 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 272 | #define INSERT_IN_DOUBLE_LINKED_LIST(backlink,object) \ |
| 273 | { \ |
| 274 | object->sibling_next=backlink; \ |
| 275 | object->sibling_prev_p=&(backlink); \ |
| 276 | backlink=object; \ |
| 277 | if (object->sibling_next) { \ |
| 278 | object->sibling_next->sibling_prev_p=&(object->sibling_next); \ |
| 279 | } \ |
| 280 | } |
| 281 | |
| 282 | #define EXTRACT_FROM_DOUBLE_LINKED_LIST(object) \ |
| 283 | { \ |
| 284 | if (object->sibling_next) { \ |
| 285 | object->sibling_next->sibling_prev_p=object->sibling_prev_p; \ |
| 286 | } \ |
| 287 | *(object->sibling_prev_p)=object->sibling_next; \ |
| 288 | } |
| 289 | |
| 290 | #define EXTRACT_FROM_DOUBLE_LINKED_LIST_MAYBE_NULL(object) \ |
| 291 | { \ |
| 292 | if (object->sibling_next) { \ |
| 293 | object->sibling_next->sibling_prev_p=object->sibling_prev_p; \ |
| 294 | } \ |
| 295 | if (object->sibling_prev_p) { \ |
| 296 | *(object->sibling_prev_p)=object->sibling_next; \ |
| 297 | } \ |
| 298 | } |
| 299 | |
| 300 | #define INSERT_IN_DOUBLE_LINKED_LIST_TXN(backlink,object) \ |
| 301 | { \ |
| 302 | object->sibling_next_txn=backlink; \ |
| 303 | object->sibling_prev_p_txn=&(backlink); \ |
| 304 | backlink=object; \ |
| 305 | if (object->sibling_next_txn) { \ |
| 306 | object->sibling_next_txn->sibling_prev_p_txn= \ |
| 307 | &(object->sibling_next_txn); \ |
| 308 | } \ |
| 309 | } |
| 310 | |
| 311 | #define EXTRACT_FROM_DOUBLE_LINKED_LIST_TXN(object) \ |
| 312 | { \ |
| 313 | if (object->sibling_next_txn) { \ |
| 314 | object->sibling_next_txn->sibling_prev_p_txn= \ |
| 315 | object->sibling_prev_p_txn; \ |
| 316 | } \ |
| 317 | *(object->sibling_prev_p_txn)=object->sibling_next_txn; \ |
| 318 | } |
| 319 | |
| 320 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 321 | #define RETURN_IF_ERR() \ |
| 322 | if (makeDBError(err)) { \ |
| 323 | return NULL; \ |
| 324 | } |
| 325 | |
| 326 | #define RETURN_NONE() Py_INCREF(Py_None); return Py_None; |
| 327 | |
Gregory P. Smith | e276717 | 2003-11-02 08:06:29 +0000 | [diff] [blame] | 328 | #define _CHECK_OBJECT_NOT_CLOSED(nonNull, pyErrObj, name) \ |
| 329 | if ((nonNull) == NULL) { \ |
| 330 | PyObject *errTuple = NULL; \ |
| 331 | errTuple = Py_BuildValue("(is)", 0, #name " object has been closed"); \ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 332 | if (errTuple) { \ |
| 333 | PyErr_SetObject((pyErrObj), errTuple); \ |
| 334 | Py_DECREF(errTuple); \ |
| 335 | } \ |
Gregory P. Smith | e276717 | 2003-11-02 08:06:29 +0000 | [diff] [blame] | 336 | return NULL; \ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Gregory P. Smith | e276717 | 2003-11-02 08:06:29 +0000 | [diff] [blame] | 339 | #define CHECK_DB_NOT_CLOSED(dbobj) \ |
| 340 | _CHECK_OBJECT_NOT_CLOSED(dbobj->db, DBError, DB) |
| 341 | |
| 342 | #define CHECK_ENV_NOT_CLOSED(env) \ |
| 343 | _CHECK_OBJECT_NOT_CLOSED(env->db_env, DBError, DBEnv) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 344 | |
| 345 | #define CHECK_CURSOR_NOT_CLOSED(curs) \ |
Gregory P. Smith | e276717 | 2003-11-02 08:06:29 +0000 | [diff] [blame] | 346 | _CHECK_OBJECT_NOT_CLOSED(curs->dbc, DBCursorClosedError, DBCursor) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 347 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 348 | #define CHECK_LOGCURSOR_NOT_CLOSED(logcurs) \ |
| 349 | _CHECK_OBJECT_NOT_CLOSED(logcurs->logc, DBCursorClosedError, DBLogCursor) |
| 350 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 351 | #define CHECK_SEQUENCE_NOT_CLOSED(curs) \ |
| 352 | _CHECK_OBJECT_NOT_CLOSED(curs->sequence, DBError, DBSequence) |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 353 | |
| 354 | #if (DBVER >= 52) |
| 355 | #define CHECK_SITE_NOT_CLOSED(db_site) \ |
| 356 | _CHECK_OBJECT_NOT_CLOSED(db_site->site, DBError, DBSite) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 357 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 358 | |
| 359 | #define CHECK_DBFLAG(mydb, flag) (((mydb)->flags & (flag)) || \ |
| 360 | (((mydb)->myenvobj != NULL) && ((mydb)->myenvobj->flags & (flag)))) |
| 361 | |
| 362 | #define CLEAR_DBT(dbt) (memset(&(dbt), 0, sizeof(dbt))) |
| 363 | |
| 364 | #define FREE_DBT(dbt) if ((dbt.flags & (DB_DBT_MALLOC|DB_DBT_REALLOC)) && \ |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 365 | dbt.data != NULL) { free(dbt.data); dbt.data = NULL; } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 366 | |
| 367 | |
| 368 | static int makeDBError(int err); |
| 369 | |
| 370 | |
| 371 | /* Return the access method type of the DBObject */ |
| 372 | static int _DB_get_type(DBObject* self) |
| 373 | { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 374 | DBTYPE type; |
| 375 | int err; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 376 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 377 | err = self->db->get_type(self->db, &type); |
| 378 | if (makeDBError(err)) { |
| 379 | return -1; |
| 380 | } |
| 381 | return type; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | |
| 385 | /* Create a DBT structure (containing key and data values) from Python |
| 386 | strings. Returns 1 on success, 0 on an error. */ |
| 387 | static int make_dbt(PyObject* obj, DBT* dbt) |
| 388 | { |
| 389 | CLEAR_DBT(*dbt); |
| 390 | if (obj == Py_None) { |
| 391 | /* no need to do anything, the structure has already been zeroed */ |
| 392 | } |
| 393 | else if (!PyArg_Parse(obj, "s#", &dbt->data, &dbt->size)) { |
| 394 | PyErr_SetString(PyExc_TypeError, |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 395 | #if (PY_VERSION_HEX < 0x03000000) |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 396 | "Data values must be of type string or None."); |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 397 | #else |
| 398 | "Data values must be of type bytes or None."); |
| 399 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 400 | return 0; |
| 401 | } |
| 402 | return 1; |
| 403 | } |
| 404 | |
| 405 | |
| 406 | /* Recno and Queue DBs can have integer keys. This function figures out |
| 407 | what's been given, verifies that it's allowed, and then makes the DBT. |
| 408 | |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 409 | Caller MUST call FREE_DBT(key) when done. */ |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 410 | static int |
| 411 | make_key_dbt(DBObject* self, PyObject* keyobj, DBT* key, int* pflags) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 412 | { |
| 413 | db_recno_t recno; |
| 414 | int type; |
| 415 | |
| 416 | CLEAR_DBT(*key); |
Gustavo Niemeyer | f073b75 | 2004-01-20 15:24:29 +0000 | [diff] [blame] | 417 | if (keyobj == Py_None) { |
Gustavo Niemeyer | 024f2de | 2004-01-20 15:14:55 +0000 | [diff] [blame] | 418 | type = _DB_get_type(self); |
Gustavo Niemeyer | 8974f72 | 2004-01-20 15:20:03 +0000 | [diff] [blame] | 419 | if (type == -1) |
| 420 | return 0; |
Gustavo Niemeyer | 024f2de | 2004-01-20 15:14:55 +0000 | [diff] [blame] | 421 | if (type == DB_RECNO || type == DB_QUEUE) { |
| 422 | PyErr_SetString( |
| 423 | PyExc_TypeError, |
| 424 | "None keys not allowed for Recno and Queue DB's"); |
| 425 | return 0; |
| 426 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 427 | /* no need to do anything, the structure has already been zeroed */ |
| 428 | } |
| 429 | |
Christian Heimes | 593daf5 | 2008-05-26 12:51:38 +0000 | [diff] [blame] | 430 | else if (PyBytes_Check(keyobj)) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 431 | /* verify access method type */ |
| 432 | type = _DB_get_type(self); |
| 433 | if (type == -1) |
| 434 | return 0; |
| 435 | if (type == DB_RECNO || type == DB_QUEUE) { |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 436 | PyErr_SetString( |
| 437 | PyExc_TypeError, |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 438 | #if (PY_VERSION_HEX < 0x03000000) |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 439 | "String keys not allowed for Recno and Queue DB's"); |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 440 | #else |
| 441 | "Bytes keys not allowed for Recno and Queue DB's"); |
| 442 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 443 | return 0; |
| 444 | } |
| 445 | |
Gregory P. Smith | 10bed54 | 2007-10-09 06:50:43 +0000 | [diff] [blame] | 446 | /* |
| 447 | * NOTE(gps): I don't like doing a data copy here, it seems |
| 448 | * wasteful. But without a clean way to tell FREE_DBT if it |
| 449 | * should free key->data or not we have to. Other places in |
| 450 | * the code check for DB_THREAD and forceably set DBT_MALLOC |
| 451 | * when we otherwise would leave flags 0 to indicate that. |
| 452 | */ |
Christian Heimes | 593daf5 | 2008-05-26 12:51:38 +0000 | [diff] [blame] | 453 | key->data = malloc(PyBytes_GET_SIZE(keyobj)); |
Gregory P. Smith | 10bed54 | 2007-10-09 06:50:43 +0000 | [diff] [blame] | 454 | if (key->data == NULL) { |
| 455 | PyErr_SetString(PyExc_MemoryError, "Key memory allocation failed"); |
| 456 | return 0; |
| 457 | } |
Christian Heimes | 593daf5 | 2008-05-26 12:51:38 +0000 | [diff] [blame] | 458 | memcpy(key->data, PyBytes_AS_STRING(keyobj), |
| 459 | PyBytes_GET_SIZE(keyobj)); |
Gregory P. Smith | 10bed54 | 2007-10-09 06:50:43 +0000 | [diff] [blame] | 460 | key->flags = DB_DBT_REALLOC; |
Christian Heimes | 593daf5 | 2008-05-26 12:51:38 +0000 | [diff] [blame] | 461 | key->size = PyBytes_GET_SIZE(keyobj); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 464 | else if (NUMBER_Check(keyobj)) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 465 | /* verify access method type */ |
| 466 | type = _DB_get_type(self); |
| 467 | if (type == -1) |
| 468 | return 0; |
| 469 | if (type == DB_BTREE && pflags != NULL) { |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 470 | /* if BTREE then an Integer key is allowed with the |
| 471 | * DB_SET_RECNO flag */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 472 | *pflags |= DB_SET_RECNO; |
| 473 | } |
| 474 | else if (type != DB_RECNO && type != DB_QUEUE) { |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 475 | PyErr_SetString( |
| 476 | PyExc_TypeError, |
| 477 | "Integer keys only allowed for Recno and Queue DB's"); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 478 | return 0; |
| 479 | } |
| 480 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 481 | /* Make a key out of the requested recno, use allocated space so DB |
| 482 | * will be able to realloc room for the real key if needed. */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 483 | recno = NUMBER_AsLong(keyobj); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 484 | key->data = malloc(sizeof(db_recno_t)); |
| 485 | if (key->data == NULL) { |
| 486 | PyErr_SetString(PyExc_MemoryError, "Key memory allocation failed"); |
| 487 | return 0; |
| 488 | } |
| 489 | key->ulen = key->size = sizeof(db_recno_t); |
| 490 | memcpy(key->data, &recno, sizeof(db_recno_t)); |
| 491 | key->flags = DB_DBT_REALLOC; |
| 492 | } |
| 493 | else { |
| 494 | PyErr_Format(PyExc_TypeError, |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 495 | #if (PY_VERSION_HEX < 0x03000000) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 496 | "String or Integer object expected for key, %s found", |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 497 | #else |
| 498 | "Bytes or Integer object expected for key, %s found", |
| 499 | #endif |
Christian Heimes | e93237d | 2007-12-19 02:37:44 +0000 | [diff] [blame] | 500 | Py_TYPE(keyobj)->tp_name); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | return 1; |
| 505 | } |
| 506 | |
| 507 | |
| 508 | /* Add partial record access to an existing DBT data struct. |
| 509 | If dlen and doff are set, then the DB_DBT_PARTIAL flag will be set |
| 510 | and the data storage/retrieval will be done using dlen and doff. */ |
| 511 | static int add_partial_dbt(DBT* d, int dlen, int doff) { |
| 512 | /* if neither were set we do nothing (-1 is the default value) */ |
| 513 | if ((dlen == -1) && (doff == -1)) { |
| 514 | return 1; |
| 515 | } |
| 516 | |
| 517 | if ((dlen < 0) || (doff < 0)) { |
| 518 | PyErr_SetString(PyExc_TypeError, "dlen and doff must both be >= 0"); |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | d->flags = d->flags | DB_DBT_PARTIAL; |
| 523 | d->dlen = (unsigned int) dlen; |
| 524 | d->doff = (unsigned int) doff; |
| 525 | return 1; |
| 526 | } |
| 527 | |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 528 | /* a safe strcpy() without the zeroing behaviour and semantics of strncpy. */ |
| 529 | /* TODO: make this use the native libc strlcpy() when available (BSD) */ |
| 530 | unsigned int our_strlcpy(char* dest, const char* src, unsigned int n) |
| 531 | { |
| 532 | unsigned int srclen, copylen; |
| 533 | |
| 534 | srclen = strlen(src); |
| 535 | if (n <= 0) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 536 | return srclen; |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 537 | copylen = (srclen > n-1) ? n-1 : srclen; |
| 538 | /* populate dest[0] thru dest[copylen-1] */ |
| 539 | memcpy(dest, src, copylen); |
| 540 | /* guarantee null termination */ |
| 541 | dest[copylen] = 0; |
| 542 | |
| 543 | return srclen; |
| 544 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 545 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 546 | /* Callback used to save away more information about errors from the DB |
| 547 | * library. */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 548 | static char _db_errmsg[1024]; |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 549 | static void _db_errorCallback(const DB_ENV *db_env, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 550 | const char* prefix, const char* msg) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 551 | { |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 552 | our_strlcpy(_db_errmsg, msg, sizeof(_db_errmsg)); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 556 | /* |
| 557 | ** We need these functions because some results |
| 558 | ** are undefined if pointer is NULL. Some other |
| 559 | ** give None instead of "". |
| 560 | ** |
| 561 | ** This functions are static and will be |
| 562 | ** -I hope- inlined. |
| 563 | */ |
| 564 | static const char *DummyString = "This string is a simple placeholder"; |
| 565 | static PyObject *Build_PyString(const char *p,int s) |
| 566 | { |
| 567 | if (!p) { |
| 568 | p=DummyString; |
| 569 | assert(s==0); |
| 570 | } |
Christian Heimes | 593daf5 | 2008-05-26 12:51:38 +0000 | [diff] [blame] | 571 | return PyBytes_FromStringAndSize(p,s); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | static PyObject *BuildValue_S(const void *p,int s) |
| 575 | { |
| 576 | if (!p) { |
| 577 | p=DummyString; |
| 578 | assert(s==0); |
| 579 | } |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 580 | return PyBytes_FromStringAndSize(p, s); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | static PyObject *BuildValue_SS(const void *p1,int s1,const void *p2,int s2) |
| 584 | { |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 585 | PyObject *a, *b, *r; |
| 586 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 587 | if (!p1) { |
| 588 | p1=DummyString; |
| 589 | assert(s1==0); |
| 590 | } |
| 591 | if (!p2) { |
| 592 | p2=DummyString; |
| 593 | assert(s2==0); |
| 594 | } |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 595 | |
| 596 | if (!(a = PyBytes_FromStringAndSize(p1, s1))) { |
| 597 | return NULL; |
| 598 | } |
| 599 | if (!(b = PyBytes_FromStringAndSize(p2, s2))) { |
| 600 | Py_DECREF(a); |
| 601 | return NULL; |
| 602 | } |
| 603 | |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 604 | r = PyTuple_Pack(2, a, b) ; |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 605 | Py_DECREF(a); |
| 606 | Py_DECREF(b); |
| 607 | return r; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | static PyObject *BuildValue_IS(int i,const void *p,int s) |
| 611 | { |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 612 | PyObject *a, *r; |
| 613 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 614 | if (!p) { |
| 615 | p=DummyString; |
| 616 | assert(s==0); |
| 617 | } |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 618 | |
| 619 | if (!(a = PyBytes_FromStringAndSize(p, s))) { |
| 620 | return NULL; |
| 621 | } |
| 622 | |
| 623 | r = Py_BuildValue("iO", i, a); |
| 624 | Py_DECREF(a); |
| 625 | return r; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 626 | } |
| 627 | |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 628 | static PyObject *BuildValue_LS(long l,const void *p,int s) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 629 | { |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 630 | PyObject *a, *r; |
| 631 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 632 | if (!p) { |
| 633 | p=DummyString; |
| 634 | assert(s==0); |
| 635 | } |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 636 | |
| 637 | if (!(a = PyBytes_FromStringAndSize(p, s))) { |
| 638 | return NULL; |
| 639 | } |
| 640 | |
| 641 | r = Py_BuildValue("lO", l, a); |
| 642 | Py_DECREF(a); |
| 643 | return r; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | |
| 647 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 648 | /* make a nice exception object to raise for errors. */ |
| 649 | static int makeDBError(int err) |
| 650 | { |
| 651 | char errTxt[2048]; /* really big, just in case... */ |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 652 | PyObject *errObj = NULL; |
| 653 | PyObject *errTuple = NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 654 | int exceptionRaised = 0; |
Neal Norwitz | dce937f | 2006-07-23 08:01:43 +0000 | [diff] [blame] | 655 | unsigned int bytes_left; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 656 | |
| 657 | switch (err) { |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 658 | case 0: /* successful, no error */ |
| 659 | return 0; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 660 | |
| 661 | case DB_KEYEMPTY: errObj = DBKeyEmptyError; break; |
| 662 | case DB_KEYEXIST: errObj = DBKeyExistError; break; |
| 663 | case DB_LOCK_DEADLOCK: errObj = DBLockDeadlockError; break; |
| 664 | case DB_LOCK_NOTGRANTED: errObj = DBLockNotGrantedError; break; |
| 665 | case DB_NOTFOUND: errObj = DBNotFoundError; break; |
| 666 | case DB_OLD_VERSION: errObj = DBOldVersionError; break; |
| 667 | case DB_RUNRECOVERY: errObj = DBRunRecoveryError; break; |
| 668 | case DB_VERIFY_BAD: errObj = DBVerifyBadError; break; |
| 669 | case DB_NOSERVER: errObj = DBNoServerError; break; |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 670 | #if (DBVER < 52) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 671 | case DB_NOSERVER_HOME: errObj = DBNoServerHomeError; break; |
| 672 | case DB_NOSERVER_ID: errObj = DBNoServerIDError; break; |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 673 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 674 | case DB_PAGE_NOTFOUND: errObj = DBPageNotFoundError; break; |
| 675 | case DB_SECONDARY_BAD: errObj = DBSecondaryBadError; break; |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 676 | case DB_BUFFER_SMALL: errObj = DBNoMemoryError; break; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 677 | |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 678 | case ENOMEM: errObj = PyExc_MemoryError; break; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 679 | case EINVAL: errObj = DBInvalidArgError; break; |
| 680 | case EACCES: errObj = DBAccessError; break; |
| 681 | case ENOSPC: errObj = DBNoSpaceError; break; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 682 | case EAGAIN: errObj = DBAgainError; break; |
| 683 | case EBUSY : errObj = DBBusyError; break; |
| 684 | case EEXIST: errObj = DBFileExistsError; break; |
| 685 | case ENOENT: errObj = DBNoSuchFileError; break; |
| 686 | case EPERM : errObj = DBPermissionsError; break; |
| 687 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 688 | case DB_REP_HANDLE_DEAD : errObj = DBRepHandleDeadError; break; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 689 | #if (DBVER >= 44) |
| 690 | case DB_REP_LOCKOUT : errObj = DBRepLockoutError; break; |
| 691 | #endif |
| 692 | |
| 693 | #if (DBVER >= 46) |
| 694 | case DB_REP_LEASE_EXPIRED : errObj = DBRepLeaseExpiredError; break; |
| 695 | #endif |
| 696 | |
| 697 | #if (DBVER >= 47) |
| 698 | case DB_FOREIGN_CONFLICT : errObj = DBForeignConflictError; break; |
| 699 | #endif |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 700 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 701 | case DB_REP_UNAVAIL : errObj = DBRepUnavailError; break; |
| 702 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 703 | default: errObj = DBError; break; |
| 704 | } |
| 705 | |
| 706 | if (errObj != NULL) { |
Neal Norwitz | dce937f | 2006-07-23 08:01:43 +0000 | [diff] [blame] | 707 | bytes_left = our_strlcpy(errTxt, db_strerror(err), sizeof(errTxt)); |
| 708 | /* Ensure that bytes_left never goes negative */ |
| 709 | if (_db_errmsg[0] && bytes_left < (sizeof(errTxt) - 4)) { |
| 710 | bytes_left = sizeof(errTxt) - bytes_left - 4 - 1; |
| 711 | assert(bytes_left >= 0); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 712 | strcat(errTxt, " -- "); |
Neal Norwitz | dce937f | 2006-07-23 08:01:43 +0000 | [diff] [blame] | 713 | strncat(errTxt, _db_errmsg, bytes_left); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 714 | } |
Neal Norwitz | dce937f | 2006-07-23 08:01:43 +0000 | [diff] [blame] | 715 | _db_errmsg[0] = 0; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 716 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 717 | errTuple = Py_BuildValue("(is)", err, errTxt); |
| 718 | if (errTuple == NULL) { |
| 719 | Py_DECREF(errObj); |
| 720 | return !0; |
| 721 | } |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 722 | PyErr_SetObject(errObj, errTuple); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 723 | Py_DECREF(errTuple); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | return ((errObj != NULL) || exceptionRaised); |
| 727 | } |
| 728 | |
| 729 | |
| 730 | |
| 731 | /* set a type exception */ |
| 732 | static void makeTypeError(char* expected, PyObject* found) |
| 733 | { |
| 734 | PyErr_Format(PyExc_TypeError, "Expected %s argument, %s found.", |
Christian Heimes | e93237d | 2007-12-19 02:37:44 +0000 | [diff] [blame] | 735 | expected, Py_TYPE(found)->tp_name); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | |
| 739 | /* verify that an obj is either None or a DBTxn, and set the txn pointer */ |
| 740 | static int checkTxnObj(PyObject* txnobj, DB_TXN** txn) |
| 741 | { |
| 742 | if (txnobj == Py_None || txnobj == NULL) { |
| 743 | *txn = NULL; |
| 744 | return 1; |
| 745 | } |
| 746 | if (DBTxnObject_Check(txnobj)) { |
| 747 | *txn = ((DBTxnObject*)txnobj)->txn; |
| 748 | return 1; |
| 749 | } |
| 750 | else |
| 751 | makeTypeError("DBTxn", txnobj); |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | |
| 756 | /* Delete a key from a database |
| 757 | Returns 0 on success, -1 on an error. */ |
| 758 | static int _DB_delete(DBObject* self, DB_TXN *txn, DBT *key, int flags) |
| 759 | { |
| 760 | int err; |
| 761 | |
| 762 | MYDB_BEGIN_ALLOW_THREADS; |
| 763 | err = self->db->del(self->db, txn, key, 0); |
| 764 | MYDB_END_ALLOW_THREADS; |
| 765 | if (makeDBError(err)) { |
| 766 | return -1; |
| 767 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | |
| 772 | /* Store a key into a database |
| 773 | Returns 0 on success, -1 on an error. */ |
| 774 | static int _DB_put(DBObject* self, DB_TXN *txn, DBT *key, DBT *data, int flags) |
| 775 | { |
| 776 | int err; |
| 777 | |
| 778 | MYDB_BEGIN_ALLOW_THREADS; |
| 779 | err = self->db->put(self->db, txn, key, data, flags); |
| 780 | MYDB_END_ALLOW_THREADS; |
| 781 | if (makeDBError(err)) { |
| 782 | return -1; |
| 783 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 784 | return 0; |
| 785 | } |
| 786 | |
| 787 | /* Get a key/data pair from a cursor */ |
| 788 | static PyObject* _DBCursor_get(DBCursorObject* self, int extra_flags, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 789 | PyObject *args, PyObject *kwargs, char *format) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 790 | { |
| 791 | int err; |
| 792 | PyObject* retval = NULL; |
| 793 | DBT key, data; |
| 794 | int dlen = -1; |
| 795 | int doff = -1; |
| 796 | int flags = 0; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 797 | static char* kwnames[] = { "flags", "dlen", "doff", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 798 | |
| 799 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, format, kwnames, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 800 | &flags, &dlen, &doff)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 801 | return NULL; |
| 802 | |
| 803 | CHECK_CURSOR_NOT_CLOSED(self); |
| 804 | |
| 805 | flags |= extra_flags; |
| 806 | CLEAR_DBT(key); |
| 807 | CLEAR_DBT(data); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 808 | if (!add_partial_dbt(&data, dlen, doff)) |
| 809 | return NULL; |
| 810 | |
| 811 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 812 | err = _DBC_get(self->dbc, &key, &data, flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 813 | MYDB_END_ALLOW_THREADS; |
| 814 | |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 815 | if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 816 | && self->mydb->moduleFlags.getReturnsNone) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 817 | Py_INCREF(Py_None); |
| 818 | retval = Py_None; |
| 819 | } |
| 820 | else if (makeDBError(err)) { |
| 821 | retval = NULL; |
| 822 | } |
| 823 | else { /* otherwise, success! */ |
| 824 | |
| 825 | /* if Recno or Queue, return the key as an Int */ |
| 826 | switch (_DB_get_type(self->mydb)) { |
| 827 | case -1: |
| 828 | retval = NULL; |
| 829 | break; |
| 830 | |
| 831 | case DB_RECNO: |
| 832 | case DB_QUEUE: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 833 | retval = BuildValue_IS(*((db_recno_t*)key.data), data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 834 | break; |
| 835 | case DB_HASH: |
| 836 | case DB_BTREE: |
| 837 | default: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 838 | retval = BuildValue_SS(key.data, key.size, data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 839 | break; |
| 840 | } |
| 841 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 842 | return retval; |
| 843 | } |
| 844 | |
| 845 | |
| 846 | /* add an integer to a dictionary using the given name as a key */ |
| 847 | static void _addIntToDict(PyObject* dict, char *name, int value) |
| 848 | { |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 849 | PyObject* v = NUMBER_FromLong((long) value); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 850 | if (!v || PyDict_SetItemString(dict, name, v)) |
| 851 | PyErr_Clear(); |
| 852 | |
| 853 | Py_XDECREF(v); |
| 854 | } |
Kristján Valur Jónsson | bd77c03 | 2007-04-26 15:24:54 +0000 | [diff] [blame] | 855 | |
| 856 | /* The same, when the value is a time_t */ |
| 857 | static void _addTimeTToDict(PyObject* dict, char *name, time_t value) |
| 858 | { |
| 859 | PyObject* v; |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 860 | /* if the value fits in regular int, use that. */ |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 861 | #ifdef PY_LONG_LONG |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 862 | if (sizeof(time_t) > sizeof(long)) |
| 863 | v = PyLong_FromLongLong((PY_LONG_LONG) value); |
| 864 | else |
Kristján Valur Jónsson | bd77c03 | 2007-04-26 15:24:54 +0000 | [diff] [blame] | 865 | #endif |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 866 | v = NUMBER_FromLong((long) value); |
Kristján Valur Jónsson | bd77c03 | 2007-04-26 15:24:54 +0000 | [diff] [blame] | 867 | if (!v || PyDict_SetItemString(dict, name, v)) |
| 868 | PyErr_Clear(); |
| 869 | |
| 870 | Py_XDECREF(v); |
| 871 | } |
| 872 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 873 | /* add an db_seq_t to a dictionary using the given name as a key */ |
| 874 | static void _addDb_seq_tToDict(PyObject* dict, char *name, db_seq_t value) |
| 875 | { |
| 876 | PyObject* v = PyLong_FromLongLong(value); |
| 877 | if (!v || PyDict_SetItemString(dict, name, v)) |
| 878 | PyErr_Clear(); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 879 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 880 | Py_XDECREF(v); |
| 881 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 882 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 883 | static void _addDB_lsnToDict(PyObject* dict, char *name, DB_LSN value) |
| 884 | { |
| 885 | PyObject *v = Py_BuildValue("(ll)",value.file,value.offset); |
| 886 | if (!v || PyDict_SetItemString(dict, name, v)) |
| 887 | PyErr_Clear(); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 888 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 889 | Py_XDECREF(v); |
| 890 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 891 | |
| 892 | /* --------------------------------------------------------------------- */ |
| 893 | /* Allocators and deallocators */ |
| 894 | |
| 895 | static DBObject* |
| 896 | newDBObject(DBEnvObject* arg, int flags) |
| 897 | { |
| 898 | DBObject* self; |
| 899 | DB_ENV* db_env = NULL; |
| 900 | int err; |
| 901 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 902 | self = PyObject_New(DBObject, &DB_Type); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 903 | if (self == NULL) |
| 904 | return NULL; |
| 905 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 906 | self->flags = 0; |
| 907 | self->setflags = 0; |
| 908 | self->myenvobj = NULL; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 909 | self->db = NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 910 | self->children_cursors = NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 911 | self->children_sequences = NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 912 | self->associateCallback = NULL; |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 913 | self->btCompareCallback = NULL; |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 914 | self->dupCompareCallback = NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 915 | self->primaryDBType = 0; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 916 | Py_INCREF(Py_None); |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 917 | self->private_obj = Py_None; |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 918 | self->in_weakreflist = NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 919 | |
| 920 | /* keep a reference to our python DBEnv object */ |
| 921 | if (arg) { |
| 922 | Py_INCREF(arg); |
| 923 | self->myenvobj = arg; |
| 924 | db_env = arg->db_env; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 925 | INSERT_IN_DOUBLE_LINKED_LIST(self->myenvobj->children_dbs,self); |
| 926 | } else { |
| 927 | self->sibling_prev_p=NULL; |
| 928 | self->sibling_next=NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 929 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 930 | self->txn=NULL; |
| 931 | self->sibling_prev_p_txn=NULL; |
| 932 | self->sibling_next_txn=NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 933 | |
| 934 | if (self->myenvobj) |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 935 | self->moduleFlags = self->myenvobj->moduleFlags; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 936 | else |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 937 | self->moduleFlags.getReturnsNone = DEFAULT_GET_RETURNS_NONE; |
| 938 | self->moduleFlags.cursorSetReturnsNone = DEFAULT_CURSOR_SET_RETURNS_NONE; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 939 | |
| 940 | MYDB_BEGIN_ALLOW_THREADS; |
| 941 | err = db_create(&self->db, db_env, flags); |
Neal Norwitz | dce937f | 2006-07-23 08:01:43 +0000 | [diff] [blame] | 942 | if (self->db != NULL) { |
| 943 | self->db->set_errcall(self->db, _db_errorCallback); |
Neal Norwitz | dce937f | 2006-07-23 08:01:43 +0000 | [diff] [blame] | 944 | self->db->app_private = (void*)self; |
Neal Norwitz | dce937f | 2006-07-23 08:01:43 +0000 | [diff] [blame] | 945 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 946 | MYDB_END_ALLOW_THREADS; |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 947 | /* TODO add a weakref(self) to the self->myenvobj->open_child_weakrefs |
| 948 | * list so that a DBEnv can refuse to close without aborting any open |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 949 | * DBTxns and closing any open DBs first. */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 950 | if (makeDBError(err)) { |
| 951 | if (self->myenvobj) { |
Serhiy Storchaka | 98a9722 | 2014-02-09 13:14:04 +0200 | [diff] [blame^] | 952 | Py_CLEAR(self->myenvobj); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 953 | } |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 954 | Py_DECREF(self); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 955 | self = NULL; |
| 956 | } |
| 957 | return self; |
| 958 | } |
| 959 | |
| 960 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 961 | /* Forward declaration */ |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 962 | static PyObject *DB_close_internal(DBObject* self, int flags, int do_not_close); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 963 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 964 | static void |
| 965 | DB_dealloc(DBObject* self) |
| 966 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 967 | PyObject *dummy; |
| 968 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 969 | if (self->db != NULL) { |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 970 | dummy=DB_close_internal(self, 0, 0); |
| 971 | /* |
| 972 | ** Raising exceptions while doing |
| 973 | ** garbage collection is a fatal error. |
| 974 | */ |
| 975 | if (dummy) |
| 976 | Py_DECREF(dummy); |
| 977 | else |
| 978 | PyErr_Clear(); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 979 | } |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 980 | if (self->in_weakreflist != NULL) { |
| 981 | PyObject_ClearWeakRefs((PyObject *) self); |
| 982 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 983 | if (self->myenvobj) { |
Serhiy Storchaka | 98a9722 | 2014-02-09 13:14:04 +0200 | [diff] [blame^] | 984 | Py_CLEAR(self->myenvobj); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 985 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 986 | if (self->associateCallback != NULL) { |
Serhiy Storchaka | 98a9722 | 2014-02-09 13:14:04 +0200 | [diff] [blame^] | 987 | Py_CLEAR(self->associateCallback); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 988 | } |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 989 | if (self->btCompareCallback != NULL) { |
Serhiy Storchaka | 98a9722 | 2014-02-09 13:14:04 +0200 | [diff] [blame^] | 990 | Py_CLEAR(self->btCompareCallback); |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 991 | } |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 992 | if (self->dupCompareCallback != NULL) { |
Serhiy Storchaka | 98a9722 | 2014-02-09 13:14:04 +0200 | [diff] [blame^] | 993 | Py_CLEAR(self->dupCompareCallback); |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 994 | } |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 995 | Py_DECREF(self->private_obj); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 996 | PyObject_Del(self); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 997 | } |
| 998 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 999 | static DBCursorObject* |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1000 | newDBCursorObject(DBC* dbc, DBTxnObject *txn, DBObject* db) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1001 | { |
Neal Norwitz | b4a5581 | 2004-07-09 23:30:57 +0000 | [diff] [blame] | 1002 | DBCursorObject* self = PyObject_New(DBCursorObject, &DBCursor_Type); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1003 | if (self == NULL) |
| 1004 | return NULL; |
| 1005 | |
| 1006 | self->dbc = dbc; |
| 1007 | self->mydb = db; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1008 | |
| 1009 | INSERT_IN_DOUBLE_LINKED_LIST(self->mydb->children_cursors,self); |
| 1010 | if (txn && ((PyObject *)txn!=Py_None)) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1011 | INSERT_IN_DOUBLE_LINKED_LIST_TXN(txn->children_cursors,self); |
| 1012 | self->txn=txn; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1013 | } else { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1014 | self->txn=NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
Gregory P. Smith | a703a21 | 2003-11-03 01:04:41 +0000 | [diff] [blame] | 1017 | self->in_weakreflist = NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1018 | Py_INCREF(self->mydb); |
| 1019 | return self; |
| 1020 | } |
| 1021 | |
| 1022 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1023 | /* Forward declaration */ |
| 1024 | static PyObject *DBC_close_internal(DBCursorObject* self); |
| 1025 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1026 | static void |
| 1027 | DBCursor_dealloc(DBCursorObject* self) |
| 1028 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1029 | PyObject *dummy; |
Gregory P. Smith | a703a21 | 2003-11-03 01:04:41 +0000 | [diff] [blame] | 1030 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1031 | if (self->dbc != NULL) { |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 1032 | dummy=DBC_close_internal(self); |
| 1033 | /* |
| 1034 | ** Raising exceptions while doing |
| 1035 | ** garbage collection is a fatal error. |
| 1036 | */ |
| 1037 | if (dummy) |
| 1038 | Py_DECREF(dummy); |
| 1039 | else |
| 1040 | PyErr_Clear(); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1041 | } |
Gregory P. Smith | a703a21 | 2003-11-03 01:04:41 +0000 | [diff] [blame] | 1042 | if (self->in_weakreflist != NULL) { |
| 1043 | PyObject_ClearWeakRefs((PyObject *) self); |
| 1044 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1045 | Py_DECREF(self->mydb); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1046 | PyObject_Del(self); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1050 | static DBLogCursorObject* |
| 1051 | newDBLogCursorObject(DB_LOGC* dblogc, DBEnvObject* env) |
| 1052 | { |
| 1053 | DBLogCursorObject* self; |
| 1054 | |
| 1055 | self = PyObject_New(DBLogCursorObject, &DBLogCursor_Type); |
| 1056 | |
| 1057 | if (self == NULL) |
| 1058 | return NULL; |
| 1059 | |
| 1060 | self->logc = dblogc; |
| 1061 | self->env = env; |
| 1062 | |
| 1063 | INSERT_IN_DOUBLE_LINKED_LIST(self->env->children_logcursors, self); |
| 1064 | |
| 1065 | self->in_weakreflist = NULL; |
| 1066 | Py_INCREF(self->env); |
| 1067 | return self; |
| 1068 | } |
| 1069 | |
| 1070 | |
| 1071 | /* Forward declaration */ |
| 1072 | static PyObject *DBLogCursor_close_internal(DBLogCursorObject* self); |
| 1073 | |
| 1074 | static void |
| 1075 | DBLogCursor_dealloc(DBLogCursorObject* self) |
| 1076 | { |
| 1077 | PyObject *dummy; |
| 1078 | |
| 1079 | if (self->logc != NULL) { |
| 1080 | dummy = DBLogCursor_close_internal(self); |
| 1081 | /* |
| 1082 | ** Raising exceptions while doing |
| 1083 | ** garbage collection is a fatal error. |
| 1084 | */ |
| 1085 | if (dummy) |
| 1086 | Py_DECREF(dummy); |
| 1087 | else |
| 1088 | PyErr_Clear(); |
| 1089 | } |
| 1090 | if (self->in_weakreflist != NULL) { |
| 1091 | PyObject_ClearWeakRefs((PyObject *) self); |
| 1092 | } |
| 1093 | Py_DECREF(self->env); |
| 1094 | PyObject_Del(self); |
| 1095 | } |
| 1096 | |
| 1097 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1098 | static DBEnvObject* |
| 1099 | newDBEnvObject(int flags) |
| 1100 | { |
| 1101 | int err; |
Neal Norwitz | b4a5581 | 2004-07-09 23:30:57 +0000 | [diff] [blame] | 1102 | DBEnvObject* self = PyObject_New(DBEnvObject, &DBEnv_Type); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1103 | if (self == NULL) |
| 1104 | return NULL; |
| 1105 | |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 1106 | self->db_env = NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1107 | self->closed = 1; |
| 1108 | self->flags = flags; |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 1109 | self->moduleFlags.getReturnsNone = DEFAULT_GET_RETURNS_NONE; |
| 1110 | self->moduleFlags.cursorSetReturnsNone = DEFAULT_CURSOR_SET_RETURNS_NONE; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1111 | self->children_dbs = NULL; |
| 1112 | self->children_txns = NULL; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1113 | self->children_logcursors = NULL ; |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 1114 | #if (DBVER >= 52) |
| 1115 | self->children_sites = NULL; |
| 1116 | #endif |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 1117 | Py_INCREF(Py_None); |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 1118 | self->private_obj = Py_None; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 1119 | Py_INCREF(Py_None); |
| 1120 | self->rep_transport = Py_None; |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 1121 | self->in_weakreflist = NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1122 | self->event_notifyCallback = NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1123 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1124 | MYDB_BEGIN_ALLOW_THREADS; |
| 1125 | err = db_env_create(&self->db_env, flags); |
| 1126 | MYDB_END_ALLOW_THREADS; |
| 1127 | if (makeDBError(err)) { |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 1128 | Py_DECREF(self); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1129 | self = NULL; |
| 1130 | } |
| 1131 | else { |
| 1132 | self->db_env->set_errcall(self->db_env, _db_errorCallback); |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 1133 | self->db_env->app_private = self; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1134 | } |
| 1135 | return self; |
| 1136 | } |
| 1137 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1138 | /* Forward declaration */ |
| 1139 | static PyObject *DBEnv_close_internal(DBEnvObject* self, int flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1140 | |
| 1141 | static void |
| 1142 | DBEnv_dealloc(DBEnvObject* self) |
| 1143 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1144 | PyObject *dummy; |
| 1145 | |
Jesus Cea | ac25fab | 2008-09-03 17:50:32 +0000 | [diff] [blame] | 1146 | if (self->db_env) { |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 1147 | dummy=DBEnv_close_internal(self, 0); |
| 1148 | /* |
| 1149 | ** Raising exceptions while doing |
| 1150 | ** garbage collection is a fatal error. |
| 1151 | */ |
| 1152 | if (dummy) |
| 1153 | Py_DECREF(dummy); |
| 1154 | else |
| 1155 | PyErr_Clear(); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Serhiy Storchaka | 98a9722 | 2014-02-09 13:14:04 +0200 | [diff] [blame^] | 1158 | Py_CLEAR(self->event_notifyCallback); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1159 | |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 1160 | if (self->in_weakreflist != NULL) { |
| 1161 | PyObject_ClearWeakRefs((PyObject *) self); |
| 1162 | } |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 1163 | Py_DECREF(self->private_obj); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 1164 | Py_DECREF(self->rep_transport); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1165 | PyObject_Del(self); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | |
| 1169 | static DBTxnObject* |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1170 | newDBTxnObject(DBEnvObject* myenv, DBTxnObject *parent, DB_TXN *txn, int flags) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1171 | { |
| 1172 | int err; |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 1173 | DB_TXN *parent_txn = NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1174 | |
Neal Norwitz | b4a5581 | 2004-07-09 23:30:57 +0000 | [diff] [blame] | 1175 | DBTxnObject* self = PyObject_New(DBTxnObject, &DBTxn_Type); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1176 | if (self == NULL) |
| 1177 | return NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1178 | |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 1179 | self->in_weakreflist = NULL; |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 1180 | self->children_txns = NULL; |
| 1181 | self->children_dbs = NULL; |
| 1182 | self->children_cursors = NULL; |
| 1183 | self->children_sequences = NULL; |
| 1184 | self->flag_prepare = 0; |
| 1185 | self->parent_txn = NULL; |
| 1186 | self->env = NULL; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1187 | /* We initialize just in case "txn_begin" fails */ |
| 1188 | self->txn = NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1189 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1190 | if (parent && ((PyObject *)parent!=Py_None)) { |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 1191 | parent_txn = parent->txn; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1192 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1193 | |
| 1194 | if (txn) { |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 1195 | self->txn = txn; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1196 | } else { |
| 1197 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1198 | err = myenv->db_env->txn_begin(myenv->db_env, parent_txn, &(self->txn), flags); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1199 | MYDB_END_ALLOW_THREADS; |
| 1200 | |
| 1201 | if (makeDBError(err)) { |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1202 | /* Free object half initialized */ |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 1203 | Py_DECREF(self); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1204 | return NULL; |
| 1205 | } |
| 1206 | } |
| 1207 | |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 1208 | /* Can't use 'parent' because could be 'parent==Py_None' */ |
| 1209 | if (parent_txn) { |
| 1210 | self->parent_txn = parent; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1211 | Py_INCREF(parent); |
| 1212 | self->env = NULL; |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 1213 | INSERT_IN_DOUBLE_LINKED_LIST(parent->children_txns, self); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1214 | } else { |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 1215 | self->parent_txn = NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1216 | Py_INCREF(myenv); |
| 1217 | self->env = myenv; |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 1218 | INSERT_IN_DOUBLE_LINKED_LIST(myenv->children_txns, self); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1221 | return self; |
| 1222 | } |
| 1223 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1224 | /* Forward declaration */ |
| 1225 | static PyObject * |
| 1226 | DBTxn_abort_discard_internal(DBTxnObject* self, int discard); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1227 | |
| 1228 | static void |
| 1229 | DBTxn_dealloc(DBTxnObject* self) |
| 1230 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1231 | PyObject *dummy; |
| 1232 | |
| 1233 | if (self->txn) { |
| 1234 | int flag_prepare = self->flag_prepare; |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 1235 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1236 | dummy=DBTxn_abort_discard_internal(self, 0); |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 1237 | /* |
| 1238 | ** Raising exceptions while doing |
| 1239 | ** garbage collection is a fatal error. |
| 1240 | */ |
| 1241 | if (dummy) |
| 1242 | Py_DECREF(dummy); |
| 1243 | else |
| 1244 | PyErr_Clear(); |
| 1245 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1246 | if (!flag_prepare) { |
| 1247 | PyErr_Warn(PyExc_RuntimeWarning, |
| 1248 | "DBTxn aborted in destructor. No prior commit() or abort()."); |
| 1249 | } |
| 1250 | } |
| 1251 | |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 1252 | if (self->in_weakreflist != NULL) { |
| 1253 | PyObject_ClearWeakRefs((PyObject *) self); |
| 1254 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1255 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1256 | if (self->env) { |
| 1257 | Py_DECREF(self->env); |
| 1258 | } else { |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1259 | /* |
| 1260 | ** We can have "self->env==NULL" and "self->parent_txn==NULL" |
| 1261 | ** if something happens when creating the transaction object |
| 1262 | ** and we abort the object while half done. |
| 1263 | */ |
| 1264 | Py_XDECREF(self->parent_txn); |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 1265 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1266 | PyObject_Del(self); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | |
| 1270 | static DBLockObject* |
| 1271 | newDBLockObject(DBEnvObject* myenv, u_int32_t locker, DBT* obj, |
| 1272 | db_lockmode_t lock_mode, int flags) |
| 1273 | { |
| 1274 | int err; |
Neal Norwitz | b4a5581 | 2004-07-09 23:30:57 +0000 | [diff] [blame] | 1275 | DBLockObject* self = PyObject_New(DBLockObject, &DBLock_Type); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1276 | if (self == NULL) |
| 1277 | return NULL; |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 1278 | self->in_weakreflist = NULL; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1279 | self->lock_initialized = 0; /* Just in case the call fails */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1280 | |
| 1281 | MYDB_BEGIN_ALLOW_THREADS; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 1282 | err = myenv->db_env->lock_get(myenv->db_env, locker, flags, obj, lock_mode, |
| 1283 | &self->lock); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1284 | MYDB_END_ALLOW_THREADS; |
| 1285 | if (makeDBError(err)) { |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 1286 | Py_DECREF(self); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1287 | self = NULL; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1288 | } else { |
| 1289 | self->lock_initialized = 1; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | return self; |
| 1293 | } |
| 1294 | |
| 1295 | |
| 1296 | static void |
| 1297 | DBLock_dealloc(DBLockObject* self) |
| 1298 | { |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 1299 | if (self->in_weakreflist != NULL) { |
| 1300 | PyObject_ClearWeakRefs((PyObject *) self); |
| 1301 | } |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 1302 | /* TODO: is this lock held? should we release it? */ |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1303 | /* CAUTION: The lock can be not initialized if the creation has failed */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1304 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1305 | PyObject_Del(self); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 1309 | static DBSequenceObject* |
| 1310 | newDBSequenceObject(DBObject* mydb, int flags) |
| 1311 | { |
| 1312 | int err; |
| 1313 | DBSequenceObject* self = PyObject_New(DBSequenceObject, &DBSequence_Type); |
| 1314 | if (self == NULL) |
| 1315 | return NULL; |
| 1316 | Py_INCREF(mydb); |
| 1317 | self->mydb = mydb; |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 1318 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1319 | INSERT_IN_DOUBLE_LINKED_LIST(self->mydb->children_sequences,self); |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 1320 | self->txn = NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1321 | |
| 1322 | self->in_weakreflist = NULL; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1323 | self->sequence = NULL; /* Just in case the call fails */ |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 1324 | |
| 1325 | MYDB_BEGIN_ALLOW_THREADS; |
| 1326 | err = db_sequence_create(&self->sequence, self->mydb->db, flags); |
| 1327 | MYDB_END_ALLOW_THREADS; |
| 1328 | if (makeDBError(err)) { |
Gregory P. Smith | 664782e | 2008-05-17 06:12:02 +0000 | [diff] [blame] | 1329 | Py_DECREF(self); |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 1330 | self = NULL; |
| 1331 | } |
| 1332 | |
| 1333 | return self; |
| 1334 | } |
| 1335 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1336 | /* Forward declaration */ |
| 1337 | static PyObject |
| 1338 | *DBSequence_close_internal(DBSequenceObject* self, int flags, int do_not_close); |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 1339 | |
| 1340 | static void |
| 1341 | DBSequence_dealloc(DBSequenceObject* self) |
| 1342 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1343 | PyObject *dummy; |
| 1344 | |
| 1345 | if (self->sequence != NULL) { |
| 1346 | dummy=DBSequence_close_internal(self,0,0); |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 1347 | /* |
| 1348 | ** Raising exceptions while doing |
| 1349 | ** garbage collection is a fatal error. |
| 1350 | */ |
| 1351 | if (dummy) |
| 1352 | Py_DECREF(dummy); |
| 1353 | else |
| 1354 | PyErr_Clear(); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 1357 | if (self->in_weakreflist != NULL) { |
| 1358 | PyObject_ClearWeakRefs((PyObject *) self); |
| 1359 | } |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 1360 | |
| 1361 | Py_DECREF(self->mydb); |
| 1362 | PyObject_Del(self); |
| 1363 | } |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 1364 | |
| 1365 | #if (DBVER >= 52) |
| 1366 | static DBSiteObject* |
| 1367 | newDBSiteObject(DB_SITE* sitep, DBEnvObject* env) |
| 1368 | { |
| 1369 | DBSiteObject* self; |
| 1370 | |
| 1371 | self = PyObject_New(DBSiteObject, &DBSite_Type); |
| 1372 | |
| 1373 | if (self == NULL) |
| 1374 | return NULL; |
| 1375 | |
| 1376 | self->site = sitep; |
| 1377 | self->env = env; |
| 1378 | |
| 1379 | INSERT_IN_DOUBLE_LINKED_LIST(self->env->children_sites, self); |
| 1380 | |
| 1381 | self->in_weakreflist = NULL; |
| 1382 | Py_INCREF(self->env); |
| 1383 | return self; |
| 1384 | } |
| 1385 | |
| 1386 | /* Forward declaration */ |
| 1387 | static PyObject *DBSite_close_internal(DBSiteObject* self); |
| 1388 | |
| 1389 | static void |
| 1390 | DBSite_dealloc(DBSiteObject* self) |
| 1391 | { |
| 1392 | PyObject *dummy; |
| 1393 | |
| 1394 | if (self->site != NULL) { |
| 1395 | dummy = DBSite_close_internal(self); |
| 1396 | /* |
| 1397 | ** Raising exceptions while doing |
| 1398 | ** garbage collection is a fatal error. |
| 1399 | */ |
| 1400 | if (dummy) |
| 1401 | Py_DECREF(dummy); |
| 1402 | else |
| 1403 | PyErr_Clear(); |
| 1404 | } |
| 1405 | if (self->in_weakreflist != NULL) { |
| 1406 | PyObject_ClearWeakRefs((PyObject *) self); |
| 1407 | } |
| 1408 | Py_DECREF(self->env); |
| 1409 | PyObject_Del(self); |
| 1410 | } |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 1411 | #endif |
| 1412 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1413 | /* --------------------------------------------------------------------- */ |
| 1414 | /* DB methods */ |
| 1415 | |
| 1416 | static PyObject* |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 1417 | DB_append(DBObject* self, PyObject* args, PyObject* kwargs) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1418 | { |
| 1419 | PyObject* txnobj = NULL; |
| 1420 | PyObject* dataobj; |
| 1421 | db_recno_t recno; |
| 1422 | DBT key, data; |
| 1423 | DB_TXN *txn = NULL; |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 1424 | static char* kwnames[] = { "data", "txn", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1425 | |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 1426 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O:append", kwnames, |
| 1427 | &dataobj, &txnobj)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1428 | return NULL; |
| 1429 | |
| 1430 | CHECK_DB_NOT_CLOSED(self); |
| 1431 | |
| 1432 | /* make a dummy key out of a recno */ |
| 1433 | recno = 0; |
| 1434 | CLEAR_DBT(key); |
| 1435 | key.data = &recno; |
| 1436 | key.size = sizeof(recno); |
| 1437 | key.ulen = key.size; |
| 1438 | key.flags = DB_DBT_USERMEM; |
| 1439 | |
| 1440 | if (!make_dbt(dataobj, &data)) return NULL; |
| 1441 | if (!checkTxnObj(txnobj, &txn)) return NULL; |
| 1442 | |
| 1443 | if (-1 == _DB_put(self, txn, &key, &data, DB_APPEND)) |
| 1444 | return NULL; |
| 1445 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 1446 | return NUMBER_FromLong(recno); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1450 | static int |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 1451 | _db_associateCallback(DB* db, const DBT* priKey, const DBT* priData, |
| 1452 | DBT* secKey) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1453 | { |
| 1454 | int retval = DB_DONOTINDEX; |
| 1455 | DBObject* secondaryDB = (DBObject*)db->app_private; |
| 1456 | PyObject* callback = secondaryDB->associateCallback; |
| 1457 | int type = secondaryDB->primaryDBType; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1458 | PyObject* args; |
Thomas Wouters | 89ba381 | 2006-03-07 14:14:51 +0000 | [diff] [blame] | 1459 | PyObject* result = NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1460 | |
| 1461 | |
| 1462 | if (callback != NULL) { |
| 1463 | MYDB_BEGIN_BLOCK_THREADS; |
| 1464 | |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 1465 | if (type == DB_RECNO || type == DB_QUEUE) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1466 | args = BuildValue_LS(*((db_recno_t*)priKey->data), priData->data, priData->size); |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 1467 | else |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1468 | args = BuildValue_SS(priKey->data, priKey->size, priData->data, priData->size); |
Thomas Wouters | 098f694 | 2006-03-07 14:13:17 +0000 | [diff] [blame] | 1469 | if (args != NULL) { |
Thomas Wouters | 098f694 | 2006-03-07 14:13:17 +0000 | [diff] [blame] | 1470 | result = PyEval_CallObject(callback, args); |
| 1471 | } |
| 1472 | if (args == NULL || result == NULL) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1473 | PyErr_Print(); |
| 1474 | } |
| 1475 | else if (result == Py_None) { |
| 1476 | retval = DB_DONOTINDEX; |
| 1477 | } |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 1478 | else if (NUMBER_Check(result)) { |
| 1479 | retval = NUMBER_AsLong(result); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1480 | } |
Christian Heimes | 593daf5 | 2008-05-26 12:51:38 +0000 | [diff] [blame] | 1481 | else if (PyBytes_Check(result)) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1482 | char* data; |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 1483 | Py_ssize_t size; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1484 | |
| 1485 | CLEAR_DBT(*secKey); |
Christian Heimes | 593daf5 | 2008-05-26 12:51:38 +0000 | [diff] [blame] | 1486 | PyBytes_AsStringAndSize(result, &data, &size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1487 | secKey->flags = DB_DBT_APPMALLOC; /* DB will free */ |
| 1488 | secKey->data = malloc(size); /* TODO, check this */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1489 | if (secKey->data) { |
| 1490 | memcpy(secKey->data, data, size); |
| 1491 | secKey->size = size; |
| 1492 | retval = 0; |
| 1493 | } |
| 1494 | else { |
| 1495 | PyErr_SetString(PyExc_MemoryError, |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 1496 | "malloc failed in _db_associateCallback"); |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1497 | PyErr_Print(); |
| 1498 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1499 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1500 | #if (DBVER >= 46) |
| 1501 | else if (PyList_Check(result)) |
| 1502 | { |
| 1503 | char* data; |
| 1504 | Py_ssize_t size; |
| 1505 | int i, listlen; |
| 1506 | DBT* dbts; |
| 1507 | |
| 1508 | listlen = PyList_Size(result); |
| 1509 | |
| 1510 | dbts = (DBT *)malloc(sizeof(DBT) * listlen); |
| 1511 | |
| 1512 | for (i=0; i<listlen; i++) |
| 1513 | { |
| 1514 | if (!PyBytes_Check(PyList_GetItem(result, i))) |
| 1515 | { |
| 1516 | PyErr_SetString( |
| 1517 | PyExc_TypeError, |
| 1518 | #if (PY_VERSION_HEX < 0x03000000) |
| 1519 | "The list returned by DB->associate callback should be a list of strings."); |
| 1520 | #else |
| 1521 | "The list returned by DB->associate callback should be a list of bytes."); |
| 1522 | #endif |
| 1523 | PyErr_Print(); |
| 1524 | } |
| 1525 | |
| 1526 | PyBytes_AsStringAndSize( |
| 1527 | PyList_GetItem(result, i), |
| 1528 | &data, &size); |
| 1529 | |
| 1530 | CLEAR_DBT(dbts[i]); |
| 1531 | dbts[i].data = malloc(size); /* TODO, check this */ |
| 1532 | |
| 1533 | if (dbts[i].data) |
| 1534 | { |
| 1535 | memcpy(dbts[i].data, data, size); |
| 1536 | dbts[i].size = size; |
| 1537 | dbts[i].ulen = dbts[i].size; |
| 1538 | dbts[i].flags = DB_DBT_APPMALLOC; /* DB will free */ |
| 1539 | } |
| 1540 | else |
| 1541 | { |
| 1542 | PyErr_SetString(PyExc_MemoryError, |
| 1543 | "malloc failed in _db_associateCallback (list)"); |
| 1544 | PyErr_Print(); |
| 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | CLEAR_DBT(*secKey); |
| 1549 | |
| 1550 | secKey->data = dbts; |
| 1551 | secKey->size = listlen; |
| 1552 | secKey->flags = DB_DBT_APPMALLOC | DB_DBT_MULTIPLE; |
| 1553 | retval = 0; |
| 1554 | } |
| 1555 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1556 | else { |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 1557 | PyErr_SetString( |
| 1558 | PyExc_TypeError, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1559 | #if (PY_VERSION_HEX < 0x03000000) |
| 1560 | "DB associate callback should return DB_DONOTINDEX/string/list of strings."); |
| 1561 | #else |
| 1562 | "DB associate callback should return DB_DONOTINDEX/bytes/list of bytes."); |
| 1563 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1564 | PyErr_Print(); |
| 1565 | } |
| 1566 | |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 1567 | Py_XDECREF(args); |
| 1568 | Py_XDECREF(result); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1569 | |
| 1570 | MYDB_END_BLOCK_THREADS; |
| 1571 | } |
| 1572 | return retval; |
| 1573 | } |
| 1574 | |
| 1575 | |
| 1576 | static PyObject* |
| 1577 | DB_associate(DBObject* self, PyObject* args, PyObject* kwargs) |
| 1578 | { |
| 1579 | int err, flags=0; |
| 1580 | DBObject* secondaryDB; |
| 1581 | PyObject* callback; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 1582 | PyObject *txnobj = NULL; |
| 1583 | DB_TXN *txn = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 1584 | static char* kwnames[] = {"secondaryDB", "callback", "flags", "txn", |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 1585 | NULL}; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1586 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 1587 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|iO:associate", kwnames, |
| 1588 | &secondaryDB, &callback, &flags, |
| 1589 | &txnobj)) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1590 | return NULL; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 1593 | if (!checkTxnObj(txnobj, &txn)) return NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1594 | |
| 1595 | CHECK_DB_NOT_CLOSED(self); |
| 1596 | if (!DBObject_Check(secondaryDB)) { |
| 1597 | makeTypeError("DB", (PyObject*)secondaryDB); |
| 1598 | return NULL; |
| 1599 | } |
Gregory P. Smith | 91116b6 | 2005-06-06 10:28:06 +0000 | [diff] [blame] | 1600 | CHECK_DB_NOT_CLOSED(secondaryDB); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1601 | if (callback == Py_None) { |
| 1602 | callback = NULL; |
| 1603 | } |
| 1604 | else if (!PyCallable_Check(callback)) { |
| 1605 | makeTypeError("Callable", callback); |
| 1606 | return NULL; |
| 1607 | } |
| 1608 | |
| 1609 | /* Save a reference to the callback in the secondary DB. */ |
Gregory P. Smith | 692ca9a | 2005-06-06 09:55:06 +0000 | [diff] [blame] | 1610 | Py_XDECREF(secondaryDB->associateCallback); |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 1611 | Py_XINCREF(callback); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1612 | secondaryDB->associateCallback = callback; |
| 1613 | secondaryDB->primaryDBType = _DB_get_type(self); |
| 1614 | |
Martin v. Löwis | b2c7aff | 2002-11-23 11:26:07 +0000 | [diff] [blame] | 1615 | /* PyEval_InitThreads is called here due to a quirk in python 1.5 |
| 1616 | * - 2.2.1 (at least) according to Russell Williamson <merel@wt.net>: |
| 1617 | * The global interepreter lock is not initialized until the first |
| 1618 | * thread is created using thread.start_new_thread() or fork() is |
| 1619 | * called. that would cause the ALLOW_THREADS here to segfault due |
| 1620 | * to a null pointer reference if no threads or child processes |
| 1621 | * have been created. This works around that and is a no-op if |
| 1622 | * threads have already been initialized. |
| 1623 | * (see pybsddb-users mailing list post on 2002-08-07) |
| 1624 | */ |
Gregory P. Smith | aa71f5f | 2003-01-17 07:56:16 +0000 | [diff] [blame] | 1625 | #ifdef WITH_THREAD |
Martin v. Löwis | b2c7aff | 2002-11-23 11:26:07 +0000 | [diff] [blame] | 1626 | PyEval_InitThreads(); |
Gregory P. Smith | aa71f5f | 2003-01-17 07:56:16 +0000 | [diff] [blame] | 1627 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1628 | MYDB_BEGIN_ALLOW_THREADS; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 1629 | err = self->db->associate(self->db, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1630 | txn, |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 1631 | secondaryDB->db, |
| 1632 | _db_associateCallback, |
| 1633 | flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1634 | MYDB_END_ALLOW_THREADS; |
| 1635 | |
| 1636 | if (err) { |
Serhiy Storchaka | 98a9722 | 2014-02-09 13:14:04 +0200 | [diff] [blame^] | 1637 | Py_CLEAR(secondaryDB->associateCallback); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1638 | secondaryDB->primaryDBType = 0; |
| 1639 | } |
| 1640 | |
| 1641 | RETURN_IF_ERR(); |
| 1642 | RETURN_NONE(); |
| 1643 | } |
| 1644 | |
| 1645 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1646 | static PyObject* |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 1647 | DB_close_internal(DBObject* self, int flags, int do_not_close) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1648 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1649 | PyObject *dummy; |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 1650 | int err = 0; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1651 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1652 | if (self->db != NULL) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1653 | /* Can be NULL if db is not in an environment */ |
| 1654 | EXTRACT_FROM_DOUBLE_LINKED_LIST_MAYBE_NULL(self); |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 1655 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1656 | if (self->txn) { |
| 1657 | EXTRACT_FROM_DOUBLE_LINKED_LIST_TXN(self); |
| 1658 | self->txn=NULL; |
| 1659 | } |
| 1660 | |
| 1661 | while(self->children_cursors) { |
| 1662 | dummy=DBC_close_internal(self->children_cursors); |
| 1663 | Py_XDECREF(dummy); |
| 1664 | } |
| 1665 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1666 | while(self->children_sequences) { |
| 1667 | dummy=DBSequence_close_internal(self->children_sequences,0,0); |
| 1668 | Py_XDECREF(dummy); |
| 1669 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1670 | |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 1671 | /* |
| 1672 | ** "do_not_close" is used to dispose all related objects in the |
| 1673 | ** tree, without actually releasing the "root" object. |
| 1674 | ** This is done, for example, because function calls like |
| 1675 | ** "DB.verify()" implicitly close the underlying handle. So |
| 1676 | ** the handle doesn't need to be closed, but related objects |
| 1677 | ** must be cleaned up. |
| 1678 | */ |
| 1679 | if (!do_not_close) { |
| 1680 | MYDB_BEGIN_ALLOW_THREADS; |
| 1681 | err = self->db->close(self->db, flags); |
| 1682 | MYDB_END_ALLOW_THREADS; |
| 1683 | self->db = NULL; |
| 1684 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1685 | RETURN_IF_ERR(); |
| 1686 | } |
| 1687 | RETURN_NONE(); |
| 1688 | } |
| 1689 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1690 | static PyObject* |
| 1691 | DB_close(DBObject* self, PyObject* args) |
| 1692 | { |
| 1693 | int flags=0; |
| 1694 | if (!PyArg_ParseTuple(args,"|i:close", &flags)) |
| 1695 | return NULL; |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 1696 | return DB_close_internal(self, flags, 0); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1697 | } |
| 1698 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1699 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1700 | static PyObject* |
| 1701 | _DB_consume(DBObject* self, PyObject* args, PyObject* kwargs, int consume_flag) |
| 1702 | { |
| 1703 | int err, flags=0, type; |
| 1704 | PyObject* txnobj = NULL; |
| 1705 | PyObject* retval = NULL; |
| 1706 | DBT key, data; |
| 1707 | DB_TXN *txn = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 1708 | static char* kwnames[] = { "txn", "flags", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1709 | |
| 1710 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Oi:consume", kwnames, |
| 1711 | &txnobj, &flags)) |
| 1712 | return NULL; |
| 1713 | |
| 1714 | CHECK_DB_NOT_CLOSED(self); |
| 1715 | type = _DB_get_type(self); |
| 1716 | if (type == -1) |
| 1717 | return NULL; |
| 1718 | if (type != DB_QUEUE) { |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 1719 | PyErr_SetString(PyExc_TypeError, |
| 1720 | "Consume methods only allowed for Queue DB's"); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1721 | return NULL; |
| 1722 | } |
| 1723 | if (!checkTxnObj(txnobj, &txn)) |
| 1724 | return NULL; |
| 1725 | |
| 1726 | CLEAR_DBT(key); |
| 1727 | CLEAR_DBT(data); |
| 1728 | if (CHECK_DBFLAG(self, DB_THREAD)) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1729 | /* Tell Berkeley DB to malloc the return value (thread safe) */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1730 | data.flags = DB_DBT_MALLOC; |
| 1731 | key.flags = DB_DBT_MALLOC; |
| 1732 | } |
| 1733 | |
| 1734 | MYDB_BEGIN_ALLOW_THREADS; |
| 1735 | err = self->db->get(self->db, txn, &key, &data, flags|consume_flag); |
| 1736 | MYDB_END_ALLOW_THREADS; |
| 1737 | |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 1738 | if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1739 | && self->moduleFlags.getReturnsNone) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1740 | err = 0; |
| 1741 | Py_INCREF(Py_None); |
| 1742 | retval = Py_None; |
| 1743 | } |
| 1744 | else if (!err) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1745 | retval = BuildValue_SS(key.data, key.size, data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1746 | FREE_DBT(key); |
| 1747 | FREE_DBT(data); |
| 1748 | } |
| 1749 | |
| 1750 | RETURN_IF_ERR(); |
| 1751 | return retval; |
| 1752 | } |
| 1753 | |
| 1754 | static PyObject* |
| 1755 | DB_consume(DBObject* self, PyObject* args, PyObject* kwargs, int consume_flag) |
| 1756 | { |
| 1757 | return _DB_consume(self, args, kwargs, DB_CONSUME); |
| 1758 | } |
| 1759 | |
| 1760 | static PyObject* |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 1761 | DB_consume_wait(DBObject* self, PyObject* args, PyObject* kwargs, |
| 1762 | int consume_flag) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1763 | { |
| 1764 | return _DB_consume(self, args, kwargs, DB_CONSUME_WAIT); |
| 1765 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1766 | |
| 1767 | |
| 1768 | static PyObject* |
| 1769 | DB_cursor(DBObject* self, PyObject* args, PyObject* kwargs) |
| 1770 | { |
| 1771 | int err, flags=0; |
| 1772 | DBC* dbc; |
| 1773 | PyObject* txnobj = NULL; |
| 1774 | DB_TXN *txn = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 1775 | static char* kwnames[] = { "txn", "flags", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1776 | |
| 1777 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Oi:cursor", kwnames, |
| 1778 | &txnobj, &flags)) |
| 1779 | return NULL; |
| 1780 | CHECK_DB_NOT_CLOSED(self); |
| 1781 | if (!checkTxnObj(txnobj, &txn)) |
| 1782 | return NULL; |
| 1783 | |
| 1784 | MYDB_BEGIN_ALLOW_THREADS; |
| 1785 | err = self->db->cursor(self->db, txn, &dbc, flags); |
| 1786 | MYDB_END_ALLOW_THREADS; |
| 1787 | RETURN_IF_ERR(); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1788 | return (PyObject*) newDBCursorObject(dbc, (DBTxnObject *)txnobj, self); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | |
| 1792 | static PyObject* |
| 1793 | DB_delete(DBObject* self, PyObject* args, PyObject* kwargs) |
| 1794 | { |
| 1795 | PyObject* txnobj = NULL; |
| 1796 | int flags = 0; |
| 1797 | PyObject* keyobj; |
| 1798 | DBT key; |
| 1799 | DB_TXN *txn = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 1800 | static char* kwnames[] = { "key", "txn", "flags", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1801 | |
| 1802 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi:delete", kwnames, |
| 1803 | &keyobj, &txnobj, &flags)) |
| 1804 | return NULL; |
| 1805 | CHECK_DB_NOT_CLOSED(self); |
| 1806 | if (!make_key_dbt(self, keyobj, &key, NULL)) |
| 1807 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 1808 | if (!checkTxnObj(txnobj, &txn)) { |
| 1809 | FREE_DBT(key); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1810 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 1811 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1812 | |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 1813 | if (-1 == _DB_delete(self, txn, &key, 0)) { |
| 1814 | FREE_DBT(key); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1815 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 1816 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1817 | |
| 1818 | FREE_DBT(key); |
| 1819 | RETURN_NONE(); |
| 1820 | } |
| 1821 | |
| 1822 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1823 | #if (DBVER >= 47) |
| 1824 | /* |
| 1825 | ** This function is available since Berkeley DB 4.4, |
| 1826 | ** but 4.6 version is so buggy that we only support |
| 1827 | ** it from BDB 4.7 and newer. |
| 1828 | */ |
| 1829 | static PyObject* |
| 1830 | DB_compact(DBObject* self, PyObject* args, PyObject* kwargs) |
| 1831 | { |
| 1832 | PyObject* txnobj = NULL; |
| 1833 | PyObject *startobj = NULL, *stopobj = NULL; |
| 1834 | int flags = 0; |
| 1835 | DB_TXN *txn = NULL; |
| 1836 | DBT *start_p = NULL, *stop_p = NULL; |
| 1837 | DBT start, stop; |
| 1838 | int err; |
| 1839 | DB_COMPACT c_data = { 0 }; |
| 1840 | static char* kwnames[] = { "txn", "start", "stop", "flags", |
| 1841 | "compact_fillpercent", "compact_pages", |
| 1842 | "compact_timeout", NULL }; |
| 1843 | |
| 1844 | |
| 1845 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOOiiiI:compact", kwnames, |
| 1846 | &txnobj, &startobj, &stopobj, &flags, |
| 1847 | &c_data.compact_fillpercent, |
| 1848 | &c_data.compact_pages, |
| 1849 | &c_data.compact_timeout)) |
| 1850 | return NULL; |
| 1851 | |
| 1852 | CHECK_DB_NOT_CLOSED(self); |
| 1853 | if (!checkTxnObj(txnobj, &txn)) { |
| 1854 | return NULL; |
| 1855 | } |
| 1856 | |
| 1857 | if (startobj && make_key_dbt(self, startobj, &start, NULL)) { |
| 1858 | start_p = &start; |
| 1859 | } |
| 1860 | if (stopobj && make_key_dbt(self, stopobj, &stop, NULL)) { |
| 1861 | stop_p = &stop; |
| 1862 | } |
| 1863 | |
| 1864 | MYDB_BEGIN_ALLOW_THREADS; |
| 1865 | err = self->db->compact(self->db, txn, start_p, stop_p, &c_data, |
| 1866 | flags, NULL); |
| 1867 | MYDB_END_ALLOW_THREADS; |
| 1868 | |
| 1869 | if (startobj) |
| 1870 | FREE_DBT(start); |
| 1871 | if (stopobj) |
| 1872 | FREE_DBT(stop); |
| 1873 | |
| 1874 | RETURN_IF_ERR(); |
| 1875 | |
| 1876 | return PyLong_FromUnsignedLong(c_data.compact_pages_truncated); |
| 1877 | } |
| 1878 | #endif |
| 1879 | |
| 1880 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1881 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 1882 | DB_fd(DBObject* self) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1883 | { |
| 1884 | int err, the_fd; |
| 1885 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1886 | CHECK_DB_NOT_CLOSED(self); |
| 1887 | |
| 1888 | MYDB_BEGIN_ALLOW_THREADS; |
| 1889 | err = self->db->fd(self->db, &the_fd); |
| 1890 | MYDB_END_ALLOW_THREADS; |
| 1891 | RETURN_IF_ERR(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 1892 | return NUMBER_FromLong(the_fd); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 1896 | #if (DBVER >= 46) |
| 1897 | static PyObject* |
| 1898 | DB_exists(DBObject* self, PyObject* args, PyObject* kwargs) |
| 1899 | { |
| 1900 | int err, flags=0; |
| 1901 | PyObject* txnobj = NULL; |
| 1902 | PyObject* keyobj; |
| 1903 | DBT key; |
| 1904 | DB_TXN *txn; |
| 1905 | |
| 1906 | static char* kwnames[] = {"key", "txn", "flags", NULL}; |
| 1907 | |
| 1908 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi:exists", kwnames, |
| 1909 | &keyobj, &txnobj, &flags)) |
| 1910 | return NULL; |
| 1911 | |
| 1912 | CHECK_DB_NOT_CLOSED(self); |
| 1913 | if (!make_key_dbt(self, keyobj, &key, NULL)) |
| 1914 | return NULL; |
| 1915 | if (!checkTxnObj(txnobj, &txn)) { |
| 1916 | FREE_DBT(key); |
| 1917 | return NULL; |
| 1918 | } |
| 1919 | |
| 1920 | MYDB_BEGIN_ALLOW_THREADS; |
| 1921 | err = self->db->exists(self->db, txn, &key, flags); |
| 1922 | MYDB_END_ALLOW_THREADS; |
| 1923 | |
| 1924 | FREE_DBT(key); |
| 1925 | |
| 1926 | if (!err) { |
| 1927 | Py_INCREF(Py_True); |
| 1928 | return Py_True; |
| 1929 | } |
| 1930 | if ((err == DB_NOTFOUND || err == DB_KEYEMPTY)) { |
| 1931 | Py_INCREF(Py_False); |
| 1932 | return Py_False; |
| 1933 | } |
| 1934 | |
| 1935 | /* |
| 1936 | ** If we reach there, there was an error. The |
| 1937 | ** "return" should be unreachable. |
| 1938 | */ |
| 1939 | RETURN_IF_ERR(); |
| 1940 | assert(0); /* This coude SHOULD be unreachable */ |
| 1941 | return NULL; |
| 1942 | } |
| 1943 | #endif |
| 1944 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1945 | static PyObject* |
| 1946 | DB_get(DBObject* self, PyObject* args, PyObject* kwargs) |
| 1947 | { |
| 1948 | int err, flags=0; |
| 1949 | PyObject* txnobj = NULL; |
| 1950 | PyObject* keyobj; |
| 1951 | PyObject* dfltobj = NULL; |
| 1952 | PyObject* retval = NULL; |
| 1953 | int dlen = -1; |
| 1954 | int doff = -1; |
| 1955 | DBT key, data; |
| 1956 | DB_TXN *txn = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 1957 | static char* kwnames[] = {"key", "default", "txn", "flags", "dlen", |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 1958 | "doff", NULL}; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1959 | |
| 1960 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OOiii:get", kwnames, |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 1961 | &keyobj, &dfltobj, &txnobj, &flags, &dlen, |
| 1962 | &doff)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1963 | return NULL; |
| 1964 | |
| 1965 | CHECK_DB_NOT_CLOSED(self); |
| 1966 | if (!make_key_dbt(self, keyobj, &key, &flags)) |
| 1967 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 1968 | if (!checkTxnObj(txnobj, &txn)) { |
| 1969 | FREE_DBT(key); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1970 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 1971 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1972 | |
| 1973 | CLEAR_DBT(data); |
| 1974 | if (CHECK_DBFLAG(self, DB_THREAD)) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 1975 | /* Tell Berkeley DB to malloc the return value (thread safe) */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1976 | data.flags = DB_DBT_MALLOC; |
| 1977 | } |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 1978 | if (!add_partial_dbt(&data, dlen, doff)) { |
| 1979 | FREE_DBT(key); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1980 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 1981 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1982 | |
| 1983 | MYDB_BEGIN_ALLOW_THREADS; |
| 1984 | err = self->db->get(self->db, txn, &key, &data, flags); |
| 1985 | MYDB_END_ALLOW_THREADS; |
| 1986 | |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 1987 | if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) && (dfltobj != NULL)) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1988 | err = 0; |
| 1989 | Py_INCREF(dfltobj); |
| 1990 | retval = dfltobj; |
| 1991 | } |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 1992 | else if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1993 | && self->moduleFlags.getReturnsNone) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 1994 | err = 0; |
| 1995 | Py_INCREF(Py_None); |
| 1996 | retval = Py_None; |
| 1997 | } |
| 1998 | else if (!err) { |
| 1999 | if (flags & DB_SET_RECNO) /* return both key and data */ |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2000 | retval = BuildValue_SS(key.data, key.size, data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2001 | else /* return just the data */ |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2002 | retval = Build_PyString(data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2003 | FREE_DBT(data); |
| 2004 | } |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 2005 | FREE_DBT(key); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2006 | |
| 2007 | RETURN_IF_ERR(); |
| 2008 | return retval; |
| 2009 | } |
| 2010 | |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 2011 | static PyObject* |
| 2012 | DB_pget(DBObject* self, PyObject* args, PyObject* kwargs) |
| 2013 | { |
| 2014 | int err, flags=0; |
| 2015 | PyObject* txnobj = NULL; |
| 2016 | PyObject* keyobj; |
| 2017 | PyObject* dfltobj = NULL; |
| 2018 | PyObject* retval = NULL; |
| 2019 | int dlen = -1; |
| 2020 | int doff = -1; |
| 2021 | DBT key, pkey, data; |
| 2022 | DB_TXN *txn = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 2023 | static char* kwnames[] = {"key", "default", "txn", "flags", "dlen", |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 2024 | "doff", NULL}; |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 2025 | |
| 2026 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OOiii:pget", kwnames, |
| 2027 | &keyobj, &dfltobj, &txnobj, &flags, &dlen, |
| 2028 | &doff)) |
| 2029 | return NULL; |
| 2030 | |
| 2031 | CHECK_DB_NOT_CLOSED(self); |
| 2032 | if (!make_key_dbt(self, keyobj, &key, &flags)) |
| 2033 | return NULL; |
| 2034 | if (!checkTxnObj(txnobj, &txn)) { |
| 2035 | FREE_DBT(key); |
| 2036 | return NULL; |
| 2037 | } |
| 2038 | |
| 2039 | CLEAR_DBT(data); |
| 2040 | if (CHECK_DBFLAG(self, DB_THREAD)) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2041 | /* Tell Berkeley DB to malloc the return value (thread safe) */ |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 2042 | data.flags = DB_DBT_MALLOC; |
| 2043 | } |
| 2044 | if (!add_partial_dbt(&data, dlen, doff)) { |
| 2045 | FREE_DBT(key); |
| 2046 | return NULL; |
| 2047 | } |
| 2048 | |
| 2049 | CLEAR_DBT(pkey); |
| 2050 | pkey.flags = DB_DBT_MALLOC; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2051 | |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 2052 | MYDB_BEGIN_ALLOW_THREADS; |
| 2053 | err = self->db->pget(self->db, txn, &key, &pkey, &data, flags); |
| 2054 | MYDB_END_ALLOW_THREADS; |
| 2055 | |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 2056 | if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) && (dfltobj != NULL)) { |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 2057 | err = 0; |
| 2058 | Py_INCREF(dfltobj); |
| 2059 | retval = dfltobj; |
| 2060 | } |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 2061 | else if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2062 | && self->moduleFlags.getReturnsNone) { |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 2063 | err = 0; |
| 2064 | Py_INCREF(Py_None); |
| 2065 | retval = Py_None; |
| 2066 | } |
| 2067 | else if (!err) { |
| 2068 | PyObject *pkeyObj; |
| 2069 | PyObject *dataObj; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2070 | dataObj = Build_PyString(data.data, data.size); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 2071 | |
| 2072 | if (self->primaryDBType == DB_RECNO || |
| 2073 | self->primaryDBType == DB_QUEUE) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2074 | pkeyObj = NUMBER_FromLong(*(int *)pkey.data); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 2075 | else |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2076 | pkeyObj = Build_PyString(pkey.data, pkey.size); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 2077 | |
| 2078 | if (flags & DB_SET_RECNO) /* return key , pkey and data */ |
| 2079 | { |
| 2080 | PyObject *keyObj; |
| 2081 | int type = _DB_get_type(self); |
| 2082 | if (type == DB_RECNO || type == DB_QUEUE) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2083 | keyObj = NUMBER_FromLong(*(int *)key.data); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 2084 | else |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2085 | keyObj = Build_PyString(key.data, key.size); |
Gregory P. Smith | 4e414d8 | 2006-01-24 19:55:02 +0000 | [diff] [blame] | 2086 | retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj); |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 2087 | Py_DECREF(keyObj); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 2088 | } |
| 2089 | else /* return just the pkey and data */ |
| 2090 | { |
Gregory P. Smith | 4e414d8 | 2006-01-24 19:55:02 +0000 | [diff] [blame] | 2091 | retval = PyTuple_Pack(2, pkeyObj, dataObj); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 2092 | } |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 2093 | Py_DECREF(dataObj); |
| 2094 | Py_DECREF(pkeyObj); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2095 | FREE_DBT(pkey); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 2096 | FREE_DBT(data); |
| 2097 | } |
| 2098 | FREE_DBT(key); |
| 2099 | |
| 2100 | RETURN_IF_ERR(); |
| 2101 | return retval; |
| 2102 | } |
| 2103 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2104 | |
| 2105 | /* Return size of entry */ |
| 2106 | static PyObject* |
| 2107 | DB_get_size(DBObject* self, PyObject* args, PyObject* kwargs) |
| 2108 | { |
| 2109 | int err, flags=0; |
| 2110 | PyObject* txnobj = NULL; |
| 2111 | PyObject* keyobj; |
| 2112 | PyObject* retval = NULL; |
| 2113 | DBT key, data; |
| 2114 | DB_TXN *txn = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 2115 | static char* kwnames[] = { "key", "txn", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2116 | |
| 2117 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O:get_size", kwnames, |
| 2118 | &keyobj, &txnobj)) |
| 2119 | return NULL; |
| 2120 | CHECK_DB_NOT_CLOSED(self); |
| 2121 | if (!make_key_dbt(self, keyobj, &key, &flags)) |
| 2122 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 2123 | if (!checkTxnObj(txnobj, &txn)) { |
| 2124 | FREE_DBT(key); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2125 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 2126 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2127 | CLEAR_DBT(data); |
| 2128 | |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 2129 | /* We don't allocate any memory, forcing a DB_BUFFER_SMALL error and |
| 2130 | thus getting the record size. */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2131 | data.flags = DB_DBT_USERMEM; |
| 2132 | data.ulen = 0; |
| 2133 | MYDB_BEGIN_ALLOW_THREADS; |
| 2134 | err = self->db->get(self->db, txn, &key, &data, flags); |
| 2135 | MYDB_END_ALLOW_THREADS; |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 2136 | if ((err == DB_BUFFER_SMALL) || (err == 0)) { |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2137 | retval = NUMBER_FromLong((long)data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2138 | err = 0; |
| 2139 | } |
| 2140 | |
| 2141 | FREE_DBT(key); |
| 2142 | FREE_DBT(data); |
| 2143 | RETURN_IF_ERR(); |
| 2144 | return retval; |
| 2145 | } |
| 2146 | |
| 2147 | |
| 2148 | static PyObject* |
| 2149 | DB_get_both(DBObject* self, PyObject* args, PyObject* kwargs) |
| 2150 | { |
| 2151 | int err, flags=0; |
| 2152 | PyObject* txnobj = NULL; |
| 2153 | PyObject* keyobj; |
| 2154 | PyObject* dataobj; |
| 2155 | PyObject* retval = NULL; |
| 2156 | DBT key, data; |
Neal Norwitz | 994ebed | 2007-06-03 20:32:50 +0000 | [diff] [blame] | 2157 | void *orig_data; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2158 | DB_TXN *txn = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 2159 | static char* kwnames[] = { "key", "data", "txn", "flags", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2160 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2161 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|Oi:get_both", kwnames, |
| 2162 | &keyobj, &dataobj, &txnobj, &flags)) |
| 2163 | return NULL; |
| 2164 | |
| 2165 | CHECK_DB_NOT_CLOSED(self); |
| 2166 | if (!make_key_dbt(self, keyobj, &key, NULL)) |
| 2167 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 2168 | if ( !make_dbt(dataobj, &data) || |
| 2169 | !checkTxnObj(txnobj, &txn) ) |
| 2170 | { |
| 2171 | FREE_DBT(key); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2172 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 2173 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2174 | |
| 2175 | flags |= DB_GET_BOTH; |
Neal Norwitz | 994ebed | 2007-06-03 20:32:50 +0000 | [diff] [blame] | 2176 | orig_data = data.data; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2177 | |
| 2178 | if (CHECK_DBFLAG(self, DB_THREAD)) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2179 | /* Tell Berkeley DB to malloc the return value (thread safe) */ |
Neal Norwitz | 994ebed | 2007-06-03 20:32:50 +0000 | [diff] [blame] | 2180 | /* XXX(nnorwitz): At least 4.4.20 and 4.5.20 require this flag. */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2181 | data.flags = DB_DBT_MALLOC; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | MYDB_BEGIN_ALLOW_THREADS; |
| 2185 | err = self->db->get(self->db, txn, &key, &data, flags); |
| 2186 | MYDB_END_ALLOW_THREADS; |
| 2187 | |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 2188 | if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2189 | && self->moduleFlags.getReturnsNone) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2190 | err = 0; |
| 2191 | Py_INCREF(Py_None); |
| 2192 | retval = Py_None; |
| 2193 | } |
| 2194 | else if (!err) { |
Neal Norwitz | 994ebed | 2007-06-03 20:32:50 +0000 | [diff] [blame] | 2195 | /* XXX(nnorwitz): can we do: retval = dataobj; Py_INCREF(retval); */ |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2196 | retval = Build_PyString(data.data, data.size); |
Neal Norwitz | 994ebed | 2007-06-03 20:32:50 +0000 | [diff] [blame] | 2197 | |
| 2198 | /* Even though the flags require DB_DBT_MALLOC, data is not always |
| 2199 | allocated. 4.4: allocated, 4.5: *not* allocated. :-( */ |
| 2200 | if (data.data != orig_data) |
| 2201 | FREE_DBT(data); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | FREE_DBT(key); |
| 2205 | RETURN_IF_ERR(); |
| 2206 | return retval; |
| 2207 | } |
| 2208 | |
| 2209 | |
| 2210 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2211 | DB_get_byteswapped(DBObject* self) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2212 | { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2213 | int err = 0; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2214 | int retval = -1; |
| 2215 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2216 | CHECK_DB_NOT_CLOSED(self); |
| 2217 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2218 | MYDB_BEGIN_ALLOW_THREADS; |
| 2219 | err = self->db->get_byteswapped(self->db, &retval); |
| 2220 | MYDB_END_ALLOW_THREADS; |
| 2221 | RETURN_IF_ERR(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2222 | return NUMBER_FromLong(retval); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | |
| 2226 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2227 | DB_get_type(DBObject* self) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2228 | { |
| 2229 | int type; |
| 2230 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2231 | CHECK_DB_NOT_CLOSED(self); |
| 2232 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2233 | type = _DB_get_type(self); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2234 | if (type == -1) |
| 2235 | return NULL; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2236 | return NUMBER_FromLong(type); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | |
| 2240 | static PyObject* |
| 2241 | DB_join(DBObject* self, PyObject* args) |
| 2242 | { |
| 2243 | int err, flags=0; |
| 2244 | int length, x; |
| 2245 | PyObject* cursorsObj; |
| 2246 | DBC** cursors; |
| 2247 | DBC* dbc; |
| 2248 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2249 | if (!PyArg_ParseTuple(args,"O|i:join", &cursorsObj, &flags)) |
| 2250 | return NULL; |
| 2251 | |
| 2252 | CHECK_DB_NOT_CLOSED(self); |
| 2253 | |
| 2254 | if (!PySequence_Check(cursorsObj)) { |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2255 | PyErr_SetString(PyExc_TypeError, |
| 2256 | "Sequence of DBCursor objects expected"); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2257 | return NULL; |
| 2258 | } |
| 2259 | |
| 2260 | length = PyObject_Length(cursorsObj); |
| 2261 | cursors = malloc((length+1) * sizeof(DBC*)); |
Neal Norwitz | 5aa9689 | 2006-08-13 18:11:43 +0000 | [diff] [blame] | 2262 | if (!cursors) { |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 2263 | PyErr_NoMemory(); |
| 2264 | return NULL; |
Neal Norwitz | 5aa9689 | 2006-08-13 18:11:43 +0000 | [diff] [blame] | 2265 | } |
| 2266 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2267 | cursors[length] = NULL; |
| 2268 | for (x=0; x<length; x++) { |
| 2269 | PyObject* item = PySequence_GetItem(cursorsObj, x); |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 2270 | if (item == NULL) { |
| 2271 | free(cursors); |
| 2272 | return NULL; |
| 2273 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2274 | if (!DBCursorObject_Check(item)) { |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2275 | PyErr_SetString(PyExc_TypeError, |
| 2276 | "Sequence of DBCursor objects expected"); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2277 | free(cursors); |
| 2278 | return NULL; |
| 2279 | } |
| 2280 | cursors[x] = ((DBCursorObject*)item)->dbc; |
Thomas Wouters | b2820ae | 2006-03-12 00:01:38 +0000 | [diff] [blame] | 2281 | Py_DECREF(item); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | MYDB_BEGIN_ALLOW_THREADS; |
| 2285 | err = self->db->join(self->db, cursors, &dbc, flags); |
| 2286 | MYDB_END_ALLOW_THREADS; |
| 2287 | free(cursors); |
| 2288 | RETURN_IF_ERR(); |
| 2289 | |
Gregory P. Smith | 7441e65 | 2003-11-03 21:35:31 +0000 | [diff] [blame] | 2290 | /* FIXME: this is a buggy interface. The returned cursor |
| 2291 | contains internal references to the passed in cursors |
| 2292 | but does not hold python references to them or prevent |
| 2293 | them from being closed prematurely. This can cause |
| 2294 | python to crash when things are done in the wrong order. */ |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2295 | return (PyObject*) newDBCursorObject(dbc, NULL, self); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | |
| 2299 | static PyObject* |
| 2300 | DB_key_range(DBObject* self, PyObject* args, PyObject* kwargs) |
| 2301 | { |
| 2302 | int err, flags=0; |
| 2303 | PyObject* txnobj = NULL; |
| 2304 | PyObject* keyobj; |
| 2305 | DBT key; |
| 2306 | DB_TXN *txn = NULL; |
| 2307 | DB_KEY_RANGE range; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 2308 | static char* kwnames[] = { "key", "txn", "flags", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2309 | |
| 2310 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi:key_range", kwnames, |
| 2311 | &keyobj, &txnobj, &flags)) |
| 2312 | return NULL; |
| 2313 | CHECK_DB_NOT_CLOSED(self); |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2314 | if (!make_dbt(keyobj, &key)) |
| 2315 | /* BTree only, don't need to allow for an int key */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2316 | return NULL; |
| 2317 | if (!checkTxnObj(txnobj, &txn)) |
| 2318 | return NULL; |
| 2319 | |
| 2320 | MYDB_BEGIN_ALLOW_THREADS; |
| 2321 | err = self->db->key_range(self->db, txn, &key, &range, flags); |
| 2322 | MYDB_END_ALLOW_THREADS; |
| 2323 | |
| 2324 | RETURN_IF_ERR(); |
| 2325 | return Py_BuildValue("ddd", range.less, range.equal, range.greater); |
| 2326 | } |
| 2327 | |
| 2328 | |
| 2329 | static PyObject* |
| 2330 | DB_open(DBObject* self, PyObject* args, PyObject* kwargs) |
| 2331 | { |
| 2332 | int err, type = DB_UNKNOWN, flags=0, mode=0660; |
| 2333 | char* filename = NULL; |
| 2334 | char* dbname = NULL; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2335 | PyObject *txnobj = NULL; |
| 2336 | DB_TXN *txn = NULL; |
| 2337 | /* with dbname */ |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 2338 | static char* kwnames[] = { |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2339 | "filename", "dbname", "dbtype", "flags", "mode", "txn", NULL}; |
| 2340 | /* without dbname */ |
Tim Peters | 85b1052 | 2006-02-28 18:33:35 +0000 | [diff] [blame] | 2341 | static char* kwnames_basic[] = { |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2342 | "filename", "dbtype", "flags", "mode", "txn", NULL}; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2343 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2344 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "z|ziiiO:open", kwnames, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2345 | &filename, &dbname, &type, &flags, &mode, |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2346 | &txnobj)) |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2347 | { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2348 | PyErr_Clear(); |
| 2349 | type = DB_UNKNOWN; flags = 0; mode = 0660; |
| 2350 | filename = NULL; dbname = NULL; |
| 2351 | if (!PyArg_ParseTupleAndKeywords(args, kwargs,"z|iiiO:open", |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2352 | kwnames_basic, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2353 | &filename, &type, &flags, &mode, |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2354 | &txnobj)) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2355 | return NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2356 | } |
| 2357 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2358 | if (!checkTxnObj(txnobj, &txn)) return NULL; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2359 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2360 | if (NULL == self->db) { |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 2361 | PyObject *t = Py_BuildValue("(is)", 0, |
| 2362 | "Cannot call open() twice for DB object"); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2363 | if (t) { |
| 2364 | PyErr_SetObject(DBError, t); |
| 2365 | Py_DECREF(t); |
| 2366 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2367 | return NULL; |
| 2368 | } |
| 2369 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2370 | if (txn) { /* Can't use 'txnobj' because could be 'txnobj==Py_None' */ |
| 2371 | INSERT_IN_DOUBLE_LINKED_LIST_TXN(((DBTxnObject *)txnobj)->children_dbs,self); |
| 2372 | self->txn=(DBTxnObject *)txnobj; |
| 2373 | } else { |
| 2374 | self->txn=NULL; |
| 2375 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2376 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2377 | MYDB_BEGIN_ALLOW_THREADS; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2378 | err = self->db->open(self->db, txn, filename, dbname, type, flags, mode); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2379 | MYDB_END_ALLOW_THREADS; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 2380 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2381 | if (makeDBError(err)) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2382 | PyObject *dummy; |
| 2383 | |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 2384 | dummy=DB_close_internal(self, 0, 0); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2385 | Py_XDECREF(dummy); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2386 | return NULL; |
| 2387 | } |
| 2388 | |
Gregory P. Smith | ec10a4a | 2007-11-05 02:32:26 +0000 | [diff] [blame] | 2389 | self->db->get_flags(self->db, &self->setflags); |
| 2390 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2391 | self->flags = flags; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2392 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2393 | RETURN_NONE(); |
| 2394 | } |
| 2395 | |
| 2396 | |
| 2397 | static PyObject* |
| 2398 | DB_put(DBObject* self, PyObject* args, PyObject* kwargs) |
| 2399 | { |
| 2400 | int flags=0; |
| 2401 | PyObject* txnobj = NULL; |
| 2402 | int dlen = -1; |
| 2403 | int doff = -1; |
| 2404 | PyObject* keyobj, *dataobj, *retval; |
| 2405 | DBT key, data; |
| 2406 | DB_TXN *txn = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 2407 | static char* kwnames[] = { "key", "data", "txn", "flags", "dlen", |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 2408 | "doff", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2409 | |
| 2410 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|Oiii:put", kwnames, |
| 2411 | &keyobj, &dataobj, &txnobj, &flags, &dlen, &doff)) |
| 2412 | return NULL; |
| 2413 | |
| 2414 | CHECK_DB_NOT_CLOSED(self); |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 2415 | if (!make_key_dbt(self, keyobj, &key, NULL)) |
| 2416 | return NULL; |
| 2417 | if ( !make_dbt(dataobj, &data) || |
| 2418 | !add_partial_dbt(&data, dlen, doff) || |
| 2419 | !checkTxnObj(txnobj, &txn) ) |
| 2420 | { |
| 2421 | FREE_DBT(key); |
| 2422 | return NULL; |
| 2423 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2424 | |
| 2425 | if (-1 == _DB_put(self, txn, &key, &data, flags)) { |
| 2426 | FREE_DBT(key); |
| 2427 | return NULL; |
| 2428 | } |
| 2429 | |
| 2430 | if (flags & DB_APPEND) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2431 | retval = NUMBER_FromLong(*((db_recno_t*)key.data)); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2432 | else { |
| 2433 | retval = Py_None; |
| 2434 | Py_INCREF(retval); |
| 2435 | } |
| 2436 | FREE_DBT(key); |
| 2437 | return retval; |
| 2438 | } |
| 2439 | |
| 2440 | |
| 2441 | |
| 2442 | static PyObject* |
| 2443 | DB_remove(DBObject* self, PyObject* args, PyObject* kwargs) |
| 2444 | { |
| 2445 | char* filename; |
| 2446 | char* database = NULL; |
| 2447 | int err, flags=0; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 2448 | static char* kwnames[] = { "filename", "dbname", "flags", NULL}; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2449 | |
| 2450 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zi:remove", kwnames, |
| 2451 | &filename, &database, &flags)) |
| 2452 | return NULL; |
| 2453 | CHECK_DB_NOT_CLOSED(self); |
| 2454 | |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 2455 | EXTRACT_FROM_DOUBLE_LINKED_LIST_MAYBE_NULL(self); |
| 2456 | |
| 2457 | MYDB_BEGIN_ALLOW_THREADS; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2458 | err = self->db->remove(self->db, filename, database, flags); |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 2459 | MYDB_END_ALLOW_THREADS; |
| 2460 | |
Gregory P. Smith | f655dff | 2003-05-15 00:13:18 +0000 | [diff] [blame] | 2461 | self->db = NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2462 | RETURN_IF_ERR(); |
| 2463 | RETURN_NONE(); |
| 2464 | } |
| 2465 | |
| 2466 | |
| 2467 | |
| 2468 | static PyObject* |
| 2469 | DB_rename(DBObject* self, PyObject* args) |
| 2470 | { |
| 2471 | char* filename; |
| 2472 | char* database; |
| 2473 | char* newname; |
| 2474 | int err, flags=0; |
| 2475 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 2476 | if (!PyArg_ParseTuple(args, "sss|i:rename", &filename, &database, &newname, |
| 2477 | &flags)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2478 | return NULL; |
| 2479 | CHECK_DB_NOT_CLOSED(self); |
| 2480 | |
| 2481 | MYDB_BEGIN_ALLOW_THREADS; |
| 2482 | err = self->db->rename(self->db, filename, database, newname, flags); |
| 2483 | MYDB_END_ALLOW_THREADS; |
| 2484 | RETURN_IF_ERR(); |
| 2485 | RETURN_NONE(); |
| 2486 | } |
| 2487 | |
| 2488 | |
| 2489 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2490 | DB_get_private(DBObject* self) |
| 2491 | { |
| 2492 | /* We can give out the private field even if db is closed */ |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 2493 | Py_INCREF(self->private_obj); |
| 2494 | return self->private_obj; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | static PyObject* |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 2498 | DB_set_private(DBObject* self, PyObject* private_obj) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2499 | { |
| 2500 | /* We can set the private field even if db is closed */ |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 2501 | Py_DECREF(self->private_obj); |
| 2502 | Py_INCREF(private_obj); |
| 2503 | self->private_obj = private_obj; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2504 | RETURN_NONE(); |
| 2505 | } |
| 2506 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 2507 | #if (DBVER >= 46) |
| 2508 | static PyObject* |
| 2509 | DB_set_priority(DBObject* self, PyObject* args) |
| 2510 | { |
| 2511 | int err, priority; |
| 2512 | |
| 2513 | if (!PyArg_ParseTuple(args,"i:set_priority", &priority)) |
| 2514 | return NULL; |
| 2515 | CHECK_DB_NOT_CLOSED(self); |
| 2516 | |
| 2517 | MYDB_BEGIN_ALLOW_THREADS; |
| 2518 | err = self->db->set_priority(self->db, priority); |
| 2519 | MYDB_END_ALLOW_THREADS; |
| 2520 | RETURN_IF_ERR(); |
| 2521 | RETURN_NONE(); |
| 2522 | } |
| 2523 | |
| 2524 | static PyObject* |
| 2525 | DB_get_priority(DBObject* self) |
| 2526 | { |
| 2527 | int err = 0; |
| 2528 | DB_CACHE_PRIORITY priority; |
| 2529 | |
| 2530 | CHECK_DB_NOT_CLOSED(self); |
| 2531 | |
| 2532 | MYDB_BEGIN_ALLOW_THREADS; |
| 2533 | err = self->db->get_priority(self->db, &priority); |
| 2534 | MYDB_END_ALLOW_THREADS; |
| 2535 | RETURN_IF_ERR(); |
| 2536 | return NUMBER_FromLong(priority); |
| 2537 | } |
| 2538 | #endif |
| 2539 | |
| 2540 | static PyObject* |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 2541 | DB_get_dbname(DBObject* self) |
| 2542 | { |
| 2543 | int err; |
| 2544 | const char *filename, *dbname; |
| 2545 | |
| 2546 | CHECK_DB_NOT_CLOSED(self); |
| 2547 | |
| 2548 | MYDB_BEGIN_ALLOW_THREADS; |
| 2549 | err = self->db->get_dbname(self->db, &filename, &dbname); |
| 2550 | MYDB_END_ALLOW_THREADS; |
| 2551 | RETURN_IF_ERR(); |
| 2552 | /* If "dbname==NULL", it is correctly converted to "None" */ |
| 2553 | return Py_BuildValue("(ss)", filename, dbname); |
| 2554 | } |
| 2555 | |
| 2556 | static PyObject* |
| 2557 | DB_get_open_flags(DBObject* self) |
| 2558 | { |
| 2559 | int err; |
| 2560 | unsigned int flags; |
| 2561 | |
| 2562 | CHECK_DB_NOT_CLOSED(self); |
| 2563 | |
| 2564 | MYDB_BEGIN_ALLOW_THREADS; |
| 2565 | err = self->db->get_open_flags(self->db, &flags); |
| 2566 | MYDB_END_ALLOW_THREADS; |
| 2567 | RETURN_IF_ERR(); |
| 2568 | return NUMBER_FromLong(flags); |
| 2569 | } |
| 2570 | |
| 2571 | static PyObject* |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 2572 | DB_set_q_extentsize(DBObject* self, PyObject* args) |
| 2573 | { |
| 2574 | int err; |
| 2575 | u_int32_t extentsize; |
| 2576 | |
| 2577 | if (!PyArg_ParseTuple(args,"i:set_q_extentsize", &extentsize)) |
| 2578 | return NULL; |
| 2579 | CHECK_DB_NOT_CLOSED(self); |
| 2580 | |
| 2581 | MYDB_BEGIN_ALLOW_THREADS; |
| 2582 | err = self->db->set_q_extentsize(self->db, extentsize); |
| 2583 | MYDB_END_ALLOW_THREADS; |
| 2584 | RETURN_IF_ERR(); |
| 2585 | RETURN_NONE(); |
| 2586 | } |
| 2587 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 2588 | static PyObject* |
| 2589 | DB_get_q_extentsize(DBObject* self) |
| 2590 | { |
| 2591 | int err = 0; |
| 2592 | u_int32_t extentsize; |
| 2593 | |
| 2594 | CHECK_DB_NOT_CLOSED(self); |
| 2595 | |
| 2596 | MYDB_BEGIN_ALLOW_THREADS; |
| 2597 | err = self->db->get_q_extentsize(self->db, &extentsize); |
| 2598 | MYDB_END_ALLOW_THREADS; |
| 2599 | RETURN_IF_ERR(); |
| 2600 | return NUMBER_FromLong(extentsize); |
| 2601 | } |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2602 | |
| 2603 | static PyObject* |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2604 | DB_set_bt_minkey(DBObject* self, PyObject* args) |
| 2605 | { |
| 2606 | int err, minkey; |
| 2607 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 2608 | if (!PyArg_ParseTuple(args,"i:set_bt_minkey", &minkey)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2609 | return NULL; |
| 2610 | CHECK_DB_NOT_CLOSED(self); |
| 2611 | |
| 2612 | MYDB_BEGIN_ALLOW_THREADS; |
| 2613 | err = self->db->set_bt_minkey(self->db, minkey); |
| 2614 | MYDB_END_ALLOW_THREADS; |
| 2615 | RETURN_IF_ERR(); |
| 2616 | RETURN_NONE(); |
| 2617 | } |
| 2618 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 2619 | static PyObject* |
| 2620 | DB_get_bt_minkey(DBObject* self) |
| 2621 | { |
| 2622 | int err; |
| 2623 | u_int32_t bt_minkey; |
| 2624 | |
| 2625 | CHECK_DB_NOT_CLOSED(self); |
| 2626 | |
| 2627 | MYDB_BEGIN_ALLOW_THREADS; |
| 2628 | err = self->db->get_bt_minkey(self->db, &bt_minkey); |
| 2629 | MYDB_END_ALLOW_THREADS; |
| 2630 | RETURN_IF_ERR(); |
| 2631 | return NUMBER_FromLong(bt_minkey); |
| 2632 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 2633 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2634 | static int |
Georg Brandl | ef1701f | 2006-03-07 14:57:48 +0000 | [diff] [blame] | 2635 | _default_cmp(const DBT *leftKey, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2636 | const DBT *rightKey) |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2637 | { |
| 2638 | int res; |
| 2639 | int lsize = leftKey->size, rsize = rightKey->size; |
| 2640 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2641 | res = memcmp(leftKey->data, rightKey->data, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2642 | lsize < rsize ? lsize : rsize); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2643 | |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2644 | if (res == 0) { |
| 2645 | if (lsize < rsize) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2646 | res = -1; |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2647 | } |
| 2648 | else if (lsize > rsize) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2649 | res = 1; |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2650 | } |
| 2651 | } |
| 2652 | return res; |
| 2653 | } |
| 2654 | |
| 2655 | static int |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 2656 | _db_compareCallback(DB* db, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2657 | const DBT *leftKey, |
| 2658 | const DBT *rightKey) |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2659 | { |
| 2660 | int res = 0; |
| 2661 | PyObject *args; |
Thomas Wouters | b2820ae | 2006-03-12 00:01:38 +0000 | [diff] [blame] | 2662 | PyObject *result = NULL; |
Georg Brandl | ef1701f | 2006-03-07 14:57:48 +0000 | [diff] [blame] | 2663 | DBObject *self = (DBObject *)db->app_private; |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2664 | |
| 2665 | if (self == NULL || self->btCompareCallback == NULL) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2666 | MYDB_BEGIN_BLOCK_THREADS; |
| 2667 | PyErr_SetString(PyExc_TypeError, |
| 2668 | (self == 0 |
| 2669 | ? "DB_bt_compare db is NULL." |
| 2670 | : "DB_bt_compare callback is NULL.")); |
| 2671 | /* we're in a callback within the DB code, we can't raise */ |
| 2672 | PyErr_Print(); |
| 2673 | res = _default_cmp(leftKey, rightKey); |
| 2674 | MYDB_END_BLOCK_THREADS; |
Georg Brandl | ef1701f | 2006-03-07 14:57:48 +0000 | [diff] [blame] | 2675 | } else { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2676 | MYDB_BEGIN_BLOCK_THREADS; |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2677 | |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2678 | args = BuildValue_SS(leftKey->data, leftKey->size, rightKey->data, rightKey->size); |
| 2679 | if (args != NULL) { |
| 2680 | result = PyEval_CallObject(self->btCompareCallback, args); |
| 2681 | } |
| 2682 | if (args == NULL || result == NULL) { |
| 2683 | /* we're in a callback within the DB code, we can't raise */ |
| 2684 | PyErr_Print(); |
| 2685 | res = _default_cmp(leftKey, rightKey); |
| 2686 | } else if (NUMBER_Check(result)) { |
| 2687 | res = NUMBER_AsLong(result); |
| 2688 | } else { |
| 2689 | PyErr_SetString(PyExc_TypeError, |
| 2690 | "DB_bt_compare callback MUST return an int."); |
| 2691 | /* we're in a callback within the DB code, we can't raise */ |
| 2692 | PyErr_Print(); |
| 2693 | res = _default_cmp(leftKey, rightKey); |
| 2694 | } |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2695 | |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2696 | Py_XDECREF(args); |
| 2697 | Py_XDECREF(result); |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2698 | |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2699 | MYDB_END_BLOCK_THREADS; |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2700 | } |
| 2701 | return res; |
| 2702 | } |
| 2703 | |
| 2704 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2705 | DB_set_bt_compare(DBObject* self, PyObject* comparator) |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2706 | { |
| 2707 | int err; |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 2708 | PyObject *tuple, *result; |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2709 | |
Georg Brandl | ef1701f | 2006-03-07 14:57:48 +0000 | [diff] [blame] | 2710 | CHECK_DB_NOT_CLOSED(self); |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2711 | |
Georg Brandl | ef1701f | 2006-03-07 14:57:48 +0000 | [diff] [blame] | 2712 | if (!PyCallable_Check(comparator)) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2713 | makeTypeError("Callable", comparator); |
| 2714 | return NULL; |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2715 | } |
| 2716 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2717 | /* |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2718 | * Perform a test call of the comparator function with two empty |
| 2719 | * string objects here. verify that it returns an int (0). |
| 2720 | * err if not. |
| 2721 | */ |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 2722 | tuple = Py_BuildValue("(ss)", "", ""); |
Georg Brandl | ef1701f | 2006-03-07 14:57:48 +0000 | [diff] [blame] | 2723 | result = PyEval_CallObject(comparator, tuple); |
| 2724 | Py_DECREF(tuple); |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 2725 | if (result == NULL) |
| 2726 | return NULL; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2727 | if (!NUMBER_Check(result)) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2728 | Py_DECREF(result); |
| 2729 | PyErr_SetString(PyExc_TypeError, |
| 2730 | "callback MUST return an int"); |
| 2731 | return NULL; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 2732 | } else if (NUMBER_AsLong(result) != 0) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2733 | Py_DECREF(result); |
| 2734 | PyErr_SetString(PyExc_TypeError, |
| 2735 | "callback failed to return 0 on two empty strings"); |
| 2736 | return NULL; |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2737 | } |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 2738 | Py_DECREF(result); |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2739 | |
| 2740 | /* We don't accept multiple set_bt_compare operations, in order to |
| 2741 | * simplify the code. This would have no real use, as one cannot |
| 2742 | * change the function once the db is opened anyway */ |
| 2743 | if (self->btCompareCallback != NULL) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2744 | PyErr_SetString(PyExc_RuntimeError, "set_bt_compare() cannot be called more than once"); |
| 2745 | return NULL; |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2746 | } |
| 2747 | |
Georg Brandl | ef1701f | 2006-03-07 14:57:48 +0000 | [diff] [blame] | 2748 | Py_INCREF(comparator); |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2749 | self->btCompareCallback = comparator; |
| 2750 | |
| 2751 | /* This is to workaround a problem with un-initialized threads (see |
| 2752 | comment in DB_associate) */ |
| 2753 | #ifdef WITH_THREAD |
| 2754 | PyEval_InitThreads(); |
| 2755 | #endif |
| 2756 | |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 2757 | err = self->db->set_bt_compare(self->db, _db_compareCallback); |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2758 | |
| 2759 | if (err) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 2760 | /* restore the old state in case of error */ |
| 2761 | Py_DECREF(comparator); |
| 2762 | self->btCompareCallback = NULL; |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2763 | } |
| 2764 | |
Georg Brandl | ef1701f | 2006-03-07 14:57:48 +0000 | [diff] [blame] | 2765 | RETURN_IF_ERR(); |
| 2766 | RETURN_NONE(); |
Gregory P. Smith | e4ed2de | 2005-06-03 07:03:07 +0000 | [diff] [blame] | 2767 | } |
| 2768 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 2769 | static int |
| 2770 | _db_dupCompareCallback(DB* db, |
| 2771 | const DBT *leftKey, |
| 2772 | const DBT *rightKey) |
| 2773 | { |
| 2774 | int res = 0; |
| 2775 | PyObject *args; |
| 2776 | PyObject *result = NULL; |
| 2777 | DBObject *self = (DBObject *)db->app_private; |
| 2778 | |
| 2779 | if (self == NULL || self->dupCompareCallback == NULL) { |
| 2780 | MYDB_BEGIN_BLOCK_THREADS; |
| 2781 | PyErr_SetString(PyExc_TypeError, |
| 2782 | (self == 0 |
| 2783 | ? "DB_dup_compare db is NULL." |
| 2784 | : "DB_dup_compare callback is NULL.")); |
| 2785 | /* we're in a callback within the DB code, we can't raise */ |
| 2786 | PyErr_Print(); |
| 2787 | res = _default_cmp(leftKey, rightKey); |
| 2788 | MYDB_END_BLOCK_THREADS; |
| 2789 | } else { |
| 2790 | MYDB_BEGIN_BLOCK_THREADS; |
| 2791 | |
| 2792 | args = BuildValue_SS(leftKey->data, leftKey->size, rightKey->data, rightKey->size); |
| 2793 | if (args != NULL) { |
| 2794 | result = PyEval_CallObject(self->dupCompareCallback, args); |
| 2795 | } |
| 2796 | if (args == NULL || result == NULL) { |
| 2797 | /* we're in a callback within the DB code, we can't raise */ |
| 2798 | PyErr_Print(); |
| 2799 | res = _default_cmp(leftKey, rightKey); |
| 2800 | } else if (NUMBER_Check(result)) { |
| 2801 | res = NUMBER_AsLong(result); |
| 2802 | } else { |
| 2803 | PyErr_SetString(PyExc_TypeError, |
| 2804 | "DB_dup_compare callback MUST return an int."); |
| 2805 | /* we're in a callback within the DB code, we can't raise */ |
| 2806 | PyErr_Print(); |
| 2807 | res = _default_cmp(leftKey, rightKey); |
| 2808 | } |
| 2809 | |
| 2810 | Py_XDECREF(args); |
| 2811 | Py_XDECREF(result); |
| 2812 | |
| 2813 | MYDB_END_BLOCK_THREADS; |
| 2814 | } |
| 2815 | return res; |
| 2816 | } |
| 2817 | |
| 2818 | static PyObject* |
| 2819 | DB_set_dup_compare(DBObject* self, PyObject* comparator) |
| 2820 | { |
| 2821 | int err; |
| 2822 | PyObject *tuple, *result; |
| 2823 | |
| 2824 | CHECK_DB_NOT_CLOSED(self); |
| 2825 | |
| 2826 | if (!PyCallable_Check(comparator)) { |
| 2827 | makeTypeError("Callable", comparator); |
| 2828 | return NULL; |
| 2829 | } |
| 2830 | |
| 2831 | /* |
| 2832 | * Perform a test call of the comparator function with two empty |
| 2833 | * string objects here. verify that it returns an int (0). |
| 2834 | * err if not. |
| 2835 | */ |
| 2836 | tuple = Py_BuildValue("(ss)", "", ""); |
| 2837 | result = PyEval_CallObject(comparator, tuple); |
| 2838 | Py_DECREF(tuple); |
| 2839 | if (result == NULL) |
| 2840 | return NULL; |
| 2841 | if (!NUMBER_Check(result)) { |
| 2842 | Py_DECREF(result); |
| 2843 | PyErr_SetString(PyExc_TypeError, |
| 2844 | "callback MUST return an int"); |
| 2845 | return NULL; |
| 2846 | } else if (NUMBER_AsLong(result) != 0) { |
| 2847 | Py_DECREF(result); |
| 2848 | PyErr_SetString(PyExc_TypeError, |
| 2849 | "callback failed to return 0 on two empty strings"); |
| 2850 | return NULL; |
| 2851 | } |
| 2852 | Py_DECREF(result); |
| 2853 | |
| 2854 | /* We don't accept multiple set_dup_compare operations, in order to |
| 2855 | * simplify the code. This would have no real use, as one cannot |
| 2856 | * change the function once the db is opened anyway */ |
| 2857 | if (self->dupCompareCallback != NULL) { |
| 2858 | PyErr_SetString(PyExc_RuntimeError, "set_dup_compare() cannot be called more than once"); |
| 2859 | return NULL; |
| 2860 | } |
| 2861 | |
| 2862 | Py_INCREF(comparator); |
| 2863 | self->dupCompareCallback = comparator; |
| 2864 | |
| 2865 | /* This is to workaround a problem with un-initialized threads (see |
| 2866 | comment in DB_associate) */ |
| 2867 | #ifdef WITH_THREAD |
| 2868 | PyEval_InitThreads(); |
| 2869 | #endif |
| 2870 | |
| 2871 | err = self->db->set_dup_compare(self->db, _db_dupCompareCallback); |
| 2872 | |
| 2873 | if (err) { |
| 2874 | /* restore the old state in case of error */ |
| 2875 | Py_DECREF(comparator); |
| 2876 | self->dupCompareCallback = NULL; |
| 2877 | } |
| 2878 | |
| 2879 | RETURN_IF_ERR(); |
| 2880 | RETURN_NONE(); |
| 2881 | } |
| 2882 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2883 | |
| 2884 | static PyObject* |
| 2885 | DB_set_cachesize(DBObject* self, PyObject* args) |
| 2886 | { |
| 2887 | int err; |
| 2888 | int gbytes = 0, bytes = 0, ncache = 0; |
| 2889 | |
| 2890 | if (!PyArg_ParseTuple(args,"ii|i:set_cachesize", |
| 2891 | &gbytes,&bytes,&ncache)) |
| 2892 | return NULL; |
| 2893 | CHECK_DB_NOT_CLOSED(self); |
| 2894 | |
| 2895 | MYDB_BEGIN_ALLOW_THREADS; |
| 2896 | err = self->db->set_cachesize(self->db, gbytes, bytes, ncache); |
| 2897 | MYDB_END_ALLOW_THREADS; |
| 2898 | RETURN_IF_ERR(); |
| 2899 | RETURN_NONE(); |
| 2900 | } |
| 2901 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 2902 | static PyObject* |
| 2903 | DB_get_cachesize(DBObject* self) |
| 2904 | { |
| 2905 | int err; |
| 2906 | u_int32_t gbytes, bytes; |
| 2907 | int ncache; |
| 2908 | |
| 2909 | CHECK_DB_NOT_CLOSED(self); |
| 2910 | |
| 2911 | MYDB_BEGIN_ALLOW_THREADS; |
| 2912 | err = self->db->get_cachesize(self->db, &gbytes, &bytes, &ncache); |
| 2913 | MYDB_END_ALLOW_THREADS; |
| 2914 | |
| 2915 | RETURN_IF_ERR(); |
| 2916 | |
| 2917 | return Py_BuildValue("(iii)", gbytes, bytes, ncache); |
| 2918 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2919 | |
| 2920 | static PyObject* |
| 2921 | DB_set_flags(DBObject* self, PyObject* args) |
| 2922 | { |
| 2923 | int err, flags; |
| 2924 | |
| 2925 | if (!PyArg_ParseTuple(args,"i:set_flags", &flags)) |
| 2926 | return NULL; |
| 2927 | CHECK_DB_NOT_CLOSED(self); |
| 2928 | |
| 2929 | MYDB_BEGIN_ALLOW_THREADS; |
| 2930 | err = self->db->set_flags(self->db, flags); |
| 2931 | MYDB_END_ALLOW_THREADS; |
| 2932 | RETURN_IF_ERR(); |
| 2933 | |
| 2934 | self->setflags |= flags; |
| 2935 | RETURN_NONE(); |
| 2936 | } |
| 2937 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 2938 | static PyObject* |
| 2939 | DB_get_flags(DBObject* self) |
| 2940 | { |
| 2941 | int err; |
| 2942 | u_int32_t flags; |
| 2943 | |
| 2944 | CHECK_DB_NOT_CLOSED(self); |
| 2945 | |
| 2946 | MYDB_BEGIN_ALLOW_THREADS; |
| 2947 | err = self->db->get_flags(self->db, &flags); |
| 2948 | MYDB_END_ALLOW_THREADS; |
| 2949 | RETURN_IF_ERR(); |
| 2950 | return NUMBER_FromLong(flags); |
| 2951 | } |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 2952 | |
| 2953 | static PyObject* |
| 2954 | DB_get_transactional(DBObject* self) |
| 2955 | { |
| 2956 | int err; |
| 2957 | |
| 2958 | CHECK_DB_NOT_CLOSED(self); |
| 2959 | |
| 2960 | MYDB_BEGIN_ALLOW_THREADS; |
| 2961 | err = self->db->get_transactional(self->db); |
| 2962 | MYDB_END_ALLOW_THREADS; |
| 2963 | |
| 2964 | if(err == 0) { |
| 2965 | Py_INCREF(Py_False); |
| 2966 | return Py_False; |
| 2967 | } else if(err == 1) { |
| 2968 | Py_INCREF(Py_True); |
| 2969 | return Py_True; |
| 2970 | } |
| 2971 | |
| 2972 | /* |
| 2973 | ** If we reach there, there was an error. The |
| 2974 | ** "return" should be unreachable. |
| 2975 | */ |
| 2976 | RETURN_IF_ERR(); |
| 2977 | assert(0); /* This code SHOULD be unreachable */ |
| 2978 | return NULL; |
| 2979 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 2980 | |
| 2981 | static PyObject* |
| 2982 | DB_set_h_ffactor(DBObject* self, PyObject* args) |
| 2983 | { |
| 2984 | int err, ffactor; |
| 2985 | |
| 2986 | if (!PyArg_ParseTuple(args,"i:set_h_ffactor", &ffactor)) |
| 2987 | return NULL; |
| 2988 | CHECK_DB_NOT_CLOSED(self); |
| 2989 | |
| 2990 | MYDB_BEGIN_ALLOW_THREADS; |
| 2991 | err = self->db->set_h_ffactor(self->db, ffactor); |
| 2992 | MYDB_END_ALLOW_THREADS; |
| 2993 | RETURN_IF_ERR(); |
| 2994 | RETURN_NONE(); |
| 2995 | } |
| 2996 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 2997 | static PyObject* |
| 2998 | DB_get_h_ffactor(DBObject* self) |
| 2999 | { |
| 3000 | int err; |
| 3001 | u_int32_t ffactor; |
| 3002 | |
| 3003 | CHECK_DB_NOT_CLOSED(self); |
| 3004 | |
| 3005 | MYDB_BEGIN_ALLOW_THREADS; |
| 3006 | err = self->db->get_h_ffactor(self->db, &ffactor); |
| 3007 | MYDB_END_ALLOW_THREADS; |
| 3008 | RETURN_IF_ERR(); |
| 3009 | return NUMBER_FromLong(ffactor); |
| 3010 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3011 | |
| 3012 | static PyObject* |
| 3013 | DB_set_h_nelem(DBObject* self, PyObject* args) |
| 3014 | { |
| 3015 | int err, nelem; |
| 3016 | |
| 3017 | if (!PyArg_ParseTuple(args,"i:set_h_nelem", &nelem)) |
| 3018 | return NULL; |
| 3019 | CHECK_DB_NOT_CLOSED(self); |
| 3020 | |
| 3021 | MYDB_BEGIN_ALLOW_THREADS; |
| 3022 | err = self->db->set_h_nelem(self->db, nelem); |
| 3023 | MYDB_END_ALLOW_THREADS; |
| 3024 | RETURN_IF_ERR(); |
| 3025 | RETURN_NONE(); |
| 3026 | } |
| 3027 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3028 | static PyObject* |
| 3029 | DB_get_h_nelem(DBObject* self) |
| 3030 | { |
| 3031 | int err; |
| 3032 | u_int32_t nelem; |
| 3033 | |
| 3034 | CHECK_DB_NOT_CLOSED(self); |
| 3035 | |
| 3036 | MYDB_BEGIN_ALLOW_THREADS; |
| 3037 | err = self->db->get_h_nelem(self->db, &nelem); |
| 3038 | MYDB_END_ALLOW_THREADS; |
| 3039 | RETURN_IF_ERR(); |
| 3040 | return NUMBER_FromLong(nelem); |
| 3041 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3042 | |
| 3043 | static PyObject* |
| 3044 | DB_set_lorder(DBObject* self, PyObject* args) |
| 3045 | { |
| 3046 | int err, lorder; |
| 3047 | |
| 3048 | if (!PyArg_ParseTuple(args,"i:set_lorder", &lorder)) |
| 3049 | return NULL; |
| 3050 | CHECK_DB_NOT_CLOSED(self); |
| 3051 | |
| 3052 | MYDB_BEGIN_ALLOW_THREADS; |
| 3053 | err = self->db->set_lorder(self->db, lorder); |
| 3054 | MYDB_END_ALLOW_THREADS; |
| 3055 | RETURN_IF_ERR(); |
| 3056 | RETURN_NONE(); |
| 3057 | } |
| 3058 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3059 | static PyObject* |
| 3060 | DB_get_lorder(DBObject* self) |
| 3061 | { |
| 3062 | int err; |
| 3063 | int lorder; |
| 3064 | |
| 3065 | CHECK_DB_NOT_CLOSED(self); |
| 3066 | |
| 3067 | MYDB_BEGIN_ALLOW_THREADS; |
| 3068 | err = self->db->get_lorder(self->db, &lorder); |
| 3069 | MYDB_END_ALLOW_THREADS; |
| 3070 | RETURN_IF_ERR(); |
| 3071 | return NUMBER_FromLong(lorder); |
| 3072 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3073 | |
| 3074 | static PyObject* |
| 3075 | DB_set_pagesize(DBObject* self, PyObject* args) |
| 3076 | { |
| 3077 | int err, pagesize; |
| 3078 | |
| 3079 | if (!PyArg_ParseTuple(args,"i:set_pagesize", &pagesize)) |
| 3080 | return NULL; |
| 3081 | CHECK_DB_NOT_CLOSED(self); |
| 3082 | |
| 3083 | MYDB_BEGIN_ALLOW_THREADS; |
| 3084 | err = self->db->set_pagesize(self->db, pagesize); |
| 3085 | MYDB_END_ALLOW_THREADS; |
| 3086 | RETURN_IF_ERR(); |
| 3087 | RETURN_NONE(); |
| 3088 | } |
| 3089 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3090 | static PyObject* |
| 3091 | DB_get_pagesize(DBObject* self) |
| 3092 | { |
| 3093 | int err; |
| 3094 | u_int32_t pagesize; |
| 3095 | |
| 3096 | CHECK_DB_NOT_CLOSED(self); |
| 3097 | |
| 3098 | MYDB_BEGIN_ALLOW_THREADS; |
| 3099 | err = self->db->get_pagesize(self->db, &pagesize); |
| 3100 | MYDB_END_ALLOW_THREADS; |
| 3101 | RETURN_IF_ERR(); |
| 3102 | return NUMBER_FromLong(pagesize); |
| 3103 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3104 | |
| 3105 | static PyObject* |
| 3106 | DB_set_re_delim(DBObject* self, PyObject* args) |
| 3107 | { |
| 3108 | int err; |
| 3109 | char delim; |
| 3110 | |
| 3111 | if (!PyArg_ParseTuple(args,"b:set_re_delim", &delim)) { |
| 3112 | PyErr_Clear(); |
| 3113 | if (!PyArg_ParseTuple(args,"c:set_re_delim", &delim)) |
| 3114 | return NULL; |
| 3115 | } |
| 3116 | |
| 3117 | CHECK_DB_NOT_CLOSED(self); |
| 3118 | |
| 3119 | MYDB_BEGIN_ALLOW_THREADS; |
| 3120 | err = self->db->set_re_delim(self->db, delim); |
| 3121 | MYDB_END_ALLOW_THREADS; |
| 3122 | RETURN_IF_ERR(); |
| 3123 | RETURN_NONE(); |
| 3124 | } |
| 3125 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3126 | static PyObject* |
| 3127 | DB_get_re_delim(DBObject* self) |
| 3128 | { |
| 3129 | int err, re_delim; |
| 3130 | |
| 3131 | CHECK_DB_NOT_CLOSED(self); |
| 3132 | |
| 3133 | MYDB_BEGIN_ALLOW_THREADS; |
| 3134 | err = self->db->get_re_delim(self->db, &re_delim); |
| 3135 | MYDB_END_ALLOW_THREADS; |
| 3136 | RETURN_IF_ERR(); |
| 3137 | return NUMBER_FromLong(re_delim); |
| 3138 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3139 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3140 | static PyObject* |
| 3141 | DB_set_re_len(DBObject* self, PyObject* args) |
| 3142 | { |
| 3143 | int err, len; |
| 3144 | |
| 3145 | if (!PyArg_ParseTuple(args,"i:set_re_len", &len)) |
| 3146 | return NULL; |
| 3147 | CHECK_DB_NOT_CLOSED(self); |
| 3148 | |
| 3149 | MYDB_BEGIN_ALLOW_THREADS; |
| 3150 | err = self->db->set_re_len(self->db, len); |
| 3151 | MYDB_END_ALLOW_THREADS; |
| 3152 | RETURN_IF_ERR(); |
| 3153 | RETURN_NONE(); |
| 3154 | } |
| 3155 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3156 | static PyObject* |
| 3157 | DB_get_re_len(DBObject* self) |
| 3158 | { |
| 3159 | int err; |
| 3160 | u_int32_t re_len; |
| 3161 | |
| 3162 | CHECK_DB_NOT_CLOSED(self); |
| 3163 | |
| 3164 | MYDB_BEGIN_ALLOW_THREADS; |
| 3165 | err = self->db->get_re_len(self->db, &re_len); |
| 3166 | MYDB_END_ALLOW_THREADS; |
| 3167 | RETURN_IF_ERR(); |
| 3168 | return NUMBER_FromLong(re_len); |
| 3169 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3170 | |
| 3171 | static PyObject* |
| 3172 | DB_set_re_pad(DBObject* self, PyObject* args) |
| 3173 | { |
| 3174 | int err; |
| 3175 | char pad; |
| 3176 | |
| 3177 | if (!PyArg_ParseTuple(args,"b:set_re_pad", &pad)) { |
| 3178 | PyErr_Clear(); |
| 3179 | if (!PyArg_ParseTuple(args,"c:set_re_pad", &pad)) |
| 3180 | return NULL; |
| 3181 | } |
| 3182 | CHECK_DB_NOT_CLOSED(self); |
| 3183 | |
| 3184 | MYDB_BEGIN_ALLOW_THREADS; |
| 3185 | err = self->db->set_re_pad(self->db, pad); |
| 3186 | MYDB_END_ALLOW_THREADS; |
| 3187 | RETURN_IF_ERR(); |
| 3188 | RETURN_NONE(); |
| 3189 | } |
| 3190 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3191 | static PyObject* |
| 3192 | DB_get_re_pad(DBObject* self) |
| 3193 | { |
| 3194 | int err, re_pad; |
| 3195 | |
| 3196 | CHECK_DB_NOT_CLOSED(self); |
| 3197 | |
| 3198 | MYDB_BEGIN_ALLOW_THREADS; |
| 3199 | err = self->db->get_re_pad(self->db, &re_pad); |
| 3200 | MYDB_END_ALLOW_THREADS; |
| 3201 | RETURN_IF_ERR(); |
| 3202 | return NUMBER_FromLong(re_pad); |
| 3203 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3204 | |
| 3205 | static PyObject* |
| 3206 | DB_set_re_source(DBObject* self, PyObject* args) |
| 3207 | { |
| 3208 | int err; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3209 | char *source; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3210 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3211 | if (!PyArg_ParseTuple(args,"s:set_re_source", &source)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3212 | return NULL; |
| 3213 | CHECK_DB_NOT_CLOSED(self); |
| 3214 | |
| 3215 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3216 | err = self->db->set_re_source(self->db, source); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3217 | MYDB_END_ALLOW_THREADS; |
| 3218 | RETURN_IF_ERR(); |
| 3219 | RETURN_NONE(); |
| 3220 | } |
| 3221 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3222 | static PyObject* |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3223 | DB_get_re_source(DBObject* self) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3224 | { |
| 3225 | int err; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3226 | const char *source; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3227 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3228 | CHECK_DB_NOT_CLOSED(self); |
| 3229 | |
| 3230 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3231 | err = self->db->get_re_source(self->db, &source); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3232 | MYDB_END_ALLOW_THREADS; |
| 3233 | RETURN_IF_ERR(); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3234 | return PyBytes_FromString(source); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3235 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3236 | |
| 3237 | static PyObject* |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 3238 | DB_stat(DBObject* self, PyObject* args, PyObject* kwargs) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3239 | { |
| 3240 | int err, flags = 0, type; |
| 3241 | void* sp; |
| 3242 | PyObject* d; |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 3243 | PyObject* txnobj = NULL; |
| 3244 | DB_TXN *txn = NULL; |
Gregory P. Smith | 2fa0679 | 2006-09-19 17:35:04 +0000 | [diff] [blame] | 3245 | static char* kwnames[] = { "flags", "txn", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3246 | |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 3247 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iO:stat", kwnames, |
| 3248 | &flags, &txnobj)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3249 | return NULL; |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 3250 | if (!checkTxnObj(txnobj, &txn)) |
| 3251 | return NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3252 | CHECK_DB_NOT_CLOSED(self); |
| 3253 | |
| 3254 | MYDB_BEGIN_ALLOW_THREADS; |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 3255 | err = self->db->stat(self->db, txn, &sp, flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3256 | MYDB_END_ALLOW_THREADS; |
| 3257 | RETURN_IF_ERR(); |
| 3258 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3259 | /* Turn the stat structure into a dictionary */ |
| 3260 | type = _DB_get_type(self); |
| 3261 | if ((type == -1) || ((d = PyDict_New()) == NULL)) { |
| 3262 | free(sp); |
| 3263 | return NULL; |
| 3264 | } |
| 3265 | |
| 3266 | #define MAKE_HASH_ENTRY(name) _addIntToDict(d, #name, ((DB_HASH_STAT*)sp)->hash_##name) |
| 3267 | #define MAKE_BT_ENTRY(name) _addIntToDict(d, #name, ((DB_BTREE_STAT*)sp)->bt_##name) |
| 3268 | #define MAKE_QUEUE_ENTRY(name) _addIntToDict(d, #name, ((DB_QUEUE_STAT*)sp)->qs_##name) |
| 3269 | |
| 3270 | switch (type) { |
| 3271 | case DB_HASH: |
| 3272 | MAKE_HASH_ENTRY(magic); |
| 3273 | MAKE_HASH_ENTRY(version); |
| 3274 | MAKE_HASH_ENTRY(nkeys); |
| 3275 | MAKE_HASH_ENTRY(ndata); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3276 | #if (DBVER >= 46) |
| 3277 | MAKE_HASH_ENTRY(pagecnt); |
| 3278 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3279 | MAKE_HASH_ENTRY(pagesize); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3280 | MAKE_HASH_ENTRY(ffactor); |
| 3281 | MAKE_HASH_ENTRY(buckets); |
| 3282 | MAKE_HASH_ENTRY(free); |
| 3283 | MAKE_HASH_ENTRY(bfree); |
| 3284 | MAKE_HASH_ENTRY(bigpages); |
| 3285 | MAKE_HASH_ENTRY(big_bfree); |
| 3286 | MAKE_HASH_ENTRY(overflows); |
| 3287 | MAKE_HASH_ENTRY(ovfl_free); |
| 3288 | MAKE_HASH_ENTRY(dup); |
| 3289 | MAKE_HASH_ENTRY(dup_free); |
| 3290 | break; |
| 3291 | |
| 3292 | case DB_BTREE: |
| 3293 | case DB_RECNO: |
| 3294 | MAKE_BT_ENTRY(magic); |
| 3295 | MAKE_BT_ENTRY(version); |
| 3296 | MAKE_BT_ENTRY(nkeys); |
| 3297 | MAKE_BT_ENTRY(ndata); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3298 | #if (DBVER >= 46) |
| 3299 | MAKE_BT_ENTRY(pagecnt); |
| 3300 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3301 | MAKE_BT_ENTRY(pagesize); |
| 3302 | MAKE_BT_ENTRY(minkey); |
| 3303 | MAKE_BT_ENTRY(re_len); |
| 3304 | MAKE_BT_ENTRY(re_pad); |
| 3305 | MAKE_BT_ENTRY(levels); |
| 3306 | MAKE_BT_ENTRY(int_pg); |
| 3307 | MAKE_BT_ENTRY(leaf_pg); |
| 3308 | MAKE_BT_ENTRY(dup_pg); |
| 3309 | MAKE_BT_ENTRY(over_pg); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3310 | MAKE_BT_ENTRY(empty_pg); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3311 | MAKE_BT_ENTRY(free); |
| 3312 | MAKE_BT_ENTRY(int_pgfree); |
| 3313 | MAKE_BT_ENTRY(leaf_pgfree); |
| 3314 | MAKE_BT_ENTRY(dup_pgfree); |
| 3315 | MAKE_BT_ENTRY(over_pgfree); |
| 3316 | break; |
| 3317 | |
| 3318 | case DB_QUEUE: |
| 3319 | MAKE_QUEUE_ENTRY(magic); |
| 3320 | MAKE_QUEUE_ENTRY(version); |
| 3321 | MAKE_QUEUE_ENTRY(nkeys); |
| 3322 | MAKE_QUEUE_ENTRY(ndata); |
| 3323 | MAKE_QUEUE_ENTRY(pagesize); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3324 | MAKE_QUEUE_ENTRY(extentsize); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3325 | MAKE_QUEUE_ENTRY(pages); |
| 3326 | MAKE_QUEUE_ENTRY(re_len); |
| 3327 | MAKE_QUEUE_ENTRY(re_pad); |
| 3328 | MAKE_QUEUE_ENTRY(pgfree); |
| 3329 | #if (DBVER == 31) |
| 3330 | MAKE_QUEUE_ENTRY(start); |
| 3331 | #endif |
| 3332 | MAKE_QUEUE_ENTRY(first_recno); |
| 3333 | MAKE_QUEUE_ENTRY(cur_recno); |
| 3334 | break; |
| 3335 | |
| 3336 | default: |
| 3337 | PyErr_SetString(PyExc_TypeError, "Unknown DB type, unable to stat"); |
| 3338 | Py_DECREF(d); |
| 3339 | d = NULL; |
| 3340 | } |
| 3341 | |
| 3342 | #undef MAKE_HASH_ENTRY |
| 3343 | #undef MAKE_BT_ENTRY |
| 3344 | #undef MAKE_QUEUE_ENTRY |
| 3345 | |
| 3346 | free(sp); |
| 3347 | return d; |
| 3348 | } |
| 3349 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3350 | static PyObject* |
| 3351 | DB_stat_print(DBObject* self, PyObject* args, PyObject *kwargs) |
| 3352 | { |
| 3353 | int err; |
| 3354 | int flags=0; |
| 3355 | static char* kwnames[] = { "flags", NULL }; |
| 3356 | |
| 3357 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:stat_print", |
| 3358 | kwnames, &flags)) |
| 3359 | { |
| 3360 | return NULL; |
| 3361 | } |
| 3362 | CHECK_DB_NOT_CLOSED(self); |
| 3363 | MYDB_BEGIN_ALLOW_THREADS; |
| 3364 | err = self->db->stat_print(self->db, flags); |
| 3365 | MYDB_END_ALLOW_THREADS; |
| 3366 | RETURN_IF_ERR(); |
| 3367 | RETURN_NONE(); |
| 3368 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3369 | |
| 3370 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3371 | static PyObject* |
| 3372 | DB_sync(DBObject* self, PyObject* args) |
| 3373 | { |
| 3374 | int err; |
| 3375 | int flags = 0; |
| 3376 | |
| 3377 | if (!PyArg_ParseTuple(args,"|i:sync", &flags )) |
| 3378 | return NULL; |
| 3379 | CHECK_DB_NOT_CLOSED(self); |
| 3380 | |
| 3381 | MYDB_BEGIN_ALLOW_THREADS; |
| 3382 | err = self->db->sync(self->db, flags); |
| 3383 | MYDB_END_ALLOW_THREADS; |
| 3384 | RETURN_IF_ERR(); |
| 3385 | RETURN_NONE(); |
| 3386 | } |
| 3387 | |
| 3388 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3389 | static PyObject* |
| 3390 | DB_truncate(DBObject* self, PyObject* args, PyObject* kwargs) |
| 3391 | { |
| 3392 | int err, flags=0; |
| 3393 | u_int32_t count=0; |
| 3394 | PyObject* txnobj = NULL; |
| 3395 | DB_TXN *txn = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 3396 | static char* kwnames[] = { "txn", "flags", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3397 | |
| 3398 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Oi:cursor", kwnames, |
| 3399 | &txnobj, &flags)) |
| 3400 | return NULL; |
| 3401 | CHECK_DB_NOT_CLOSED(self); |
| 3402 | if (!checkTxnObj(txnobj, &txn)) |
| 3403 | return NULL; |
| 3404 | |
| 3405 | MYDB_BEGIN_ALLOW_THREADS; |
| 3406 | err = self->db->truncate(self->db, txn, &count, flags); |
| 3407 | MYDB_END_ALLOW_THREADS; |
| 3408 | RETURN_IF_ERR(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 3409 | return NUMBER_FromLong(count); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3410 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3411 | |
| 3412 | |
| 3413 | static PyObject* |
| 3414 | DB_upgrade(DBObject* self, PyObject* args) |
| 3415 | { |
| 3416 | int err, flags=0; |
| 3417 | char *filename; |
| 3418 | |
| 3419 | if (!PyArg_ParseTuple(args,"s|i:upgrade", &filename, &flags)) |
| 3420 | return NULL; |
| 3421 | CHECK_DB_NOT_CLOSED(self); |
| 3422 | |
| 3423 | MYDB_BEGIN_ALLOW_THREADS; |
| 3424 | err = self->db->upgrade(self->db, filename, flags); |
| 3425 | MYDB_END_ALLOW_THREADS; |
| 3426 | RETURN_IF_ERR(); |
| 3427 | RETURN_NONE(); |
| 3428 | } |
| 3429 | |
| 3430 | |
| 3431 | static PyObject* |
| 3432 | DB_verify(DBObject* self, PyObject* args, PyObject* kwargs) |
| 3433 | { |
| 3434 | int err, flags=0; |
| 3435 | char* fileName; |
| 3436 | char* dbName=NULL; |
| 3437 | char* outFileName=NULL; |
| 3438 | FILE* outFile=NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 3439 | static char* kwnames[] = { "filename", "dbname", "outfile", "flags", |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 3440 | NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3441 | |
| 3442 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zzi:verify", kwnames, |
| 3443 | &fileName, &dbName, &outFileName, &flags)) |
| 3444 | return NULL; |
| 3445 | |
| 3446 | CHECK_DB_NOT_CLOSED(self); |
| 3447 | if (outFileName) |
| 3448 | outFile = fopen(outFileName, "w"); |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 3449 | /* XXX(nnorwitz): it should probably be an exception if outFile |
| 3450 | can't be opened. */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3451 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3452 | { /* DB.verify acts as a DB handle destructor (like close) */ |
| 3453 | PyObject *error; |
| 3454 | |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 3455 | error=DB_close_internal(self, 0, 1); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3456 | if (error) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3457 | return error; |
| 3458 | } |
| 3459 | } |
Gregory P. Smith | 41631e8 | 2003-09-21 00:08:14 +0000 | [diff] [blame] | 3460 | |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 3461 | MYDB_BEGIN_ALLOW_THREADS; |
| 3462 | err = self->db->verify(self->db, fileName, dbName, outFile, flags); |
| 3463 | MYDB_END_ALLOW_THREADS; |
| 3464 | |
| 3465 | self->db = NULL; /* Implicit close; related objects already released */ |
| 3466 | |
| 3467 | if (outFile) |
| 3468 | fclose(outFile); |
| 3469 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3470 | RETURN_IF_ERR(); |
| 3471 | RETURN_NONE(); |
| 3472 | } |
| 3473 | |
| 3474 | |
| 3475 | static PyObject* |
| 3476 | DB_set_get_returns_none(DBObject* self, PyObject* args) |
| 3477 | { |
| 3478 | int flags=0; |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 3479 | int oldValue=0; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3480 | |
| 3481 | if (!PyArg_ParseTuple(args,"i:set_get_returns_none", &flags)) |
| 3482 | return NULL; |
| 3483 | CHECK_DB_NOT_CLOSED(self); |
| 3484 | |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 3485 | if (self->moduleFlags.getReturnsNone) |
| 3486 | ++oldValue; |
| 3487 | if (self->moduleFlags.cursorSetReturnsNone) |
| 3488 | ++oldValue; |
| 3489 | self->moduleFlags.getReturnsNone = (flags >= 1); |
| 3490 | self->moduleFlags.cursorSetReturnsNone = (flags >= 2); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 3491 | return NUMBER_FromLong(oldValue); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3492 | } |
| 3493 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 3494 | static PyObject* |
| 3495 | DB_set_encrypt(DBObject* self, PyObject* args, PyObject* kwargs) |
| 3496 | { |
| 3497 | int err; |
| 3498 | u_int32_t flags=0; |
| 3499 | char *passwd = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 3500 | static char* kwnames[] = { "passwd", "flags", NULL }; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 3501 | |
| 3502 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|i:set_encrypt", kwnames, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 3503 | &passwd, &flags)) { |
| 3504 | return NULL; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | MYDB_BEGIN_ALLOW_THREADS; |
| 3508 | err = self->db->set_encrypt(self->db, passwd, flags); |
| 3509 | MYDB_END_ALLOW_THREADS; |
| 3510 | |
| 3511 | RETURN_IF_ERR(); |
| 3512 | RETURN_NONE(); |
| 3513 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3514 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3515 | static PyObject* |
| 3516 | DB_get_encrypt_flags(DBObject* self) |
| 3517 | { |
| 3518 | int err; |
| 3519 | u_int32_t flags; |
| 3520 | |
| 3521 | MYDB_BEGIN_ALLOW_THREADS; |
| 3522 | err = self->db->get_encrypt_flags(self->db, &flags); |
| 3523 | MYDB_END_ALLOW_THREADS; |
| 3524 | |
| 3525 | RETURN_IF_ERR(); |
| 3526 | |
| 3527 | return NUMBER_FromLong(flags); |
| 3528 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3529 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 3530 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3531 | |
| 3532 | /*-------------------------------------------------------------- */ |
| 3533 | /* Mapping and Dictionary-like access routines */ |
| 3534 | |
Martin v. Löwis | 70ee3cc | 2006-06-12 04:26:31 +0000 | [diff] [blame] | 3535 | Py_ssize_t DB_length(PyObject* _self) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3536 | { |
| 3537 | int err; |
Gregory P. Smith | 3c228b1 | 2006-06-05 23:59:37 +0000 | [diff] [blame] | 3538 | Py_ssize_t size = 0; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3539 | void* sp; |
Martin v. Löwis | 70ee3cc | 2006-06-12 04:26:31 +0000 | [diff] [blame] | 3540 | DBObject* self = (DBObject*)_self; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3541 | |
| 3542 | if (self->db == NULL) { |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 3543 | PyObject *t = Py_BuildValue("(is)", 0, "DB object has been closed"); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 3544 | if (t) { |
| 3545 | PyErr_SetObject(DBError, t); |
| 3546 | Py_DECREF(t); |
| 3547 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3548 | return -1; |
| 3549 | } |
| 3550 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3551 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3552 | err = self->db->stat(self->db, /*txnid*/ NULL, &sp, 0); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3553 | MYDB_END_ALLOW_THREADS; |
Gregory P. Smith | 3c228b1 | 2006-06-05 23:59:37 +0000 | [diff] [blame] | 3554 | |
| 3555 | /* All the stat structures have matching fields upto the ndata field, |
| 3556 | so we can use any of them for the type cast */ |
| 3557 | size = ((DB_BTREE_STAT*)sp)->bt_ndata; |
| 3558 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3559 | if (err) |
| 3560 | return -1; |
| 3561 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3562 | free(sp); |
| 3563 | return size; |
| 3564 | } |
| 3565 | |
| 3566 | |
| 3567 | PyObject* DB_subscript(DBObject* self, PyObject* keyobj) |
| 3568 | { |
| 3569 | int err; |
| 3570 | PyObject* retval; |
| 3571 | DBT key; |
| 3572 | DBT data; |
| 3573 | |
| 3574 | CHECK_DB_NOT_CLOSED(self); |
| 3575 | if (!make_key_dbt(self, keyobj, &key, NULL)) |
| 3576 | return NULL; |
| 3577 | |
| 3578 | CLEAR_DBT(data); |
| 3579 | if (CHECK_DBFLAG(self, DB_THREAD)) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3580 | /* Tell Berkeley DB to malloc the return value (thread safe) */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3581 | data.flags = DB_DBT_MALLOC; |
| 3582 | } |
| 3583 | MYDB_BEGIN_ALLOW_THREADS; |
| 3584 | err = self->db->get(self->db, NULL, &key, &data, 0); |
| 3585 | MYDB_END_ALLOW_THREADS; |
| 3586 | if (err == DB_NOTFOUND || err == DB_KEYEMPTY) { |
| 3587 | PyErr_SetObject(PyExc_KeyError, keyobj); |
| 3588 | retval = NULL; |
| 3589 | } |
| 3590 | else if (makeDBError(err)) { |
| 3591 | retval = NULL; |
| 3592 | } |
| 3593 | else { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3594 | retval = Build_PyString(data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3595 | FREE_DBT(data); |
| 3596 | } |
| 3597 | |
| 3598 | FREE_DBT(key); |
| 3599 | return retval; |
| 3600 | } |
| 3601 | |
| 3602 | |
| 3603 | static int |
| 3604 | DB_ass_sub(DBObject* self, PyObject* keyobj, PyObject* dataobj) |
| 3605 | { |
| 3606 | DBT key, data; |
| 3607 | int retval; |
| 3608 | int flags = 0; |
| 3609 | |
| 3610 | if (self->db == NULL) { |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 3611 | PyObject *t = Py_BuildValue("(is)", 0, "DB object has been closed"); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 3612 | if (t) { |
| 3613 | PyErr_SetObject(DBError, t); |
| 3614 | Py_DECREF(t); |
| 3615 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3616 | return -1; |
| 3617 | } |
| 3618 | |
| 3619 | if (!make_key_dbt(self, keyobj, &key, NULL)) |
| 3620 | return -1; |
| 3621 | |
| 3622 | if (dataobj != NULL) { |
| 3623 | if (!make_dbt(dataobj, &data)) |
| 3624 | retval = -1; |
| 3625 | else { |
| 3626 | if (self->setflags & (DB_DUP|DB_DUPSORT)) |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 3627 | /* dictionaries shouldn't have duplicate keys */ |
| 3628 | flags = DB_NOOVERWRITE; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3629 | retval = _DB_put(self, NULL, &key, &data, flags); |
| 3630 | |
| 3631 | if ((retval == -1) && (self->setflags & (DB_DUP|DB_DUPSORT))) { |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 3632 | /* try deleting any old record that matches and then PUT it |
| 3633 | * again... */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3634 | _DB_delete(self, NULL, &key, 0); |
| 3635 | PyErr_Clear(); |
| 3636 | retval = _DB_put(self, NULL, &key, &data, flags); |
| 3637 | } |
| 3638 | } |
| 3639 | } |
| 3640 | else { |
| 3641 | /* dataobj == NULL, so delete the key */ |
| 3642 | retval = _DB_delete(self, NULL, &key, 0); |
| 3643 | } |
| 3644 | FREE_DBT(key); |
| 3645 | return retval; |
| 3646 | } |
| 3647 | |
| 3648 | |
| 3649 | static PyObject* |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3650 | _DB_has_key(DBObject* self, PyObject* keyobj, PyObject* txnobj) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3651 | { |
| 3652 | int err; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3653 | DBT key; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3654 | DB_TXN *txn = NULL; |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 3655 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3656 | CHECK_DB_NOT_CLOSED(self); |
| 3657 | if (!make_key_dbt(self, keyobj, &key, NULL)) |
| 3658 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 3659 | if (!checkTxnObj(txnobj, &txn)) { |
| 3660 | FREE_DBT(key); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3661 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 3662 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3663 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3664 | #if (DBVER < 46) |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 3665 | /* This causes DB_BUFFER_SMALL to be returned when the db has the key because |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3666 | it has a record but can't allocate a buffer for the data. This saves |
| 3667 | having to deal with data we won't be using. |
| 3668 | */ |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3669 | { |
| 3670 | DBT data ; |
| 3671 | CLEAR_DBT(data); |
| 3672 | data.flags = DB_DBT_USERMEM; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3673 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3674 | MYDB_BEGIN_ALLOW_THREADS; |
| 3675 | err = self->db->get(self->db, txn, &key, &data, 0); |
| 3676 | MYDB_END_ALLOW_THREADS; |
| 3677 | } |
| 3678 | #else |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3679 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3680 | err = self->db->exists(self->db, txn, &key, 0); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3681 | MYDB_END_ALLOW_THREADS; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3682 | #endif |
| 3683 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3684 | FREE_DBT(key); |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 3685 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3686 | /* |
| 3687 | ** DB_BUFFER_SMALL is only used if we use "get". |
| 3688 | ** We can drop it when we only use "exists", |
| 3689 | ** when we drop suport for Berkeley DB < 4.6. |
| 3690 | */ |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 3691 | if (err == DB_BUFFER_SMALL || err == 0) { |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3692 | Py_INCREF(Py_True); |
| 3693 | return Py_True; |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 3694 | } else if (err == DB_NOTFOUND || err == DB_KEYEMPTY) { |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3695 | Py_INCREF(Py_False); |
| 3696 | return Py_False; |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 3697 | } |
| 3698 | |
| 3699 | makeDBError(err); |
| 3700 | return NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3701 | } |
| 3702 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3703 | static PyObject* |
| 3704 | DB_has_key(DBObject* self, PyObject* args, PyObject* kwargs) |
| 3705 | { |
| 3706 | PyObject* keyobj; |
| 3707 | PyObject* txnobj = NULL; |
| 3708 | static char* kwnames[] = {"key","txn", NULL}; |
| 3709 | |
| 3710 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O:has_key", kwnames, |
| 3711 | &keyobj, &txnobj)) |
| 3712 | return NULL; |
| 3713 | |
| 3714 | return _DB_has_key(self, keyobj, txnobj); |
| 3715 | } |
| 3716 | |
| 3717 | |
| 3718 | static int DB_contains(DBObject* self, PyObject* keyobj) |
| 3719 | { |
| 3720 | PyObject* result; |
| 3721 | int result2 = 0; |
| 3722 | |
| 3723 | result = _DB_has_key(self, keyobj, NULL) ; |
| 3724 | if (result == NULL) { |
| 3725 | return -1; /* Propague exception */ |
| 3726 | } |
| 3727 | if (result != Py_False) { |
| 3728 | result2 = 1; |
| 3729 | } |
| 3730 | |
| 3731 | Py_DECREF(result); |
| 3732 | return result2; |
| 3733 | } |
| 3734 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3735 | |
| 3736 | #define _KEYS_LIST 1 |
| 3737 | #define _VALUES_LIST 2 |
| 3738 | #define _ITEMS_LIST 3 |
| 3739 | |
| 3740 | static PyObject* |
| 3741 | _DB_make_list(DBObject* self, DB_TXN* txn, int type) |
| 3742 | { |
| 3743 | int err, dbtype; |
| 3744 | DBT key; |
| 3745 | DBT data; |
| 3746 | DBC *cursor; |
| 3747 | PyObject* list; |
| 3748 | PyObject* item = NULL; |
| 3749 | |
| 3750 | CHECK_DB_NOT_CLOSED(self); |
| 3751 | CLEAR_DBT(key); |
| 3752 | CLEAR_DBT(data); |
| 3753 | |
| 3754 | dbtype = _DB_get_type(self); |
| 3755 | if (dbtype == -1) |
| 3756 | return NULL; |
| 3757 | |
| 3758 | list = PyList_New(0); |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 3759 | if (list == NULL) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3760 | return NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3761 | |
| 3762 | /* get a cursor */ |
| 3763 | MYDB_BEGIN_ALLOW_THREADS; |
Gregory P. Smith | 442c9fc | 2004-09-04 01:36:59 +0000 | [diff] [blame] | 3764 | err = self->db->cursor(self->db, txn, &cursor, 0); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3765 | MYDB_END_ALLOW_THREADS; |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 3766 | if (makeDBError(err)) { |
| 3767 | Py_DECREF(list); |
| 3768 | return NULL; |
| 3769 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3770 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3771 | while (1) { /* use the cursor to traverse the DB, collecting items */ |
| 3772 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3773 | err = _DBC_get(cursor, &key, &data, DB_NEXT); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3774 | MYDB_END_ALLOW_THREADS; |
| 3775 | |
| 3776 | if (err) { |
| 3777 | /* for any error, break out of the loop */ |
| 3778 | break; |
| 3779 | } |
| 3780 | |
| 3781 | switch (type) { |
| 3782 | case _KEYS_LIST: |
| 3783 | switch(dbtype) { |
| 3784 | case DB_BTREE: |
| 3785 | case DB_HASH: |
| 3786 | default: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3787 | item = Build_PyString(key.data, key.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3788 | break; |
| 3789 | case DB_RECNO: |
| 3790 | case DB_QUEUE: |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 3791 | item = NUMBER_FromLong(*((db_recno_t*)key.data)); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3792 | break; |
| 3793 | } |
| 3794 | break; |
| 3795 | |
| 3796 | case _VALUES_LIST: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3797 | item = Build_PyString(data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3798 | break; |
| 3799 | |
| 3800 | case _ITEMS_LIST: |
| 3801 | switch(dbtype) { |
| 3802 | case DB_BTREE: |
| 3803 | case DB_HASH: |
| 3804 | default: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3805 | item = BuildValue_SS(key.data, key.size, data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3806 | break; |
| 3807 | case DB_RECNO: |
| 3808 | case DB_QUEUE: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3809 | item = BuildValue_IS(*((db_recno_t*)key.data), data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3810 | break; |
| 3811 | } |
| 3812 | break; |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 3813 | default: |
| 3814 | PyErr_Format(PyExc_ValueError, "Unknown key type 0x%x", type); |
| 3815 | item = NULL; |
| 3816 | break; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3817 | } |
| 3818 | if (item == NULL) { |
| 3819 | Py_DECREF(list); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3820 | list = NULL; |
| 3821 | goto done; |
| 3822 | } |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 3823 | if (PyList_Append(list, item)) { |
| 3824 | Py_DECREF(list); |
| 3825 | Py_DECREF(item); |
| 3826 | list = NULL; |
| 3827 | goto done; |
| 3828 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3829 | Py_DECREF(item); |
| 3830 | } |
| 3831 | |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 3832 | /* DB_NOTFOUND || DB_KEYEMPTY is okay, it means we got to the end */ |
| 3833 | if (err != DB_NOTFOUND && err != DB_KEYEMPTY && makeDBError(err)) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3834 | Py_DECREF(list); |
| 3835 | list = NULL; |
| 3836 | } |
| 3837 | |
| 3838 | done: |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3839 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 3840 | _DBC_close(cursor); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3841 | MYDB_END_ALLOW_THREADS; |
| 3842 | return list; |
| 3843 | } |
| 3844 | |
| 3845 | |
| 3846 | static PyObject* |
| 3847 | DB_keys(DBObject* self, PyObject* args) |
| 3848 | { |
| 3849 | PyObject* txnobj = NULL; |
| 3850 | DB_TXN *txn = NULL; |
| 3851 | |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 3852 | if (!PyArg_UnpackTuple(args, "keys", 0, 1, &txnobj)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3853 | return NULL; |
| 3854 | if (!checkTxnObj(txnobj, &txn)) |
| 3855 | return NULL; |
| 3856 | return _DB_make_list(self, txn, _KEYS_LIST); |
| 3857 | } |
| 3858 | |
| 3859 | |
| 3860 | static PyObject* |
| 3861 | DB_items(DBObject* self, PyObject* args) |
| 3862 | { |
| 3863 | PyObject* txnobj = NULL; |
| 3864 | DB_TXN *txn = NULL; |
| 3865 | |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 3866 | if (!PyArg_UnpackTuple(args, "items", 0, 1, &txnobj)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3867 | return NULL; |
| 3868 | if (!checkTxnObj(txnobj, &txn)) |
| 3869 | return NULL; |
| 3870 | return _DB_make_list(self, txn, _ITEMS_LIST); |
| 3871 | } |
| 3872 | |
| 3873 | |
| 3874 | static PyObject* |
| 3875 | DB_values(DBObject* self, PyObject* args) |
| 3876 | { |
| 3877 | PyObject* txnobj = NULL; |
| 3878 | DB_TXN *txn = NULL; |
| 3879 | |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 3880 | if (!PyArg_UnpackTuple(args, "values", 0, 1, &txnobj)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3881 | return NULL; |
| 3882 | if (!checkTxnObj(txnobj, &txn)) |
| 3883 | return NULL; |
| 3884 | return _DB_make_list(self, txn, _VALUES_LIST); |
| 3885 | } |
| 3886 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 3887 | /* --------------------------------------------------------------------- */ |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 3888 | /* DBLogCursor methods */ |
| 3889 | |
| 3890 | |
| 3891 | static PyObject* |
| 3892 | DBLogCursor_close_internal(DBLogCursorObject* self) |
| 3893 | { |
| 3894 | int err = 0; |
| 3895 | |
| 3896 | if (self->logc != NULL) { |
| 3897 | EXTRACT_FROM_DOUBLE_LINKED_LIST(self); |
| 3898 | |
| 3899 | MYDB_BEGIN_ALLOW_THREADS; |
| 3900 | err = self->logc->close(self->logc, 0); |
| 3901 | MYDB_END_ALLOW_THREADS; |
| 3902 | self->logc = NULL; |
| 3903 | } |
| 3904 | RETURN_IF_ERR(); |
| 3905 | RETURN_NONE(); |
| 3906 | } |
| 3907 | |
| 3908 | static PyObject* |
| 3909 | DBLogCursor_close(DBLogCursorObject* self) |
| 3910 | { |
| 3911 | return DBLogCursor_close_internal(self); |
| 3912 | } |
| 3913 | |
| 3914 | |
| 3915 | static PyObject* |
| 3916 | _DBLogCursor_get(DBLogCursorObject* self, int flag, DB_LSN *lsn2) |
| 3917 | { |
| 3918 | int err; |
| 3919 | DBT data; |
| 3920 | DB_LSN lsn = {0, 0}; |
| 3921 | PyObject *dummy, *retval; |
| 3922 | |
| 3923 | CLEAR_DBT(data); |
| 3924 | data.flags = DB_DBT_MALLOC; /* Berkeley DB must do the malloc */ |
| 3925 | |
| 3926 | CHECK_LOGCURSOR_NOT_CLOSED(self); |
| 3927 | |
| 3928 | if (lsn2) |
| 3929 | lsn = *lsn2; |
| 3930 | |
| 3931 | MYDB_BEGIN_ALLOW_THREADS; |
| 3932 | err = self->logc->get(self->logc, &lsn, &data, flag); |
| 3933 | MYDB_END_ALLOW_THREADS; |
| 3934 | |
| 3935 | if (err == DB_NOTFOUND) { |
| 3936 | Py_INCREF(Py_None); |
| 3937 | retval = Py_None; |
| 3938 | } |
| 3939 | else if (makeDBError(err)) { |
| 3940 | retval = NULL; |
| 3941 | } |
| 3942 | else { |
| 3943 | retval = dummy = BuildValue_S(data.data, data.size); |
| 3944 | if (dummy) { |
| 3945 | retval = Py_BuildValue("(ii)O", lsn.file, lsn.offset, dummy); |
| 3946 | Py_DECREF(dummy); |
| 3947 | } |
| 3948 | } |
| 3949 | |
| 3950 | FREE_DBT(data); |
| 3951 | return retval; |
| 3952 | } |
| 3953 | |
| 3954 | static PyObject* |
| 3955 | DBLogCursor_current(DBLogCursorObject* self) |
| 3956 | { |
| 3957 | return _DBLogCursor_get(self, DB_CURRENT, NULL); |
| 3958 | } |
| 3959 | |
| 3960 | static PyObject* |
| 3961 | DBLogCursor_first(DBLogCursorObject* self) |
| 3962 | { |
| 3963 | return _DBLogCursor_get(self, DB_FIRST, NULL); |
| 3964 | } |
| 3965 | |
| 3966 | static PyObject* |
| 3967 | DBLogCursor_last(DBLogCursorObject* self) |
| 3968 | { |
| 3969 | return _DBLogCursor_get(self, DB_LAST, NULL); |
| 3970 | } |
| 3971 | |
| 3972 | static PyObject* |
| 3973 | DBLogCursor_next(DBLogCursorObject* self) |
| 3974 | { |
| 3975 | return _DBLogCursor_get(self, DB_NEXT, NULL); |
| 3976 | } |
| 3977 | |
| 3978 | static PyObject* |
| 3979 | DBLogCursor_prev(DBLogCursorObject* self) |
| 3980 | { |
| 3981 | return _DBLogCursor_get(self, DB_PREV, NULL); |
| 3982 | } |
| 3983 | |
| 3984 | static PyObject* |
| 3985 | DBLogCursor_set(DBLogCursorObject* self, PyObject* args) |
| 3986 | { |
| 3987 | DB_LSN lsn; |
| 3988 | |
| 3989 | if (!PyArg_ParseTuple(args, "(ii):set", &lsn.file, &lsn.offset)) |
| 3990 | return NULL; |
| 3991 | |
| 3992 | return _DBLogCursor_get(self, DB_SET, &lsn); |
| 3993 | } |
| 3994 | |
| 3995 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 3996 | /* --------------------------------------------------------------------- */ |
| 3997 | /* DBSite methods */ |
| 3998 | |
| 3999 | |
| 4000 | #if (DBVER >= 52) |
| 4001 | static PyObject* |
| 4002 | DBSite_close_internal(DBSiteObject* self) |
| 4003 | { |
| 4004 | int err = 0; |
| 4005 | |
| 4006 | if (self->site != NULL) { |
| 4007 | EXTRACT_FROM_DOUBLE_LINKED_LIST(self); |
| 4008 | |
| 4009 | MYDB_BEGIN_ALLOW_THREADS; |
| 4010 | err = self->site->close(self->site); |
| 4011 | MYDB_END_ALLOW_THREADS; |
| 4012 | self->site = NULL; |
| 4013 | } |
| 4014 | RETURN_IF_ERR(); |
| 4015 | RETURN_NONE(); |
| 4016 | } |
| 4017 | |
| 4018 | static PyObject* |
| 4019 | DBSite_close(DBSiteObject* self) |
| 4020 | { |
| 4021 | return DBSite_close_internal(self); |
| 4022 | } |
| 4023 | |
| 4024 | static PyObject* |
| 4025 | DBSite_remove(DBSiteObject* self) |
| 4026 | { |
| 4027 | int err = 0; |
| 4028 | |
| 4029 | CHECK_SITE_NOT_CLOSED(self); |
| 4030 | |
| 4031 | MYDB_BEGIN_ALLOW_THREADS; |
| 4032 | err = self->site->remove(self->site); |
| 4033 | MYDB_END_ALLOW_THREADS; |
| 4034 | |
| 4035 | RETURN_IF_ERR(); |
| 4036 | RETURN_NONE(); |
| 4037 | } |
| 4038 | |
| 4039 | static PyObject* |
| 4040 | DBSite_get_eid(DBSiteObject* self) |
| 4041 | { |
| 4042 | int err = 0; |
| 4043 | int eid; |
| 4044 | |
| 4045 | CHECK_SITE_NOT_CLOSED(self); |
| 4046 | |
| 4047 | MYDB_BEGIN_ALLOW_THREADS; |
| 4048 | err = self->site->get_eid(self->site, &eid); |
| 4049 | MYDB_END_ALLOW_THREADS; |
| 4050 | |
| 4051 | RETURN_IF_ERR(); |
| 4052 | return NUMBER_FromLong(eid); |
| 4053 | } |
| 4054 | |
| 4055 | static PyObject* |
| 4056 | DBSite_get_address(DBSiteObject* self) |
| 4057 | { |
| 4058 | int err = 0; |
| 4059 | const char *host; |
| 4060 | u_int port; |
| 4061 | |
| 4062 | CHECK_SITE_NOT_CLOSED(self); |
| 4063 | |
| 4064 | MYDB_BEGIN_ALLOW_THREADS; |
| 4065 | err = self->site->get_address(self->site, &host, &port); |
| 4066 | MYDB_END_ALLOW_THREADS; |
| 4067 | |
| 4068 | RETURN_IF_ERR(); |
| 4069 | |
| 4070 | return Py_BuildValue("(sI)", host, port); |
| 4071 | } |
| 4072 | |
| 4073 | static PyObject* |
| 4074 | DBSite_get_config(DBSiteObject* self, PyObject* args, PyObject* kwargs) |
| 4075 | { |
| 4076 | int err = 0; |
| 4077 | u_int32_t which, value; |
| 4078 | static char* kwnames[] = { "which", NULL }; |
| 4079 | |
| 4080 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:get_config", kwnames, |
| 4081 | &which)) |
| 4082 | return NULL; |
| 4083 | |
| 4084 | CHECK_SITE_NOT_CLOSED(self); |
| 4085 | |
| 4086 | MYDB_BEGIN_ALLOW_THREADS; |
| 4087 | err = self->site->get_config(self->site, which, &value); |
| 4088 | MYDB_END_ALLOW_THREADS; |
| 4089 | |
| 4090 | RETURN_IF_ERR(); |
| 4091 | |
| 4092 | if (value) { |
| 4093 | Py_INCREF(Py_True); |
| 4094 | return Py_True; |
| 4095 | } else { |
| 4096 | Py_INCREF(Py_False); |
| 4097 | return Py_False; |
| 4098 | } |
| 4099 | } |
| 4100 | |
| 4101 | static PyObject* |
| 4102 | DBSite_set_config(DBSiteObject* self, PyObject* args, PyObject* kwargs) |
| 4103 | { |
| 4104 | int err = 0; |
| 4105 | u_int32_t which, value; |
| 4106 | PyObject *valueO; |
| 4107 | static char* kwnames[] = { "which", "value", NULL }; |
| 4108 | |
| 4109 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO:set_config", kwnames, |
| 4110 | &which, &valueO)) |
| 4111 | return NULL; |
| 4112 | |
| 4113 | CHECK_SITE_NOT_CLOSED(self); |
| 4114 | |
| 4115 | value = PyObject_IsTrue(valueO); |
| 4116 | |
| 4117 | MYDB_BEGIN_ALLOW_THREADS; |
| 4118 | err = self->site->set_config(self->site, which, value); |
| 4119 | MYDB_END_ALLOW_THREADS; |
| 4120 | |
| 4121 | RETURN_IF_ERR(); |
| 4122 | RETURN_NONE(); |
| 4123 | } |
| 4124 | #endif |
| 4125 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 4126 | |
| 4127 | /* --------------------------------------------------------------------- */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4128 | /* DBCursor methods */ |
| 4129 | |
| 4130 | |
| 4131 | static PyObject* |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4132 | DBC_close_internal(DBCursorObject* self) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4133 | { |
| 4134 | int err = 0; |
| 4135 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4136 | if (self->dbc != NULL) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4137 | EXTRACT_FROM_DOUBLE_LINKED_LIST(self); |
| 4138 | if (self->txn) { |
| 4139 | EXTRACT_FROM_DOUBLE_LINKED_LIST_TXN(self); |
| 4140 | self->txn=NULL; |
| 4141 | } |
| 4142 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4143 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4144 | err = _DBC_close(self->dbc); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4145 | MYDB_END_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4146 | self->dbc = NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4147 | } |
| 4148 | RETURN_IF_ERR(); |
| 4149 | RETURN_NONE(); |
| 4150 | } |
| 4151 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4152 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 4153 | DBC_close(DBCursorObject* self) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4154 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4155 | return DBC_close_internal(self); |
| 4156 | } |
| 4157 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4158 | |
| 4159 | static PyObject* |
| 4160 | DBC_count(DBCursorObject* self, PyObject* args) |
| 4161 | { |
| 4162 | int err = 0; |
| 4163 | db_recno_t count; |
| 4164 | int flags = 0; |
| 4165 | |
| 4166 | if (!PyArg_ParseTuple(args, "|i:count", &flags)) |
| 4167 | return NULL; |
| 4168 | |
| 4169 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4170 | |
| 4171 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4172 | err = _DBC_count(self->dbc, &count, flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4173 | MYDB_END_ALLOW_THREADS; |
| 4174 | RETURN_IF_ERR(); |
| 4175 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 4176 | return NUMBER_FromLong(count); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | |
| 4180 | static PyObject* |
| 4181 | DBC_current(DBCursorObject* self, PyObject* args, PyObject *kwargs) |
| 4182 | { |
| 4183 | return _DBCursor_get(self,DB_CURRENT,args,kwargs,"|iii:current"); |
| 4184 | } |
| 4185 | |
| 4186 | |
| 4187 | static PyObject* |
| 4188 | DBC_delete(DBCursorObject* self, PyObject* args) |
| 4189 | { |
| 4190 | int err, flags=0; |
| 4191 | |
| 4192 | if (!PyArg_ParseTuple(args, "|i:delete", &flags)) |
| 4193 | return NULL; |
| 4194 | |
| 4195 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4196 | |
| 4197 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4198 | err = _DBC_del(self->dbc, flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4199 | MYDB_END_ALLOW_THREADS; |
| 4200 | RETURN_IF_ERR(); |
| 4201 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4202 | RETURN_NONE(); |
| 4203 | } |
| 4204 | |
| 4205 | |
| 4206 | static PyObject* |
| 4207 | DBC_dup(DBCursorObject* self, PyObject* args) |
| 4208 | { |
| 4209 | int err, flags =0; |
| 4210 | DBC* dbc = NULL; |
| 4211 | |
| 4212 | if (!PyArg_ParseTuple(args, "|i:dup", &flags)) |
| 4213 | return NULL; |
| 4214 | |
| 4215 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4216 | |
| 4217 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4218 | err = _DBC_dup(self->dbc, &dbc, flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4219 | MYDB_END_ALLOW_THREADS; |
| 4220 | RETURN_IF_ERR(); |
| 4221 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4222 | return (PyObject*) newDBCursorObject(dbc, self->txn, self->mydb); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | static PyObject* |
| 4226 | DBC_first(DBCursorObject* self, PyObject* args, PyObject* kwargs) |
| 4227 | { |
| 4228 | return _DBCursor_get(self,DB_FIRST,args,kwargs,"|iii:first"); |
| 4229 | } |
| 4230 | |
| 4231 | |
| 4232 | static PyObject* |
| 4233 | DBC_get(DBCursorObject* self, PyObject* args, PyObject *kwargs) |
| 4234 | { |
Martin v. Löwis | b2c7aff | 2002-11-23 11:26:07 +0000 | [diff] [blame] | 4235 | int err, flags=0; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4236 | PyObject* keyobj = NULL; |
| 4237 | PyObject* dataobj = NULL; |
| 4238 | PyObject* retval = NULL; |
| 4239 | int dlen = -1; |
| 4240 | int doff = -1; |
| 4241 | DBT key, data; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 4242 | static char* kwnames[] = { "key","data", "flags", "dlen", "doff", |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 4243 | NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4244 | |
| 4245 | CLEAR_DBT(key); |
| 4246 | CLEAR_DBT(data); |
| 4247 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|ii:get", &kwnames[2], |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4248 | &flags, &dlen, &doff)) |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 4249 | { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4250 | PyErr_Clear(); |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 4251 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi|ii:get", |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 4252 | &kwnames[1], |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4253 | &keyobj, &flags, &dlen, &doff)) |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 4254 | { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4255 | PyErr_Clear(); |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 4256 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOi|ii:get", |
| 4257 | kwnames, &keyobj, &dataobj, |
| 4258 | &flags, &dlen, &doff)) |
| 4259 | { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4260 | return NULL; |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4261 | } |
| 4262 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4266 | |
| 4267 | if (keyobj && !make_key_dbt(self->mydb, keyobj, &key, NULL)) |
| 4268 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4269 | if ( (dataobj && !make_dbt(dataobj, &data)) || |
| 4270 | (!add_partial_dbt(&data, dlen, doff)) ) |
| 4271 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4272 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4273 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4274 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4275 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4276 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4277 | err = _DBC_get(self->dbc, &key, &data, flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4278 | MYDB_END_ALLOW_THREADS; |
| 4279 | |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 4280 | if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4281 | && self->mydb->moduleFlags.getReturnsNone) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4282 | Py_INCREF(Py_None); |
| 4283 | retval = Py_None; |
| 4284 | } |
| 4285 | else if (makeDBError(err)) { |
| 4286 | retval = NULL; |
| 4287 | } |
| 4288 | else { |
| 4289 | switch (_DB_get_type(self->mydb)) { |
| 4290 | case -1: |
| 4291 | retval = NULL; |
| 4292 | break; |
| 4293 | case DB_BTREE: |
| 4294 | case DB_HASH: |
| 4295 | default: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4296 | retval = BuildValue_SS(key.data, key.size, data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4297 | break; |
| 4298 | case DB_RECNO: |
| 4299 | case DB_QUEUE: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4300 | retval = BuildValue_IS(*((db_recno_t*)key.data), data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4301 | break; |
| 4302 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4303 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4304 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4305 | return retval; |
| 4306 | } |
| 4307 | |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4308 | static PyObject* |
| 4309 | DBC_pget(DBCursorObject* self, PyObject* args, PyObject *kwargs) |
| 4310 | { |
| 4311 | int err, flags=0; |
| 4312 | PyObject* keyobj = NULL; |
| 4313 | PyObject* dataobj = NULL; |
| 4314 | PyObject* retval = NULL; |
| 4315 | int dlen = -1; |
| 4316 | int doff = -1; |
| 4317 | DBT key, pkey, data; |
Gregory P. Smith | 372b583 | 2006-06-05 18:48:21 +0000 | [diff] [blame] | 4318 | static char* kwnames_keyOnly[] = { "key", "flags", "dlen", "doff", NULL }; |
| 4319 | static char* kwnames[] = { "key", "data", "flags", "dlen", "doff", NULL }; |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4320 | |
| 4321 | CLEAR_DBT(key); |
| 4322 | CLEAR_DBT(data); |
| 4323 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|ii:pget", &kwnames[2], |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4324 | &flags, &dlen, &doff)) |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4325 | { |
| 4326 | PyErr_Clear(); |
| 4327 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi|ii:pget", |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 4328 | kwnames_keyOnly, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4329 | &keyobj, &flags, &dlen, &doff)) |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4330 | { |
| 4331 | PyErr_Clear(); |
| 4332 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOi|ii:pget", |
| 4333 | kwnames, &keyobj, &dataobj, |
| 4334 | &flags, &dlen, &doff)) |
| 4335 | { |
| 4336 | return NULL; |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4337 | } |
| 4338 | } |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4342 | |
| 4343 | if (keyobj && !make_key_dbt(self->mydb, keyobj, &key, NULL)) |
| 4344 | return NULL; |
| 4345 | if ( (dataobj && !make_dbt(dataobj, &data)) || |
| 4346 | (!add_partial_dbt(&data, dlen, doff)) ) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4347 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4348 | return NULL; |
| 4349 | } |
| 4350 | |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4351 | CLEAR_DBT(pkey); |
| 4352 | pkey.flags = DB_DBT_MALLOC; |
| 4353 | |
| 4354 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4355 | err = _DBC_pget(self->dbc, &key, &pkey, &data, flags); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4356 | MYDB_END_ALLOW_THREADS; |
| 4357 | |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 4358 | if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4359 | && self->mydb->moduleFlags.getReturnsNone) { |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4360 | Py_INCREF(Py_None); |
| 4361 | retval = Py_None; |
| 4362 | } |
| 4363 | else if (makeDBError(err)) { |
| 4364 | retval = NULL; |
| 4365 | } |
| 4366 | else { |
| 4367 | PyObject *pkeyObj; |
| 4368 | PyObject *dataObj; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4369 | dataObj = Build_PyString(data.data, data.size); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4370 | |
| 4371 | if (self->mydb->primaryDBType == DB_RECNO || |
| 4372 | self->mydb->primaryDBType == DB_QUEUE) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 4373 | pkeyObj = NUMBER_FromLong(*(int *)pkey.data); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4374 | else |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4375 | pkeyObj = Build_PyString(pkey.data, pkey.size); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4376 | |
Gregory P. Smith | 4e414d8 | 2006-01-24 19:55:02 +0000 | [diff] [blame] | 4377 | if (key.data && key.size) /* return key, pkey and data */ |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4378 | { |
| 4379 | PyObject *keyObj; |
| 4380 | int type = _DB_get_type(self->mydb); |
| 4381 | if (type == DB_RECNO || type == DB_QUEUE) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 4382 | keyObj = NUMBER_FromLong(*(int *)key.data); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4383 | else |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4384 | keyObj = Build_PyString(key.data, key.size); |
Gregory P. Smith | 4e414d8 | 2006-01-24 19:55:02 +0000 | [diff] [blame] | 4385 | retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj); |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 4386 | Py_DECREF(keyObj); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4387 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4388 | } |
| 4389 | else /* return just the pkey and data */ |
| 4390 | { |
Gregory P. Smith | 4e414d8 | 2006-01-24 19:55:02 +0000 | [diff] [blame] | 4391 | retval = PyTuple_Pack(2, pkeyObj, dataObj); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4392 | } |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 4393 | Py_DECREF(dataObj); |
| 4394 | Py_DECREF(pkeyObj); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4395 | FREE_DBT(pkey); |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4396 | } |
| 4397 | /* the only time REALLOC should be set is if we used an integer |
| 4398 | * key that make_key_dbt malloc'd for us. always free these. */ |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4399 | if (key.flags & DB_DBT_REALLOC) { /* 'make_key_dbt' could do a 'malloc' */ |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4400 | FREE_DBT(key); |
| 4401 | } |
| 4402 | return retval; |
| 4403 | } |
| 4404 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4405 | |
| 4406 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 4407 | DBC_get_recno(DBCursorObject* self) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4408 | { |
| 4409 | int err; |
| 4410 | db_recno_t recno; |
| 4411 | DBT key; |
| 4412 | DBT data; |
| 4413 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4414 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4415 | |
| 4416 | CLEAR_DBT(key); |
| 4417 | CLEAR_DBT(data); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4418 | |
| 4419 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4420 | err = _DBC_get(self->dbc, &key, &data, DB_GET_RECNO); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4421 | MYDB_END_ALLOW_THREADS; |
| 4422 | RETURN_IF_ERR(); |
| 4423 | |
| 4424 | recno = *((db_recno_t*)data.data); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 4425 | return NUMBER_FromLong(recno); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4426 | } |
| 4427 | |
| 4428 | |
| 4429 | static PyObject* |
| 4430 | DBC_last(DBCursorObject* self, PyObject* args, PyObject *kwargs) |
| 4431 | { |
| 4432 | return _DBCursor_get(self,DB_LAST,args,kwargs,"|iii:last"); |
| 4433 | } |
| 4434 | |
| 4435 | |
| 4436 | static PyObject* |
| 4437 | DBC_next(DBCursorObject* self, PyObject* args, PyObject *kwargs) |
| 4438 | { |
| 4439 | return _DBCursor_get(self,DB_NEXT,args,kwargs,"|iii:next"); |
| 4440 | } |
| 4441 | |
| 4442 | |
| 4443 | static PyObject* |
| 4444 | DBC_prev(DBCursorObject* self, PyObject* args, PyObject *kwargs) |
| 4445 | { |
| 4446 | return _DBCursor_get(self,DB_PREV,args,kwargs,"|iii:prev"); |
| 4447 | } |
| 4448 | |
| 4449 | |
| 4450 | static PyObject* |
| 4451 | DBC_put(DBCursorObject* self, PyObject* args, PyObject* kwargs) |
| 4452 | { |
| 4453 | int err, flags = 0; |
| 4454 | PyObject* keyobj, *dataobj; |
| 4455 | DBT key, data; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 4456 | static char* kwnames[] = { "key", "data", "flags", "dlen", "doff", |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 4457 | NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4458 | int dlen = -1; |
| 4459 | int doff = -1; |
| 4460 | |
| 4461 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|iii:put", kwnames, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4462 | &keyobj, &dataobj, &flags, &dlen, &doff)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4463 | return NULL; |
| 4464 | |
| 4465 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4466 | |
| 4467 | if (!make_key_dbt(self->mydb, keyobj, &key, NULL)) |
| 4468 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4469 | if (!make_dbt(dataobj, &data) || |
| 4470 | !add_partial_dbt(&data, dlen, doff) ) |
| 4471 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4472 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4473 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4474 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4475 | |
| 4476 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4477 | err = _DBC_put(self->dbc, &key, &data, flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4478 | MYDB_END_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4479 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4480 | RETURN_IF_ERR(); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4481 | RETURN_NONE(); |
| 4482 | } |
| 4483 | |
| 4484 | |
| 4485 | static PyObject* |
| 4486 | DBC_set(DBCursorObject* self, PyObject* args, PyObject *kwargs) |
| 4487 | { |
| 4488 | int err, flags = 0; |
| 4489 | DBT key, data; |
| 4490 | PyObject* retval, *keyobj; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 4491 | static char* kwnames[] = { "key", "flags", "dlen", "doff", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4492 | int dlen = -1; |
| 4493 | int doff = -1; |
| 4494 | |
| 4495 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iii:set", kwnames, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4496 | &keyobj, &flags, &dlen, &doff)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4497 | return NULL; |
| 4498 | |
| 4499 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4500 | |
| 4501 | if (!make_key_dbt(self->mydb, keyobj, &key, NULL)) |
| 4502 | return NULL; |
| 4503 | |
| 4504 | CLEAR_DBT(data); |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4505 | if (!add_partial_dbt(&data, dlen, doff)) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4506 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4507 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4508 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4509 | |
| 4510 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4511 | err = _DBC_get(self->dbc, &key, &data, flags|DB_SET); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4512 | MYDB_END_ALLOW_THREADS; |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 4513 | if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4514 | && self->mydb->moduleFlags.cursorSetReturnsNone) { |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4515 | Py_INCREF(Py_None); |
| 4516 | retval = Py_None; |
| 4517 | } |
| 4518 | else if (makeDBError(err)) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4519 | retval = NULL; |
| 4520 | } |
| 4521 | else { |
| 4522 | switch (_DB_get_type(self->mydb)) { |
| 4523 | case -1: |
| 4524 | retval = NULL; |
| 4525 | break; |
| 4526 | case DB_BTREE: |
| 4527 | case DB_HASH: |
| 4528 | default: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4529 | retval = BuildValue_SS(key.data, key.size, data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4530 | break; |
| 4531 | case DB_RECNO: |
| 4532 | case DB_QUEUE: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4533 | retval = BuildValue_IS(*((db_recno_t*)key.data), data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4534 | break; |
| 4535 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4536 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4537 | } |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4538 | /* the only time REALLOC should be set is if we used an integer |
| 4539 | * key that make_key_dbt malloc'd for us. always free these. */ |
| 4540 | if (key.flags & DB_DBT_REALLOC) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4541 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4542 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4543 | |
| 4544 | return retval; |
| 4545 | } |
| 4546 | |
| 4547 | |
| 4548 | static PyObject* |
| 4549 | DBC_set_range(DBCursorObject* self, PyObject* args, PyObject* kwargs) |
| 4550 | { |
| 4551 | int err, flags = 0; |
| 4552 | DBT key, data; |
| 4553 | PyObject* retval, *keyobj; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 4554 | static char* kwnames[] = { "key", "flags", "dlen", "doff", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4555 | int dlen = -1; |
| 4556 | int doff = -1; |
| 4557 | |
| 4558 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iii:set_range", kwnames, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4559 | &keyobj, &flags, &dlen, &doff)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4560 | return NULL; |
| 4561 | |
| 4562 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4563 | |
| 4564 | if (!make_key_dbt(self->mydb, keyobj, &key, NULL)) |
| 4565 | return NULL; |
| 4566 | |
| 4567 | CLEAR_DBT(data); |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4568 | if (!add_partial_dbt(&data, dlen, doff)) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4569 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4570 | return NULL; |
| 4571 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4572 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4573 | err = _DBC_get(self->dbc, &key, &data, flags|DB_SET_RANGE); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4574 | MYDB_END_ALLOW_THREADS; |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 4575 | if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4576 | && self->mydb->moduleFlags.cursorSetReturnsNone) { |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4577 | Py_INCREF(Py_None); |
| 4578 | retval = Py_None; |
| 4579 | } |
| 4580 | else if (makeDBError(err)) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4581 | retval = NULL; |
| 4582 | } |
| 4583 | else { |
| 4584 | switch (_DB_get_type(self->mydb)) { |
| 4585 | case -1: |
| 4586 | retval = NULL; |
| 4587 | break; |
| 4588 | case DB_BTREE: |
| 4589 | case DB_HASH: |
| 4590 | default: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4591 | retval = BuildValue_SS(key.data, key.size, data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4592 | break; |
| 4593 | case DB_RECNO: |
| 4594 | case DB_QUEUE: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4595 | retval = BuildValue_IS(*((db_recno_t*)key.data), data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4596 | break; |
| 4597 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4598 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4599 | } |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4600 | /* the only time REALLOC should be set is if we used an integer |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 4601 | * key that make_key_dbt malloc'd for us. always free these. */ |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4602 | if (key.flags & DB_DBT_REALLOC) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4603 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4604 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4605 | |
| 4606 | return retval; |
| 4607 | } |
| 4608 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4609 | static PyObject* |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4610 | _DBC_get_set_both(DBCursorObject* self, PyObject* keyobj, PyObject* dataobj, |
| 4611 | int flags, unsigned int returnsNone) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4612 | { |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4613 | int err; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4614 | DBT key, data; |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4615 | PyObject* retval; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4616 | |
Gregory P. Smith | 7441e65 | 2003-11-03 21:35:31 +0000 | [diff] [blame] | 4617 | /* the caller did this: CHECK_CURSOR_NOT_CLOSED(self); */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4618 | if (!make_key_dbt(self->mydb, keyobj, &key, NULL)) |
| 4619 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4620 | if (!make_dbt(dataobj, &data)) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4621 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4622 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4623 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4624 | |
| 4625 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4626 | err = _DBC_get(self->dbc, &key, &data, flags|DB_GET_BOTH); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4627 | MYDB_END_ALLOW_THREADS; |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 4628 | if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) && returnsNone) { |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4629 | Py_INCREF(Py_None); |
| 4630 | retval = Py_None; |
| 4631 | } |
| 4632 | else if (makeDBError(err)) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4633 | retval = NULL; |
| 4634 | } |
| 4635 | else { |
| 4636 | switch (_DB_get_type(self->mydb)) { |
| 4637 | case -1: |
| 4638 | retval = NULL; |
| 4639 | break; |
| 4640 | case DB_BTREE: |
| 4641 | case DB_HASH: |
| 4642 | default: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4643 | retval = BuildValue_SS(key.data, key.size, data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4644 | break; |
| 4645 | case DB_RECNO: |
| 4646 | case DB_QUEUE: |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4647 | retval = BuildValue_IS(*((db_recno_t*)key.data), data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4648 | break; |
| 4649 | } |
| 4650 | } |
| 4651 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4652 | FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4653 | return retval; |
| 4654 | } |
| 4655 | |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4656 | static PyObject* |
| 4657 | DBC_get_both(DBCursorObject* self, PyObject* args) |
| 4658 | { |
| 4659 | int flags=0; |
| 4660 | PyObject *keyobj, *dataobj; |
| 4661 | |
| 4662 | if (!PyArg_ParseTuple(args, "OO|i:get_both", &keyobj, &dataobj, &flags)) |
| 4663 | return NULL; |
| 4664 | |
Gregory P. Smith | 7441e65 | 2003-11-03 21:35:31 +0000 | [diff] [blame] | 4665 | /* if the cursor is closed, self->mydb may be invalid */ |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4666 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4667 | |
| 4668 | return _DBC_get_set_both(self, keyobj, dataobj, flags, |
| 4669 | self->mydb->moduleFlags.getReturnsNone); |
| 4670 | } |
| 4671 | |
Gregory P. Smith | be0db8b | 2003-10-01 06:48:51 +0000 | [diff] [blame] | 4672 | /* Return size of entry */ |
| 4673 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 4674 | DBC_get_current_size(DBCursorObject* self) |
Gregory P. Smith | be0db8b | 2003-10-01 06:48:51 +0000 | [diff] [blame] | 4675 | { |
| 4676 | int err, flags=DB_CURRENT; |
| 4677 | PyObject* retval = NULL; |
| 4678 | DBT key, data; |
| 4679 | |
Gregory P. Smith | be0db8b | 2003-10-01 06:48:51 +0000 | [diff] [blame] | 4680 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4681 | CLEAR_DBT(key); |
| 4682 | CLEAR_DBT(data); |
| 4683 | |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 4684 | /* We don't allocate any memory, forcing a DB_BUFFER_SMALL error and thus |
Gregory P. Smith | be0db8b | 2003-10-01 06:48:51 +0000 | [diff] [blame] | 4685 | getting the record size. */ |
| 4686 | data.flags = DB_DBT_USERMEM; |
| 4687 | data.ulen = 0; |
| 4688 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4689 | err = _DBC_get(self->dbc, &key, &data, flags); |
Gregory P. Smith | be0db8b | 2003-10-01 06:48:51 +0000 | [diff] [blame] | 4690 | MYDB_END_ALLOW_THREADS; |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 4691 | if (err == DB_BUFFER_SMALL || !err) { |
| 4692 | /* DB_BUFFER_SMALL means positive size, !err means zero length value */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 4693 | retval = NUMBER_FromLong((long)data.size); |
Gregory P. Smith | be0db8b | 2003-10-01 06:48:51 +0000 | [diff] [blame] | 4694 | err = 0; |
| 4695 | } |
| 4696 | |
Gregory P. Smith | be0db8b | 2003-10-01 06:48:51 +0000 | [diff] [blame] | 4697 | RETURN_IF_ERR(); |
| 4698 | return retval; |
| 4699 | } |
| 4700 | |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4701 | static PyObject* |
| 4702 | DBC_set_both(DBCursorObject* self, PyObject* args) |
| 4703 | { |
| 4704 | int flags=0; |
| 4705 | PyObject *keyobj, *dataobj; |
| 4706 | |
| 4707 | if (!PyArg_ParseTuple(args, "OO|i:set_both", &keyobj, &dataobj, &flags)) |
| 4708 | return NULL; |
| 4709 | |
Gregory P. Smith | 7441e65 | 2003-11-03 21:35:31 +0000 | [diff] [blame] | 4710 | /* if the cursor is closed, self->mydb may be invalid */ |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4711 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4712 | |
| 4713 | return _DBC_get_set_both(self, keyobj, dataobj, flags, |
| 4714 | self->mydb->moduleFlags.cursorSetReturnsNone); |
| 4715 | } |
| 4716 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4717 | |
| 4718 | static PyObject* |
| 4719 | DBC_set_recno(DBCursorObject* self, PyObject* args, PyObject *kwargs) |
| 4720 | { |
| 4721 | int err, irecno, flags=0; |
| 4722 | db_recno_t recno; |
| 4723 | DBT key, data; |
| 4724 | PyObject* retval; |
| 4725 | int dlen = -1; |
| 4726 | int doff = -1; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 4727 | static char* kwnames[] = { "recno","flags", "dlen", "doff", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4728 | |
| 4729 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|iii:set_recno", kwnames, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4730 | &irecno, &flags, &dlen, &doff)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4731 | return NULL; |
| 4732 | |
| 4733 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4734 | |
| 4735 | CLEAR_DBT(key); |
| 4736 | recno = (db_recno_t) irecno; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 4737 | /* use allocated space so DB will be able to realloc room for the real |
| 4738 | * key */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4739 | key.data = malloc(sizeof(db_recno_t)); |
| 4740 | if (key.data == NULL) { |
| 4741 | PyErr_SetString(PyExc_MemoryError, "Key memory allocation failed"); |
| 4742 | return NULL; |
| 4743 | } |
| 4744 | key.size = sizeof(db_recno_t); |
| 4745 | key.ulen = key.size; |
| 4746 | memcpy(key.data, &recno, sizeof(db_recno_t)); |
| 4747 | key.flags = DB_DBT_REALLOC; |
| 4748 | |
| 4749 | CLEAR_DBT(data); |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4750 | if (!add_partial_dbt(&data, dlen, doff)) { |
| 4751 | FREE_DBT(key); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4752 | return NULL; |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4753 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4754 | |
| 4755 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4756 | err = _DBC_get(self->dbc, &key, &data, flags|DB_SET_RECNO); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4757 | MYDB_END_ALLOW_THREADS; |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 4758 | if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4759 | && self->mydb->moduleFlags.cursorSetReturnsNone) { |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4760 | Py_INCREF(Py_None); |
| 4761 | retval = Py_None; |
| 4762 | } |
| 4763 | else if (makeDBError(err)) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4764 | retval = NULL; |
| 4765 | } |
| 4766 | else { /* Can only be used for BTrees, so no need to return int key */ |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4767 | retval = BuildValue_SS(key.data, key.size, data.data, data.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4768 | } |
Gregory P. Smith | dc5af70 | 2004-06-27 23:32:34 +0000 | [diff] [blame] | 4769 | FREE_DBT(key); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4770 | |
| 4771 | return retval; |
| 4772 | } |
| 4773 | |
| 4774 | |
| 4775 | static PyObject* |
| 4776 | DBC_consume(DBCursorObject* self, PyObject* args, PyObject *kwargs) |
| 4777 | { |
| 4778 | return _DBCursor_get(self,DB_CONSUME,args,kwargs,"|iii:consume"); |
| 4779 | } |
| 4780 | |
| 4781 | |
| 4782 | static PyObject* |
| 4783 | DBC_next_dup(DBCursorObject* self, PyObject* args, PyObject *kwargs) |
| 4784 | { |
| 4785 | return _DBCursor_get(self,DB_NEXT_DUP,args,kwargs,"|iii:next_dup"); |
| 4786 | } |
| 4787 | |
| 4788 | |
| 4789 | static PyObject* |
| 4790 | DBC_next_nodup(DBCursorObject* self, PyObject* args, PyObject *kwargs) |
| 4791 | { |
| 4792 | return _DBCursor_get(self,DB_NEXT_NODUP,args,kwargs,"|iii:next_nodup"); |
| 4793 | } |
| 4794 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 4795 | #if (DBVER >= 46) |
| 4796 | static PyObject* |
| 4797 | DBC_prev_dup(DBCursorObject* self, PyObject* args, PyObject *kwargs) |
| 4798 | { |
| 4799 | return _DBCursor_get(self,DB_PREV_DUP,args,kwargs,"|iii:prev_dup"); |
| 4800 | } |
| 4801 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4802 | |
| 4803 | static PyObject* |
| 4804 | DBC_prev_nodup(DBCursorObject* self, PyObject* args, PyObject *kwargs) |
| 4805 | { |
| 4806 | return _DBCursor_get(self,DB_PREV_NODUP,args,kwargs,"|iii:prev_nodup"); |
| 4807 | } |
| 4808 | |
| 4809 | |
| 4810 | static PyObject* |
| 4811 | DBC_join_item(DBCursorObject* self, PyObject* args) |
| 4812 | { |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4813 | int err, flags=0; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4814 | DBT key, data; |
| 4815 | PyObject* retval; |
| 4816 | |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4817 | if (!PyArg_ParseTuple(args, "|i:join_item", &flags)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4818 | return NULL; |
| 4819 | |
| 4820 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4821 | |
| 4822 | CLEAR_DBT(key); |
| 4823 | CLEAR_DBT(data); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4824 | |
| 4825 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4826 | err = _DBC_get(self->dbc, &key, &data, flags | DB_JOIN_ITEM); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4827 | MYDB_END_ALLOW_THREADS; |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 4828 | if ((err == DB_NOTFOUND || err == DB_KEYEMPTY) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4829 | && self->mydb->moduleFlags.getReturnsNone) { |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 4830 | Py_INCREF(Py_None); |
| 4831 | retval = Py_None; |
| 4832 | } |
| 4833 | else if (makeDBError(err)) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4834 | retval = NULL; |
| 4835 | } |
| 4836 | else { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4837 | retval = BuildValue_S(key.data, key.size); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | return retval; |
| 4841 | } |
| 4842 | |
| 4843 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 4844 | #if (DBVER >= 46) |
| 4845 | static PyObject* |
| 4846 | DBC_set_priority(DBCursorObject* self, PyObject* args, PyObject* kwargs) |
| 4847 | { |
| 4848 | int err, priority; |
| 4849 | static char* kwnames[] = { "priority", NULL }; |
| 4850 | |
| 4851 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:set_priority", kwnames, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 4852 | &priority)) |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 4853 | return NULL; |
| 4854 | |
| 4855 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4856 | |
| 4857 | MYDB_BEGIN_ALLOW_THREADS; |
| 4858 | err = self->dbc->set_priority(self->dbc, priority); |
| 4859 | MYDB_END_ALLOW_THREADS; |
| 4860 | RETURN_IF_ERR(); |
| 4861 | RETURN_NONE(); |
| 4862 | } |
| 4863 | |
| 4864 | |
| 4865 | static PyObject* |
| 4866 | DBC_get_priority(DBCursorObject* self) |
| 4867 | { |
| 4868 | int err; |
| 4869 | DB_CACHE_PRIORITY priority; |
| 4870 | |
| 4871 | CHECK_CURSOR_NOT_CLOSED(self); |
| 4872 | |
| 4873 | MYDB_BEGIN_ALLOW_THREADS; |
| 4874 | err = self->dbc->get_priority(self->dbc, &priority); |
| 4875 | MYDB_END_ALLOW_THREADS; |
| 4876 | RETURN_IF_ERR(); |
| 4877 | return NUMBER_FromLong(priority); |
| 4878 | } |
| 4879 | #endif |
| 4880 | |
| 4881 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4882 | |
| 4883 | /* --------------------------------------------------------------------- */ |
| 4884 | /* DBEnv methods */ |
| 4885 | |
| 4886 | |
| 4887 | static PyObject* |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4888 | DBEnv_close_internal(DBEnvObject* self, int flags) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4889 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4890 | PyObject *dummy; |
| 4891 | int err; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4892 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4893 | if (!self->closed) { /* Don't close more than once */ |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4894 | while(self->children_txns) { |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 4895 | dummy = DBTxn_abort_discard_internal(self->children_txns, 0); |
| 4896 | Py_XDECREF(dummy); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4897 | } |
| 4898 | while(self->children_dbs) { |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 4899 | dummy = DB_close_internal(self->children_dbs, 0, 0); |
| 4900 | Py_XDECREF(dummy); |
| 4901 | } |
| 4902 | while(self->children_logcursors) { |
| 4903 | dummy = DBLogCursor_close_internal(self->children_logcursors); |
| 4904 | Py_XDECREF(dummy); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4905 | } |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 4906 | #if (DBVER >= 52) |
| 4907 | while(self->children_sites) { |
| 4908 | dummy = DBSite_close_internal(self->children_sites); |
| 4909 | Py_XDECREF(dummy); |
| 4910 | } |
| 4911 | #endif |
Jesus Cea | ac25fab | 2008-09-03 17:50:32 +0000 | [diff] [blame] | 4912 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4913 | |
Jesus Cea | ac25fab | 2008-09-03 17:50:32 +0000 | [diff] [blame] | 4914 | self->closed = 1; |
| 4915 | if (self->db_env) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4916 | MYDB_BEGIN_ALLOW_THREADS; |
| 4917 | err = self->db_env->close(self->db_env, flags); |
| 4918 | MYDB_END_ALLOW_THREADS; |
| 4919 | /* after calling DBEnv->close, regardless of error, this DBEnv |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4920 | * may not be accessed again (Berkeley DB docs). */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4921 | self->db_env = NULL; |
| 4922 | RETURN_IF_ERR(); |
| 4923 | } |
| 4924 | RETURN_NONE(); |
| 4925 | } |
| 4926 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4927 | static PyObject* |
| 4928 | DBEnv_close(DBEnvObject* self, PyObject* args) |
| 4929 | { |
| 4930 | int flags = 0; |
| 4931 | |
| 4932 | if (!PyArg_ParseTuple(args, "|i:close", &flags)) |
| 4933 | return NULL; |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 4934 | return DBEnv_close_internal(self, flags); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 4935 | } |
| 4936 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 4937 | |
| 4938 | static PyObject* |
| 4939 | DBEnv_open(DBEnvObject* self, PyObject* args) |
| 4940 | { |
| 4941 | int err, flags=0, mode=0660; |
| 4942 | char *db_home; |
| 4943 | |
| 4944 | if (!PyArg_ParseTuple(args, "z|ii:open", &db_home, &flags, &mode)) |
| 4945 | return NULL; |
| 4946 | |
| 4947 | CHECK_ENV_NOT_CLOSED(self); |
| 4948 | |
| 4949 | MYDB_BEGIN_ALLOW_THREADS; |
| 4950 | err = self->db_env->open(self->db_env, db_home, flags, mode); |
| 4951 | MYDB_END_ALLOW_THREADS; |
| 4952 | RETURN_IF_ERR(); |
| 4953 | self->closed = 0; |
| 4954 | self->flags = flags; |
| 4955 | RETURN_NONE(); |
| 4956 | } |
| 4957 | |
| 4958 | |
| 4959 | static PyObject* |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 4960 | DBEnv_memp_stat(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 4961 | { |
| 4962 | int err; |
| 4963 | DB_MPOOL_STAT *gsp; |
| 4964 | DB_MPOOL_FSTAT **fsp, **fsp2; |
| 4965 | PyObject* d = NULL, *d2, *d3, *r; |
| 4966 | u_int32_t flags = 0; |
| 4967 | static char* kwnames[] = { "flags", NULL }; |
| 4968 | |
| 4969 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:memp_stat", |
| 4970 | kwnames, &flags)) |
| 4971 | return NULL; |
| 4972 | |
| 4973 | CHECK_ENV_NOT_CLOSED(self); |
| 4974 | |
| 4975 | MYDB_BEGIN_ALLOW_THREADS; |
| 4976 | err = self->db_env->memp_stat(self->db_env, &gsp, &fsp, flags); |
| 4977 | MYDB_END_ALLOW_THREADS; |
| 4978 | RETURN_IF_ERR(); |
| 4979 | |
| 4980 | /* Turn the stat structure into a dictionary */ |
| 4981 | d = PyDict_New(); |
| 4982 | if (d == NULL) { |
| 4983 | if (gsp) |
| 4984 | free(gsp); |
| 4985 | return NULL; |
| 4986 | } |
| 4987 | |
| 4988 | #define MAKE_ENTRY(name) _addIntToDict(d, #name, gsp->st_##name) |
| 4989 | |
| 4990 | MAKE_ENTRY(gbytes); |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 4991 | MAKE_ENTRY(bytes); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 4992 | MAKE_ENTRY(ncache); |
| 4993 | #if (DBVER >= 46) |
| 4994 | MAKE_ENTRY(max_ncache); |
| 4995 | #endif |
| 4996 | MAKE_ENTRY(regsize); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 4997 | MAKE_ENTRY(mmapsize); |
| 4998 | MAKE_ENTRY(maxopenfd); |
| 4999 | MAKE_ENTRY(maxwrite); |
| 5000 | MAKE_ENTRY(maxwrite_sleep); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5001 | MAKE_ENTRY(map); |
| 5002 | MAKE_ENTRY(cache_hit); |
| 5003 | MAKE_ENTRY(cache_miss); |
| 5004 | MAKE_ENTRY(page_create); |
| 5005 | MAKE_ENTRY(page_in); |
| 5006 | MAKE_ENTRY(page_out); |
| 5007 | MAKE_ENTRY(ro_evict); |
| 5008 | MAKE_ENTRY(rw_evict); |
| 5009 | MAKE_ENTRY(page_trickle); |
| 5010 | MAKE_ENTRY(pages); |
| 5011 | MAKE_ENTRY(page_clean); |
| 5012 | MAKE_ENTRY(page_dirty); |
| 5013 | MAKE_ENTRY(hash_buckets); |
| 5014 | MAKE_ENTRY(hash_searches); |
| 5015 | MAKE_ENTRY(hash_longest); |
| 5016 | MAKE_ENTRY(hash_examined); |
| 5017 | MAKE_ENTRY(hash_nowait); |
| 5018 | MAKE_ENTRY(hash_wait); |
| 5019 | #if (DBVER >= 45) |
| 5020 | MAKE_ENTRY(hash_max_nowait); |
| 5021 | #endif |
| 5022 | MAKE_ENTRY(hash_max_wait); |
| 5023 | MAKE_ENTRY(region_wait); |
| 5024 | MAKE_ENTRY(region_nowait); |
| 5025 | #if (DBVER >= 45) |
| 5026 | MAKE_ENTRY(mvcc_frozen); |
| 5027 | MAKE_ENTRY(mvcc_thawed); |
| 5028 | MAKE_ENTRY(mvcc_freed); |
| 5029 | #endif |
| 5030 | MAKE_ENTRY(alloc); |
| 5031 | MAKE_ENTRY(alloc_buckets); |
| 5032 | MAKE_ENTRY(alloc_max_buckets); |
| 5033 | MAKE_ENTRY(alloc_pages); |
| 5034 | MAKE_ENTRY(alloc_max_pages); |
| 5035 | #if (DBVER >= 45) |
| 5036 | MAKE_ENTRY(io_wait); |
| 5037 | #endif |
| 5038 | #if (DBVER >= 48) |
| 5039 | MAKE_ENTRY(sync_interrupted); |
| 5040 | #endif |
| 5041 | |
| 5042 | #undef MAKE_ENTRY |
| 5043 | free(gsp); |
| 5044 | |
| 5045 | d2 = PyDict_New(); |
| 5046 | if (d2 == NULL) { |
| 5047 | Py_DECREF(d); |
| 5048 | if (fsp) |
| 5049 | free(fsp); |
| 5050 | return NULL; |
| 5051 | } |
| 5052 | #define MAKE_ENTRY(name) _addIntToDict(d3, #name, (*fsp2)->st_##name) |
| 5053 | for(fsp2=fsp;*fsp2; fsp2++) { |
| 5054 | d3 = PyDict_New(); |
| 5055 | if (d3 == NULL) { |
| 5056 | Py_DECREF(d); |
| 5057 | Py_DECREF(d2); |
| 5058 | if (fsp) |
| 5059 | free(fsp); |
| 5060 | return NULL; |
| 5061 | } |
| 5062 | MAKE_ENTRY(pagesize); |
| 5063 | MAKE_ENTRY(cache_hit); |
| 5064 | MAKE_ENTRY(cache_miss); |
| 5065 | MAKE_ENTRY(map); |
| 5066 | MAKE_ENTRY(page_create); |
| 5067 | MAKE_ENTRY(page_in); |
| 5068 | MAKE_ENTRY(page_out); |
| 5069 | if(PyDict_SetItemString(d2, (*fsp2)->file_name, d3)) { |
| 5070 | Py_DECREF(d); |
| 5071 | Py_DECREF(d2); |
| 5072 | Py_DECREF(d3); |
| 5073 | if (fsp) |
| 5074 | free(fsp); |
| 5075 | return NULL; |
| 5076 | } |
| 5077 | Py_DECREF(d3); |
| 5078 | } |
| 5079 | |
| 5080 | #undef MAKE_ENTRY |
| 5081 | free(fsp); |
| 5082 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 5083 | r = PyTuple_Pack(2, d, d2); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5084 | Py_DECREF(d); |
| 5085 | Py_DECREF(d2); |
| 5086 | return r; |
| 5087 | } |
| 5088 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5089 | static PyObject* |
| 5090 | DBEnv_memp_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 5091 | { |
| 5092 | int err; |
| 5093 | int flags=0; |
| 5094 | static char* kwnames[] = { "flags", NULL }; |
| 5095 | |
| 5096 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:memp_stat_print", |
| 5097 | kwnames, &flags)) |
| 5098 | { |
| 5099 | return NULL; |
| 5100 | } |
| 5101 | CHECK_ENV_NOT_CLOSED(self); |
| 5102 | MYDB_BEGIN_ALLOW_THREADS; |
| 5103 | err = self->db_env->memp_stat_print(self->db_env, flags); |
| 5104 | MYDB_END_ALLOW_THREADS; |
| 5105 | RETURN_IF_ERR(); |
| 5106 | RETURN_NONE(); |
| 5107 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5108 | |
| 5109 | |
| 5110 | static PyObject* |
| 5111 | DBEnv_memp_trickle(DBEnvObject* self, PyObject* args) |
| 5112 | { |
| 5113 | int err, percent, nwrotep; |
| 5114 | |
| 5115 | if (!PyArg_ParseTuple(args, "i:memp_trickle", &percent)) |
| 5116 | return NULL; |
| 5117 | CHECK_ENV_NOT_CLOSED(self); |
| 5118 | MYDB_BEGIN_ALLOW_THREADS; |
| 5119 | err = self->db_env->memp_trickle(self->db_env, percent, &nwrotep); |
| 5120 | MYDB_END_ALLOW_THREADS; |
| 5121 | RETURN_IF_ERR(); |
| 5122 | return NUMBER_FromLong(nwrotep); |
| 5123 | } |
| 5124 | |
| 5125 | static PyObject* |
| 5126 | DBEnv_memp_sync(DBEnvObject* self, PyObject* args) |
| 5127 | { |
| 5128 | int err; |
| 5129 | DB_LSN lsn = {0, 0}; |
| 5130 | DB_LSN *lsn_p = NULL; |
| 5131 | |
| 5132 | if (!PyArg_ParseTuple(args, "|(ii):memp_sync", &lsn.file, &lsn.offset)) |
| 5133 | return NULL; |
| 5134 | if ((lsn.file!=0) || (lsn.offset!=0)) { |
| 5135 | lsn_p = &lsn; |
| 5136 | } |
| 5137 | CHECK_ENV_NOT_CLOSED(self); |
| 5138 | MYDB_BEGIN_ALLOW_THREADS; |
| 5139 | err = self->db_env->memp_sync(self->db_env, lsn_p); |
| 5140 | MYDB_END_ALLOW_THREADS; |
| 5141 | RETURN_IF_ERR(); |
| 5142 | RETURN_NONE(); |
| 5143 | } |
| 5144 | |
| 5145 | static PyObject* |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5146 | DBEnv_remove(DBEnvObject* self, PyObject* args) |
| 5147 | { |
| 5148 | int err, flags=0; |
| 5149 | char *db_home; |
| 5150 | |
| 5151 | if (!PyArg_ParseTuple(args, "s|i:remove", &db_home, &flags)) |
| 5152 | return NULL; |
| 5153 | CHECK_ENV_NOT_CLOSED(self); |
| 5154 | MYDB_BEGIN_ALLOW_THREADS; |
| 5155 | err = self->db_env->remove(self->db_env, db_home, flags); |
| 5156 | MYDB_END_ALLOW_THREADS; |
| 5157 | RETURN_IF_ERR(); |
| 5158 | RETURN_NONE(); |
| 5159 | } |
| 5160 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 5161 | static PyObject* |
| 5162 | DBEnv_dbremove(DBEnvObject* self, PyObject* args, PyObject* kwargs) |
| 5163 | { |
| 5164 | int err; |
| 5165 | u_int32_t flags=0; |
| 5166 | char *file = NULL; |
| 5167 | char *database = NULL; |
| 5168 | PyObject *txnobj = NULL; |
| 5169 | DB_TXN *txn = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 5170 | static char* kwnames[] = { "file", "database", "txn", "flags", |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 5171 | NULL }; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 5172 | |
Gregory P. Smith | 641cddf | 2006-07-28 01:35:25 +0000 | [diff] [blame] | 5173 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zOi:dbremove", kwnames, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 5174 | &file, &database, &txnobj, &flags)) { |
| 5175 | return NULL; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 5176 | } |
| 5177 | if (!checkTxnObj(txnobj, &txn)) { |
| 5178 | return NULL; |
| 5179 | } |
| 5180 | CHECK_ENV_NOT_CLOSED(self); |
| 5181 | MYDB_BEGIN_ALLOW_THREADS; |
| 5182 | err = self->db_env->dbremove(self->db_env, txn, file, database, flags); |
| 5183 | MYDB_END_ALLOW_THREADS; |
| 5184 | RETURN_IF_ERR(); |
| 5185 | RETURN_NONE(); |
| 5186 | } |
| 5187 | |
| 5188 | static PyObject* |
| 5189 | DBEnv_dbrename(DBEnvObject* self, PyObject* args, PyObject* kwargs) |
| 5190 | { |
| 5191 | int err; |
| 5192 | u_int32_t flags=0; |
| 5193 | char *file = NULL; |
| 5194 | char *database = NULL; |
| 5195 | char *newname = NULL; |
| 5196 | PyObject *txnobj = NULL; |
| 5197 | DB_TXN *txn = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 5198 | static char* kwnames[] = { "file", "database", "newname", "txn", |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 5199 | "flags", NULL }; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 5200 | |
Gregory P. Smith | 641cddf | 2006-07-28 01:35:25 +0000 | [diff] [blame] | 5201 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "szs|Oi:dbrename", kwnames, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 5202 | &file, &database, &newname, &txnobj, &flags)) { |
| 5203 | return NULL; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 5204 | } |
| 5205 | if (!checkTxnObj(txnobj, &txn)) { |
| 5206 | return NULL; |
| 5207 | } |
| 5208 | CHECK_ENV_NOT_CLOSED(self); |
| 5209 | MYDB_BEGIN_ALLOW_THREADS; |
| 5210 | err = self->db_env->dbrename(self->db_env, txn, file, database, newname, |
| 5211 | flags); |
| 5212 | MYDB_END_ALLOW_THREADS; |
| 5213 | RETURN_IF_ERR(); |
| 5214 | RETURN_NONE(); |
| 5215 | } |
| 5216 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5217 | |
| 5218 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 5219 | static PyObject* |
| 5220 | DBEnv_set_encrypt(DBEnvObject* self, PyObject* args, PyObject* kwargs) |
| 5221 | { |
| 5222 | int err; |
| 5223 | u_int32_t flags=0; |
| 5224 | char *passwd = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 5225 | static char* kwnames[] = { "passwd", "flags", NULL }; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 5226 | |
| 5227 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|i:set_encrypt", kwnames, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 5228 | &passwd, &flags)) { |
| 5229 | return NULL; |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | MYDB_BEGIN_ALLOW_THREADS; |
| 5233 | err = self->db_env->set_encrypt(self->db_env, passwd, flags); |
| 5234 | MYDB_END_ALLOW_THREADS; |
| 5235 | |
| 5236 | RETURN_IF_ERR(); |
| 5237 | RETURN_NONE(); |
| 5238 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5239 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5240 | static PyObject* |
| 5241 | DBEnv_get_encrypt_flags(DBEnvObject* self) |
| 5242 | { |
| 5243 | int err; |
| 5244 | u_int32_t flags; |
| 5245 | |
| 5246 | CHECK_ENV_NOT_CLOSED(self); |
| 5247 | |
| 5248 | MYDB_BEGIN_ALLOW_THREADS; |
| 5249 | err = self->db_env->get_encrypt_flags(self->db_env, &flags); |
| 5250 | MYDB_END_ALLOW_THREADS; |
| 5251 | |
| 5252 | RETURN_IF_ERR(); |
| 5253 | |
| 5254 | return NUMBER_FromLong(flags); |
| 5255 | } |
| 5256 | |
| 5257 | static PyObject* |
| 5258 | DBEnv_get_timeout(DBEnvObject* self, PyObject* args, PyObject* kwargs) |
| 5259 | { |
| 5260 | int err; |
| 5261 | int flag; |
| 5262 | u_int32_t timeout; |
| 5263 | static char* kwnames[] = {"flag", NULL }; |
| 5264 | |
| 5265 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:get_timeout", kwnames, |
| 5266 | &flag)) { |
| 5267 | return NULL; |
| 5268 | } |
| 5269 | CHECK_ENV_NOT_CLOSED(self); |
| 5270 | |
| 5271 | MYDB_BEGIN_ALLOW_THREADS; |
| 5272 | err = self->db_env->get_timeout(self->db_env, &timeout, flag); |
| 5273 | MYDB_END_ALLOW_THREADS; |
| 5274 | RETURN_IF_ERR(); |
| 5275 | return NUMBER_FromLong(timeout); |
| 5276 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5277 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5278 | |
Gregory P. Smith | fe11d3e | 2003-03-27 17:23:29 +0000 | [diff] [blame] | 5279 | static PyObject* |
| 5280 | DBEnv_set_timeout(DBEnvObject* self, PyObject* args, PyObject* kwargs) |
| 5281 | { |
| 5282 | int err; |
| 5283 | u_int32_t flags=0; |
| 5284 | u_int32_t timeout = 0; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 5285 | static char* kwnames[] = { "timeout", "flags", NULL }; |
Gregory P. Smith | fe11d3e | 2003-03-27 17:23:29 +0000 | [diff] [blame] | 5286 | |
| 5287 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:set_timeout", kwnames, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 5288 | &timeout, &flags)) { |
| 5289 | return NULL; |
Gregory P. Smith | fe11d3e | 2003-03-27 17:23:29 +0000 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | MYDB_BEGIN_ALLOW_THREADS; |
| 5293 | err = self->db_env->set_timeout(self->db_env, (db_timeout_t)timeout, flags); |
| 5294 | MYDB_END_ALLOW_THREADS; |
| 5295 | |
| 5296 | RETURN_IF_ERR(); |
| 5297 | RETURN_NONE(); |
| 5298 | } |
Gregory P. Smith | fe11d3e | 2003-03-27 17:23:29 +0000 | [diff] [blame] | 5299 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5300 | static PyObject* |
Gregory P. Smith | 6676f6e | 2003-08-28 21:50:30 +0000 | [diff] [blame] | 5301 | DBEnv_set_shm_key(DBEnvObject* self, PyObject* args) |
| 5302 | { |
| 5303 | int err; |
| 5304 | long shm_key = 0; |
| 5305 | |
| 5306 | if (!PyArg_ParseTuple(args, "l:set_shm_key", &shm_key)) |
| 5307 | return NULL; |
| 5308 | CHECK_ENV_NOT_CLOSED(self); |
| 5309 | |
| 5310 | err = self->db_env->set_shm_key(self->db_env, shm_key); |
| 5311 | RETURN_IF_ERR(); |
| 5312 | RETURN_NONE(); |
| 5313 | } |
| 5314 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5315 | static PyObject* |
| 5316 | DBEnv_get_shm_key(DBEnvObject* self) |
| 5317 | { |
| 5318 | int err; |
| 5319 | long shm_key; |
| 5320 | |
| 5321 | CHECK_ENV_NOT_CLOSED(self); |
| 5322 | |
| 5323 | MYDB_BEGIN_ALLOW_THREADS; |
| 5324 | err = self->db_env->get_shm_key(self->db_env, &shm_key); |
| 5325 | MYDB_END_ALLOW_THREADS; |
| 5326 | |
| 5327 | RETURN_IF_ERR(); |
| 5328 | |
| 5329 | return NUMBER_FromLong(shm_key); |
| 5330 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5331 | |
| 5332 | #if (DBVER >= 46) |
| 5333 | static PyObject* |
| 5334 | DBEnv_set_cache_max(DBEnvObject* self, PyObject* args) |
| 5335 | { |
| 5336 | int err, gbytes, bytes; |
| 5337 | |
| 5338 | if (!PyArg_ParseTuple(args, "ii:set_cache_max", |
| 5339 | &gbytes, &bytes)) |
| 5340 | return NULL; |
| 5341 | CHECK_ENV_NOT_CLOSED(self); |
| 5342 | |
| 5343 | MYDB_BEGIN_ALLOW_THREADS; |
| 5344 | err = self->db_env->set_cache_max(self->db_env, gbytes, bytes); |
| 5345 | MYDB_END_ALLOW_THREADS; |
| 5346 | RETURN_IF_ERR(); |
| 5347 | RETURN_NONE(); |
| 5348 | } |
| 5349 | |
| 5350 | static PyObject* |
| 5351 | DBEnv_get_cache_max(DBEnvObject* self) |
| 5352 | { |
| 5353 | int err; |
| 5354 | u_int32_t gbytes, bytes; |
| 5355 | |
| 5356 | CHECK_ENV_NOT_CLOSED(self); |
| 5357 | |
| 5358 | MYDB_BEGIN_ALLOW_THREADS; |
| 5359 | err = self->db_env->get_cache_max(self->db_env, &gbytes, &bytes); |
| 5360 | MYDB_END_ALLOW_THREADS; |
| 5361 | |
| 5362 | RETURN_IF_ERR(); |
| 5363 | |
| 5364 | return Py_BuildValue("(ii)", gbytes, bytes); |
| 5365 | } |
| 5366 | #endif |
| 5367 | |
| 5368 | #if (DBVER >= 46) |
| 5369 | static PyObject* |
| 5370 | DBEnv_set_thread_count(DBEnvObject* self, PyObject* args) |
| 5371 | { |
| 5372 | int err; |
| 5373 | u_int32_t count; |
| 5374 | |
| 5375 | if (!PyArg_ParseTuple(args, "i:set_thread_count", &count)) |
| 5376 | return NULL; |
| 5377 | CHECK_ENV_NOT_CLOSED(self); |
| 5378 | |
| 5379 | MYDB_BEGIN_ALLOW_THREADS; |
| 5380 | err = self->db_env->set_thread_count(self->db_env, count); |
| 5381 | MYDB_END_ALLOW_THREADS; |
| 5382 | RETURN_IF_ERR(); |
| 5383 | RETURN_NONE(); |
| 5384 | } |
| 5385 | |
| 5386 | static PyObject* |
| 5387 | DBEnv_get_thread_count(DBEnvObject* self) |
| 5388 | { |
| 5389 | int err; |
| 5390 | u_int32_t count; |
| 5391 | |
| 5392 | CHECK_ENV_NOT_CLOSED(self); |
| 5393 | |
| 5394 | MYDB_BEGIN_ALLOW_THREADS; |
| 5395 | err = self->db_env->get_thread_count(self->db_env, &count); |
| 5396 | MYDB_END_ALLOW_THREADS; |
| 5397 | RETURN_IF_ERR(); |
| 5398 | return NUMBER_FromLong(count); |
| 5399 | } |
| 5400 | #endif |
| 5401 | |
Gregory P. Smith | 6676f6e | 2003-08-28 21:50:30 +0000 | [diff] [blame] | 5402 | static PyObject* |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5403 | DBEnv_set_cachesize(DBEnvObject* self, PyObject* args) |
| 5404 | { |
| 5405 | int err, gbytes=0, bytes=0, ncache=0; |
| 5406 | |
| 5407 | if (!PyArg_ParseTuple(args, "ii|i:set_cachesize", |
| 5408 | &gbytes, &bytes, &ncache)) |
| 5409 | return NULL; |
| 5410 | CHECK_ENV_NOT_CLOSED(self); |
| 5411 | |
| 5412 | MYDB_BEGIN_ALLOW_THREADS; |
| 5413 | err = self->db_env->set_cachesize(self->db_env, gbytes, bytes, ncache); |
| 5414 | MYDB_END_ALLOW_THREADS; |
| 5415 | RETURN_IF_ERR(); |
| 5416 | RETURN_NONE(); |
| 5417 | } |
| 5418 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5419 | static PyObject* |
| 5420 | DBEnv_get_cachesize(DBEnvObject* self) |
| 5421 | { |
| 5422 | int err; |
| 5423 | u_int32_t gbytes, bytes; |
| 5424 | int ncache; |
| 5425 | |
| 5426 | CHECK_ENV_NOT_CLOSED(self); |
| 5427 | |
| 5428 | MYDB_BEGIN_ALLOW_THREADS; |
| 5429 | err = self->db_env->get_cachesize(self->db_env, &gbytes, &bytes, &ncache); |
| 5430 | MYDB_END_ALLOW_THREADS; |
| 5431 | |
| 5432 | RETURN_IF_ERR(); |
| 5433 | |
| 5434 | return Py_BuildValue("(iii)", gbytes, bytes, ncache); |
| 5435 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5436 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5437 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5438 | static PyObject* |
| 5439 | DBEnv_set_flags(DBEnvObject* self, PyObject* args) |
| 5440 | { |
| 5441 | int err, flags=0, onoff=0; |
| 5442 | |
| 5443 | if (!PyArg_ParseTuple(args, "ii:set_flags", |
| 5444 | &flags, &onoff)) |
| 5445 | return NULL; |
| 5446 | CHECK_ENV_NOT_CLOSED(self); |
| 5447 | |
| 5448 | MYDB_BEGIN_ALLOW_THREADS; |
| 5449 | err = self->db_env->set_flags(self->db_env, flags, onoff); |
| 5450 | MYDB_END_ALLOW_THREADS; |
| 5451 | RETURN_IF_ERR(); |
| 5452 | RETURN_NONE(); |
| 5453 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5454 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5455 | static PyObject* |
| 5456 | DBEnv_get_flags(DBEnvObject* self) |
| 5457 | { |
| 5458 | int err; |
| 5459 | u_int32_t flags; |
| 5460 | |
| 5461 | CHECK_ENV_NOT_CLOSED(self); |
| 5462 | |
| 5463 | MYDB_BEGIN_ALLOW_THREADS; |
| 5464 | err = self->db_env->get_flags(self->db_env, &flags); |
| 5465 | MYDB_END_ALLOW_THREADS; |
| 5466 | RETURN_IF_ERR(); |
| 5467 | return NUMBER_FromLong(flags); |
| 5468 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5469 | |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 5470 | #if (DBVER >= 47) |
| 5471 | static PyObject* |
| 5472 | DBEnv_log_set_config(DBEnvObject* self, PyObject* args) |
| 5473 | { |
| 5474 | int err, flags, onoff; |
| 5475 | |
| 5476 | if (!PyArg_ParseTuple(args, "ii:log_set_config", |
| 5477 | &flags, &onoff)) |
| 5478 | return NULL; |
| 5479 | CHECK_ENV_NOT_CLOSED(self); |
| 5480 | |
| 5481 | MYDB_BEGIN_ALLOW_THREADS; |
| 5482 | err = self->db_env->log_set_config(self->db_env, flags, onoff); |
| 5483 | MYDB_END_ALLOW_THREADS; |
| 5484 | RETURN_IF_ERR(); |
| 5485 | RETURN_NONE(); |
| 5486 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5487 | |
| 5488 | static PyObject* |
| 5489 | DBEnv_log_get_config(DBEnvObject* self, PyObject* args) |
| 5490 | { |
| 5491 | int err, flag, onoff; |
| 5492 | |
| 5493 | if (!PyArg_ParseTuple(args, "i:log_get_config", &flag)) |
| 5494 | return NULL; |
| 5495 | CHECK_ENV_NOT_CLOSED(self); |
| 5496 | |
| 5497 | MYDB_BEGIN_ALLOW_THREADS; |
| 5498 | err = self->db_env->log_get_config(self->db_env, flag, &onoff); |
| 5499 | MYDB_END_ALLOW_THREADS; |
| 5500 | RETURN_IF_ERR(); |
| 5501 | return PyBool_FromLong(onoff); |
| 5502 | } |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 5503 | #endif /* DBVER >= 47 */ |
| 5504 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5505 | #if (DBVER >= 44) |
| 5506 | static PyObject* |
| 5507 | DBEnv_mutex_set_max(DBEnvObject* self, PyObject* args) |
| 5508 | { |
| 5509 | int err; |
| 5510 | int value; |
| 5511 | |
| 5512 | if (!PyArg_ParseTuple(args, "i:mutex_set_max", &value)) |
| 5513 | return NULL; |
| 5514 | |
| 5515 | CHECK_ENV_NOT_CLOSED(self); |
| 5516 | |
| 5517 | MYDB_BEGIN_ALLOW_THREADS; |
| 5518 | err = self->db_env->mutex_set_max(self->db_env, value); |
| 5519 | MYDB_END_ALLOW_THREADS; |
| 5520 | |
| 5521 | RETURN_IF_ERR(); |
| 5522 | RETURN_NONE(); |
| 5523 | } |
| 5524 | |
| 5525 | static PyObject* |
| 5526 | DBEnv_mutex_get_max(DBEnvObject* self) |
| 5527 | { |
| 5528 | int err; |
| 5529 | u_int32_t value; |
| 5530 | |
| 5531 | CHECK_ENV_NOT_CLOSED(self); |
| 5532 | |
| 5533 | MYDB_BEGIN_ALLOW_THREADS; |
| 5534 | err = self->db_env->mutex_get_max(self->db_env, &value); |
| 5535 | MYDB_END_ALLOW_THREADS; |
| 5536 | |
| 5537 | RETURN_IF_ERR(); |
| 5538 | |
| 5539 | return NUMBER_FromLong(value); |
| 5540 | } |
| 5541 | |
| 5542 | static PyObject* |
| 5543 | DBEnv_mutex_set_align(DBEnvObject* self, PyObject* args) |
| 5544 | { |
| 5545 | int err; |
| 5546 | int align; |
| 5547 | |
| 5548 | if (!PyArg_ParseTuple(args, "i:mutex_set_align", &align)) |
| 5549 | return NULL; |
| 5550 | |
| 5551 | CHECK_ENV_NOT_CLOSED(self); |
| 5552 | |
| 5553 | MYDB_BEGIN_ALLOW_THREADS; |
| 5554 | err = self->db_env->mutex_set_align(self->db_env, align); |
| 5555 | MYDB_END_ALLOW_THREADS; |
| 5556 | |
| 5557 | RETURN_IF_ERR(); |
| 5558 | RETURN_NONE(); |
| 5559 | } |
| 5560 | |
| 5561 | static PyObject* |
| 5562 | DBEnv_mutex_get_align(DBEnvObject* self) |
| 5563 | { |
| 5564 | int err; |
| 5565 | u_int32_t align; |
| 5566 | |
| 5567 | CHECK_ENV_NOT_CLOSED(self); |
| 5568 | |
| 5569 | MYDB_BEGIN_ALLOW_THREADS; |
| 5570 | err = self->db_env->mutex_get_align(self->db_env, &align); |
| 5571 | MYDB_END_ALLOW_THREADS; |
| 5572 | |
| 5573 | RETURN_IF_ERR(); |
| 5574 | |
| 5575 | return NUMBER_FromLong(align); |
| 5576 | } |
| 5577 | |
| 5578 | static PyObject* |
| 5579 | DBEnv_mutex_set_increment(DBEnvObject* self, PyObject* args) |
| 5580 | { |
| 5581 | int err; |
| 5582 | int increment; |
| 5583 | |
| 5584 | if (!PyArg_ParseTuple(args, "i:mutex_set_increment", &increment)) |
| 5585 | return NULL; |
| 5586 | |
| 5587 | CHECK_ENV_NOT_CLOSED(self); |
| 5588 | |
| 5589 | MYDB_BEGIN_ALLOW_THREADS; |
| 5590 | err = self->db_env->mutex_set_increment(self->db_env, increment); |
| 5591 | MYDB_END_ALLOW_THREADS; |
| 5592 | |
| 5593 | RETURN_IF_ERR(); |
| 5594 | RETURN_NONE(); |
| 5595 | } |
| 5596 | |
| 5597 | static PyObject* |
| 5598 | DBEnv_mutex_get_increment(DBEnvObject* self) |
| 5599 | { |
| 5600 | int err; |
| 5601 | u_int32_t increment; |
| 5602 | |
| 5603 | CHECK_ENV_NOT_CLOSED(self); |
| 5604 | |
| 5605 | MYDB_BEGIN_ALLOW_THREADS; |
| 5606 | err = self->db_env->mutex_get_increment(self->db_env, &increment); |
| 5607 | MYDB_END_ALLOW_THREADS; |
| 5608 | |
| 5609 | RETURN_IF_ERR(); |
| 5610 | |
| 5611 | return NUMBER_FromLong(increment); |
| 5612 | } |
| 5613 | |
| 5614 | static PyObject* |
| 5615 | DBEnv_mutex_set_tas_spins(DBEnvObject* self, PyObject* args) |
| 5616 | { |
| 5617 | int err; |
| 5618 | int tas_spins; |
| 5619 | |
| 5620 | if (!PyArg_ParseTuple(args, "i:mutex_set_tas_spins", &tas_spins)) |
| 5621 | return NULL; |
| 5622 | |
| 5623 | CHECK_ENV_NOT_CLOSED(self); |
| 5624 | |
| 5625 | MYDB_BEGIN_ALLOW_THREADS; |
| 5626 | err = self->db_env->mutex_set_tas_spins(self->db_env, tas_spins); |
| 5627 | MYDB_END_ALLOW_THREADS; |
| 5628 | |
| 5629 | RETURN_IF_ERR(); |
| 5630 | RETURN_NONE(); |
| 5631 | } |
| 5632 | |
| 5633 | static PyObject* |
| 5634 | DBEnv_mutex_get_tas_spins(DBEnvObject* self) |
| 5635 | { |
| 5636 | int err; |
| 5637 | u_int32_t tas_spins; |
| 5638 | |
| 5639 | CHECK_ENV_NOT_CLOSED(self); |
| 5640 | |
| 5641 | MYDB_BEGIN_ALLOW_THREADS; |
| 5642 | err = self->db_env->mutex_get_tas_spins(self->db_env, &tas_spins); |
| 5643 | MYDB_END_ALLOW_THREADS; |
| 5644 | |
| 5645 | RETURN_IF_ERR(); |
| 5646 | |
| 5647 | return NUMBER_FromLong(tas_spins); |
| 5648 | } |
| 5649 | #endif |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 5650 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5651 | static PyObject* |
| 5652 | DBEnv_set_data_dir(DBEnvObject* self, PyObject* args) |
| 5653 | { |
| 5654 | int err; |
| 5655 | char *dir; |
| 5656 | |
| 5657 | if (!PyArg_ParseTuple(args, "s:set_data_dir", &dir)) |
| 5658 | return NULL; |
| 5659 | CHECK_ENV_NOT_CLOSED(self); |
| 5660 | |
| 5661 | MYDB_BEGIN_ALLOW_THREADS; |
| 5662 | err = self->db_env->set_data_dir(self->db_env, dir); |
| 5663 | MYDB_END_ALLOW_THREADS; |
| 5664 | RETURN_IF_ERR(); |
| 5665 | RETURN_NONE(); |
| 5666 | } |
| 5667 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5668 | static PyObject* |
| 5669 | DBEnv_get_data_dirs(DBEnvObject* self) |
| 5670 | { |
| 5671 | int err; |
| 5672 | PyObject *tuple; |
| 5673 | PyObject *item; |
| 5674 | const char **dirpp; |
| 5675 | int size, i; |
| 5676 | |
| 5677 | CHECK_ENV_NOT_CLOSED(self); |
| 5678 | |
| 5679 | MYDB_BEGIN_ALLOW_THREADS; |
| 5680 | err = self->db_env->get_data_dirs(self->db_env, &dirpp); |
| 5681 | MYDB_END_ALLOW_THREADS; |
| 5682 | |
| 5683 | RETURN_IF_ERR(); |
| 5684 | |
| 5685 | /* |
| 5686 | ** Calculate size. Python C API |
| 5687 | ** actually allows for tuple resizing, |
| 5688 | ** but this is simple enough. |
| 5689 | */ |
| 5690 | for (size=0; *(dirpp+size) ; size++); |
| 5691 | |
| 5692 | tuple = PyTuple_New(size); |
| 5693 | if (!tuple) |
| 5694 | return NULL; |
| 5695 | |
| 5696 | for (i=0; i<size; i++) { |
| 5697 | item = PyBytes_FromString (*(dirpp+i)); |
| 5698 | if (item == NULL) { |
| 5699 | Py_DECREF(tuple); |
| 5700 | tuple = NULL; |
| 5701 | break; |
| 5702 | } |
| 5703 | PyTuple_SET_ITEM(tuple, i, item); |
| 5704 | } |
| 5705 | return tuple; |
| 5706 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5707 | |
| 5708 | #if (DBVER >= 44) |
| 5709 | static PyObject* |
| 5710 | DBEnv_set_lg_filemode(DBEnvObject* self, PyObject* args) |
| 5711 | { |
| 5712 | int err, filemode; |
| 5713 | |
| 5714 | if (!PyArg_ParseTuple(args, "i:set_lg_filemode", &filemode)) |
| 5715 | return NULL; |
| 5716 | CHECK_ENV_NOT_CLOSED(self); |
| 5717 | |
| 5718 | MYDB_BEGIN_ALLOW_THREADS; |
| 5719 | err = self->db_env->set_lg_filemode(self->db_env, filemode); |
| 5720 | MYDB_END_ALLOW_THREADS; |
| 5721 | RETURN_IF_ERR(); |
| 5722 | RETURN_NONE(); |
| 5723 | } |
| 5724 | |
| 5725 | static PyObject* |
| 5726 | DBEnv_get_lg_filemode(DBEnvObject* self) |
| 5727 | { |
| 5728 | int err, filemode; |
| 5729 | |
| 5730 | CHECK_ENV_NOT_CLOSED(self); |
| 5731 | |
| 5732 | MYDB_BEGIN_ALLOW_THREADS; |
| 5733 | err = self->db_env->get_lg_filemode(self->db_env, &filemode); |
| 5734 | MYDB_END_ALLOW_THREADS; |
| 5735 | RETURN_IF_ERR(); |
| 5736 | return NUMBER_FromLong(filemode); |
| 5737 | } |
| 5738 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5739 | |
| 5740 | static PyObject* |
| 5741 | DBEnv_set_lg_bsize(DBEnvObject* self, PyObject* args) |
| 5742 | { |
| 5743 | int err, lg_bsize; |
| 5744 | |
| 5745 | if (!PyArg_ParseTuple(args, "i:set_lg_bsize", &lg_bsize)) |
| 5746 | return NULL; |
| 5747 | CHECK_ENV_NOT_CLOSED(self); |
| 5748 | |
| 5749 | MYDB_BEGIN_ALLOW_THREADS; |
| 5750 | err = self->db_env->set_lg_bsize(self->db_env, lg_bsize); |
| 5751 | MYDB_END_ALLOW_THREADS; |
| 5752 | RETURN_IF_ERR(); |
| 5753 | RETURN_NONE(); |
| 5754 | } |
| 5755 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5756 | static PyObject* |
| 5757 | DBEnv_get_lg_bsize(DBEnvObject* self) |
| 5758 | { |
| 5759 | int err; |
| 5760 | u_int32_t lg_bsize; |
| 5761 | |
| 5762 | CHECK_ENV_NOT_CLOSED(self); |
| 5763 | |
| 5764 | MYDB_BEGIN_ALLOW_THREADS; |
| 5765 | err = self->db_env->get_lg_bsize(self->db_env, &lg_bsize); |
| 5766 | MYDB_END_ALLOW_THREADS; |
| 5767 | RETURN_IF_ERR(); |
| 5768 | return NUMBER_FromLong(lg_bsize); |
| 5769 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5770 | |
| 5771 | static PyObject* |
| 5772 | DBEnv_set_lg_dir(DBEnvObject* self, PyObject* args) |
| 5773 | { |
| 5774 | int err; |
| 5775 | char *dir; |
| 5776 | |
| 5777 | if (!PyArg_ParseTuple(args, "s:set_lg_dir", &dir)) |
| 5778 | return NULL; |
| 5779 | CHECK_ENV_NOT_CLOSED(self); |
| 5780 | |
| 5781 | MYDB_BEGIN_ALLOW_THREADS; |
| 5782 | err = self->db_env->set_lg_dir(self->db_env, dir); |
| 5783 | MYDB_END_ALLOW_THREADS; |
| 5784 | RETURN_IF_ERR(); |
| 5785 | RETURN_NONE(); |
| 5786 | } |
| 5787 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5788 | static PyObject* |
| 5789 | DBEnv_get_lg_dir(DBEnvObject* self) |
| 5790 | { |
| 5791 | int err; |
| 5792 | const char *dirp; |
| 5793 | |
| 5794 | CHECK_ENV_NOT_CLOSED(self); |
| 5795 | |
| 5796 | MYDB_BEGIN_ALLOW_THREADS; |
| 5797 | err = self->db_env->get_lg_dir(self->db_env, &dirp); |
| 5798 | MYDB_END_ALLOW_THREADS; |
| 5799 | RETURN_IF_ERR(); |
| 5800 | return PyBytes_FromString(dirp); |
| 5801 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5802 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5803 | static PyObject* |
| 5804 | DBEnv_set_lg_max(DBEnvObject* self, PyObject* args) |
| 5805 | { |
| 5806 | int err, lg_max; |
| 5807 | |
| 5808 | if (!PyArg_ParseTuple(args, "i:set_lg_max", &lg_max)) |
| 5809 | return NULL; |
| 5810 | CHECK_ENV_NOT_CLOSED(self); |
| 5811 | |
| 5812 | MYDB_BEGIN_ALLOW_THREADS; |
| 5813 | err = self->db_env->set_lg_max(self->db_env, lg_max); |
| 5814 | MYDB_END_ALLOW_THREADS; |
| 5815 | RETURN_IF_ERR(); |
| 5816 | RETURN_NONE(); |
| 5817 | } |
| 5818 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 5819 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 5820 | DBEnv_get_lg_max(DBEnvObject* self) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 5821 | { |
| 5822 | int err; |
| 5823 | u_int32_t lg_max; |
| 5824 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 5825 | CHECK_ENV_NOT_CLOSED(self); |
| 5826 | |
| 5827 | MYDB_BEGIN_ALLOW_THREADS; |
| 5828 | err = self->db_env->get_lg_max(self->db_env, &lg_max); |
| 5829 | MYDB_END_ALLOW_THREADS; |
| 5830 | RETURN_IF_ERR(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 5831 | return NUMBER_FromLong(lg_max); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 5832 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5833 | |
| 5834 | static PyObject* |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 5835 | DBEnv_set_lg_regionmax(DBEnvObject* self, PyObject* args) |
| 5836 | { |
| 5837 | int err, lg_max; |
| 5838 | |
| 5839 | if (!PyArg_ParseTuple(args, "i:set_lg_regionmax", &lg_max)) |
| 5840 | return NULL; |
| 5841 | CHECK_ENV_NOT_CLOSED(self); |
| 5842 | |
| 5843 | MYDB_BEGIN_ALLOW_THREADS; |
| 5844 | err = self->db_env->set_lg_regionmax(self->db_env, lg_max); |
| 5845 | MYDB_END_ALLOW_THREADS; |
| 5846 | RETURN_IF_ERR(); |
| 5847 | RETURN_NONE(); |
| 5848 | } |
| 5849 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5850 | static PyObject* |
| 5851 | DBEnv_get_lg_regionmax(DBEnvObject* self) |
| 5852 | { |
| 5853 | int err; |
| 5854 | u_int32_t lg_regionmax; |
| 5855 | |
| 5856 | CHECK_ENV_NOT_CLOSED(self); |
| 5857 | |
| 5858 | MYDB_BEGIN_ALLOW_THREADS; |
| 5859 | err = self->db_env->get_lg_regionmax(self->db_env, &lg_regionmax); |
| 5860 | MYDB_END_ALLOW_THREADS; |
| 5861 | RETURN_IF_ERR(); |
| 5862 | return NUMBER_FromLong(lg_regionmax); |
| 5863 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5864 | |
| 5865 | #if (DBVER >= 47) |
| 5866 | static PyObject* |
| 5867 | DBEnv_set_lk_partitions(DBEnvObject* self, PyObject* args) |
| 5868 | { |
| 5869 | int err, lk_partitions; |
| 5870 | |
| 5871 | if (!PyArg_ParseTuple(args, "i:set_lk_partitions", &lk_partitions)) |
| 5872 | return NULL; |
| 5873 | CHECK_ENV_NOT_CLOSED(self); |
| 5874 | |
| 5875 | MYDB_BEGIN_ALLOW_THREADS; |
| 5876 | err = self->db_env->set_lk_partitions(self->db_env, lk_partitions); |
| 5877 | MYDB_END_ALLOW_THREADS; |
| 5878 | RETURN_IF_ERR(); |
| 5879 | RETURN_NONE(); |
| 5880 | } |
| 5881 | |
| 5882 | static PyObject* |
| 5883 | DBEnv_get_lk_partitions(DBEnvObject* self) |
| 5884 | { |
| 5885 | int err; |
| 5886 | u_int32_t lk_partitions; |
| 5887 | |
| 5888 | CHECK_ENV_NOT_CLOSED(self); |
| 5889 | |
| 5890 | MYDB_BEGIN_ALLOW_THREADS; |
| 5891 | err = self->db_env->get_lk_partitions(self->db_env, &lk_partitions); |
| 5892 | MYDB_END_ALLOW_THREADS; |
| 5893 | RETURN_IF_ERR(); |
| 5894 | return NUMBER_FromLong(lk_partitions); |
| 5895 | } |
| 5896 | #endif |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 5897 | |
| 5898 | static PyObject* |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5899 | DBEnv_set_lk_detect(DBEnvObject* self, PyObject* args) |
| 5900 | { |
| 5901 | int err, lk_detect; |
| 5902 | |
| 5903 | if (!PyArg_ParseTuple(args, "i:set_lk_detect", &lk_detect)) |
| 5904 | return NULL; |
| 5905 | CHECK_ENV_NOT_CLOSED(self); |
| 5906 | |
| 5907 | MYDB_BEGIN_ALLOW_THREADS; |
| 5908 | err = self->db_env->set_lk_detect(self->db_env, lk_detect); |
| 5909 | MYDB_END_ALLOW_THREADS; |
| 5910 | RETURN_IF_ERR(); |
| 5911 | RETURN_NONE(); |
| 5912 | } |
| 5913 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5914 | static PyObject* |
| 5915 | DBEnv_get_lk_detect(DBEnvObject* self) |
| 5916 | { |
| 5917 | int err; |
| 5918 | u_int32_t lk_detect; |
| 5919 | |
| 5920 | CHECK_ENV_NOT_CLOSED(self); |
| 5921 | |
| 5922 | MYDB_BEGIN_ALLOW_THREADS; |
| 5923 | err = self->db_env->get_lk_detect(self->db_env, &lk_detect); |
| 5924 | MYDB_END_ALLOW_THREADS; |
| 5925 | RETURN_IF_ERR(); |
| 5926 | return NUMBER_FromLong(lk_detect); |
| 5927 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5928 | |
Gregory P. Smith | 8b96a35 | 2007-01-05 01:59:42 +0000 | [diff] [blame] | 5929 | #if (DBVER < 45) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5930 | static PyObject* |
| 5931 | DBEnv_set_lk_max(DBEnvObject* self, PyObject* args) |
| 5932 | { |
| 5933 | int err, max; |
| 5934 | |
| 5935 | if (!PyArg_ParseTuple(args, "i:set_lk_max", &max)) |
| 5936 | return NULL; |
| 5937 | CHECK_ENV_NOT_CLOSED(self); |
| 5938 | |
| 5939 | MYDB_BEGIN_ALLOW_THREADS; |
| 5940 | err = self->db_env->set_lk_max(self->db_env, max); |
| 5941 | MYDB_END_ALLOW_THREADS; |
| 5942 | RETURN_IF_ERR(); |
| 5943 | RETURN_NONE(); |
| 5944 | } |
Gregory P. Smith | 8b96a35 | 2007-01-05 01:59:42 +0000 | [diff] [blame] | 5945 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5946 | |
| 5947 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5948 | |
| 5949 | static PyObject* |
| 5950 | DBEnv_set_lk_max_locks(DBEnvObject* self, PyObject* args) |
| 5951 | { |
| 5952 | int err, max; |
| 5953 | |
| 5954 | if (!PyArg_ParseTuple(args, "i:set_lk_max_locks", &max)) |
| 5955 | return NULL; |
| 5956 | CHECK_ENV_NOT_CLOSED(self); |
| 5957 | |
| 5958 | MYDB_BEGIN_ALLOW_THREADS; |
| 5959 | err = self->db_env->set_lk_max_locks(self->db_env, max); |
| 5960 | MYDB_END_ALLOW_THREADS; |
| 5961 | RETURN_IF_ERR(); |
| 5962 | RETURN_NONE(); |
| 5963 | } |
| 5964 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5965 | static PyObject* |
| 5966 | DBEnv_get_lk_max_locks(DBEnvObject* self) |
| 5967 | { |
| 5968 | int err; |
| 5969 | u_int32_t lk_max; |
| 5970 | |
| 5971 | CHECK_ENV_NOT_CLOSED(self); |
| 5972 | |
| 5973 | MYDB_BEGIN_ALLOW_THREADS; |
| 5974 | err = self->db_env->get_lk_max_locks(self->db_env, &lk_max); |
| 5975 | MYDB_END_ALLOW_THREADS; |
| 5976 | RETURN_IF_ERR(); |
| 5977 | return NUMBER_FromLong(lk_max); |
| 5978 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 5979 | |
| 5980 | static PyObject* |
| 5981 | DBEnv_set_lk_max_lockers(DBEnvObject* self, PyObject* args) |
| 5982 | { |
| 5983 | int err, max; |
| 5984 | |
| 5985 | if (!PyArg_ParseTuple(args, "i:set_lk_max_lockers", &max)) |
| 5986 | return NULL; |
| 5987 | CHECK_ENV_NOT_CLOSED(self); |
| 5988 | |
| 5989 | MYDB_BEGIN_ALLOW_THREADS; |
| 5990 | err = self->db_env->set_lk_max_lockers(self->db_env, max); |
| 5991 | MYDB_END_ALLOW_THREADS; |
| 5992 | RETURN_IF_ERR(); |
| 5993 | RETURN_NONE(); |
| 5994 | } |
| 5995 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 5996 | static PyObject* |
| 5997 | DBEnv_get_lk_max_lockers(DBEnvObject* self) |
| 5998 | { |
| 5999 | int err; |
| 6000 | u_int32_t lk_max; |
| 6001 | |
| 6002 | CHECK_ENV_NOT_CLOSED(self); |
| 6003 | |
| 6004 | MYDB_BEGIN_ALLOW_THREADS; |
| 6005 | err = self->db_env->get_lk_max_lockers(self->db_env, &lk_max); |
| 6006 | MYDB_END_ALLOW_THREADS; |
| 6007 | RETURN_IF_ERR(); |
| 6008 | return NUMBER_FromLong(lk_max); |
| 6009 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6010 | |
| 6011 | static PyObject* |
| 6012 | DBEnv_set_lk_max_objects(DBEnvObject* self, PyObject* args) |
| 6013 | { |
| 6014 | int err, max; |
| 6015 | |
| 6016 | if (!PyArg_ParseTuple(args, "i:set_lk_max_objects", &max)) |
| 6017 | return NULL; |
| 6018 | CHECK_ENV_NOT_CLOSED(self); |
| 6019 | |
| 6020 | MYDB_BEGIN_ALLOW_THREADS; |
| 6021 | err = self->db_env->set_lk_max_objects(self->db_env, max); |
| 6022 | MYDB_END_ALLOW_THREADS; |
| 6023 | RETURN_IF_ERR(); |
| 6024 | RETURN_NONE(); |
| 6025 | } |
| 6026 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6027 | static PyObject* |
| 6028 | DBEnv_get_lk_max_objects(DBEnvObject* self) |
| 6029 | { |
| 6030 | int err; |
| 6031 | u_int32_t lk_max; |
| 6032 | |
| 6033 | CHECK_ENV_NOT_CLOSED(self); |
| 6034 | |
| 6035 | MYDB_BEGIN_ALLOW_THREADS; |
| 6036 | err = self->db_env->get_lk_max_objects(self->db_env, &lk_max); |
| 6037 | MYDB_END_ALLOW_THREADS; |
| 6038 | RETURN_IF_ERR(); |
| 6039 | return NUMBER_FromLong(lk_max); |
| 6040 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6041 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6042 | static PyObject* |
| 6043 | DBEnv_get_mp_mmapsize(DBEnvObject* self) |
| 6044 | { |
| 6045 | int err; |
| 6046 | size_t mmapsize; |
| 6047 | |
| 6048 | CHECK_ENV_NOT_CLOSED(self); |
| 6049 | |
| 6050 | MYDB_BEGIN_ALLOW_THREADS; |
| 6051 | err = self->db_env->get_mp_mmapsize(self->db_env, &mmapsize); |
| 6052 | MYDB_END_ALLOW_THREADS; |
| 6053 | RETURN_IF_ERR(); |
| 6054 | return NUMBER_FromLong(mmapsize); |
| 6055 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6056 | |
| 6057 | static PyObject* |
| 6058 | DBEnv_set_mp_mmapsize(DBEnvObject* self, PyObject* args) |
| 6059 | { |
| 6060 | int err, mp_mmapsize; |
| 6061 | |
| 6062 | if (!PyArg_ParseTuple(args, "i:set_mp_mmapsize", &mp_mmapsize)) |
| 6063 | return NULL; |
| 6064 | CHECK_ENV_NOT_CLOSED(self); |
| 6065 | |
| 6066 | MYDB_BEGIN_ALLOW_THREADS; |
| 6067 | err = self->db_env->set_mp_mmapsize(self->db_env, mp_mmapsize); |
| 6068 | MYDB_END_ALLOW_THREADS; |
| 6069 | RETURN_IF_ERR(); |
| 6070 | RETURN_NONE(); |
| 6071 | } |
| 6072 | |
| 6073 | |
| 6074 | static PyObject* |
| 6075 | DBEnv_set_tmp_dir(DBEnvObject* self, PyObject* args) |
| 6076 | { |
| 6077 | int err; |
| 6078 | char *dir; |
| 6079 | |
| 6080 | if (!PyArg_ParseTuple(args, "s:set_tmp_dir", &dir)) |
| 6081 | return NULL; |
| 6082 | CHECK_ENV_NOT_CLOSED(self); |
| 6083 | |
| 6084 | MYDB_BEGIN_ALLOW_THREADS; |
| 6085 | err = self->db_env->set_tmp_dir(self->db_env, dir); |
| 6086 | MYDB_END_ALLOW_THREADS; |
| 6087 | RETURN_IF_ERR(); |
| 6088 | RETURN_NONE(); |
| 6089 | } |
| 6090 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6091 | static PyObject* |
| 6092 | DBEnv_get_tmp_dir(DBEnvObject* self) |
| 6093 | { |
| 6094 | int err; |
| 6095 | const char *dirpp; |
| 6096 | |
| 6097 | CHECK_ENV_NOT_CLOSED(self); |
| 6098 | |
| 6099 | MYDB_BEGIN_ALLOW_THREADS; |
| 6100 | err = self->db_env->get_tmp_dir(self->db_env, &dirpp); |
| 6101 | MYDB_END_ALLOW_THREADS; |
| 6102 | |
| 6103 | RETURN_IF_ERR(); |
| 6104 | |
| 6105 | return PyBytes_FromString(dirpp); |
| 6106 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6107 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6108 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 6109 | DBEnv_txn_recover(DBEnvObject* self) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6110 | { |
| 6111 | int flags = DB_FIRST; |
| 6112 | int err, i; |
| 6113 | PyObject *list, *tuple, *gid; |
| 6114 | DBTxnObject *txn; |
| 6115 | #define PREPLIST_LEN 16 |
| 6116 | DB_PREPLIST preplist[PREPLIST_LEN]; |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 6117 | #if (DBVER < 48) || (DBVER >= 52) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6118 | long retp; |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 6119 | #else |
| 6120 | u_int32_t retp; |
| 6121 | #endif |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6122 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6123 | CHECK_ENV_NOT_CLOSED(self); |
| 6124 | |
| 6125 | list=PyList_New(0); |
| 6126 | if (!list) |
| 6127 | return NULL; |
| 6128 | while (!0) { |
| 6129 | MYDB_BEGIN_ALLOW_THREADS |
| 6130 | err=self->db_env->txn_recover(self->db_env, |
| 6131 | preplist, PREPLIST_LEN, &retp, flags); |
| 6132 | #undef PREPLIST_LEN |
| 6133 | MYDB_END_ALLOW_THREADS |
| 6134 | if (err) { |
| 6135 | Py_DECREF(list); |
| 6136 | RETURN_IF_ERR(); |
| 6137 | } |
| 6138 | if (!retp) break; |
| 6139 | flags=DB_NEXT; /* Prepare for next loop pass */ |
| 6140 | for (i=0; i<retp; i++) { |
Christian Heimes | 593daf5 | 2008-05-26 12:51:38 +0000 | [diff] [blame] | 6141 | gid=PyBytes_FromStringAndSize((char *)(preplist[i].gid), |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 6142 | DB_GID_SIZE); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6143 | if (!gid) { |
| 6144 | Py_DECREF(list); |
| 6145 | return NULL; |
| 6146 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6147 | txn=newDBTxnObject(self, NULL, preplist[i].txn, 0); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6148 | if (!txn) { |
| 6149 | Py_DECREF(list); |
| 6150 | Py_DECREF(gid); |
| 6151 | return NULL; |
| 6152 | } |
| 6153 | txn->flag_prepare=1; /* Recover state */ |
| 6154 | tuple=PyTuple_New(2); |
| 6155 | if (!tuple) { |
| 6156 | Py_DECREF(list); |
| 6157 | Py_DECREF(gid); |
| 6158 | Py_DECREF(txn); |
| 6159 | return NULL; |
| 6160 | } |
| 6161 | if (PyTuple_SetItem(tuple, 0, gid)) { |
| 6162 | Py_DECREF(list); |
| 6163 | Py_DECREF(gid); |
| 6164 | Py_DECREF(txn); |
| 6165 | Py_DECREF(tuple); |
| 6166 | return NULL; |
| 6167 | } |
| 6168 | if (PyTuple_SetItem(tuple, 1, (PyObject *)txn)) { |
| 6169 | Py_DECREF(list); |
| 6170 | Py_DECREF(txn); |
| 6171 | Py_DECREF(tuple); /* This delete the "gid" also */ |
| 6172 | return NULL; |
| 6173 | } |
| 6174 | if (PyList_Append(list, tuple)) { |
| 6175 | Py_DECREF(list); |
| 6176 | Py_DECREF(tuple);/* This delete the "gid" and the "txn" also */ |
| 6177 | return NULL; |
| 6178 | } |
| 6179 | Py_DECREF(tuple); |
| 6180 | } |
| 6181 | } |
| 6182 | return list; |
| 6183 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6184 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6185 | static PyObject* |
| 6186 | DBEnv_txn_begin(DBEnvObject* self, PyObject* args, PyObject* kwargs) |
| 6187 | { |
| 6188 | int flags = 0; |
| 6189 | PyObject* txnobj = NULL; |
| 6190 | DB_TXN *txn = NULL; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 6191 | static char* kwnames[] = { "parent", "flags", NULL }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6192 | |
| 6193 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Oi:txn_begin", kwnames, |
| 6194 | &txnobj, &flags)) |
| 6195 | return NULL; |
| 6196 | |
| 6197 | if (!checkTxnObj(txnobj, &txn)) |
| 6198 | return NULL; |
| 6199 | CHECK_ENV_NOT_CLOSED(self); |
| 6200 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6201 | return (PyObject*)newDBTxnObject(self, (DBTxnObject *)txnobj, NULL, flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6202 | } |
| 6203 | |
| 6204 | |
| 6205 | static PyObject* |
| 6206 | DBEnv_txn_checkpoint(DBEnvObject* self, PyObject* args) |
| 6207 | { |
| 6208 | int err, kbyte=0, min=0, flags=0; |
| 6209 | |
| 6210 | if (!PyArg_ParseTuple(args, "|iii:txn_checkpoint", &kbyte, &min, &flags)) |
| 6211 | return NULL; |
| 6212 | CHECK_ENV_NOT_CLOSED(self); |
| 6213 | |
| 6214 | MYDB_BEGIN_ALLOW_THREADS; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6215 | err = self->db_env->txn_checkpoint(self->db_env, kbyte, min, flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6216 | MYDB_END_ALLOW_THREADS; |
| 6217 | RETURN_IF_ERR(); |
| 6218 | RETURN_NONE(); |
| 6219 | } |
| 6220 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6221 | static PyObject* |
| 6222 | DBEnv_get_tx_max(DBEnvObject* self) |
| 6223 | { |
| 6224 | int err; |
| 6225 | u_int32_t max; |
| 6226 | |
| 6227 | CHECK_ENV_NOT_CLOSED(self); |
| 6228 | |
| 6229 | MYDB_BEGIN_ALLOW_THREADS; |
| 6230 | err = self->db_env->get_tx_max(self->db_env, &max); |
| 6231 | MYDB_END_ALLOW_THREADS; |
| 6232 | RETURN_IF_ERR(); |
| 6233 | return PyLong_FromUnsignedLong(max); |
| 6234 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6235 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6236 | static PyObject* |
| 6237 | DBEnv_set_tx_max(DBEnvObject* self, PyObject* args) |
| 6238 | { |
| 6239 | int err, max; |
| 6240 | |
| 6241 | if (!PyArg_ParseTuple(args, "i:set_tx_max", &max)) |
| 6242 | return NULL; |
| 6243 | CHECK_ENV_NOT_CLOSED(self); |
| 6244 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6245 | MYDB_BEGIN_ALLOW_THREADS; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6246 | err = self->db_env->set_tx_max(self->db_env, max); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6247 | MYDB_END_ALLOW_THREADS; |
Gregory P. Smith | 8a47404 | 2006-01-27 07:05:40 +0000 | [diff] [blame] | 6248 | RETURN_IF_ERR(); |
| 6249 | RETURN_NONE(); |
| 6250 | } |
| 6251 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6252 | static PyObject* |
| 6253 | DBEnv_get_tx_timestamp(DBEnvObject* self) |
| 6254 | { |
| 6255 | int err; |
| 6256 | time_t timestamp; |
| 6257 | |
| 6258 | CHECK_ENV_NOT_CLOSED(self); |
| 6259 | |
| 6260 | MYDB_BEGIN_ALLOW_THREADS; |
| 6261 | err = self->db_env->get_tx_timestamp(self->db_env, ×tamp); |
| 6262 | MYDB_END_ALLOW_THREADS; |
| 6263 | RETURN_IF_ERR(); |
| 6264 | return NUMBER_FromLong(timestamp); |
| 6265 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6266 | |
Gregory P. Smith | 8a47404 | 2006-01-27 07:05:40 +0000 | [diff] [blame] | 6267 | static PyObject* |
| 6268 | DBEnv_set_tx_timestamp(DBEnvObject* self, PyObject* args) |
| 6269 | { |
| 6270 | int err; |
Thomas Wouters | 9d63cca | 2006-03-01 01:01:55 +0000 | [diff] [blame] | 6271 | long stamp; |
| 6272 | time_t timestamp; |
Gregory P. Smith | 8a47404 | 2006-01-27 07:05:40 +0000 | [diff] [blame] | 6273 | |
Thomas Wouters | 9d63cca | 2006-03-01 01:01:55 +0000 | [diff] [blame] | 6274 | if (!PyArg_ParseTuple(args, "l:set_tx_timestamp", &stamp)) |
Gregory P. Smith | 8a47404 | 2006-01-27 07:05:40 +0000 | [diff] [blame] | 6275 | return NULL; |
| 6276 | CHECK_ENV_NOT_CLOSED(self); |
Thomas Wouters | 9d63cca | 2006-03-01 01:01:55 +0000 | [diff] [blame] | 6277 | timestamp = (time_t)stamp; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6278 | MYDB_BEGIN_ALLOW_THREADS; |
Thomas Wouters | 9d63cca | 2006-03-01 01:01:55 +0000 | [diff] [blame] | 6279 | err = self->db_env->set_tx_timestamp(self->db_env, ×tamp); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6280 | MYDB_END_ALLOW_THREADS; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6281 | RETURN_IF_ERR(); |
| 6282 | RETURN_NONE(); |
| 6283 | } |
| 6284 | |
| 6285 | |
| 6286 | static PyObject* |
| 6287 | DBEnv_lock_detect(DBEnvObject* self, PyObject* args) |
| 6288 | { |
| 6289 | int err, atype, flags=0; |
| 6290 | int aborted = 0; |
| 6291 | |
| 6292 | if (!PyArg_ParseTuple(args, "i|i:lock_detect", &atype, &flags)) |
| 6293 | return NULL; |
| 6294 | CHECK_ENV_NOT_CLOSED(self); |
| 6295 | |
| 6296 | MYDB_BEGIN_ALLOW_THREADS; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6297 | err = self->db_env->lock_detect(self->db_env, flags, atype, &aborted); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6298 | MYDB_END_ALLOW_THREADS; |
| 6299 | RETURN_IF_ERR(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 6300 | return NUMBER_FromLong(aborted); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6301 | } |
| 6302 | |
| 6303 | |
| 6304 | static PyObject* |
| 6305 | DBEnv_lock_get(DBEnvObject* self, PyObject* args) |
| 6306 | { |
| 6307 | int flags=0; |
| 6308 | int locker, lock_mode; |
| 6309 | DBT obj; |
| 6310 | PyObject* objobj; |
| 6311 | |
| 6312 | if (!PyArg_ParseTuple(args, "iOi|i:lock_get", &locker, &objobj, &lock_mode, &flags)) |
| 6313 | return NULL; |
| 6314 | |
| 6315 | |
| 6316 | if (!make_dbt(objobj, &obj)) |
| 6317 | return NULL; |
| 6318 | |
| 6319 | return (PyObject*)newDBLockObject(self, locker, &obj, lock_mode, flags); |
| 6320 | } |
| 6321 | |
| 6322 | |
| 6323 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 6324 | DBEnv_lock_id(DBEnvObject* self) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6325 | { |
| 6326 | int err; |
| 6327 | u_int32_t theID; |
| 6328 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6329 | CHECK_ENV_NOT_CLOSED(self); |
| 6330 | MYDB_BEGIN_ALLOW_THREADS; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6331 | err = self->db_env->lock_id(self->db_env, &theID); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6332 | MYDB_END_ALLOW_THREADS; |
| 6333 | RETURN_IF_ERR(); |
| 6334 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 6335 | return NUMBER_FromLong((long)theID); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6336 | } |
| 6337 | |
Gregory P. Smith | ac11e02 | 2007-11-05 02:56:31 +0000 | [diff] [blame] | 6338 | static PyObject* |
| 6339 | DBEnv_lock_id_free(DBEnvObject* self, PyObject* args) |
| 6340 | { |
| 6341 | int err; |
| 6342 | u_int32_t theID; |
| 6343 | |
| 6344 | if (!PyArg_ParseTuple(args, "I:lock_id_free", &theID)) |
| 6345 | return NULL; |
| 6346 | |
| 6347 | CHECK_ENV_NOT_CLOSED(self); |
| 6348 | MYDB_BEGIN_ALLOW_THREADS; |
| 6349 | err = self->db_env->lock_id_free(self->db_env, theID); |
| 6350 | MYDB_END_ALLOW_THREADS; |
| 6351 | RETURN_IF_ERR(); |
| 6352 | RETURN_NONE(); |
| 6353 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6354 | |
| 6355 | static PyObject* |
| 6356 | DBEnv_lock_put(DBEnvObject* self, PyObject* args) |
| 6357 | { |
| 6358 | int err; |
| 6359 | DBLockObject* dblockobj; |
| 6360 | |
| 6361 | if (!PyArg_ParseTuple(args, "O!:lock_put", &DBLock_Type, &dblockobj)) |
| 6362 | return NULL; |
| 6363 | |
| 6364 | CHECK_ENV_NOT_CLOSED(self); |
| 6365 | MYDB_BEGIN_ALLOW_THREADS; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6366 | err = self->db_env->lock_put(self->db_env, &dblockobj->lock); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6367 | MYDB_END_ALLOW_THREADS; |
| 6368 | RETURN_IF_ERR(); |
| 6369 | RETURN_NONE(); |
| 6370 | } |
| 6371 | |
Gregory P. Smith | db8a807 | 2006-06-05 01:56:15 +0000 | [diff] [blame] | 6372 | #if (DBVER >= 44) |
| 6373 | static PyObject* |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6374 | DBEnv_fileid_reset(DBEnvObject* self, PyObject* args, PyObject* kwargs) |
| 6375 | { |
| 6376 | int err; |
| 6377 | char *file; |
| 6378 | u_int32_t flags = 0; |
| 6379 | static char* kwnames[] = { "file", "flags", NULL}; |
| 6380 | |
| 6381 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "z|i:fileid_reset", kwnames, |
| 6382 | &file, &flags)) |
| 6383 | return NULL; |
| 6384 | CHECK_ENV_NOT_CLOSED(self); |
| 6385 | |
| 6386 | MYDB_BEGIN_ALLOW_THREADS; |
| 6387 | err = self->db_env->fileid_reset(self->db_env, file, flags); |
| 6388 | MYDB_END_ALLOW_THREADS; |
| 6389 | RETURN_IF_ERR(); |
| 6390 | RETURN_NONE(); |
| 6391 | } |
| 6392 | |
| 6393 | static PyObject* |
Gregory P. Smith | db8a807 | 2006-06-05 01:56:15 +0000 | [diff] [blame] | 6394 | DBEnv_lsn_reset(DBEnvObject* self, PyObject* args, PyObject* kwargs) |
| 6395 | { |
| 6396 | int err; |
| 6397 | char *file; |
| 6398 | u_int32_t flags = 0; |
| 6399 | static char* kwnames[] = { "file", "flags", NULL}; |
| 6400 | |
| 6401 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "z|i:lsn_reset", kwnames, |
| 6402 | &file, &flags)) |
| 6403 | return NULL; |
| 6404 | CHECK_ENV_NOT_CLOSED(self); |
| 6405 | |
| 6406 | MYDB_BEGIN_ALLOW_THREADS; |
| 6407 | err = self->db_env->lsn_reset(self->db_env, file, flags); |
| 6408 | MYDB_END_ALLOW_THREADS; |
| 6409 | RETURN_IF_ERR(); |
| 6410 | RETURN_NONE(); |
| 6411 | } |
| 6412 | #endif /* DBVER >= 4.4 */ |
| 6413 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6414 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6415 | static PyObject* |
| 6416 | DBEnv_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 6417 | { |
| 6418 | int err; |
| 6419 | int flags=0; |
| 6420 | static char* kwnames[] = { "flags", NULL }; |
| 6421 | |
| 6422 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:stat_print", |
| 6423 | kwnames, &flags)) |
| 6424 | { |
| 6425 | return NULL; |
| 6426 | } |
| 6427 | CHECK_ENV_NOT_CLOSED(self); |
| 6428 | MYDB_BEGIN_ALLOW_THREADS; |
| 6429 | err = self->db_env->stat_print(self->db_env, flags); |
| 6430 | MYDB_END_ALLOW_THREADS; |
| 6431 | RETURN_IF_ERR(); |
| 6432 | RETURN_NONE(); |
| 6433 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6434 | |
| 6435 | |
Gregory P. Smith | 76a82e8 | 2006-06-05 01:39:52 +0000 | [diff] [blame] | 6436 | static PyObject* |
| 6437 | DBEnv_log_stat(DBEnvObject* self, PyObject* args) |
| 6438 | { |
| 6439 | int err; |
| 6440 | DB_LOG_STAT* statp = NULL; |
| 6441 | PyObject* d = NULL; |
| 6442 | u_int32_t flags = 0; |
| 6443 | |
| 6444 | if (!PyArg_ParseTuple(args, "|i:log_stat", &flags)) |
| 6445 | return NULL; |
| 6446 | CHECK_ENV_NOT_CLOSED(self); |
| 6447 | |
| 6448 | MYDB_BEGIN_ALLOW_THREADS; |
| 6449 | err = self->db_env->log_stat(self->db_env, &statp, flags); |
| 6450 | MYDB_END_ALLOW_THREADS; |
| 6451 | RETURN_IF_ERR(); |
| 6452 | |
| 6453 | /* Turn the stat structure into a dictionary */ |
| 6454 | d = PyDict_New(); |
| 6455 | if (d == NULL) { |
| 6456 | if (statp) |
| 6457 | free(statp); |
| 6458 | return NULL; |
| 6459 | } |
| 6460 | |
| 6461 | #define MAKE_ENTRY(name) _addIntToDict(d, #name, statp->st_##name) |
| 6462 | |
| 6463 | MAKE_ENTRY(magic); |
| 6464 | MAKE_ENTRY(version); |
| 6465 | MAKE_ENTRY(mode); |
| 6466 | MAKE_ENTRY(lg_bsize); |
| 6467 | #if (DBVER >= 44) |
| 6468 | MAKE_ENTRY(lg_size); |
| 6469 | MAKE_ENTRY(record); |
| 6470 | #endif |
Gregory P. Smith | 76a82e8 | 2006-06-05 01:39:52 +0000 | [diff] [blame] | 6471 | MAKE_ENTRY(w_mbytes); |
| 6472 | MAKE_ENTRY(w_bytes); |
| 6473 | MAKE_ENTRY(wc_mbytes); |
| 6474 | MAKE_ENTRY(wc_bytes); |
| 6475 | MAKE_ENTRY(wcount); |
| 6476 | MAKE_ENTRY(wcount_fill); |
| 6477 | #if (DBVER >= 44) |
| 6478 | MAKE_ENTRY(rcount); |
| 6479 | #endif |
| 6480 | MAKE_ENTRY(scount); |
| 6481 | MAKE_ENTRY(cur_file); |
| 6482 | MAKE_ENTRY(cur_offset); |
| 6483 | MAKE_ENTRY(disk_file); |
| 6484 | MAKE_ENTRY(disk_offset); |
| 6485 | MAKE_ENTRY(maxcommitperflush); |
| 6486 | MAKE_ENTRY(mincommitperflush); |
| 6487 | MAKE_ENTRY(regsize); |
| 6488 | MAKE_ENTRY(region_wait); |
| 6489 | MAKE_ENTRY(region_nowait); |
| 6490 | |
| 6491 | #undef MAKE_ENTRY |
| 6492 | free(statp); |
| 6493 | return d; |
| 6494 | } /* DBEnv_log_stat */ |
Gregory P. Smith | 76a82e8 | 2006-06-05 01:39:52 +0000 | [diff] [blame] | 6495 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6496 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6497 | static PyObject* |
| 6498 | DBEnv_log_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 6499 | { |
| 6500 | int err; |
| 6501 | int flags=0; |
| 6502 | static char* kwnames[] = { "flags", NULL }; |
| 6503 | |
| 6504 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:log_stat_print", |
| 6505 | kwnames, &flags)) |
| 6506 | { |
| 6507 | return NULL; |
| 6508 | } |
| 6509 | CHECK_ENV_NOT_CLOSED(self); |
| 6510 | MYDB_BEGIN_ALLOW_THREADS; |
| 6511 | err = self->db_env->log_stat_print(self->db_env, flags); |
| 6512 | MYDB_END_ALLOW_THREADS; |
| 6513 | RETURN_IF_ERR(); |
| 6514 | RETURN_NONE(); |
| 6515 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6516 | |
| 6517 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6518 | static PyObject* |
| 6519 | DBEnv_lock_stat(DBEnvObject* self, PyObject* args) |
| 6520 | { |
| 6521 | int err; |
| 6522 | DB_LOCK_STAT* sp; |
| 6523 | PyObject* d = NULL; |
Martin v. Löwis | b2c7aff | 2002-11-23 11:26:07 +0000 | [diff] [blame] | 6524 | u_int32_t flags = 0; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6525 | |
| 6526 | if (!PyArg_ParseTuple(args, "|i:lock_stat", &flags)) |
| 6527 | return NULL; |
| 6528 | CHECK_ENV_NOT_CLOSED(self); |
| 6529 | |
| 6530 | MYDB_BEGIN_ALLOW_THREADS; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6531 | err = self->db_env->lock_stat(self->db_env, &sp, flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6532 | MYDB_END_ALLOW_THREADS; |
| 6533 | RETURN_IF_ERR(); |
| 6534 | |
| 6535 | /* Turn the stat structure into a dictionary */ |
| 6536 | d = PyDict_New(); |
| 6537 | if (d == NULL) { |
| 6538 | free(sp); |
| 6539 | return NULL; |
| 6540 | } |
| 6541 | |
| 6542 | #define MAKE_ENTRY(name) _addIntToDict(d, #name, sp->st_##name) |
| 6543 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6544 | MAKE_ENTRY(id); |
| 6545 | MAKE_ENTRY(cur_maxid); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6546 | MAKE_ENTRY(nmodes); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6547 | MAKE_ENTRY(maxlocks); |
| 6548 | MAKE_ENTRY(maxlockers); |
| 6549 | MAKE_ENTRY(maxobjects); |
| 6550 | MAKE_ENTRY(nlocks); |
| 6551 | MAKE_ENTRY(maxnlocks); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6552 | MAKE_ENTRY(nlockers); |
| 6553 | MAKE_ENTRY(maxnlockers); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6554 | MAKE_ENTRY(nobjects); |
| 6555 | MAKE_ENTRY(maxnobjects); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6556 | MAKE_ENTRY(nrequests); |
| 6557 | MAKE_ENTRY(nreleases); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6558 | #if (DBVER >= 44) |
| 6559 | MAKE_ENTRY(nupgrade); |
| 6560 | MAKE_ENTRY(ndowngrade); |
| 6561 | #endif |
Gregory P. Smith | 29602d2 | 2006-01-24 09:46:48 +0000 | [diff] [blame] | 6562 | #if (DBVER < 44) |
| 6563 | MAKE_ENTRY(nnowaits); /* these were renamed in 4.4 */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6564 | MAKE_ENTRY(nconflicts); |
Gregory P. Smith | 29602d2 | 2006-01-24 09:46:48 +0000 | [diff] [blame] | 6565 | #else |
| 6566 | MAKE_ENTRY(lock_nowait); |
| 6567 | MAKE_ENTRY(lock_wait); |
| 6568 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6569 | MAKE_ENTRY(ndeadlocks); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6570 | MAKE_ENTRY(locktimeout); |
| 6571 | MAKE_ENTRY(txntimeout); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6572 | MAKE_ENTRY(nlocktimeouts); |
| 6573 | MAKE_ENTRY(ntxntimeouts); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6574 | #if (DBVER >= 46) |
| 6575 | MAKE_ENTRY(objs_wait); |
| 6576 | MAKE_ENTRY(objs_nowait); |
| 6577 | MAKE_ENTRY(lockers_wait); |
| 6578 | MAKE_ENTRY(lockers_nowait); |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 6579 | #if (DBVER >= 47) |
| 6580 | MAKE_ENTRY(lock_wait); |
| 6581 | MAKE_ENTRY(lock_nowait); |
| 6582 | #else |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6583 | MAKE_ENTRY(locks_wait); |
| 6584 | MAKE_ENTRY(locks_nowait); |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 6585 | #endif |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6586 | MAKE_ENTRY(hash_len); |
| 6587 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6588 | MAKE_ENTRY(regsize); |
| 6589 | MAKE_ENTRY(region_wait); |
| 6590 | MAKE_ENTRY(region_nowait); |
| 6591 | |
| 6592 | #undef MAKE_ENTRY |
| 6593 | free(sp); |
| 6594 | return d; |
| 6595 | } |
| 6596 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6597 | static PyObject* |
| 6598 | DBEnv_lock_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 6599 | { |
| 6600 | int err; |
| 6601 | int flags=0; |
| 6602 | static char* kwnames[] = { "flags", NULL }; |
| 6603 | |
| 6604 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:lock_stat_print", |
| 6605 | kwnames, &flags)) |
| 6606 | { |
| 6607 | return NULL; |
| 6608 | } |
| 6609 | CHECK_ENV_NOT_CLOSED(self); |
| 6610 | MYDB_BEGIN_ALLOW_THREADS; |
| 6611 | err = self->db_env->lock_stat_print(self->db_env, flags); |
| 6612 | MYDB_END_ALLOW_THREADS; |
| 6613 | RETURN_IF_ERR(); |
| 6614 | RETURN_NONE(); |
| 6615 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6616 | |
| 6617 | |
| 6618 | static PyObject* |
| 6619 | DBEnv_log_cursor(DBEnvObject* self) |
| 6620 | { |
| 6621 | int err; |
| 6622 | DB_LOGC* dblogc; |
| 6623 | |
| 6624 | CHECK_ENV_NOT_CLOSED(self); |
| 6625 | |
| 6626 | MYDB_BEGIN_ALLOW_THREADS; |
| 6627 | err = self->db_env->log_cursor(self->db_env, &dblogc, 0); |
| 6628 | MYDB_END_ALLOW_THREADS; |
| 6629 | RETURN_IF_ERR(); |
| 6630 | return (PyObject*) newDBLogCursorObject(dblogc, self); |
| 6631 | } |
| 6632 | |
| 6633 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6634 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 6635 | DBEnv_log_flush(DBEnvObject* self) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6636 | { |
| 6637 | int err; |
| 6638 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6639 | CHECK_ENV_NOT_CLOSED(self); |
| 6640 | |
| 6641 | MYDB_BEGIN_ALLOW_THREADS |
| 6642 | err = self->db_env->log_flush(self->db_env, NULL); |
| 6643 | MYDB_END_ALLOW_THREADS |
| 6644 | |
| 6645 | RETURN_IF_ERR(); |
| 6646 | RETURN_NONE(); |
| 6647 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6648 | |
| 6649 | static PyObject* |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6650 | DBEnv_log_file(DBEnvObject* self, PyObject* args) |
| 6651 | { |
| 6652 | int err; |
| 6653 | DB_LSN lsn = {0, 0}; |
| 6654 | int size = 20; |
| 6655 | char *name = NULL; |
| 6656 | PyObject *retval; |
| 6657 | |
| 6658 | if (!PyArg_ParseTuple(args, "(ii):log_file", &lsn.file, &lsn.offset)) |
| 6659 | return NULL; |
| 6660 | |
| 6661 | CHECK_ENV_NOT_CLOSED(self); |
| 6662 | |
| 6663 | do { |
| 6664 | name = malloc(size); |
| 6665 | if (!name) { |
| 6666 | PyErr_NoMemory(); |
| 6667 | return NULL; |
| 6668 | } |
| 6669 | MYDB_BEGIN_ALLOW_THREADS; |
| 6670 | err = self->db_env->log_file(self->db_env, &lsn, name, size); |
| 6671 | MYDB_END_ALLOW_THREADS; |
| 6672 | if (err == EINVAL) { |
| 6673 | free(name); |
| 6674 | size *= 2; |
| 6675 | } else if (err) { |
| 6676 | free(name); |
| 6677 | RETURN_IF_ERR(); |
| 6678 | assert(0); /* Unreachable... supposely */ |
| 6679 | return NULL; |
| 6680 | } |
| 6681 | /* |
| 6682 | ** If the final buffer we try is too small, we will |
| 6683 | ** get this exception: |
| 6684 | ** DBInvalidArgError: |
| 6685 | ** (22, 'Invalid argument -- DB_ENV->log_file: name buffer is too short') |
| 6686 | */ |
| 6687 | } while ((err == EINVAL) && (size<(1<<17))); |
| 6688 | |
| 6689 | RETURN_IF_ERR(); /* Maybe the size is not the problem */ |
| 6690 | |
| 6691 | retval = Py_BuildValue("s", name); |
| 6692 | free(name); |
| 6693 | return retval; |
| 6694 | } |
| 6695 | |
| 6696 | |
| 6697 | #if (DBVER >= 44) |
| 6698 | static PyObject* |
| 6699 | DBEnv_log_printf(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 6700 | { |
| 6701 | int err; |
| 6702 | char *string; |
| 6703 | PyObject *txnobj = NULL; |
| 6704 | DB_TXN *txn = NULL; |
| 6705 | static char* kwnames[] = {"string", "txn", NULL }; |
| 6706 | |
| 6707 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|O:log_printf", kwnames, |
| 6708 | &string, &txnobj)) |
| 6709 | return NULL; |
| 6710 | |
| 6711 | CHECK_ENV_NOT_CLOSED(self); |
| 6712 | |
| 6713 | if (!checkTxnObj(txnobj, &txn)) |
| 6714 | return NULL; |
| 6715 | |
| 6716 | /* |
| 6717 | ** Do not use the format string directly, to avoid attacks. |
| 6718 | */ |
| 6719 | MYDB_BEGIN_ALLOW_THREADS; |
| 6720 | err = self->db_env->log_printf(self->db_env, txn, "%s", string); |
| 6721 | MYDB_END_ALLOW_THREADS; |
| 6722 | |
| 6723 | RETURN_IF_ERR(); |
| 6724 | RETURN_NONE(); |
| 6725 | } |
| 6726 | #endif |
| 6727 | |
| 6728 | |
| 6729 | static PyObject* |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6730 | DBEnv_log_archive(DBEnvObject* self, PyObject* args) |
| 6731 | { |
| 6732 | int flags=0; |
| 6733 | int err; |
Gregory P. Smith | 3dd2002 | 2006-06-05 00:31:01 +0000 | [diff] [blame] | 6734 | char **log_list = NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6735 | PyObject* list; |
| 6736 | PyObject* item = NULL; |
| 6737 | |
| 6738 | if (!PyArg_ParseTuple(args, "|i:log_archive", &flags)) |
| 6739 | return NULL; |
| 6740 | |
| 6741 | CHECK_ENV_NOT_CLOSED(self); |
| 6742 | MYDB_BEGIN_ALLOW_THREADS; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6743 | err = self->db_env->log_archive(self->db_env, &log_list, flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6744 | MYDB_END_ALLOW_THREADS; |
| 6745 | RETURN_IF_ERR(); |
| 6746 | |
Gregory P. Smith | bad4745 | 2006-06-05 00:33:35 +0000 | [diff] [blame] | 6747 | list = PyList_New(0); |
| 6748 | if (list == NULL) { |
| 6749 | if (log_list) |
| 6750 | free(log_list); |
| 6751 | return NULL; |
| 6752 | } |
| 6753 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6754 | if (log_list) { |
Gregory P. Smith | 3dd2002 | 2006-06-05 00:31:01 +0000 | [diff] [blame] | 6755 | char **log_list_start; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6756 | for (log_list_start = log_list; *log_list != NULL; ++log_list) { |
Christian Heimes | 593daf5 | 2008-05-26 12:51:38 +0000 | [diff] [blame] | 6757 | item = PyBytes_FromString (*log_list); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6758 | if (item == NULL) { |
| 6759 | Py_DECREF(list); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6760 | list = NULL; |
| 6761 | break; |
| 6762 | } |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 6763 | if (PyList_Append(list, item)) { |
| 6764 | Py_DECREF(list); |
| 6765 | list = NULL; |
| 6766 | Py_DECREF(item); |
| 6767 | break; |
| 6768 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6769 | Py_DECREF(item); |
| 6770 | } |
| 6771 | free(log_list_start); |
| 6772 | } |
| 6773 | return list; |
| 6774 | } |
| 6775 | |
| 6776 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 6777 | #if (DBVER >= 52) |
| 6778 | static PyObject* |
| 6779 | DBEnv_repmgr_site(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 6780 | { |
| 6781 | int err; |
| 6782 | DB_SITE* site; |
| 6783 | char *host; |
| 6784 | u_int port; |
| 6785 | static char* kwnames[] = {"host", "port", NULL}; |
| 6786 | |
| 6787 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "si:repmgr_site", kwnames, |
| 6788 | &host, &port)) |
| 6789 | return NULL; |
| 6790 | |
| 6791 | CHECK_ENV_NOT_CLOSED(self); |
| 6792 | |
| 6793 | MYDB_BEGIN_ALLOW_THREADS; |
| 6794 | err = self->db_env->repmgr_site(self->db_env, host, port, &site, 0); |
| 6795 | MYDB_END_ALLOW_THREADS; |
| 6796 | RETURN_IF_ERR(); |
| 6797 | return (PyObject*) newDBSiteObject(site, self); |
| 6798 | } |
| 6799 | |
| 6800 | static PyObject* |
| 6801 | DBEnv_repmgr_site_by_eid(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 6802 | { |
| 6803 | int err; |
| 6804 | DB_SITE* site; |
| 6805 | int eid; |
| 6806 | static char* kwnames[] = {"eid", NULL}; |
| 6807 | |
| 6808 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:repmgr_site_by_eid", |
| 6809 | kwnames, &eid)) |
| 6810 | return NULL; |
| 6811 | |
| 6812 | CHECK_ENV_NOT_CLOSED(self); |
| 6813 | |
| 6814 | MYDB_BEGIN_ALLOW_THREADS; |
| 6815 | err = self->db_env->repmgr_site_by_eid(self->db_env, eid, &site); |
| 6816 | MYDB_END_ALLOW_THREADS; |
| 6817 | RETURN_IF_ERR(); |
| 6818 | return (PyObject*) newDBSiteObject(site, self); |
| 6819 | } |
| 6820 | #endif |
| 6821 | |
| 6822 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6823 | #if (DBVER >= 44) |
| 6824 | static PyObject* |
| 6825 | DBEnv_mutex_stat(DBEnvObject* self, PyObject* args) |
| 6826 | { |
| 6827 | int err; |
| 6828 | DB_MUTEX_STAT* statp = NULL; |
| 6829 | PyObject* d = NULL; |
| 6830 | u_int32_t flags = 0; |
| 6831 | |
| 6832 | if (!PyArg_ParseTuple(args, "|i:mutex_stat", &flags)) |
| 6833 | return NULL; |
| 6834 | CHECK_ENV_NOT_CLOSED(self); |
| 6835 | |
| 6836 | MYDB_BEGIN_ALLOW_THREADS; |
| 6837 | err = self->db_env->mutex_stat(self->db_env, &statp, flags); |
| 6838 | MYDB_END_ALLOW_THREADS; |
| 6839 | RETURN_IF_ERR(); |
| 6840 | |
| 6841 | /* Turn the stat structure into a dictionary */ |
| 6842 | d = PyDict_New(); |
| 6843 | if (d == NULL) { |
| 6844 | if (statp) |
| 6845 | free(statp); |
| 6846 | return NULL; |
| 6847 | } |
| 6848 | |
| 6849 | #define MAKE_ENTRY(name) _addIntToDict(d, #name, statp->st_##name) |
| 6850 | |
| 6851 | MAKE_ENTRY(mutex_align); |
| 6852 | MAKE_ENTRY(mutex_tas_spins); |
| 6853 | MAKE_ENTRY(mutex_cnt); |
| 6854 | MAKE_ENTRY(mutex_free); |
| 6855 | MAKE_ENTRY(mutex_inuse); |
| 6856 | MAKE_ENTRY(mutex_inuse_max); |
| 6857 | MAKE_ENTRY(regsize); |
| 6858 | MAKE_ENTRY(region_wait); |
| 6859 | MAKE_ENTRY(region_nowait); |
| 6860 | |
| 6861 | #undef MAKE_ENTRY |
| 6862 | free(statp); |
| 6863 | return d; |
| 6864 | } |
| 6865 | #endif |
| 6866 | |
| 6867 | |
| 6868 | #if (DBVER >= 44) |
| 6869 | static PyObject* |
| 6870 | DBEnv_mutex_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 6871 | { |
| 6872 | int err; |
| 6873 | int flags=0; |
| 6874 | static char* kwnames[] = { "flags", NULL }; |
| 6875 | |
| 6876 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:mutex_stat_print", |
| 6877 | kwnames, &flags)) |
| 6878 | { |
| 6879 | return NULL; |
| 6880 | } |
| 6881 | CHECK_ENV_NOT_CLOSED(self); |
| 6882 | MYDB_BEGIN_ALLOW_THREADS; |
| 6883 | err = self->db_env->mutex_stat_print(self->db_env, flags); |
| 6884 | MYDB_END_ALLOW_THREADS; |
| 6885 | RETURN_IF_ERR(); |
| 6886 | RETURN_NONE(); |
| 6887 | } |
| 6888 | #endif |
| 6889 | |
| 6890 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6891 | static PyObject* |
| 6892 | DBEnv_txn_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 6893 | { |
| 6894 | int err; |
| 6895 | int flags=0; |
| 6896 | static char* kwnames[] = { "flags", NULL }; |
| 6897 | |
| 6898 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:stat_print", |
| 6899 | kwnames, &flags)) |
| 6900 | { |
| 6901 | return NULL; |
| 6902 | } |
| 6903 | |
| 6904 | CHECK_ENV_NOT_CLOSED(self); |
| 6905 | |
| 6906 | MYDB_BEGIN_ALLOW_THREADS; |
| 6907 | err = self->db_env->txn_stat_print(self->db_env, flags); |
| 6908 | MYDB_END_ALLOW_THREADS; |
| 6909 | RETURN_IF_ERR(); |
| 6910 | RETURN_NONE(); |
| 6911 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 6912 | |
| 6913 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6914 | static PyObject* |
| 6915 | DBEnv_txn_stat(DBEnvObject* self, PyObject* args) |
| 6916 | { |
| 6917 | int err; |
| 6918 | DB_TXN_STAT* sp; |
| 6919 | PyObject* d = NULL; |
Martin v. Löwis | b2c7aff | 2002-11-23 11:26:07 +0000 | [diff] [blame] | 6920 | u_int32_t flags=0; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6921 | |
| 6922 | if (!PyArg_ParseTuple(args, "|i:txn_stat", &flags)) |
| 6923 | return NULL; |
| 6924 | CHECK_ENV_NOT_CLOSED(self); |
| 6925 | |
| 6926 | MYDB_BEGIN_ALLOW_THREADS; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6927 | err = self->db_env->txn_stat(self->db_env, &sp, flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6928 | MYDB_END_ALLOW_THREADS; |
| 6929 | RETURN_IF_ERR(); |
| 6930 | |
| 6931 | /* Turn the stat structure into a dictionary */ |
| 6932 | d = PyDict_New(); |
| 6933 | if (d == NULL) { |
| 6934 | free(sp); |
| 6935 | return NULL; |
| 6936 | } |
| 6937 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6938 | #define MAKE_ENTRY(name) _addIntToDict(d, #name, sp->st_##name) |
| 6939 | #define MAKE_TIME_T_ENTRY(name) _addTimeTToDict(d, #name, sp->st_##name) |
| 6940 | #define MAKE_DB_LSN_ENTRY(name) _addDB_lsnToDict(d, #name, sp->st_##name) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6941 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6942 | MAKE_DB_LSN_ENTRY(last_ckp); |
Kristján Valur Jónsson | bd77c03 | 2007-04-26 15:24:54 +0000 | [diff] [blame] | 6943 | MAKE_TIME_T_ENTRY(time_ckp); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6944 | MAKE_ENTRY(last_txnid); |
| 6945 | MAKE_ENTRY(maxtxns); |
| 6946 | MAKE_ENTRY(nactive); |
| 6947 | MAKE_ENTRY(maxnactive); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6948 | #if (DBVER >= 45) |
| 6949 | MAKE_ENTRY(nsnapshot); |
| 6950 | MAKE_ENTRY(maxnsnapshot); |
| 6951 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6952 | MAKE_ENTRY(nbegins); |
| 6953 | MAKE_ENTRY(naborts); |
| 6954 | MAKE_ENTRY(ncommits); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6955 | MAKE_ENTRY(nrestores); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6956 | MAKE_ENTRY(regsize); |
| 6957 | MAKE_ENTRY(region_wait); |
| 6958 | MAKE_ENTRY(region_nowait); |
| 6959 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 6960 | #undef MAKE_DB_LSN_ENTRY |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6961 | #undef MAKE_ENTRY |
Kristján Valur Jónsson | bd77c03 | 2007-04-26 15:24:54 +0000 | [diff] [blame] | 6962 | #undef MAKE_TIME_T_ENTRY |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6963 | free(sp); |
| 6964 | return d; |
| 6965 | } |
| 6966 | |
| 6967 | |
| 6968 | static PyObject* |
| 6969 | DBEnv_set_get_returns_none(DBEnvObject* self, PyObject* args) |
| 6970 | { |
| 6971 | int flags=0; |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 6972 | int oldValue=0; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6973 | |
| 6974 | if (!PyArg_ParseTuple(args,"i:set_get_returns_none", &flags)) |
| 6975 | return NULL; |
| 6976 | CHECK_ENV_NOT_CLOSED(self); |
| 6977 | |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 6978 | if (self->moduleFlags.getReturnsNone) |
| 6979 | ++oldValue; |
| 6980 | if (self->moduleFlags.cursorSetReturnsNone) |
| 6981 | ++oldValue; |
| 6982 | self->moduleFlags.getReturnsNone = (flags >= 1); |
| 6983 | self->moduleFlags.cursorSetReturnsNone = (flags >= 2); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 6984 | return NUMBER_FromLong(oldValue); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 6985 | } |
| 6986 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 6987 | static PyObject* |
| 6988 | DBEnv_get_private(DBEnvObject* self) |
| 6989 | { |
| 6990 | /* We can give out the private field even if dbenv is closed */ |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 6991 | Py_INCREF(self->private_obj); |
| 6992 | return self->private_obj; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 6993 | } |
| 6994 | |
| 6995 | static PyObject* |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 6996 | DBEnv_set_private(DBEnvObject* self, PyObject* private_obj) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 6997 | { |
| 6998 | /* We can set the private field even if dbenv is closed */ |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 6999 | Py_DECREF(self->private_obj); |
| 7000 | Py_INCREF(private_obj); |
| 7001 | self->private_obj = private_obj; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7002 | RETURN_NONE(); |
| 7003 | } |
| 7004 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 7005 | #if (DBVER >= 47) |
| 7006 | static PyObject* |
| 7007 | DBEnv_set_intermediate_dir_mode(DBEnvObject* self, PyObject* args) |
| 7008 | { |
| 7009 | int err; |
| 7010 | const char *mode; |
| 7011 | |
| 7012 | if (!PyArg_ParseTuple(args,"s:set_intermediate_dir_mode", &mode)) |
| 7013 | return NULL; |
| 7014 | |
| 7015 | CHECK_ENV_NOT_CLOSED(self); |
| 7016 | |
| 7017 | MYDB_BEGIN_ALLOW_THREADS; |
| 7018 | err = self->db_env->set_intermediate_dir_mode(self->db_env, mode); |
| 7019 | MYDB_END_ALLOW_THREADS; |
| 7020 | RETURN_IF_ERR(); |
| 7021 | RETURN_NONE(); |
| 7022 | } |
| 7023 | |
| 7024 | static PyObject* |
| 7025 | DBEnv_get_intermediate_dir_mode(DBEnvObject* self) |
| 7026 | { |
| 7027 | int err; |
| 7028 | const char *mode; |
| 7029 | |
| 7030 | CHECK_ENV_NOT_CLOSED(self); |
| 7031 | |
| 7032 | MYDB_BEGIN_ALLOW_THREADS; |
| 7033 | err = self->db_env->get_intermediate_dir_mode(self->db_env, &mode); |
| 7034 | MYDB_END_ALLOW_THREADS; |
| 7035 | RETURN_IF_ERR(); |
| 7036 | return Py_BuildValue("s", mode); |
| 7037 | } |
| 7038 | #endif |
| 7039 | |
| 7040 | #if (DBVER < 47) |
| 7041 | static PyObject* |
| 7042 | DBEnv_set_intermediate_dir(DBEnvObject* self, PyObject* args) |
| 7043 | { |
| 7044 | int err; |
| 7045 | int mode; |
| 7046 | u_int32_t flags; |
| 7047 | |
| 7048 | if (!PyArg_ParseTuple(args, "iI:set_intermediate_dir", &mode, &flags)) |
| 7049 | return NULL; |
| 7050 | |
| 7051 | CHECK_ENV_NOT_CLOSED(self); |
| 7052 | |
| 7053 | MYDB_BEGIN_ALLOW_THREADS; |
| 7054 | err = self->db_env->set_intermediate_dir(self->db_env, mode, flags); |
| 7055 | MYDB_END_ALLOW_THREADS; |
| 7056 | RETURN_IF_ERR(); |
| 7057 | RETURN_NONE(); |
| 7058 | } |
| 7059 | #endif |
| 7060 | |
| 7061 | static PyObject* |
| 7062 | DBEnv_get_open_flags(DBEnvObject* self) |
| 7063 | { |
| 7064 | int err; |
| 7065 | unsigned int flags; |
| 7066 | |
| 7067 | CHECK_ENV_NOT_CLOSED(self); |
| 7068 | |
| 7069 | MYDB_BEGIN_ALLOW_THREADS; |
| 7070 | err = self->db_env->get_open_flags(self->db_env, &flags); |
| 7071 | MYDB_END_ALLOW_THREADS; |
| 7072 | RETURN_IF_ERR(); |
| 7073 | return NUMBER_FromLong(flags); |
| 7074 | } |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7075 | |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 7076 | #if (DBVER < 48) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7077 | static PyObject* |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 7078 | DBEnv_set_rpc_server(DBEnvObject* self, PyObject* args, PyObject* kwargs) |
| 7079 | { |
| 7080 | int err; |
| 7081 | char *host; |
| 7082 | long cl_timeout=0, sv_timeout=0; |
| 7083 | |
| 7084 | static char* kwnames[] = { "host", "cl_timeout", "sv_timeout", NULL}; |
| 7085 | |
| 7086 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|ll:set_rpc_server", kwnames, |
| 7087 | &host, &cl_timeout, &sv_timeout)) |
| 7088 | return NULL; |
| 7089 | CHECK_ENV_NOT_CLOSED(self); |
| 7090 | |
| 7091 | MYDB_BEGIN_ALLOW_THREADS; |
| 7092 | err = self->db_env->set_rpc_server(self->db_env, NULL, host, cl_timeout, |
| 7093 | sv_timeout, 0); |
| 7094 | MYDB_END_ALLOW_THREADS; |
| 7095 | RETURN_IF_ERR(); |
| 7096 | RETURN_NONE(); |
| 7097 | } |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 7098 | #endif |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 7099 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 7100 | static PyObject* |
| 7101 | DBEnv_set_mp_max_openfd(DBEnvObject* self, PyObject* args) |
| 7102 | { |
| 7103 | int err; |
| 7104 | int maxopenfd; |
| 7105 | |
| 7106 | if (!PyArg_ParseTuple(args, "i:set_mp_max_openfd", &maxopenfd)) { |
| 7107 | return NULL; |
| 7108 | } |
| 7109 | CHECK_ENV_NOT_CLOSED(self); |
| 7110 | MYDB_BEGIN_ALLOW_THREADS; |
| 7111 | err = self->db_env->set_mp_max_openfd(self->db_env, maxopenfd); |
| 7112 | MYDB_END_ALLOW_THREADS; |
| 7113 | RETURN_IF_ERR(); |
| 7114 | RETURN_NONE(); |
| 7115 | } |
| 7116 | |
| 7117 | static PyObject* |
| 7118 | DBEnv_get_mp_max_openfd(DBEnvObject* self) |
| 7119 | { |
| 7120 | int err; |
| 7121 | int maxopenfd; |
| 7122 | |
| 7123 | CHECK_ENV_NOT_CLOSED(self); |
| 7124 | |
| 7125 | MYDB_BEGIN_ALLOW_THREADS; |
| 7126 | err = self->db_env->get_mp_max_openfd(self->db_env, &maxopenfd); |
| 7127 | MYDB_END_ALLOW_THREADS; |
| 7128 | RETURN_IF_ERR(); |
| 7129 | return NUMBER_FromLong(maxopenfd); |
| 7130 | } |
| 7131 | |
| 7132 | |
| 7133 | static PyObject* |
| 7134 | DBEnv_set_mp_max_write(DBEnvObject* self, PyObject* args) |
| 7135 | { |
| 7136 | int err; |
| 7137 | int maxwrite, maxwrite_sleep; |
| 7138 | |
| 7139 | if (!PyArg_ParseTuple(args, "ii:set_mp_max_write", &maxwrite, |
| 7140 | &maxwrite_sleep)) { |
| 7141 | return NULL; |
| 7142 | } |
| 7143 | CHECK_ENV_NOT_CLOSED(self); |
| 7144 | MYDB_BEGIN_ALLOW_THREADS; |
| 7145 | err = self->db_env->set_mp_max_write(self->db_env, maxwrite, |
| 7146 | maxwrite_sleep); |
| 7147 | MYDB_END_ALLOW_THREADS; |
| 7148 | RETURN_IF_ERR(); |
| 7149 | RETURN_NONE(); |
| 7150 | } |
| 7151 | |
| 7152 | static PyObject* |
| 7153 | DBEnv_get_mp_max_write(DBEnvObject* self) |
| 7154 | { |
| 7155 | int err; |
| 7156 | int maxwrite; |
| 7157 | #if (DBVER >= 46) |
| 7158 | db_timeout_t maxwrite_sleep; |
| 7159 | #else |
| 7160 | int maxwrite_sleep; |
| 7161 | #endif |
| 7162 | |
| 7163 | CHECK_ENV_NOT_CLOSED(self); |
| 7164 | |
| 7165 | MYDB_BEGIN_ALLOW_THREADS; |
| 7166 | err = self->db_env->get_mp_max_write(self->db_env, &maxwrite, |
| 7167 | &maxwrite_sleep); |
| 7168 | MYDB_END_ALLOW_THREADS; |
| 7169 | RETURN_IF_ERR(); |
| 7170 | |
| 7171 | return Py_BuildValue("(ii)", maxwrite, (int)maxwrite_sleep); |
| 7172 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 7173 | |
| 7174 | |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 7175 | static PyObject* |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7176 | DBEnv_set_verbose(DBEnvObject* self, PyObject* args) |
| 7177 | { |
| 7178 | int err; |
| 7179 | int which, onoff; |
| 7180 | |
| 7181 | if (!PyArg_ParseTuple(args, "ii:set_verbose", &which, &onoff)) { |
| 7182 | return NULL; |
| 7183 | } |
| 7184 | CHECK_ENV_NOT_CLOSED(self); |
| 7185 | MYDB_BEGIN_ALLOW_THREADS; |
| 7186 | err = self->db_env->set_verbose(self->db_env, which, onoff); |
| 7187 | MYDB_END_ALLOW_THREADS; |
| 7188 | RETURN_IF_ERR(); |
| 7189 | RETURN_NONE(); |
| 7190 | } |
| 7191 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7192 | static PyObject* |
| 7193 | DBEnv_get_verbose(DBEnvObject* self, PyObject* args) |
| 7194 | { |
| 7195 | int err; |
| 7196 | int which; |
| 7197 | int verbose; |
| 7198 | |
| 7199 | if (!PyArg_ParseTuple(args, "i:get_verbose", &which)) { |
| 7200 | return NULL; |
| 7201 | } |
| 7202 | CHECK_ENV_NOT_CLOSED(self); |
| 7203 | MYDB_BEGIN_ALLOW_THREADS; |
| 7204 | err = self->db_env->get_verbose(self->db_env, which, &verbose); |
| 7205 | MYDB_END_ALLOW_THREADS; |
| 7206 | RETURN_IF_ERR(); |
| 7207 | return PyBool_FromLong(verbose); |
| 7208 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7209 | |
| 7210 | #if (DBVER >= 45) |
| 7211 | static void |
| 7212 | _dbenv_event_notifyCallback(DB_ENV* db_env, u_int32_t event, void *event_info) |
| 7213 | { |
| 7214 | DBEnvObject *dbenv; |
| 7215 | PyObject* callback; |
| 7216 | PyObject* args; |
| 7217 | PyObject* result = NULL; |
| 7218 | |
| 7219 | MYDB_BEGIN_BLOCK_THREADS; |
| 7220 | dbenv = (DBEnvObject *)db_env->app_private; |
| 7221 | callback = dbenv->event_notifyCallback; |
| 7222 | if (callback) { |
| 7223 | if (event == DB_EVENT_REP_NEWMASTER) { |
| 7224 | args = Py_BuildValue("(Oii)", dbenv, event, *((int *)event_info)); |
| 7225 | } else { |
| 7226 | args = Py_BuildValue("(OiO)", dbenv, event, Py_None); |
| 7227 | } |
| 7228 | if (args) { |
| 7229 | result = PyEval_CallObject(callback, args); |
| 7230 | } |
| 7231 | if ((!args) || (!result)) { |
| 7232 | PyErr_Print(); |
| 7233 | } |
| 7234 | Py_XDECREF(args); |
| 7235 | Py_XDECREF(result); |
| 7236 | } |
| 7237 | MYDB_END_BLOCK_THREADS; |
| 7238 | } |
| 7239 | #endif |
| 7240 | |
| 7241 | #if (DBVER >= 45) |
| 7242 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7243 | DBEnv_set_event_notify(DBEnvObject* self, PyObject* notifyFunc) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7244 | { |
| 7245 | int err; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7246 | |
| 7247 | CHECK_ENV_NOT_CLOSED(self); |
| 7248 | |
| 7249 | if (!PyCallable_Check(notifyFunc)) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 7250 | makeTypeError("Callable", notifyFunc); |
| 7251 | return NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7252 | } |
| 7253 | |
| 7254 | Py_XDECREF(self->event_notifyCallback); |
| 7255 | Py_INCREF(notifyFunc); |
| 7256 | self->event_notifyCallback = notifyFunc; |
| 7257 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7258 | /* This is to workaround a problem with un-initialized threads (see |
| 7259 | comment in DB_associate) */ |
| 7260 | #ifdef WITH_THREAD |
| 7261 | PyEval_InitThreads(); |
| 7262 | #endif |
| 7263 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7264 | MYDB_BEGIN_ALLOW_THREADS; |
| 7265 | err = self->db_env->set_event_notify(self->db_env, _dbenv_event_notifyCallback); |
| 7266 | MYDB_END_ALLOW_THREADS; |
| 7267 | |
| 7268 | if (err) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 7269 | Py_DECREF(notifyFunc); |
| 7270 | self->event_notifyCallback = NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7271 | } |
| 7272 | |
| 7273 | RETURN_IF_ERR(); |
| 7274 | RETURN_NONE(); |
| 7275 | } |
| 7276 | #endif |
| 7277 | |
| 7278 | |
| 7279 | /* --------------------------------------------------------------------- */ |
| 7280 | /* REPLICATION METHODS: Base Replication */ |
| 7281 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7282 | |
| 7283 | static PyObject* |
| 7284 | DBEnv_rep_process_message(DBEnvObject* self, PyObject* args) |
| 7285 | { |
| 7286 | int err; |
| 7287 | PyObject *control_py, *rec_py; |
| 7288 | DBT control, rec; |
| 7289 | int envid; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7290 | DB_LSN lsn; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7291 | |
| 7292 | if (!PyArg_ParseTuple(args, "OOi:rep_process_message", &control_py, |
| 7293 | &rec_py, &envid)) |
| 7294 | return NULL; |
| 7295 | CHECK_ENV_NOT_CLOSED(self); |
| 7296 | |
| 7297 | if (!make_dbt(control_py, &control)) |
| 7298 | return NULL; |
| 7299 | if (!make_dbt(rec_py, &rec)) |
| 7300 | return NULL; |
| 7301 | |
| 7302 | MYDB_BEGIN_ALLOW_THREADS; |
| 7303 | #if (DBVER >= 46) |
| 7304 | err = self->db_env->rep_process_message(self->db_env, &control, &rec, |
| 7305 | envid, &lsn); |
| 7306 | #else |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7307 | err = self->db_env->rep_process_message(self->db_env, &control, &rec, |
| 7308 | &envid, &lsn); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7309 | #endif |
| 7310 | MYDB_END_ALLOW_THREADS; |
| 7311 | switch (err) { |
| 7312 | case DB_REP_NEWMASTER : |
| 7313 | return Py_BuildValue("(iO)", envid, Py_None); |
| 7314 | break; |
| 7315 | |
| 7316 | case DB_REP_DUPMASTER : |
| 7317 | case DB_REP_HOLDELECTION : |
| 7318 | #if (DBVER >= 44) |
| 7319 | case DB_REP_IGNORE : |
| 7320 | case DB_REP_JOIN_FAILURE : |
| 7321 | #endif |
| 7322 | return Py_BuildValue("(iO)", err, Py_None); |
| 7323 | break; |
| 7324 | case DB_REP_NEWSITE : |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 7325 | { |
| 7326 | PyObject *tmp, *r; |
| 7327 | |
| 7328 | if (!(tmp = PyBytes_FromStringAndSize(rec.data, rec.size))) { |
| 7329 | return NULL; |
| 7330 | } |
| 7331 | |
| 7332 | r = Py_BuildValue("(iO)", err, tmp); |
| 7333 | Py_DECREF(tmp); |
| 7334 | return r; |
| 7335 | break; |
| 7336 | } |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7337 | case DB_REP_NOTPERM : |
| 7338 | case DB_REP_ISPERM : |
| 7339 | return Py_BuildValue("(i(ll))", err, lsn.file, lsn.offset); |
| 7340 | break; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7341 | } |
| 7342 | RETURN_IF_ERR(); |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 7343 | return PyTuple_Pack(2, Py_None, Py_None); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7344 | } |
| 7345 | |
| 7346 | static int |
| 7347 | _DBEnv_rep_transportCallback(DB_ENV* db_env, const DBT* control, const DBT* rec, |
| 7348 | const DB_LSN *lsn, int envid, u_int32_t flags) |
| 7349 | { |
| 7350 | DBEnvObject *dbenv; |
| 7351 | PyObject* rep_transport; |
| 7352 | PyObject* args; |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 7353 | PyObject *a, *b; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7354 | PyObject* result = NULL; |
| 7355 | int ret=0; |
| 7356 | |
| 7357 | MYDB_BEGIN_BLOCK_THREADS; |
| 7358 | dbenv = (DBEnvObject *)db_env->app_private; |
| 7359 | rep_transport = dbenv->rep_transport; |
| 7360 | |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 7361 | /* |
| 7362 | ** The errors in 'a' or 'b' are detected in "Py_BuildValue". |
| 7363 | */ |
| 7364 | a = PyBytes_FromStringAndSize(control->data, control->size); |
| 7365 | b = PyBytes_FromStringAndSize(rec->data, rec->size); |
| 7366 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7367 | args = Py_BuildValue( |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 7368 | "(OOO(ll)iI)", |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7369 | dbenv, |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 7370 | a, b, |
| 7371 | lsn->file, lsn->offset, envid, flags); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7372 | if (args) { |
| 7373 | result = PyEval_CallObject(rep_transport, args); |
| 7374 | } |
| 7375 | |
| 7376 | if ((!args) || (!result)) { |
| 7377 | PyErr_Print(); |
| 7378 | ret = -1; |
| 7379 | } |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 7380 | Py_XDECREF(a); |
| 7381 | Py_XDECREF(b); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7382 | Py_XDECREF(args); |
| 7383 | Py_XDECREF(result); |
| 7384 | MYDB_END_BLOCK_THREADS; |
| 7385 | return ret; |
| 7386 | } |
| 7387 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7388 | static PyObject* |
| 7389 | DBEnv_rep_set_transport(DBEnvObject* self, PyObject* args) |
| 7390 | { |
| 7391 | int err; |
| 7392 | int envid; |
| 7393 | PyObject *rep_transport; |
| 7394 | |
| 7395 | if (!PyArg_ParseTuple(args, "iO:rep_set_transport", &envid, &rep_transport)) |
| 7396 | return NULL; |
| 7397 | CHECK_ENV_NOT_CLOSED(self); |
| 7398 | if (!PyCallable_Check(rep_transport)) { |
| 7399 | makeTypeError("Callable", rep_transport); |
| 7400 | return NULL; |
| 7401 | } |
| 7402 | |
| 7403 | MYDB_BEGIN_ALLOW_THREADS; |
| 7404 | #if (DBVER >=45) |
| 7405 | err = self->db_env->rep_set_transport(self->db_env, envid, |
| 7406 | &_DBEnv_rep_transportCallback); |
| 7407 | #else |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7408 | err = self->db_env->set_rep_transport(self->db_env, envid, |
| 7409 | &_DBEnv_rep_transportCallback); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7410 | #endif |
| 7411 | MYDB_END_ALLOW_THREADS; |
| 7412 | RETURN_IF_ERR(); |
| 7413 | |
| 7414 | Py_DECREF(self->rep_transport); |
| 7415 | Py_INCREF(rep_transport); |
| 7416 | self->rep_transport = rep_transport; |
| 7417 | RETURN_NONE(); |
| 7418 | } |
| 7419 | |
| 7420 | #if (DBVER >= 47) |
| 7421 | static PyObject* |
| 7422 | DBEnv_rep_set_request(DBEnvObject* self, PyObject* args) |
| 7423 | { |
| 7424 | int err; |
| 7425 | unsigned int minimum, maximum; |
| 7426 | |
| 7427 | if (!PyArg_ParseTuple(args,"II:rep_set_request", &minimum, &maximum)) |
| 7428 | return NULL; |
| 7429 | CHECK_ENV_NOT_CLOSED(self); |
| 7430 | |
| 7431 | MYDB_BEGIN_ALLOW_THREADS; |
| 7432 | err = self->db_env->rep_set_request(self->db_env, minimum, maximum); |
| 7433 | MYDB_END_ALLOW_THREADS; |
| 7434 | RETURN_IF_ERR(); |
| 7435 | RETURN_NONE(); |
| 7436 | } |
| 7437 | |
| 7438 | static PyObject* |
| 7439 | DBEnv_rep_get_request(DBEnvObject* self) |
| 7440 | { |
| 7441 | int err; |
| 7442 | u_int32_t minimum, maximum; |
| 7443 | |
| 7444 | CHECK_ENV_NOT_CLOSED(self); |
| 7445 | MYDB_BEGIN_ALLOW_THREADS; |
| 7446 | err = self->db_env->rep_get_request(self->db_env, &minimum, &maximum); |
| 7447 | MYDB_END_ALLOW_THREADS; |
| 7448 | RETURN_IF_ERR(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7449 | return Py_BuildValue("II", minimum, maximum); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7450 | } |
| 7451 | #endif |
| 7452 | |
| 7453 | #if (DBVER >= 45) |
| 7454 | static PyObject* |
| 7455 | DBEnv_rep_set_limit(DBEnvObject* self, PyObject* args) |
| 7456 | { |
| 7457 | int err; |
| 7458 | int limit; |
| 7459 | |
| 7460 | if (!PyArg_ParseTuple(args,"i:rep_set_limit", &limit)) |
| 7461 | return NULL; |
| 7462 | CHECK_ENV_NOT_CLOSED(self); |
| 7463 | |
| 7464 | MYDB_BEGIN_ALLOW_THREADS; |
| 7465 | err = self->db_env->rep_set_limit(self->db_env, 0, limit); |
| 7466 | MYDB_END_ALLOW_THREADS; |
| 7467 | RETURN_IF_ERR(); |
| 7468 | RETURN_NONE(); |
| 7469 | } |
| 7470 | |
| 7471 | static PyObject* |
| 7472 | DBEnv_rep_get_limit(DBEnvObject* self) |
| 7473 | { |
| 7474 | int err; |
| 7475 | u_int32_t gbytes, bytes; |
| 7476 | |
| 7477 | CHECK_ENV_NOT_CLOSED(self); |
| 7478 | MYDB_BEGIN_ALLOW_THREADS; |
| 7479 | err = self->db_env->rep_get_limit(self->db_env, &gbytes, &bytes); |
| 7480 | MYDB_END_ALLOW_THREADS; |
| 7481 | RETURN_IF_ERR(); |
| 7482 | return NUMBER_FromLong(bytes); |
| 7483 | } |
| 7484 | #endif |
| 7485 | |
| 7486 | #if (DBVER >= 44) |
| 7487 | static PyObject* |
| 7488 | DBEnv_rep_set_config(DBEnvObject* self, PyObject* args) |
| 7489 | { |
| 7490 | int err; |
| 7491 | int which; |
| 7492 | int onoff; |
| 7493 | |
| 7494 | if (!PyArg_ParseTuple(args,"ii:rep_set_config", &which, &onoff)) |
| 7495 | return NULL; |
| 7496 | CHECK_ENV_NOT_CLOSED(self); |
| 7497 | |
| 7498 | MYDB_BEGIN_ALLOW_THREADS; |
| 7499 | err = self->db_env->rep_set_config(self->db_env, which, onoff); |
| 7500 | MYDB_END_ALLOW_THREADS; |
| 7501 | RETURN_IF_ERR(); |
| 7502 | RETURN_NONE(); |
| 7503 | } |
| 7504 | |
| 7505 | static PyObject* |
| 7506 | DBEnv_rep_get_config(DBEnvObject* self, PyObject* args) |
| 7507 | { |
| 7508 | int err; |
| 7509 | int which; |
| 7510 | int onoff; |
| 7511 | |
| 7512 | if (!PyArg_ParseTuple(args, "i:rep_get_config", &which)) { |
| 7513 | return NULL; |
| 7514 | } |
| 7515 | CHECK_ENV_NOT_CLOSED(self); |
| 7516 | MYDB_BEGIN_ALLOW_THREADS; |
| 7517 | err = self->db_env->rep_get_config(self->db_env, which, &onoff); |
| 7518 | MYDB_END_ALLOW_THREADS; |
| 7519 | RETURN_IF_ERR(); |
| 7520 | return PyBool_FromLong(onoff); |
| 7521 | } |
| 7522 | #endif |
| 7523 | |
| 7524 | #if (DBVER >= 46) |
| 7525 | static PyObject* |
| 7526 | DBEnv_rep_elect(DBEnvObject* self, PyObject* args) |
| 7527 | { |
| 7528 | int err; |
| 7529 | u_int32_t nsites, nvotes; |
| 7530 | |
| 7531 | if (!PyArg_ParseTuple(args, "II:rep_elect", &nsites, &nvotes)) { |
| 7532 | return NULL; |
| 7533 | } |
| 7534 | CHECK_ENV_NOT_CLOSED(self); |
| 7535 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | 2ab4a91 | 2012-01-16 23:57:34 +0100 | [diff] [blame] | 7536 | err = self->db_env->rep_elect(self->db_env, nsites, nvotes, 0); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7537 | MYDB_END_ALLOW_THREADS; |
| 7538 | RETURN_IF_ERR(); |
| 7539 | RETURN_NONE(); |
| 7540 | } |
| 7541 | #endif |
| 7542 | |
| 7543 | static PyObject* |
| 7544 | DBEnv_rep_start(DBEnvObject* self, PyObject* args, PyObject* kwargs) |
| 7545 | { |
| 7546 | int err; |
| 7547 | PyObject *cdata_py = Py_None; |
| 7548 | DBT cdata; |
| 7549 | int flags; |
| 7550 | static char* kwnames[] = {"flags","cdata", NULL}; |
| 7551 | |
| 7552 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 7553 | "i|O:rep_start", kwnames, &flags, &cdata_py)) |
| 7554 | { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 7555 | return NULL; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7556 | } |
| 7557 | CHECK_ENV_NOT_CLOSED(self); |
| 7558 | |
| 7559 | if (!make_dbt(cdata_py, &cdata)) |
| 7560 | return NULL; |
| 7561 | |
| 7562 | MYDB_BEGIN_ALLOW_THREADS; |
| 7563 | err = self->db_env->rep_start(self->db_env, cdata.size ? &cdata : NULL, |
| 7564 | flags); |
| 7565 | MYDB_END_ALLOW_THREADS; |
| 7566 | RETURN_IF_ERR(); |
| 7567 | RETURN_NONE(); |
| 7568 | } |
| 7569 | |
| 7570 | #if (DBVER >= 44) |
| 7571 | static PyObject* |
| 7572 | DBEnv_rep_sync(DBEnvObject* self) |
| 7573 | { |
| 7574 | int err; |
| 7575 | |
| 7576 | CHECK_ENV_NOT_CLOSED(self); |
| 7577 | MYDB_BEGIN_ALLOW_THREADS; |
| 7578 | err = self->db_env->rep_sync(self->db_env, 0); |
| 7579 | MYDB_END_ALLOW_THREADS; |
| 7580 | RETURN_IF_ERR(); |
| 7581 | RETURN_NONE(); |
| 7582 | } |
| 7583 | #endif |
| 7584 | |
| 7585 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7586 | #if (DBVER >= 45) |
| 7587 | static PyObject* |
| 7588 | DBEnv_rep_set_nsites(DBEnvObject* self, PyObject* args) |
| 7589 | { |
| 7590 | int err; |
| 7591 | int nsites; |
| 7592 | |
| 7593 | if (!PyArg_ParseTuple(args, "i:rep_set_nsites", &nsites)) { |
| 7594 | return NULL; |
| 7595 | } |
| 7596 | CHECK_ENV_NOT_CLOSED(self); |
| 7597 | MYDB_BEGIN_ALLOW_THREADS; |
| 7598 | err = self->db_env->rep_set_nsites(self->db_env, nsites); |
| 7599 | MYDB_END_ALLOW_THREADS; |
| 7600 | RETURN_IF_ERR(); |
| 7601 | RETURN_NONE(); |
| 7602 | } |
| 7603 | |
| 7604 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7605 | DBEnv_rep_get_nsites(DBEnvObject* self) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7606 | { |
| 7607 | int err; |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 7608 | #if (DBVER >= 47) |
| 7609 | u_int32_t nsites; |
| 7610 | #else |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7611 | int nsites; |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 7612 | #endif |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7613 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7614 | CHECK_ENV_NOT_CLOSED(self); |
| 7615 | MYDB_BEGIN_ALLOW_THREADS; |
| 7616 | err = self->db_env->rep_get_nsites(self->db_env, &nsites); |
| 7617 | MYDB_END_ALLOW_THREADS; |
| 7618 | RETURN_IF_ERR(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7619 | return NUMBER_FromLong(nsites); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7620 | } |
| 7621 | |
| 7622 | static PyObject* |
| 7623 | DBEnv_rep_set_priority(DBEnvObject* self, PyObject* args) |
| 7624 | { |
| 7625 | int err; |
| 7626 | int priority; |
| 7627 | |
| 7628 | if (!PyArg_ParseTuple(args, "i:rep_set_priority", &priority)) { |
| 7629 | return NULL; |
| 7630 | } |
| 7631 | CHECK_ENV_NOT_CLOSED(self); |
| 7632 | MYDB_BEGIN_ALLOW_THREADS; |
| 7633 | err = self->db_env->rep_set_priority(self->db_env, priority); |
| 7634 | MYDB_END_ALLOW_THREADS; |
| 7635 | RETURN_IF_ERR(); |
| 7636 | RETURN_NONE(); |
| 7637 | } |
| 7638 | |
| 7639 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7640 | DBEnv_rep_get_priority(DBEnvObject* self) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7641 | { |
| 7642 | int err; |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 7643 | #if (DBVER >= 47) |
| 7644 | u_int32_t priority; |
| 7645 | #else |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7646 | int priority; |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 7647 | #endif |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7648 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7649 | CHECK_ENV_NOT_CLOSED(self); |
| 7650 | MYDB_BEGIN_ALLOW_THREADS; |
| 7651 | err = self->db_env->rep_get_priority(self->db_env, &priority); |
| 7652 | MYDB_END_ALLOW_THREADS; |
| 7653 | RETURN_IF_ERR(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7654 | return NUMBER_FromLong(priority); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7655 | } |
| 7656 | |
| 7657 | static PyObject* |
| 7658 | DBEnv_rep_set_timeout(DBEnvObject* self, PyObject* args) |
| 7659 | { |
| 7660 | int err; |
| 7661 | int which, timeout; |
| 7662 | |
| 7663 | if (!PyArg_ParseTuple(args, "ii:rep_set_timeout", &which, &timeout)) { |
| 7664 | return NULL; |
| 7665 | } |
| 7666 | CHECK_ENV_NOT_CLOSED(self); |
| 7667 | MYDB_BEGIN_ALLOW_THREADS; |
| 7668 | err = self->db_env->rep_set_timeout(self->db_env, which, timeout); |
| 7669 | MYDB_END_ALLOW_THREADS; |
| 7670 | RETURN_IF_ERR(); |
| 7671 | RETURN_NONE(); |
| 7672 | } |
| 7673 | |
| 7674 | static PyObject* |
| 7675 | DBEnv_rep_get_timeout(DBEnvObject* self, PyObject* args) |
| 7676 | { |
| 7677 | int err; |
| 7678 | int which; |
| 7679 | u_int32_t timeout; |
| 7680 | |
| 7681 | if (!PyArg_ParseTuple(args, "i:rep_get_timeout", &which)) { |
| 7682 | return NULL; |
| 7683 | } |
| 7684 | CHECK_ENV_NOT_CLOSED(self); |
| 7685 | MYDB_BEGIN_ALLOW_THREADS; |
| 7686 | err = self->db_env->rep_get_timeout(self->db_env, which, &timeout); |
| 7687 | MYDB_END_ALLOW_THREADS; |
| 7688 | RETURN_IF_ERR(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7689 | return NUMBER_FromLong(timeout); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7690 | } |
| 7691 | #endif |
| 7692 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 7693 | |
| 7694 | #if (DBVER >= 47) |
| 7695 | static PyObject* |
| 7696 | DBEnv_rep_set_clockskew(DBEnvObject* self, PyObject* args) |
| 7697 | { |
| 7698 | int err; |
| 7699 | unsigned int fast, slow; |
| 7700 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 7701 | if (!PyArg_ParseTuple(args,"II:rep_set_clockskew", &fast, &slow)) |
| 7702 | return NULL; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 7703 | |
| 7704 | CHECK_ENV_NOT_CLOSED(self); |
| 7705 | |
| 7706 | MYDB_BEGIN_ALLOW_THREADS; |
| 7707 | err = self->db_env->rep_set_clockskew(self->db_env, fast, slow); |
| 7708 | MYDB_END_ALLOW_THREADS; |
| 7709 | RETURN_IF_ERR(); |
| 7710 | RETURN_NONE(); |
| 7711 | } |
| 7712 | |
| 7713 | static PyObject* |
| 7714 | DBEnv_rep_get_clockskew(DBEnvObject* self) |
| 7715 | { |
| 7716 | int err; |
| 7717 | unsigned int fast, slow; |
| 7718 | |
| 7719 | CHECK_ENV_NOT_CLOSED(self); |
| 7720 | MYDB_BEGIN_ALLOW_THREADS; |
| 7721 | err = self->db_env->rep_get_clockskew(self->db_env, &fast, &slow); |
| 7722 | MYDB_END_ALLOW_THREADS; |
| 7723 | RETURN_IF_ERR(); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 7724 | return Py_BuildValue("(II)", fast, slow); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 7725 | } |
| 7726 | #endif |
| 7727 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 7728 | static PyObject* |
| 7729 | DBEnv_rep_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 7730 | { |
| 7731 | int err; |
| 7732 | int flags=0; |
| 7733 | static char* kwnames[] = { "flags", NULL }; |
| 7734 | |
| 7735 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:rep_stat_print", |
| 7736 | kwnames, &flags)) |
| 7737 | { |
| 7738 | return NULL; |
| 7739 | } |
| 7740 | CHECK_ENV_NOT_CLOSED(self); |
| 7741 | MYDB_BEGIN_ALLOW_THREADS; |
| 7742 | err = self->db_env->rep_stat_print(self->db_env, flags); |
| 7743 | MYDB_END_ALLOW_THREADS; |
| 7744 | RETURN_IF_ERR(); |
| 7745 | RETURN_NONE(); |
| 7746 | } |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 7747 | |
| 7748 | static PyObject* |
| 7749 | DBEnv_rep_stat(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 7750 | { |
| 7751 | int err; |
| 7752 | int flags=0; |
| 7753 | DB_REP_STAT *statp; |
| 7754 | PyObject *stats; |
| 7755 | static char* kwnames[] = { "flags", NULL }; |
| 7756 | |
| 7757 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:rep_stat", |
| 7758 | kwnames, &flags)) |
| 7759 | { |
| 7760 | return NULL; |
| 7761 | } |
| 7762 | CHECK_ENV_NOT_CLOSED(self); |
| 7763 | MYDB_BEGIN_ALLOW_THREADS; |
| 7764 | err = self->db_env->rep_stat(self->db_env, &statp, flags); |
| 7765 | MYDB_END_ALLOW_THREADS; |
| 7766 | RETURN_IF_ERR(); |
| 7767 | |
| 7768 | stats=PyDict_New(); |
| 7769 | if (stats == NULL) { |
| 7770 | free(statp); |
| 7771 | return NULL; |
| 7772 | } |
| 7773 | |
| 7774 | #define MAKE_ENTRY(name) _addIntToDict(stats, #name, statp->st_##name) |
| 7775 | #define MAKE_DB_LSN_ENTRY(name) _addDB_lsnToDict(stats , #name, statp->st_##name) |
| 7776 | |
| 7777 | #if (DBVER >= 44) |
| 7778 | MAKE_ENTRY(bulk_fills); |
| 7779 | MAKE_ENTRY(bulk_overflows); |
| 7780 | MAKE_ENTRY(bulk_records); |
| 7781 | MAKE_ENTRY(bulk_transfers); |
| 7782 | MAKE_ENTRY(client_rerequests); |
| 7783 | MAKE_ENTRY(client_svc_miss); |
| 7784 | MAKE_ENTRY(client_svc_req); |
| 7785 | #endif |
| 7786 | MAKE_ENTRY(dupmasters); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 7787 | MAKE_ENTRY(egen); |
| 7788 | MAKE_ENTRY(election_nvotes); |
| 7789 | MAKE_ENTRY(startup_complete); |
| 7790 | MAKE_ENTRY(pg_duplicated); |
| 7791 | MAKE_ENTRY(pg_records); |
| 7792 | MAKE_ENTRY(pg_requested); |
| 7793 | MAKE_ENTRY(next_pg); |
| 7794 | MAKE_ENTRY(waiting_pg); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 7795 | MAKE_ENTRY(election_cur_winner); |
| 7796 | MAKE_ENTRY(election_gen); |
| 7797 | MAKE_DB_LSN_ENTRY(election_lsn); |
| 7798 | MAKE_ENTRY(election_nsites); |
| 7799 | MAKE_ENTRY(election_priority); |
| 7800 | #if (DBVER >= 44) |
| 7801 | MAKE_ENTRY(election_sec); |
| 7802 | MAKE_ENTRY(election_usec); |
| 7803 | #endif |
| 7804 | MAKE_ENTRY(election_status); |
| 7805 | MAKE_ENTRY(election_tiebreaker); |
| 7806 | MAKE_ENTRY(election_votes); |
| 7807 | MAKE_ENTRY(elections); |
| 7808 | MAKE_ENTRY(elections_won); |
| 7809 | MAKE_ENTRY(env_id); |
| 7810 | MAKE_ENTRY(env_priority); |
| 7811 | MAKE_ENTRY(gen); |
| 7812 | MAKE_ENTRY(log_duplicated); |
| 7813 | MAKE_ENTRY(log_queued); |
| 7814 | MAKE_ENTRY(log_queued_max); |
| 7815 | MAKE_ENTRY(log_queued_total); |
| 7816 | MAKE_ENTRY(log_records); |
| 7817 | MAKE_ENTRY(log_requested); |
| 7818 | MAKE_ENTRY(master); |
| 7819 | MAKE_ENTRY(master_changes); |
| 7820 | #if (DBVER >= 47) |
| 7821 | MAKE_ENTRY(max_lease_sec); |
| 7822 | MAKE_ENTRY(max_lease_usec); |
| 7823 | MAKE_DB_LSN_ENTRY(max_perm_lsn); |
| 7824 | #endif |
| 7825 | MAKE_ENTRY(msgs_badgen); |
| 7826 | MAKE_ENTRY(msgs_processed); |
| 7827 | MAKE_ENTRY(msgs_recover); |
| 7828 | MAKE_ENTRY(msgs_send_failures); |
| 7829 | MAKE_ENTRY(msgs_sent); |
| 7830 | MAKE_ENTRY(newsites); |
| 7831 | MAKE_DB_LSN_ENTRY(next_lsn); |
| 7832 | MAKE_ENTRY(nsites); |
| 7833 | MAKE_ENTRY(nthrottles); |
| 7834 | MAKE_ENTRY(outdated); |
| 7835 | #if (DBVER >= 46) |
| 7836 | MAKE_ENTRY(startsync_delayed); |
| 7837 | #endif |
| 7838 | MAKE_ENTRY(status); |
| 7839 | MAKE_ENTRY(txns_applied); |
| 7840 | MAKE_DB_LSN_ENTRY(waiting_lsn); |
| 7841 | |
| 7842 | #undef MAKE_DB_LSN_ENTRY |
| 7843 | #undef MAKE_ENTRY |
| 7844 | |
| 7845 | free(statp); |
| 7846 | return stats; |
| 7847 | } |
| 7848 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7849 | /* --------------------------------------------------------------------- */ |
| 7850 | /* REPLICATION METHODS: Replication Manager */ |
| 7851 | |
| 7852 | #if (DBVER >= 45) |
| 7853 | static PyObject* |
| 7854 | DBEnv_repmgr_start(DBEnvObject* self, PyObject* args, PyObject* |
| 7855 | kwargs) |
| 7856 | { |
| 7857 | int err; |
| 7858 | int nthreads, flags; |
| 7859 | static char* kwnames[] = {"nthreads","flags", NULL}; |
| 7860 | |
| 7861 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 7862 | "ii:repmgr_start", kwnames, &nthreads, &flags)) |
| 7863 | { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 7864 | return NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7865 | } |
| 7866 | CHECK_ENV_NOT_CLOSED(self); |
| 7867 | MYDB_BEGIN_ALLOW_THREADS; |
| 7868 | err = self->db_env->repmgr_start(self->db_env, nthreads, flags); |
| 7869 | MYDB_END_ALLOW_THREADS; |
| 7870 | RETURN_IF_ERR(); |
| 7871 | RETURN_NONE(); |
| 7872 | } |
| 7873 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 7874 | #if (DBVER < 52) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7875 | static PyObject* |
| 7876 | DBEnv_repmgr_set_local_site(DBEnvObject* self, PyObject* args, PyObject* |
| 7877 | kwargs) |
| 7878 | { |
| 7879 | int err; |
| 7880 | char *host; |
| 7881 | int port; |
| 7882 | int flags = 0; |
| 7883 | static char* kwnames[] = {"host", "port", "flags", NULL}; |
| 7884 | |
| 7885 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 7886 | "si|i:repmgr_set_local_site", kwnames, &host, &port, &flags)) |
| 7887 | { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 7888 | return NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7889 | } |
| 7890 | CHECK_ENV_NOT_CLOSED(self); |
| 7891 | MYDB_BEGIN_ALLOW_THREADS; |
| 7892 | err = self->db_env->repmgr_set_local_site(self->db_env, host, port, flags); |
| 7893 | MYDB_END_ALLOW_THREADS; |
| 7894 | RETURN_IF_ERR(); |
| 7895 | RETURN_NONE(); |
| 7896 | } |
| 7897 | |
| 7898 | static PyObject* |
| 7899 | DBEnv_repmgr_add_remote_site(DBEnvObject* self, PyObject* args, PyObject* |
| 7900 | kwargs) |
| 7901 | { |
| 7902 | int err; |
| 7903 | char *host; |
| 7904 | int port; |
| 7905 | int flags = 0; |
| 7906 | int eidp; |
| 7907 | static char* kwnames[] = {"host", "port", "flags", NULL}; |
| 7908 | |
| 7909 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 7910 | "si|i:repmgr_add_remote_site", kwnames, &host, &port, &flags)) |
| 7911 | { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 7912 | return NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7913 | } |
| 7914 | CHECK_ENV_NOT_CLOSED(self); |
| 7915 | MYDB_BEGIN_ALLOW_THREADS; |
| 7916 | err = self->db_env->repmgr_add_remote_site(self->db_env, host, port, &eidp, flags); |
| 7917 | MYDB_END_ALLOW_THREADS; |
| 7918 | RETURN_IF_ERR(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7919 | return NUMBER_FromLong(eidp); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7920 | } |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 7921 | #endif |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7922 | |
| 7923 | static PyObject* |
| 7924 | DBEnv_repmgr_set_ack_policy(DBEnvObject* self, PyObject* args) |
| 7925 | { |
| 7926 | int err; |
| 7927 | int ack_policy; |
| 7928 | |
| 7929 | if (!PyArg_ParseTuple(args, "i:repmgr_set_ack_policy", &ack_policy)) |
| 7930 | { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 7931 | return NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7932 | } |
| 7933 | CHECK_ENV_NOT_CLOSED(self); |
| 7934 | MYDB_BEGIN_ALLOW_THREADS; |
| 7935 | err = self->db_env->repmgr_set_ack_policy(self->db_env, ack_policy); |
| 7936 | MYDB_END_ALLOW_THREADS; |
| 7937 | RETURN_IF_ERR(); |
| 7938 | RETURN_NONE(); |
| 7939 | } |
| 7940 | |
| 7941 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7942 | DBEnv_repmgr_get_ack_policy(DBEnvObject* self) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7943 | { |
| 7944 | int err; |
| 7945 | int ack_policy; |
| 7946 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7947 | CHECK_ENV_NOT_CLOSED(self); |
| 7948 | MYDB_BEGIN_ALLOW_THREADS; |
| 7949 | err = self->db_env->repmgr_get_ack_policy(self->db_env, &ack_policy); |
| 7950 | MYDB_END_ALLOW_THREADS; |
| 7951 | RETURN_IF_ERR(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7952 | return NUMBER_FromLong(ack_policy); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7953 | } |
| 7954 | |
| 7955 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7956 | DBEnv_repmgr_site_list(DBEnvObject* self) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7957 | { |
| 7958 | int err; |
| 7959 | unsigned int countp; |
| 7960 | DB_REPMGR_SITE *listp; |
| 7961 | PyObject *stats, *key, *tuple; |
| 7962 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7963 | CHECK_ENV_NOT_CLOSED(self); |
| 7964 | MYDB_BEGIN_ALLOW_THREADS; |
| 7965 | err = self->db_env->repmgr_site_list(self->db_env, &countp, &listp); |
| 7966 | MYDB_END_ALLOW_THREADS; |
| 7967 | RETURN_IF_ERR(); |
| 7968 | |
| 7969 | stats=PyDict_New(); |
| 7970 | if (stats == NULL) { |
| 7971 | free(listp); |
| 7972 | return NULL; |
| 7973 | } |
| 7974 | |
| 7975 | for(;countp--;) { |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 7976 | key=NUMBER_FromLong(listp[countp].eid); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7977 | if(!key) { |
| 7978 | Py_DECREF(stats); |
| 7979 | free(listp); |
| 7980 | return NULL; |
| 7981 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7982 | tuple=Py_BuildValue("(sII)", listp[countp].host, |
| 7983 | listp[countp].port, listp[countp].status); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7984 | if(!tuple) { |
| 7985 | Py_DECREF(key); |
| 7986 | Py_DECREF(stats); |
| 7987 | free(listp); |
| 7988 | return NULL; |
| 7989 | } |
| 7990 | if(PyDict_SetItem(stats, key, tuple)) { |
| 7991 | Py_DECREF(key); |
| 7992 | Py_DECREF(tuple); |
| 7993 | Py_DECREF(stats); |
| 7994 | free(listp); |
| 7995 | return NULL; |
| 7996 | } |
Florent Xicluna | e7901c5 | 2010-03-01 20:45:01 +0000 | [diff] [blame] | 7997 | Py_DECREF(key); |
| 7998 | Py_DECREF(tuple); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 7999 | } |
| 8000 | free(listp); |
| 8001 | return stats; |
| 8002 | } |
| 8003 | #endif |
| 8004 | |
| 8005 | #if (DBVER >= 46) |
| 8006 | static PyObject* |
| 8007 | DBEnv_repmgr_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 8008 | { |
| 8009 | int err; |
| 8010 | int flags=0; |
| 8011 | static char* kwnames[] = { "flags", NULL }; |
| 8012 | |
| 8013 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:repmgr_stat_print", |
| 8014 | kwnames, &flags)) |
| 8015 | { |
| 8016 | return NULL; |
| 8017 | } |
| 8018 | CHECK_ENV_NOT_CLOSED(self); |
| 8019 | MYDB_BEGIN_ALLOW_THREADS; |
| 8020 | err = self->db_env->repmgr_stat_print(self->db_env, flags); |
| 8021 | MYDB_END_ALLOW_THREADS; |
| 8022 | RETURN_IF_ERR(); |
| 8023 | RETURN_NONE(); |
| 8024 | } |
| 8025 | |
| 8026 | static PyObject* |
| 8027 | DBEnv_repmgr_stat(DBEnvObject* self, PyObject* args, PyObject *kwargs) |
| 8028 | { |
| 8029 | int err; |
| 8030 | int flags=0; |
| 8031 | DB_REPMGR_STAT *statp; |
| 8032 | PyObject *stats; |
| 8033 | static char* kwnames[] = { "flags", NULL }; |
| 8034 | |
| 8035 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:repmgr_stat", |
| 8036 | kwnames, &flags)) |
| 8037 | { |
| 8038 | return NULL; |
| 8039 | } |
| 8040 | CHECK_ENV_NOT_CLOSED(self); |
| 8041 | MYDB_BEGIN_ALLOW_THREADS; |
| 8042 | err = self->db_env->repmgr_stat(self->db_env, &statp, flags); |
| 8043 | MYDB_END_ALLOW_THREADS; |
| 8044 | RETURN_IF_ERR(); |
| 8045 | |
| 8046 | stats=PyDict_New(); |
| 8047 | if (stats == NULL) { |
| 8048 | free(statp); |
| 8049 | return NULL; |
| 8050 | } |
| 8051 | |
| 8052 | #define MAKE_ENTRY(name) _addIntToDict(stats, #name, statp->st_##name) |
| 8053 | |
| 8054 | MAKE_ENTRY(perm_failed); |
| 8055 | MAKE_ENTRY(msgs_queued); |
| 8056 | MAKE_ENTRY(msgs_dropped); |
| 8057 | MAKE_ENTRY(connection_drop); |
| 8058 | MAKE_ENTRY(connect_fail); |
| 8059 | |
| 8060 | #undef MAKE_ENTRY |
| 8061 | |
| 8062 | free(statp); |
| 8063 | return stats; |
| 8064 | } |
| 8065 | #endif |
| 8066 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8067 | |
| 8068 | /* --------------------------------------------------------------------- */ |
| 8069 | /* DBTxn methods */ |
| 8070 | |
| 8071 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8072 | static void _close_transaction_cursors(DBTxnObject* txn) |
| 8073 | { |
| 8074 | PyObject *dummy; |
| 8075 | |
| 8076 | while(txn->children_cursors) { |
| 8077 | PyErr_Warn(PyExc_RuntimeWarning, |
| 8078 | "Must close cursors before resolving a transaction."); |
| 8079 | dummy=DBC_close_internal(txn->children_cursors); |
| 8080 | Py_XDECREF(dummy); |
| 8081 | } |
| 8082 | } |
| 8083 | |
| 8084 | static void _promote_transaction_dbs_and_sequences(DBTxnObject *txn) |
| 8085 | { |
| 8086 | DBObject *db; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8087 | DBSequenceObject *dbs; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8088 | |
| 8089 | while (txn->children_dbs) { |
| 8090 | db=txn->children_dbs; |
| 8091 | EXTRACT_FROM_DOUBLE_LINKED_LIST_TXN(db); |
| 8092 | if (txn->parent_txn) { |
| 8093 | INSERT_IN_DOUBLE_LINKED_LIST_TXN(txn->parent_txn->children_dbs,db); |
| 8094 | db->txn=txn->parent_txn; |
| 8095 | } else { |
| 8096 | /* The db is already linked to its environment, |
| 8097 | ** so nothing to do. |
| 8098 | */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 8099 | db->txn=NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8100 | } |
| 8101 | } |
| 8102 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8103 | while (txn->children_sequences) { |
| 8104 | dbs=txn->children_sequences; |
| 8105 | EXTRACT_FROM_DOUBLE_LINKED_LIST_TXN(dbs); |
| 8106 | if (txn->parent_txn) { |
| 8107 | INSERT_IN_DOUBLE_LINKED_LIST_TXN(txn->parent_txn->children_sequences,dbs); |
| 8108 | dbs->txn=txn->parent_txn; |
| 8109 | } else { |
| 8110 | /* The sequence is already linked to its |
| 8111 | ** parent db. Nothing to do. |
| 8112 | */ |
| 8113 | dbs->txn=NULL; |
| 8114 | } |
| 8115 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8116 | } |
| 8117 | |
| 8118 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8119 | static PyObject* |
| 8120 | DBTxn_commit(DBTxnObject* self, PyObject* args) |
| 8121 | { |
| 8122 | int flags=0, err; |
Gregory P. Smith | c25fd3f | 2003-01-17 07:52:59 +0000 | [diff] [blame] | 8123 | DB_TXN *txn; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8124 | |
| 8125 | if (!PyArg_ParseTuple(args, "|i:commit", &flags)) |
| 8126 | return NULL; |
| 8127 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8128 | _close_transaction_cursors(self); |
| 8129 | |
Gregory P. Smith | c25fd3f | 2003-01-17 07:52:59 +0000 | [diff] [blame] | 8130 | if (!self->txn) { |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 8131 | PyObject *t = Py_BuildValue("(is)", 0, "DBTxn must not be used " |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8132 | "after txn_commit, txn_abort " |
| 8133 | "or txn_discard"); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8134 | if (t) { |
| 8135 | PyErr_SetObject(DBError, t); |
| 8136 | Py_DECREF(t); |
| 8137 | } |
Gregory P. Smith | c25fd3f | 2003-01-17 07:52:59 +0000 | [diff] [blame] | 8138 | return NULL; |
| 8139 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8140 | self->flag_prepare=0; |
Gregory P. Smith | c25fd3f | 2003-01-17 07:52:59 +0000 | [diff] [blame] | 8141 | txn = self->txn; |
| 8142 | self->txn = NULL; /* this DB_TXN is no longer valid after this call */ |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8143 | |
| 8144 | EXTRACT_FROM_DOUBLE_LINKED_LIST(self); |
| 8145 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8146 | MYDB_BEGIN_ALLOW_THREADS; |
Gregory P. Smith | c25fd3f | 2003-01-17 07:52:59 +0000 | [diff] [blame] | 8147 | err = txn->commit(txn, flags); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8148 | MYDB_END_ALLOW_THREADS; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8149 | |
| 8150 | _promote_transaction_dbs_and_sequences(self); |
| 8151 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8152 | RETURN_IF_ERR(); |
| 8153 | RETURN_NONE(); |
| 8154 | } |
| 8155 | |
| 8156 | static PyObject* |
| 8157 | DBTxn_prepare(DBTxnObject* self, PyObject* args) |
| 8158 | { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8159 | int err; |
| 8160 | char* gid=NULL; |
| 8161 | int gid_size=0; |
| 8162 | |
| 8163 | if (!PyArg_ParseTuple(args, "s#:prepare", &gid, &gid_size)) |
| 8164 | return NULL; |
| 8165 | |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 8166 | if (gid_size != DB_GID_SIZE) { |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8167 | PyErr_SetString(PyExc_TypeError, |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 8168 | "gid must be DB_GID_SIZE bytes long"); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8169 | return NULL; |
| 8170 | } |
| 8171 | |
Gregory P. Smith | c25fd3f | 2003-01-17 07:52:59 +0000 | [diff] [blame] | 8172 | if (!self->txn) { |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 8173 | PyObject *t = Py_BuildValue("(is)", 0,"DBTxn must not be used " |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8174 | "after txn_commit, txn_abort " |
| 8175 | "or txn_discard"); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8176 | if (t) { |
| 8177 | PyErr_SetObject(DBError, t); |
| 8178 | Py_DECREF(t); |
| 8179 | } |
Gregory P. Smith | c25fd3f | 2003-01-17 07:52:59 +0000 | [diff] [blame] | 8180 | return NULL; |
| 8181 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8182 | self->flag_prepare=1; /* Prepare state */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8183 | MYDB_BEGIN_ALLOW_THREADS; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8184 | err = self->txn->prepare(self->txn, (u_int8_t*)gid); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8185 | MYDB_END_ALLOW_THREADS; |
| 8186 | RETURN_IF_ERR(); |
| 8187 | RETURN_NONE(); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8188 | } |
| 8189 | |
| 8190 | |
| 8191 | static PyObject* |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8192 | DBTxn_abort_discard_internal(DBTxnObject* self, int discard) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8193 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8194 | PyObject *dummy; |
| 8195 | int err=0; |
Gregory P. Smith | c25fd3f | 2003-01-17 07:52:59 +0000 | [diff] [blame] | 8196 | DB_TXN *txn; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8197 | |
Gregory P. Smith | c25fd3f | 2003-01-17 07:52:59 +0000 | [diff] [blame] | 8198 | if (!self->txn) { |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 8199 | PyObject *t = Py_BuildValue("(is)", 0, "DBTxn must not be used " |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8200 | "after txn_commit, txn_abort " |
| 8201 | "or txn_discard"); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8202 | if (t) { |
| 8203 | PyErr_SetObject(DBError, t); |
| 8204 | Py_DECREF(t); |
| 8205 | } |
Gregory P. Smith | c25fd3f | 2003-01-17 07:52:59 +0000 | [diff] [blame] | 8206 | return NULL; |
| 8207 | } |
| 8208 | txn = self->txn; |
| 8209 | self->txn = NULL; /* this DB_TXN is no longer valid after this call */ |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8210 | |
| 8211 | _close_transaction_cursors(self); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8212 | while (self->children_sequences) { |
| 8213 | dummy=DBSequence_close_internal(self->children_sequences,0,0); |
| 8214 | Py_XDECREF(dummy); |
| 8215 | } |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8216 | while (self->children_dbs) { |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 8217 | dummy=DB_close_internal(self->children_dbs, 0, 0); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8218 | Py_XDECREF(dummy); |
| 8219 | } |
| 8220 | |
| 8221 | EXTRACT_FROM_DOUBLE_LINKED_LIST(self); |
| 8222 | |
| 8223 | MYDB_BEGIN_ALLOW_THREADS; |
| 8224 | if (discard) { |
| 8225 | assert(!self->flag_prepare); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8226 | err = txn->discard(txn,0); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8227 | } else { |
| 8228 | /* |
| 8229 | ** If the transaction is in the "prepare" or "recover" state, |
| 8230 | ** we better do not implicitly abort it. |
| 8231 | */ |
| 8232 | if (!self->flag_prepare) { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8233 | err = txn->abort(txn); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8234 | } |
| 8235 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8236 | MYDB_END_ALLOW_THREADS; |
| 8237 | RETURN_IF_ERR(); |
| 8238 | RETURN_NONE(); |
| 8239 | } |
| 8240 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8241 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8242 | DBTxn_abort(DBTxnObject* self) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8243 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8244 | self->flag_prepare=0; |
| 8245 | _close_transaction_cursors(self); |
| 8246 | |
| 8247 | return DBTxn_abort_discard_internal(self,0); |
| 8248 | } |
| 8249 | |
| 8250 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8251 | DBTxn_discard(DBTxnObject* self) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8252 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8253 | self->flag_prepare=0; |
| 8254 | _close_transaction_cursors(self); |
| 8255 | |
| 8256 | return DBTxn_abort_discard_internal(self,1); |
| 8257 | } |
| 8258 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8259 | |
| 8260 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8261 | DBTxn_id(DBTxnObject* self) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8262 | { |
| 8263 | int id; |
| 8264 | |
Gregory P. Smith | c25fd3f | 2003-01-17 07:52:59 +0000 | [diff] [blame] | 8265 | if (!self->txn) { |
Thomas Wouters | b315383 | 2006-03-08 01:47:19 +0000 | [diff] [blame] | 8266 | PyObject *t = Py_BuildValue("(is)", 0, "DBTxn must not be used " |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8267 | "after txn_commit, txn_abort " |
| 8268 | "or txn_discard"); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8269 | if (t) { |
| 8270 | PyErr_SetObject(DBError, t); |
| 8271 | Py_DECREF(t); |
| 8272 | } |
Gregory P. Smith | c25fd3f | 2003-01-17 07:52:59 +0000 | [diff] [blame] | 8273 | return NULL; |
| 8274 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8275 | MYDB_BEGIN_ALLOW_THREADS; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8276 | id = self->txn->id(self->txn); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8277 | MYDB_END_ALLOW_THREADS; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8278 | return NUMBER_FromLong(id); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8279 | } |
| 8280 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8281 | |
| 8282 | static PyObject* |
| 8283 | DBTxn_set_timeout(DBTxnObject* self, PyObject* args, PyObject* kwargs) |
| 8284 | { |
| 8285 | int err; |
| 8286 | u_int32_t flags=0; |
| 8287 | u_int32_t timeout = 0; |
| 8288 | static char* kwnames[] = { "timeout", "flags", NULL }; |
| 8289 | |
| 8290 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:set_timeout", kwnames, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 8291 | &timeout, &flags)) { |
| 8292 | return NULL; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8293 | } |
| 8294 | |
| 8295 | MYDB_BEGIN_ALLOW_THREADS; |
| 8296 | err = self->txn->set_timeout(self->txn, (db_timeout_t)timeout, flags); |
| 8297 | MYDB_END_ALLOW_THREADS; |
| 8298 | |
| 8299 | RETURN_IF_ERR(); |
| 8300 | RETURN_NONE(); |
| 8301 | } |
| 8302 | |
| 8303 | |
| 8304 | #if (DBVER >= 44) |
| 8305 | static PyObject* |
| 8306 | DBTxn_set_name(DBTxnObject* self, PyObject* args) |
| 8307 | { |
| 8308 | int err; |
| 8309 | const char *name; |
| 8310 | |
| 8311 | if (!PyArg_ParseTuple(args, "s:set_name", &name)) |
| 8312 | return NULL; |
| 8313 | |
| 8314 | MYDB_BEGIN_ALLOW_THREADS; |
| 8315 | err = self->txn->set_name(self->txn, name); |
| 8316 | MYDB_END_ALLOW_THREADS; |
| 8317 | |
| 8318 | RETURN_IF_ERR(); |
| 8319 | RETURN_NONE(); |
| 8320 | } |
| 8321 | #endif |
| 8322 | |
| 8323 | |
| 8324 | #if (DBVER >= 44) |
| 8325 | static PyObject* |
| 8326 | DBTxn_get_name(DBTxnObject* self) |
| 8327 | { |
| 8328 | int err; |
| 8329 | const char *name; |
| 8330 | |
| 8331 | MYDB_BEGIN_ALLOW_THREADS; |
| 8332 | err = self->txn->get_name(self->txn, &name); |
| 8333 | MYDB_END_ALLOW_THREADS; |
| 8334 | |
| 8335 | RETURN_IF_ERR(); |
| 8336 | #if (PY_VERSION_HEX < 0x03000000) |
| 8337 | if (!name) { |
| 8338 | return PyString_FromString(""); |
| 8339 | } |
| 8340 | return PyString_FromString(name); |
| 8341 | #else |
| 8342 | if (!name) { |
| 8343 | return PyUnicode_FromString(""); |
| 8344 | } |
| 8345 | return PyUnicode_FromString(name); |
| 8346 | #endif |
| 8347 | } |
| 8348 | #endif |
| 8349 | |
| 8350 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8351 | /* --------------------------------------------------------------------- */ |
| 8352 | /* DBSequence methods */ |
| 8353 | |
| 8354 | |
| 8355 | static PyObject* |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8356 | DBSequence_close_internal(DBSequenceObject* self, int flags, int do_not_close) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8357 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8358 | int err=0; |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8359 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8360 | if (self->sequence!=NULL) { |
| 8361 | EXTRACT_FROM_DOUBLE_LINKED_LIST(self); |
| 8362 | if (self->txn) { |
| 8363 | EXTRACT_FROM_DOUBLE_LINKED_LIST_TXN(self); |
| 8364 | self->txn=NULL; |
| 8365 | } |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8366 | |
Jesus Cea | 5cd5f12 | 2008-09-23 18:54:08 +0000 | [diff] [blame] | 8367 | /* |
| 8368 | ** "do_not_close" is used to dispose all related objects in the |
| 8369 | ** tree, without actually releasing the "root" object. |
| 8370 | ** This is done, for example, because function calls like |
| 8371 | ** "DBSequence.remove()" implicitly close the underlying handle. So |
| 8372 | ** the handle doesn't need to be closed, but related objects |
| 8373 | ** must be cleaned up. |
| 8374 | */ |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8375 | if (!do_not_close) { |
| 8376 | MYDB_BEGIN_ALLOW_THREADS |
| 8377 | err = self->sequence->close(self->sequence, flags); |
| 8378 | MYDB_END_ALLOW_THREADS |
| 8379 | } |
| 8380 | self->sequence = NULL; |
| 8381 | |
| 8382 | RETURN_IF_ERR(); |
| 8383 | } |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8384 | |
| 8385 | RETURN_NONE(); |
| 8386 | } |
| 8387 | |
| 8388 | static PyObject* |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8389 | DBSequence_close(DBSequenceObject* self, PyObject* args) |
| 8390 | { |
| 8391 | int flags=0; |
| 8392 | if (!PyArg_ParseTuple(args,"|i:close", &flags)) |
| 8393 | return NULL; |
| 8394 | |
| 8395 | return DBSequence_close_internal(self,flags,0); |
| 8396 | } |
| 8397 | |
| 8398 | static PyObject* |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8399 | DBSequence_get(DBSequenceObject* self, PyObject* args, PyObject* kwargs) |
| 8400 | { |
| 8401 | int err, flags = 0; |
| 8402 | int delta = 1; |
| 8403 | db_seq_t value; |
| 8404 | PyObject *txnobj = NULL; |
| 8405 | DB_TXN *txn = NULL; |
| 8406 | static char* kwnames[] = {"delta", "txn", "flags", NULL }; |
| 8407 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iOi:get", kwnames, &delta, &txnobj, &flags)) |
| 8408 | return NULL; |
| 8409 | CHECK_SEQUENCE_NOT_CLOSED(self) |
| 8410 | |
| 8411 | if (!checkTxnObj(txnobj, &txn)) |
| 8412 | return NULL; |
| 8413 | |
| 8414 | MYDB_BEGIN_ALLOW_THREADS |
| 8415 | err = self->sequence->get(self->sequence, txn, delta, &value, flags); |
| 8416 | MYDB_END_ALLOW_THREADS |
| 8417 | |
| 8418 | RETURN_IF_ERR(); |
| 8419 | return PyLong_FromLongLong(value); |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8420 | } |
| 8421 | |
| 8422 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8423 | DBSequence_get_dbp(DBSequenceObject* self) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8424 | { |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8425 | CHECK_SEQUENCE_NOT_CLOSED(self) |
| 8426 | Py_INCREF(self->mydb); |
| 8427 | return (PyObject* )self->mydb; |
| 8428 | } |
| 8429 | |
| 8430 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8431 | DBSequence_get_key(DBSequenceObject* self) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8432 | { |
| 8433 | int err; |
| 8434 | DBT key; |
Neal Norwitz | 088beae | 2007-10-12 03:01:54 +0000 | [diff] [blame] | 8435 | PyObject *retval = NULL; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8436 | |
Gregory P. Smith | e70be5c | 2007-10-06 07:48:10 +0000 | [diff] [blame] | 8437 | key.flags = DB_DBT_MALLOC; |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8438 | CHECK_SEQUENCE_NOT_CLOSED(self) |
| 8439 | MYDB_BEGIN_ALLOW_THREADS |
| 8440 | err = self->sequence->get_key(self->sequence, &key); |
| 8441 | MYDB_END_ALLOW_THREADS |
| 8442 | |
Gregory P. Smith | e70be5c | 2007-10-06 07:48:10 +0000 | [diff] [blame] | 8443 | if (!err) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8444 | retval = Build_PyString(key.data, key.size); |
Gregory P. Smith | e70be5c | 2007-10-06 07:48:10 +0000 | [diff] [blame] | 8445 | |
| 8446 | FREE_DBT(key); |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8447 | RETURN_IF_ERR(); |
| 8448 | |
Gregory P. Smith | e70be5c | 2007-10-06 07:48:10 +0000 | [diff] [blame] | 8449 | return retval; |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8450 | } |
| 8451 | |
| 8452 | static PyObject* |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8453 | DBSequence_initial_value(DBSequenceObject* self, PyObject* args) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8454 | { |
| 8455 | int err; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8456 | PY_LONG_LONG value; |
| 8457 | db_seq_t value2; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8458 | if (!PyArg_ParseTuple(args,"L:initial_value", &value)) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8459 | return NULL; |
| 8460 | CHECK_SEQUENCE_NOT_CLOSED(self) |
| 8461 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8462 | value2=value; /* If truncation, compiler should show a warning */ |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8463 | MYDB_BEGIN_ALLOW_THREADS |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8464 | err = self->sequence->initial_value(self->sequence, value2); |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8465 | MYDB_END_ALLOW_THREADS |
| 8466 | |
| 8467 | RETURN_IF_ERR(); |
| 8468 | |
| 8469 | RETURN_NONE(); |
| 8470 | } |
| 8471 | |
| 8472 | static PyObject* |
| 8473 | DBSequence_open(DBSequenceObject* self, PyObject* args, PyObject* kwargs) |
| 8474 | { |
| 8475 | int err, flags = 0; |
| 8476 | PyObject* keyobj; |
| 8477 | PyObject *txnobj = NULL; |
| 8478 | DB_TXN *txn = NULL; |
| 8479 | DBT key; |
| 8480 | |
| 8481 | static char* kwnames[] = {"key", "txn", "flags", NULL }; |
Neal Norwitz | dd2a6bf | 2006-06-06 07:23:01 +0000 | [diff] [blame] | 8482 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi:open", kwnames, &keyobj, &txnobj, &flags)) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8483 | return NULL; |
| 8484 | |
| 8485 | if (!checkTxnObj(txnobj, &txn)) |
| 8486 | return NULL; |
| 8487 | |
| 8488 | if (!make_key_dbt(self->mydb, keyobj, &key, NULL)) |
| 8489 | return NULL; |
| 8490 | |
| 8491 | MYDB_BEGIN_ALLOW_THREADS |
| 8492 | err = self->sequence->open(self->sequence, txn, &key, flags); |
| 8493 | MYDB_END_ALLOW_THREADS |
| 8494 | |
Jesus Cea | ac25fab | 2008-09-03 17:50:32 +0000 | [diff] [blame] | 8495 | FREE_DBT(key); |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8496 | RETURN_IF_ERR(); |
| 8497 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8498 | if (txn) { |
| 8499 | INSERT_IN_DOUBLE_LINKED_LIST_TXN(((DBTxnObject *)txnobj)->children_sequences,self); |
| 8500 | self->txn=(DBTxnObject *)txnobj; |
| 8501 | } |
| 8502 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8503 | RETURN_NONE(); |
| 8504 | } |
| 8505 | |
| 8506 | static PyObject* |
| 8507 | DBSequence_remove(DBSequenceObject* self, PyObject* args, PyObject* kwargs) |
| 8508 | { |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8509 | PyObject *dummy; |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8510 | int err, flags = 0; |
| 8511 | PyObject *txnobj = NULL; |
| 8512 | DB_TXN *txn = NULL; |
| 8513 | |
| 8514 | static char* kwnames[] = {"txn", "flags", NULL }; |
Neal Norwitz | dd2a6bf | 2006-06-06 07:23:01 +0000 | [diff] [blame] | 8515 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Oi:remove", kwnames, &txnobj, &flags)) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8516 | return NULL; |
| 8517 | |
| 8518 | if (!checkTxnObj(txnobj, &txn)) |
| 8519 | return NULL; |
| 8520 | |
| 8521 | CHECK_SEQUENCE_NOT_CLOSED(self) |
| 8522 | |
| 8523 | MYDB_BEGIN_ALLOW_THREADS |
| 8524 | err = self->sequence->remove(self->sequence, txn, flags); |
| 8525 | MYDB_END_ALLOW_THREADS |
| 8526 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8527 | dummy=DBSequence_close_internal(self,flags,1); |
| 8528 | Py_XDECREF(dummy); |
| 8529 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8530 | RETURN_IF_ERR(); |
| 8531 | RETURN_NONE(); |
| 8532 | } |
| 8533 | |
| 8534 | static PyObject* |
| 8535 | DBSequence_set_cachesize(DBSequenceObject* self, PyObject* args) |
| 8536 | { |
| 8537 | int err, size; |
Neal Norwitz | dd2a6bf | 2006-06-06 07:23:01 +0000 | [diff] [blame] | 8538 | if (!PyArg_ParseTuple(args,"i:set_cachesize", &size)) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8539 | return NULL; |
| 8540 | CHECK_SEQUENCE_NOT_CLOSED(self) |
| 8541 | |
| 8542 | MYDB_BEGIN_ALLOW_THREADS |
| 8543 | err = self->sequence->set_cachesize(self->sequence, size); |
| 8544 | MYDB_END_ALLOW_THREADS |
| 8545 | |
| 8546 | RETURN_IF_ERR(); |
| 8547 | RETURN_NONE(); |
| 8548 | } |
| 8549 | |
| 8550 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8551 | DBSequence_get_cachesize(DBSequenceObject* self) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8552 | { |
| 8553 | int err, size; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8554 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8555 | CHECK_SEQUENCE_NOT_CLOSED(self) |
| 8556 | |
| 8557 | MYDB_BEGIN_ALLOW_THREADS |
| 8558 | err = self->sequence->get_cachesize(self->sequence, &size); |
| 8559 | MYDB_END_ALLOW_THREADS |
| 8560 | |
| 8561 | RETURN_IF_ERR(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8562 | return NUMBER_FromLong(size); |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8563 | } |
| 8564 | |
| 8565 | static PyObject* |
| 8566 | DBSequence_set_flags(DBSequenceObject* self, PyObject* args) |
| 8567 | { |
| 8568 | int err, flags = 0; |
Neal Norwitz | dd2a6bf | 2006-06-06 07:23:01 +0000 | [diff] [blame] | 8569 | if (!PyArg_ParseTuple(args,"i:set_flags", &flags)) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8570 | return NULL; |
| 8571 | CHECK_SEQUENCE_NOT_CLOSED(self) |
| 8572 | |
| 8573 | MYDB_BEGIN_ALLOW_THREADS |
| 8574 | err = self->sequence->set_flags(self->sequence, flags); |
| 8575 | MYDB_END_ALLOW_THREADS |
| 8576 | |
| 8577 | RETURN_IF_ERR(); |
| 8578 | RETURN_NONE(); |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8579 | } |
| 8580 | |
| 8581 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8582 | DBSequence_get_flags(DBSequenceObject* self) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8583 | { |
| 8584 | unsigned int flags; |
| 8585 | int err; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8586 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8587 | CHECK_SEQUENCE_NOT_CLOSED(self) |
| 8588 | |
| 8589 | MYDB_BEGIN_ALLOW_THREADS |
| 8590 | err = self->sequence->get_flags(self->sequence, &flags); |
| 8591 | MYDB_END_ALLOW_THREADS |
| 8592 | |
| 8593 | RETURN_IF_ERR(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8594 | return NUMBER_FromLong((int)flags); |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8595 | } |
| 8596 | |
| 8597 | static PyObject* |
| 8598 | DBSequence_set_range(DBSequenceObject* self, PyObject* args) |
| 8599 | { |
| 8600 | int err; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8601 | PY_LONG_LONG min, max; |
| 8602 | db_seq_t min2, max2; |
Tim Peters | bb21b2c | 2006-06-06 15:50:17 +0000 | [diff] [blame] | 8603 | if (!PyArg_ParseTuple(args,"(LL):set_range", &min, &max)) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8604 | return NULL; |
| 8605 | CHECK_SEQUENCE_NOT_CLOSED(self) |
| 8606 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8607 | min2=min; /* If truncation, compiler should show a warning */ |
| 8608 | max2=max; |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8609 | MYDB_BEGIN_ALLOW_THREADS |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8610 | err = self->sequence->set_range(self->sequence, min2, max2); |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8611 | MYDB_END_ALLOW_THREADS |
| 8612 | |
| 8613 | RETURN_IF_ERR(); |
| 8614 | RETURN_NONE(); |
| 8615 | } |
| 8616 | |
| 8617 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8618 | DBSequence_get_range(DBSequenceObject* self) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8619 | { |
| 8620 | int err; |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8621 | PY_LONG_LONG min, max; |
| 8622 | db_seq_t min2, max2; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8623 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8624 | CHECK_SEQUENCE_NOT_CLOSED(self) |
| 8625 | |
| 8626 | MYDB_BEGIN_ALLOW_THREADS |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8627 | err = self->sequence->get_range(self->sequence, &min2, &max2); |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8628 | MYDB_END_ALLOW_THREADS |
| 8629 | |
| 8630 | RETURN_IF_ERR(); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 8631 | min=min2; /* If truncation, compiler should show a warning */ |
| 8632 | max=max2; |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8633 | return Py_BuildValue("(LL)", min, max); |
| 8634 | } |
| 8635 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8636 | |
| 8637 | static PyObject* |
| 8638 | DBSequence_stat_print(DBSequenceObject* self, PyObject* args, PyObject *kwargs) |
| 8639 | { |
| 8640 | int err; |
| 8641 | int flags=0; |
| 8642 | static char* kwnames[] = { "flags", NULL }; |
| 8643 | |
| 8644 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:stat_print", |
| 8645 | kwnames, &flags)) |
| 8646 | { |
| 8647 | return NULL; |
| 8648 | } |
| 8649 | |
| 8650 | CHECK_SEQUENCE_NOT_CLOSED(self); |
| 8651 | |
| 8652 | MYDB_BEGIN_ALLOW_THREADS; |
| 8653 | err = self->sequence->stat_print(self->sequence, flags); |
| 8654 | MYDB_END_ALLOW_THREADS; |
| 8655 | RETURN_IF_ERR(); |
| 8656 | RETURN_NONE(); |
| 8657 | } |
| 8658 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8659 | static PyObject* |
| 8660 | DBSequence_stat(DBSequenceObject* self, PyObject* args, PyObject* kwargs) |
| 8661 | { |
| 8662 | int err, flags = 0; |
| 8663 | DB_SEQUENCE_STAT* sp = NULL; |
| 8664 | PyObject* dict_stat; |
| 8665 | static char* kwnames[] = {"flags", NULL }; |
| 8666 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:stat", kwnames, &flags)) |
| 8667 | return NULL; |
| 8668 | CHECK_SEQUENCE_NOT_CLOSED(self); |
| 8669 | |
| 8670 | MYDB_BEGIN_ALLOW_THREADS; |
| 8671 | err = self->sequence->stat(self->sequence, &sp, flags); |
| 8672 | MYDB_END_ALLOW_THREADS; |
| 8673 | RETURN_IF_ERR(); |
| 8674 | |
| 8675 | if ((dict_stat = PyDict_New()) == NULL) { |
| 8676 | free(sp); |
| 8677 | return NULL; |
| 8678 | } |
| 8679 | |
| 8680 | |
| 8681 | #define MAKE_INT_ENTRY(name) _addIntToDict(dict_stat, #name, sp->st_##name) |
| 8682 | #define MAKE_LONG_LONG_ENTRY(name) _addDb_seq_tToDict(dict_stat, #name, sp->st_##name) |
| 8683 | |
| 8684 | MAKE_INT_ENTRY(wait); |
| 8685 | MAKE_INT_ENTRY(nowait); |
| 8686 | MAKE_LONG_LONG_ENTRY(current); |
| 8687 | MAKE_LONG_LONG_ENTRY(value); |
| 8688 | MAKE_LONG_LONG_ENTRY(last_value); |
| 8689 | MAKE_LONG_LONG_ENTRY(min); |
| 8690 | MAKE_LONG_LONG_ENTRY(max); |
| 8691 | MAKE_INT_ENTRY(cache_size); |
| 8692 | MAKE_INT_ENTRY(flags); |
| 8693 | |
| 8694 | #undef MAKE_INT_ENTRY |
| 8695 | #undef MAKE_LONG_LONG_ENTRY |
| 8696 | |
| 8697 | free(sp); |
| 8698 | return dict_stat; |
| 8699 | } |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 8700 | |
| 8701 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8702 | /* --------------------------------------------------------------------- */ |
| 8703 | /* Method definition tables and type objects */ |
| 8704 | |
| 8705 | static PyMethodDef DB_methods[] = { |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 8706 | {"append", (PyCFunction)DB_append, METH_VARARGS|METH_KEYWORDS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8707 | {"associate", (PyCFunction)DB_associate, METH_VARARGS|METH_KEYWORDS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8708 | {"close", (PyCFunction)DB_close, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8709 | #if (DBVER >= 47) |
| 8710 | {"compact", (PyCFunction)DB_compact, METH_VARARGS|METH_KEYWORDS}, |
| 8711 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8712 | {"consume", (PyCFunction)DB_consume, METH_VARARGS|METH_KEYWORDS}, |
| 8713 | {"consume_wait", (PyCFunction)DB_consume_wait, METH_VARARGS|METH_KEYWORDS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8714 | {"cursor", (PyCFunction)DB_cursor, METH_VARARGS|METH_KEYWORDS}, |
| 8715 | {"delete", (PyCFunction)DB_delete, METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8716 | {"fd", (PyCFunction)DB_fd, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8717 | #if (DBVER >= 46) |
| 8718 | {"exists", (PyCFunction)DB_exists, |
| 8719 | METH_VARARGS|METH_KEYWORDS}, |
| 8720 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8721 | {"get", (PyCFunction)DB_get, METH_VARARGS|METH_KEYWORDS}, |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 8722 | {"pget", (PyCFunction)DB_pget, METH_VARARGS|METH_KEYWORDS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8723 | {"get_both", (PyCFunction)DB_get_both, METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8724 | {"get_byteswapped", (PyCFunction)DB_get_byteswapped,METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8725 | {"get_size", (PyCFunction)DB_get_size, METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8726 | {"get_type", (PyCFunction)DB_get_type, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8727 | {"join", (PyCFunction)DB_join, METH_VARARGS}, |
| 8728 | {"key_range", (PyCFunction)DB_key_range, METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 4907d27 | 2008-08-31 14:00:51 +0000 | [diff] [blame] | 8729 | {"has_key", (PyCFunction)DB_has_key, METH_VARARGS|METH_KEYWORDS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8730 | {"items", (PyCFunction)DB_items, METH_VARARGS}, |
| 8731 | {"keys", (PyCFunction)DB_keys, METH_VARARGS}, |
| 8732 | {"open", (PyCFunction)DB_open, METH_VARARGS|METH_KEYWORDS}, |
| 8733 | {"put", (PyCFunction)DB_put, METH_VARARGS|METH_KEYWORDS}, |
| 8734 | {"remove", (PyCFunction)DB_remove, METH_VARARGS|METH_KEYWORDS}, |
| 8735 | {"rename", (PyCFunction)DB_rename, METH_VARARGS}, |
| 8736 | {"set_bt_minkey", (PyCFunction)DB_set_bt_minkey, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8737 | {"get_bt_minkey", (PyCFunction)DB_get_bt_minkey, METH_NOARGS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8738 | {"set_bt_compare", (PyCFunction)DB_set_bt_compare, METH_O}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8739 | {"set_cachesize", (PyCFunction)DB_set_cachesize, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8740 | {"get_cachesize", (PyCFunction)DB_get_cachesize, METH_NOARGS}, |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 8741 | {"set_dup_compare", (PyCFunction)DB_set_dup_compare, METH_O}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8742 | {"set_encrypt", (PyCFunction)DB_set_encrypt, METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8743 | {"get_encrypt_flags", (PyCFunction)DB_get_encrypt_flags, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8744 | {"set_flags", (PyCFunction)DB_set_flags, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8745 | {"get_flags", (PyCFunction)DB_get_flags, METH_NOARGS}, |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 8746 | {"get_transactional", (PyCFunction)DB_get_transactional, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8747 | {"set_h_ffactor", (PyCFunction)DB_set_h_ffactor, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8748 | {"get_h_ffactor", (PyCFunction)DB_get_h_ffactor, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8749 | {"set_h_nelem", (PyCFunction)DB_set_h_nelem, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8750 | {"get_h_nelem", (PyCFunction)DB_get_h_nelem, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8751 | {"set_lorder", (PyCFunction)DB_set_lorder, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8752 | {"get_lorder", (PyCFunction)DB_get_lorder, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8753 | {"set_pagesize", (PyCFunction)DB_set_pagesize, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8754 | {"get_pagesize", (PyCFunction)DB_get_pagesize, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8755 | {"set_re_delim", (PyCFunction)DB_set_re_delim, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8756 | {"get_re_delim", (PyCFunction)DB_get_re_delim, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8757 | {"set_re_len", (PyCFunction)DB_set_re_len, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8758 | {"get_re_len", (PyCFunction)DB_get_re_len, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8759 | {"set_re_pad", (PyCFunction)DB_set_re_pad, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8760 | {"get_re_pad", (PyCFunction)DB_get_re_pad, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8761 | {"set_re_source", (PyCFunction)DB_set_re_source, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8762 | {"get_re_source", (PyCFunction)DB_get_re_source, METH_NOARGS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8763 | {"set_q_extentsize",(PyCFunction)DB_set_q_extentsize, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8764 | {"get_q_extentsize",(PyCFunction)DB_get_q_extentsize, METH_NOARGS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8765 | {"set_private", (PyCFunction)DB_set_private, METH_O}, |
| 8766 | {"get_private", (PyCFunction)DB_get_private, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8767 | #if (DBVER >= 46) |
| 8768 | {"set_priority", (PyCFunction)DB_set_priority, METH_VARARGS}, |
| 8769 | {"get_priority", (PyCFunction)DB_get_priority, METH_NOARGS}, |
| 8770 | #endif |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 8771 | {"get_dbname", (PyCFunction)DB_get_dbname, METH_NOARGS}, |
| 8772 | {"get_open_flags", (PyCFunction)DB_get_open_flags, METH_NOARGS}, |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 8773 | {"stat", (PyCFunction)DB_stat, METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8774 | {"stat_print", (PyCFunction)DB_stat_print, |
| 8775 | METH_VARARGS|METH_KEYWORDS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8776 | {"sync", (PyCFunction)DB_sync, METH_VARARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8777 | {"truncate", (PyCFunction)DB_truncate, METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8778 | {"type", (PyCFunction)DB_get_type, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8779 | {"upgrade", (PyCFunction)DB_upgrade, METH_VARARGS}, |
| 8780 | {"values", (PyCFunction)DB_values, METH_VARARGS}, |
| 8781 | {"verify", (PyCFunction)DB_verify, METH_VARARGS|METH_KEYWORDS}, |
| 8782 | {"set_get_returns_none",(PyCFunction)DB_set_get_returns_none, METH_VARARGS}, |
| 8783 | {NULL, NULL} /* sentinel */ |
| 8784 | }; |
| 8785 | |
| 8786 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8787 | /* We need this to support __contains__() */ |
| 8788 | static PySequenceMethods DB_sequence = { |
| 8789 | 0, /* sq_length, mapping wins here */ |
| 8790 | 0, /* sq_concat */ |
| 8791 | 0, /* sq_repeat */ |
| 8792 | 0, /* sq_item */ |
| 8793 | 0, /* sq_slice */ |
| 8794 | 0, /* sq_ass_item */ |
| 8795 | 0, /* sq_ass_slice */ |
| 8796 | (objobjproc)DB_contains, /* sq_contains */ |
| 8797 | 0, /* sq_inplace_concat */ |
| 8798 | 0, /* sq_inplace_repeat */ |
| 8799 | }; |
| 8800 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8801 | static PyMappingMethods DB_mapping = { |
Martin v. Löwis | 70ee3cc | 2006-06-12 04:26:31 +0000 | [diff] [blame] | 8802 | DB_length, /*mp_length*/ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8803 | (binaryfunc)DB_subscript, /*mp_subscript*/ |
| 8804 | (objobjargproc)DB_ass_sub, /*mp_ass_subscript*/ |
| 8805 | }; |
| 8806 | |
| 8807 | |
| 8808 | static PyMethodDef DBCursor_methods[] = { |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8809 | {"close", (PyCFunction)DBC_close, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8810 | {"count", (PyCFunction)DBC_count, METH_VARARGS}, |
| 8811 | {"current", (PyCFunction)DBC_current, METH_VARARGS|METH_KEYWORDS}, |
| 8812 | {"delete", (PyCFunction)DBC_delete, METH_VARARGS}, |
| 8813 | {"dup", (PyCFunction)DBC_dup, METH_VARARGS}, |
| 8814 | {"first", (PyCFunction)DBC_first, METH_VARARGS|METH_KEYWORDS}, |
| 8815 | {"get", (PyCFunction)DBC_get, METH_VARARGS|METH_KEYWORDS}, |
Gregory P. Smith | 19699a9 | 2004-06-28 04:06:49 +0000 | [diff] [blame] | 8816 | {"pget", (PyCFunction)DBC_pget, METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8817 | {"get_recno", (PyCFunction)DBC_get_recno, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8818 | {"last", (PyCFunction)DBC_last, METH_VARARGS|METH_KEYWORDS}, |
| 8819 | {"next", (PyCFunction)DBC_next, METH_VARARGS|METH_KEYWORDS}, |
| 8820 | {"prev", (PyCFunction)DBC_prev, METH_VARARGS|METH_KEYWORDS}, |
| 8821 | {"put", (PyCFunction)DBC_put, METH_VARARGS|METH_KEYWORDS}, |
| 8822 | {"set", (PyCFunction)DBC_set, METH_VARARGS|METH_KEYWORDS}, |
| 8823 | {"set_range", (PyCFunction)DBC_set_range, METH_VARARGS|METH_KEYWORDS}, |
| 8824 | {"get_both", (PyCFunction)DBC_get_both, METH_VARARGS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 8825 | {"get_current_size",(PyCFunction)DBC_get_current_size, METH_NOARGS}, |
Gregory P. Smith | 455d46f | 2003-07-09 04:45:59 +0000 | [diff] [blame] | 8826 | {"set_both", (PyCFunction)DBC_set_both, METH_VARARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8827 | {"set_recno", (PyCFunction)DBC_set_recno, METH_VARARGS|METH_KEYWORDS}, |
| 8828 | {"consume", (PyCFunction)DBC_consume, METH_VARARGS|METH_KEYWORDS}, |
| 8829 | {"next_dup", (PyCFunction)DBC_next_dup, METH_VARARGS|METH_KEYWORDS}, |
| 8830 | {"next_nodup", (PyCFunction)DBC_next_nodup, METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8831 | #if (DBVER >= 46) |
| 8832 | {"prev_dup", (PyCFunction)DBC_prev_dup, |
| 8833 | METH_VARARGS|METH_KEYWORDS}, |
| 8834 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8835 | {"prev_nodup", (PyCFunction)DBC_prev_nodup, METH_VARARGS|METH_KEYWORDS}, |
| 8836 | {"join_item", (PyCFunction)DBC_join_item, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8837 | #if (DBVER >= 46) |
| 8838 | {"set_priority", (PyCFunction)DBC_set_priority, |
| 8839 | METH_VARARGS|METH_KEYWORDS}, |
| 8840 | {"get_priority", (PyCFunction)DBC_get_priority, METH_NOARGS}, |
| 8841 | #endif |
| 8842 | {NULL, NULL} /* sentinel */ |
| 8843 | }; |
| 8844 | |
| 8845 | |
| 8846 | static PyMethodDef DBLogCursor_methods[] = { |
| 8847 | {"close", (PyCFunction)DBLogCursor_close, METH_NOARGS}, |
| 8848 | {"current", (PyCFunction)DBLogCursor_current, METH_NOARGS}, |
| 8849 | {"first", (PyCFunction)DBLogCursor_first, METH_NOARGS}, |
| 8850 | {"last", (PyCFunction)DBLogCursor_last, METH_NOARGS}, |
| 8851 | {"next", (PyCFunction)DBLogCursor_next, METH_NOARGS}, |
| 8852 | {"prev", (PyCFunction)DBLogCursor_prev, METH_NOARGS}, |
| 8853 | {"set", (PyCFunction)DBLogCursor_set, METH_VARARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8854 | {NULL, NULL} /* sentinel */ |
| 8855 | }; |
| 8856 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 8857 | #if (DBVER >= 52) |
| 8858 | static PyMethodDef DBSite_methods[] = { |
| 8859 | {"get_config", (PyCFunction)DBSite_get_config, |
| 8860 | METH_VARARGS | METH_KEYWORDS}, |
| 8861 | {"set_config", (PyCFunction)DBSite_set_config, |
| 8862 | METH_VARARGS | METH_KEYWORDS}, |
| 8863 | {"remove", (PyCFunction)DBSite_remove, METH_NOARGS}, |
| 8864 | {"get_eid", (PyCFunction)DBSite_get_eid, METH_NOARGS}, |
| 8865 | {"get_address", (PyCFunction)DBSite_get_address, METH_NOARGS}, |
| 8866 | {"close", (PyCFunction)DBSite_close, METH_NOARGS}, |
| 8867 | {NULL, NULL} /* sentinel */ |
| 8868 | }; |
| 8869 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8870 | |
| 8871 | static PyMethodDef DBEnv_methods[] = { |
| 8872 | {"close", (PyCFunction)DBEnv_close, METH_VARARGS}, |
| 8873 | {"open", (PyCFunction)DBEnv_open, METH_VARARGS}, |
| 8874 | {"remove", (PyCFunction)DBEnv_remove, METH_VARARGS}, |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 8875 | {"dbremove", (PyCFunction)DBEnv_dbremove, METH_VARARGS|METH_KEYWORDS}, |
| 8876 | {"dbrename", (PyCFunction)DBEnv_dbrename, METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8877 | #if (DBVER >= 46) |
| 8878 | {"set_thread_count", (PyCFunction)DBEnv_set_thread_count, METH_VARARGS}, |
| 8879 | {"get_thread_count", (PyCFunction)DBEnv_get_thread_count, METH_NOARGS}, |
| 8880 | #endif |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 8881 | {"set_encrypt", (PyCFunction)DBEnv_set_encrypt, METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8882 | {"get_encrypt_flags", (PyCFunction)DBEnv_get_encrypt_flags, METH_NOARGS}, |
| 8883 | {"get_timeout", (PyCFunction)DBEnv_get_timeout, |
| 8884 | METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8885 | {"set_timeout", (PyCFunction)DBEnv_set_timeout, METH_VARARGS|METH_KEYWORDS}, |
| 8886 | {"set_shm_key", (PyCFunction)DBEnv_set_shm_key, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8887 | {"get_shm_key", (PyCFunction)DBEnv_get_shm_key, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8888 | #if (DBVER >= 46) |
| 8889 | {"set_cache_max", (PyCFunction)DBEnv_set_cache_max, METH_VARARGS}, |
| 8890 | {"get_cache_max", (PyCFunction)DBEnv_get_cache_max, METH_NOARGS}, |
| 8891 | #endif |
| 8892 | {"set_cachesize", (PyCFunction)DBEnv_set_cachesize, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8893 | {"get_cachesize", (PyCFunction)DBEnv_get_cachesize, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8894 | {"memp_trickle", (PyCFunction)DBEnv_memp_trickle, METH_VARARGS}, |
| 8895 | {"memp_sync", (PyCFunction)DBEnv_memp_sync, METH_VARARGS}, |
| 8896 | {"memp_stat", (PyCFunction)DBEnv_memp_stat, |
| 8897 | METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8898 | {"memp_stat_print", (PyCFunction)DBEnv_memp_stat_print, |
| 8899 | METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8900 | #if (DBVER >= 44) |
| 8901 | {"mutex_set_max", (PyCFunction)DBEnv_mutex_set_max, METH_VARARGS}, |
| 8902 | {"mutex_get_max", (PyCFunction)DBEnv_mutex_get_max, METH_NOARGS}, |
| 8903 | {"mutex_set_align", (PyCFunction)DBEnv_mutex_set_align, METH_VARARGS}, |
| 8904 | {"mutex_get_align", (PyCFunction)DBEnv_mutex_get_align, METH_NOARGS}, |
| 8905 | {"mutex_set_increment", (PyCFunction)DBEnv_mutex_set_increment, |
| 8906 | METH_VARARGS}, |
| 8907 | {"mutex_get_increment", (PyCFunction)DBEnv_mutex_get_increment, |
| 8908 | METH_NOARGS}, |
| 8909 | {"mutex_set_tas_spins", (PyCFunction)DBEnv_mutex_set_tas_spins, |
| 8910 | METH_VARARGS}, |
| 8911 | {"mutex_get_tas_spins", (PyCFunction)DBEnv_mutex_get_tas_spins, |
| 8912 | METH_NOARGS}, |
| 8913 | {"mutex_stat", (PyCFunction)DBEnv_mutex_stat, METH_VARARGS}, |
| 8914 | #if (DBVER >= 44) |
| 8915 | {"mutex_stat_print", (PyCFunction)DBEnv_mutex_stat_print, |
| 8916 | METH_VARARGS|METH_KEYWORDS}, |
| 8917 | #endif |
| 8918 | #endif |
| 8919 | {"set_data_dir", (PyCFunction)DBEnv_set_data_dir, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8920 | {"get_data_dirs", (PyCFunction)DBEnv_get_data_dirs, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8921 | {"get_flags", (PyCFunction)DBEnv_get_flags, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8922 | {"set_flags", (PyCFunction)DBEnv_set_flags, METH_VARARGS}, |
| 8923 | #if (DBVER >= 47) |
| 8924 | {"log_set_config", (PyCFunction)DBEnv_log_set_config, METH_VARARGS}, |
| 8925 | {"log_get_config", (PyCFunction)DBEnv_log_get_config, METH_VARARGS}, |
| 8926 | #endif |
| 8927 | {"set_lg_bsize", (PyCFunction)DBEnv_set_lg_bsize, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8928 | {"get_lg_bsize", (PyCFunction)DBEnv_get_lg_bsize, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8929 | {"set_lg_dir", (PyCFunction)DBEnv_set_lg_dir, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8930 | {"get_lg_dir", (PyCFunction)DBEnv_get_lg_dir, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8931 | {"set_lg_max", (PyCFunction)DBEnv_set_lg_max, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8932 | {"get_lg_max", (PyCFunction)DBEnv_get_lg_max, METH_NOARGS}, |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 8933 | {"set_lg_regionmax",(PyCFunction)DBEnv_set_lg_regionmax, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8934 | {"get_lg_regionmax",(PyCFunction)DBEnv_get_lg_regionmax, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8935 | #if (DBVER >= 44) |
| 8936 | {"set_lg_filemode", (PyCFunction)DBEnv_set_lg_filemode, METH_VARARGS}, |
| 8937 | {"get_lg_filemode", (PyCFunction)DBEnv_get_lg_filemode, METH_NOARGS}, |
| 8938 | #endif |
| 8939 | #if (DBVER >= 47) |
| 8940 | {"set_lk_partitions", (PyCFunction)DBEnv_set_lk_partitions, METH_VARARGS}, |
| 8941 | {"get_lk_partitions", (PyCFunction)DBEnv_get_lk_partitions, METH_NOARGS}, |
| 8942 | #endif |
| 8943 | {"set_lk_detect", (PyCFunction)DBEnv_set_lk_detect, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8944 | {"get_lk_detect", (PyCFunction)DBEnv_get_lk_detect, METH_NOARGS}, |
Gregory P. Smith | 8b96a35 | 2007-01-05 01:59:42 +0000 | [diff] [blame] | 8945 | #if (DBVER < 45) |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8946 | {"set_lk_max", (PyCFunction)DBEnv_set_lk_max, METH_VARARGS}, |
Gregory P. Smith | 8b96a35 | 2007-01-05 01:59:42 +0000 | [diff] [blame] | 8947 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8948 | {"set_lk_max_locks", (PyCFunction)DBEnv_set_lk_max_locks, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8949 | {"get_lk_max_locks", (PyCFunction)DBEnv_get_lk_max_locks, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8950 | {"set_lk_max_lockers", (PyCFunction)DBEnv_set_lk_max_lockers, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8951 | {"get_lk_max_lockers", (PyCFunction)DBEnv_get_lk_max_lockers, METH_NOARGS}, |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8952 | {"set_lk_max_objects", (PyCFunction)DBEnv_set_lk_max_objects, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8953 | {"get_lk_max_objects", (PyCFunction)DBEnv_get_lk_max_objects, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8954 | {"stat_print", (PyCFunction)DBEnv_stat_print, |
| 8955 | METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8956 | {"set_mp_mmapsize", (PyCFunction)DBEnv_set_mp_mmapsize, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8957 | {"get_mp_mmapsize", (PyCFunction)DBEnv_get_mp_mmapsize, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8958 | {"set_tmp_dir", (PyCFunction)DBEnv_set_tmp_dir, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8959 | {"get_tmp_dir", (PyCFunction)DBEnv_get_tmp_dir, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8960 | {"txn_begin", (PyCFunction)DBEnv_txn_begin, METH_VARARGS|METH_KEYWORDS}, |
| 8961 | {"txn_checkpoint", (PyCFunction)DBEnv_txn_checkpoint, METH_VARARGS}, |
| 8962 | {"txn_stat", (PyCFunction)DBEnv_txn_stat, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8963 | {"txn_stat_print", (PyCFunction)DBEnv_txn_stat_print, |
| 8964 | METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8965 | {"get_tx_max", (PyCFunction)DBEnv_get_tx_max, METH_NOARGS}, |
| 8966 | {"get_tx_timestamp", (PyCFunction)DBEnv_get_tx_timestamp, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8967 | {"set_tx_max", (PyCFunction)DBEnv_set_tx_max, METH_VARARGS}, |
Gregory P. Smith | 8a47404 | 2006-01-27 07:05:40 +0000 | [diff] [blame] | 8968 | {"set_tx_timestamp", (PyCFunction)DBEnv_set_tx_timestamp, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8969 | {"lock_detect", (PyCFunction)DBEnv_lock_detect, METH_VARARGS}, |
| 8970 | {"lock_get", (PyCFunction)DBEnv_lock_get, METH_VARARGS}, |
| 8971 | {"lock_id", (PyCFunction)DBEnv_lock_id, METH_NOARGS}, |
| 8972 | {"lock_id_free", (PyCFunction)DBEnv_lock_id_free, METH_VARARGS}, |
| 8973 | {"lock_put", (PyCFunction)DBEnv_lock_put, METH_VARARGS}, |
| 8974 | {"lock_stat", (PyCFunction)DBEnv_lock_stat, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8975 | {"lock_stat_print", (PyCFunction)DBEnv_lock_stat_print, |
| 8976 | METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8977 | {"log_cursor", (PyCFunction)DBEnv_log_cursor, METH_NOARGS}, |
| 8978 | {"log_file", (PyCFunction)DBEnv_log_file, METH_VARARGS}, |
Gregory P. Smith | db8a807 | 2006-06-05 01:56:15 +0000 | [diff] [blame] | 8979 | #if (DBVER >= 44) |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8980 | {"log_printf", (PyCFunction)DBEnv_log_printf, |
| 8981 | METH_VARARGS|METH_KEYWORDS}, |
| 8982 | #endif |
| 8983 | {"log_archive", (PyCFunction)DBEnv_log_archive, METH_VARARGS}, |
| 8984 | {"log_flush", (PyCFunction)DBEnv_log_flush, METH_NOARGS}, |
| 8985 | {"log_stat", (PyCFunction)DBEnv_log_stat, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8986 | {"log_stat_print", (PyCFunction)DBEnv_log_stat_print, |
| 8987 | METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8988 | #if (DBVER >= 44) |
| 8989 | {"fileid_reset", (PyCFunction)DBEnv_fileid_reset, METH_VARARGS|METH_KEYWORDS}, |
| 8990 | {"lsn_reset", (PyCFunction)DBEnv_lsn_reset, METH_VARARGS|METH_KEYWORDS}, |
Gregory P. Smith | db8a807 | 2006-06-05 01:56:15 +0000 | [diff] [blame] | 8991 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 8992 | {"set_get_returns_none",(PyCFunction)DBEnv_set_get_returns_none, METH_VARARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8993 | {"txn_recover", (PyCFunction)DBEnv_txn_recover, METH_NOARGS}, |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 8994 | #if (DBVER < 48) |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 8995 | {"set_rpc_server", (PyCFunction)DBEnv_set_rpc_server, |
Stefan Krah | 7711273 | 2011-09-15 22:56:00 +0200 | [diff] [blame] | 8996 | METH_VARARGS|METH_KEYWORDS}, |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 8997 | #endif |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 8998 | {"set_mp_max_openfd", (PyCFunction)DBEnv_set_mp_max_openfd, METH_VARARGS}, |
| 8999 | {"get_mp_max_openfd", (PyCFunction)DBEnv_get_mp_max_openfd, METH_NOARGS}, |
| 9000 | {"set_mp_max_write", (PyCFunction)DBEnv_set_mp_max_write, METH_VARARGS}, |
| 9001 | {"get_mp_max_write", (PyCFunction)DBEnv_get_mp_max_write, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9002 | {"set_verbose", (PyCFunction)DBEnv_set_verbose, METH_VARARGS}, |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9003 | {"get_verbose", (PyCFunction)DBEnv_get_verbose, METH_VARARGS}, |
| 9004 | {"set_private", (PyCFunction)DBEnv_set_private, METH_O}, |
| 9005 | {"get_private", (PyCFunction)DBEnv_get_private, METH_NOARGS}, |
| 9006 | {"get_open_flags", (PyCFunction)DBEnv_get_open_flags, METH_NOARGS}, |
| 9007 | #if (DBVER >= 47) |
| 9008 | {"set_intermediate_dir_mode", (PyCFunction)DBEnv_set_intermediate_dir_mode, |
| 9009 | METH_VARARGS}, |
| 9010 | {"get_intermediate_dir_mode", (PyCFunction)DBEnv_get_intermediate_dir_mode, |
| 9011 | METH_NOARGS}, |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9012 | #endif |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9013 | #if (DBVER < 47) |
| 9014 | {"set_intermediate_dir", (PyCFunction)DBEnv_set_intermediate_dir, |
| 9015 | METH_VARARGS}, |
| 9016 | #endif |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9017 | {"rep_start", (PyCFunction)DBEnv_rep_start, |
| 9018 | METH_VARARGS|METH_KEYWORDS}, |
| 9019 | {"rep_set_transport", (PyCFunction)DBEnv_rep_set_transport, METH_VARARGS}, |
| 9020 | {"rep_process_message", (PyCFunction)DBEnv_rep_process_message, |
| 9021 | METH_VARARGS}, |
| 9022 | #if (DBVER >= 46) |
| 9023 | {"rep_elect", (PyCFunction)DBEnv_rep_elect, METH_VARARGS}, |
| 9024 | #endif |
| 9025 | #if (DBVER >= 44) |
| 9026 | {"rep_set_config", (PyCFunction)DBEnv_rep_set_config, METH_VARARGS}, |
| 9027 | {"rep_get_config", (PyCFunction)DBEnv_rep_get_config, METH_VARARGS}, |
| 9028 | {"rep_sync", (PyCFunction)DBEnv_rep_sync, METH_NOARGS}, |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9029 | #endif |
| 9030 | #if (DBVER >= 45) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9031 | {"rep_set_limit", (PyCFunction)DBEnv_rep_set_limit, METH_VARARGS}, |
| 9032 | {"rep_get_limit", (PyCFunction)DBEnv_rep_get_limit, METH_NOARGS}, |
| 9033 | #endif |
| 9034 | #if (DBVER >= 47) |
| 9035 | {"rep_set_request", (PyCFunction)DBEnv_rep_set_request, METH_VARARGS}, |
| 9036 | {"rep_get_request", (PyCFunction)DBEnv_rep_get_request, METH_NOARGS}, |
| 9037 | #endif |
| 9038 | #if (DBVER >= 45) |
| 9039 | {"set_event_notify", (PyCFunction)DBEnv_set_event_notify, METH_O}, |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9040 | #endif |
| 9041 | #if (DBVER >= 45) |
| 9042 | {"rep_set_nsites", (PyCFunction)DBEnv_rep_set_nsites, METH_VARARGS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9043 | {"rep_get_nsites", (PyCFunction)DBEnv_rep_get_nsites, METH_NOARGS}, |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9044 | {"rep_set_priority", (PyCFunction)DBEnv_rep_set_priority, METH_VARARGS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9045 | {"rep_get_priority", (PyCFunction)DBEnv_rep_get_priority, METH_NOARGS}, |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9046 | {"rep_set_timeout", (PyCFunction)DBEnv_rep_set_timeout, METH_VARARGS}, |
| 9047 | {"rep_get_timeout", (PyCFunction)DBEnv_rep_get_timeout, METH_VARARGS}, |
| 9048 | #endif |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9049 | #if (DBVER >= 47) |
| 9050 | {"rep_set_clockskew", (PyCFunction)DBEnv_rep_set_clockskew, METH_VARARGS}, |
| 9051 | {"rep_get_clockskew", (PyCFunction)DBEnv_rep_get_clockskew, METH_VARARGS}, |
| 9052 | #endif |
| 9053 | {"rep_stat", (PyCFunction)DBEnv_rep_stat, |
| 9054 | METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9055 | {"rep_stat_print", (PyCFunction)DBEnv_rep_stat_print, |
| 9056 | METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9057 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9058 | #if (DBVER >= 45) |
| 9059 | {"repmgr_start", (PyCFunction)DBEnv_repmgr_start, |
| 9060 | METH_VARARGS|METH_KEYWORDS}, |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9061 | #if (DBVER < 52) |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9062 | {"repmgr_set_local_site", (PyCFunction)DBEnv_repmgr_set_local_site, |
| 9063 | METH_VARARGS|METH_KEYWORDS}, |
| 9064 | {"repmgr_add_remote_site", (PyCFunction)DBEnv_repmgr_add_remote_site, |
| 9065 | METH_VARARGS|METH_KEYWORDS}, |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9066 | #endif |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9067 | {"repmgr_set_ack_policy", (PyCFunction)DBEnv_repmgr_set_ack_policy, |
| 9068 | METH_VARARGS}, |
| 9069 | {"repmgr_get_ack_policy", (PyCFunction)DBEnv_repmgr_get_ack_policy, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9070 | METH_NOARGS}, |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9071 | {"repmgr_site_list", (PyCFunction)DBEnv_repmgr_site_list, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9072 | METH_NOARGS}, |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9073 | #endif |
| 9074 | #if (DBVER >= 46) |
| 9075 | {"repmgr_stat", (PyCFunction)DBEnv_repmgr_stat, |
| 9076 | METH_VARARGS|METH_KEYWORDS}, |
| 9077 | {"repmgr_stat_print", (PyCFunction)DBEnv_repmgr_stat_print, |
| 9078 | METH_VARARGS|METH_KEYWORDS}, |
| 9079 | #endif |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9080 | #if (DBVER >= 52) |
| 9081 | {"repmgr_site", (PyCFunction)DBEnv_repmgr_site, |
| 9082 | METH_VARARGS | METH_KEYWORDS}, |
| 9083 | {"repmgr_site_by_eid", (PyCFunction)DBEnv_repmgr_site_by_eid, |
| 9084 | METH_VARARGS | METH_KEYWORDS}, |
| 9085 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9086 | {NULL, NULL} /* sentinel */ |
| 9087 | }; |
| 9088 | |
| 9089 | |
| 9090 | static PyMethodDef DBTxn_methods[] = { |
| 9091 | {"commit", (PyCFunction)DBTxn_commit, METH_VARARGS}, |
| 9092 | {"prepare", (PyCFunction)DBTxn_prepare, METH_VARARGS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9093 | {"discard", (PyCFunction)DBTxn_discard, METH_NOARGS}, |
| 9094 | {"abort", (PyCFunction)DBTxn_abort, METH_NOARGS}, |
| 9095 | {"id", (PyCFunction)DBTxn_id, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9096 | {"set_timeout", (PyCFunction)DBTxn_set_timeout, |
| 9097 | METH_VARARGS|METH_KEYWORDS}, |
| 9098 | #if (DBVER >= 44) |
| 9099 | {"set_name", (PyCFunction)DBTxn_set_name, METH_VARARGS}, |
| 9100 | {"get_name", (PyCFunction)DBTxn_get_name, METH_NOARGS}, |
| 9101 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9102 | {NULL, NULL} /* sentinel */ |
| 9103 | }; |
| 9104 | |
| 9105 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9106 | static PyMethodDef DBSequence_methods[] = { |
| 9107 | {"close", (PyCFunction)DBSequence_close, METH_VARARGS}, |
| 9108 | {"get", (PyCFunction)DBSequence_get, METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9109 | {"get_dbp", (PyCFunction)DBSequence_get_dbp, METH_NOARGS}, |
| 9110 | {"get_key", (PyCFunction)DBSequence_get_key, METH_NOARGS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9111 | {"initial_value", (PyCFunction)DBSequence_initial_value, METH_VARARGS}, |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9112 | {"open", (PyCFunction)DBSequence_open, METH_VARARGS|METH_KEYWORDS}, |
| 9113 | {"remove", (PyCFunction)DBSequence_remove, METH_VARARGS|METH_KEYWORDS}, |
| 9114 | {"set_cachesize", (PyCFunction)DBSequence_set_cachesize, METH_VARARGS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9115 | {"get_cachesize", (PyCFunction)DBSequence_get_cachesize, METH_NOARGS}, |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9116 | {"set_flags", (PyCFunction)DBSequence_set_flags, METH_VARARGS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9117 | {"get_flags", (PyCFunction)DBSequence_get_flags, METH_NOARGS}, |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9118 | {"set_range", (PyCFunction)DBSequence_set_range, METH_VARARGS}, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9119 | {"get_range", (PyCFunction)DBSequence_get_range, METH_NOARGS}, |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9120 | {"stat", (PyCFunction)DBSequence_stat, METH_VARARGS|METH_KEYWORDS}, |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9121 | {"stat_print", (PyCFunction)DBSequence_stat_print, |
| 9122 | METH_VARARGS|METH_KEYWORDS}, |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9123 | {NULL, NULL} /* sentinel */ |
| 9124 | }; |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9125 | |
| 9126 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9127 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9128 | DBEnv_db_home_get(DBEnvObject* self) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9129 | { |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9130 | const char *home = NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9131 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9132 | CHECK_ENV_NOT_CLOSED(self); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9133 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9134 | MYDB_BEGIN_ALLOW_THREADS; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9135 | self->db_env->get_home(self->db_env, &home); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9136 | MYDB_END_ALLOW_THREADS; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9137 | |
| 9138 | if (home == NULL) { |
| 9139 | RETURN_NONE(); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9140 | } |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9141 | return PyBytes_FromString(home); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9142 | } |
| 9143 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9144 | static PyGetSetDef DBEnv_getsets[] = { |
| 9145 | {"db_home", (getter)DBEnv_db_home_get, NULL,}, |
| 9146 | {NULL} |
| 9147 | }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9148 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9149 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9150 | statichere PyTypeObject DB_Type = { |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9151 | #if (PY_VERSION_HEX < 0x03000000) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9152 | PyObject_HEAD_INIT(NULL) |
| 9153 | 0, /*ob_size*/ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9154 | #else |
| 9155 | PyVarObject_HEAD_INIT(NULL, 0) |
| 9156 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9157 | "DB", /*tp_name*/ |
| 9158 | sizeof(DBObject), /*tp_basicsize*/ |
| 9159 | 0, /*tp_itemsize*/ |
| 9160 | /* methods */ |
| 9161 | (destructor)DB_dealloc, /*tp_dealloc*/ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9162 | 0, /*tp_print*/ |
| 9163 | 0, /*tp_getattr*/ |
| 9164 | 0, /*tp_setattr*/ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9165 | 0, /*tp_compare*/ |
| 9166 | 0, /*tp_repr*/ |
| 9167 | 0, /*tp_as_number*/ |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9168 | &DB_sequence,/*tp_as_sequence*/ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9169 | &DB_mapping,/*tp_as_mapping*/ |
| 9170 | 0, /*tp_hash*/ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9171 | 0, /* tp_call */ |
| 9172 | 0, /* tp_str */ |
| 9173 | 0, /* tp_getattro */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9174 | 0, /* tp_setattro */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9175 | 0, /* tp_as_buffer */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9176 | #if (PY_VERSION_HEX < 0x03000000) |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 9177 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9178 | #else |
| 9179 | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
| 9180 | #endif |
| 9181 | 0, /* tp_doc */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9182 | 0, /* tp_traverse */ |
| 9183 | 0, /* tp_clear */ |
| 9184 | 0, /* tp_richcompare */ |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 9185 | offsetof(DBObject, in_weakreflist), /* tp_weaklistoffset */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9186 | 0, /*tp_iter*/ |
| 9187 | 0, /*tp_iternext*/ |
| 9188 | DB_methods, /*tp_methods*/ |
| 9189 | 0, /*tp_members*/ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9190 | }; |
| 9191 | |
| 9192 | |
| 9193 | statichere PyTypeObject DBCursor_Type = { |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9194 | #if (PY_VERSION_HEX < 0x03000000) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9195 | PyObject_HEAD_INIT(NULL) |
| 9196 | 0, /*ob_size*/ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9197 | #else |
| 9198 | PyVarObject_HEAD_INIT(NULL, 0) |
| 9199 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9200 | "DBCursor", /*tp_name*/ |
| 9201 | sizeof(DBCursorObject), /*tp_basicsize*/ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9202 | 0, /*tp_itemsize*/ |
| 9203 | /* methods */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9204 | (destructor)DBCursor_dealloc,/*tp_dealloc*/ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9205 | 0, /*tp_print*/ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9206 | 0, /*tp_getattr*/ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9207 | 0, /*tp_setattr*/ |
| 9208 | 0, /*tp_compare*/ |
| 9209 | 0, /*tp_repr*/ |
| 9210 | 0, /*tp_as_number*/ |
| 9211 | 0, /*tp_as_sequence*/ |
| 9212 | 0, /*tp_as_mapping*/ |
| 9213 | 0, /*tp_hash*/ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9214 | 0, /*tp_call*/ |
| 9215 | 0, /*tp_str*/ |
| 9216 | 0, /*tp_getattro*/ |
| 9217 | 0, /*tp_setattro*/ |
| 9218 | 0, /*tp_as_buffer*/ |
| 9219 | #if (PY_VERSION_HEX < 0x03000000) |
Gregory P. Smith | 31c5065 | 2004-06-28 01:20:40 +0000 | [diff] [blame] | 9220 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9221 | #else |
| 9222 | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
| 9223 | #endif |
| 9224 | 0, /* tp_doc */ |
| 9225 | 0, /* tp_traverse */ |
| 9226 | 0, /* tp_clear */ |
| 9227 | 0, /* tp_richcompare */ |
| 9228 | offsetof(DBCursorObject, in_weakreflist), /* tp_weaklistoffset */ |
| 9229 | 0, /*tp_iter*/ |
| 9230 | 0, /*tp_iternext*/ |
| 9231 | DBCursor_methods, /*tp_methods*/ |
| 9232 | 0, /*tp_members*/ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9233 | }; |
| 9234 | |
| 9235 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9236 | statichere PyTypeObject DBLogCursor_Type = { |
| 9237 | #if (PY_VERSION_HEX < 0x03000000) |
| 9238 | PyObject_HEAD_INIT(NULL) |
| 9239 | 0, /*ob_size*/ |
| 9240 | #else |
| 9241 | PyVarObject_HEAD_INIT(NULL, 0) |
| 9242 | #endif |
| 9243 | "DBLogCursor", /*tp_name*/ |
| 9244 | sizeof(DBLogCursorObject), /*tp_basicsize*/ |
| 9245 | 0, /*tp_itemsize*/ |
| 9246 | /* methods */ |
| 9247 | (destructor)DBLogCursor_dealloc,/*tp_dealloc*/ |
| 9248 | 0, /*tp_print*/ |
| 9249 | 0, /*tp_getattr*/ |
| 9250 | 0, /*tp_setattr*/ |
| 9251 | 0, /*tp_compare*/ |
| 9252 | 0, /*tp_repr*/ |
| 9253 | 0, /*tp_as_number*/ |
| 9254 | 0, /*tp_as_sequence*/ |
| 9255 | 0, /*tp_as_mapping*/ |
| 9256 | 0, /*tp_hash*/ |
| 9257 | 0, /*tp_call*/ |
| 9258 | 0, /*tp_str*/ |
| 9259 | 0, /*tp_getattro*/ |
| 9260 | 0, /*tp_setattro*/ |
| 9261 | 0, /*tp_as_buffer*/ |
| 9262 | #if (PY_VERSION_HEX < 0x03000000) |
| 9263 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ |
| 9264 | #else |
| 9265 | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
| 9266 | #endif |
| 9267 | 0, /* tp_doc */ |
| 9268 | 0, /* tp_traverse */ |
| 9269 | 0, /* tp_clear */ |
| 9270 | 0, /* tp_richcompare */ |
| 9271 | offsetof(DBLogCursorObject, in_weakreflist), /* tp_weaklistoffset */ |
| 9272 | 0, /*tp_iter*/ |
| 9273 | 0, /*tp_iternext*/ |
| 9274 | DBLogCursor_methods, /*tp_methods*/ |
| 9275 | 0, /*tp_members*/ |
| 9276 | }; |
| 9277 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9278 | #if (DBVER >= 52) |
| 9279 | statichere PyTypeObject DBSite_Type = { |
| 9280 | #if (PY_VERSION_HEX < 0x03000000) |
| 9281 | PyObject_HEAD_INIT(NULL) |
| 9282 | 0, /*ob_size*/ |
| 9283 | #else |
| 9284 | PyVarObject_HEAD_INIT(NULL, 0) |
| 9285 | #endif |
| 9286 | "DBSite", /*tp_name*/ |
| 9287 | sizeof(DBSiteObject), /*tp_basicsize*/ |
| 9288 | 0, /*tp_itemsize*/ |
| 9289 | /* methods */ |
| 9290 | (destructor)DBSite_dealloc,/*tp_dealloc*/ |
| 9291 | 0, /*tp_print*/ |
| 9292 | 0, /*tp_getattr*/ |
| 9293 | 0, /*tp_setattr*/ |
| 9294 | 0, /*tp_compare*/ |
| 9295 | 0, /*tp_repr*/ |
| 9296 | 0, /*tp_as_number*/ |
| 9297 | 0, /*tp_as_sequence*/ |
| 9298 | 0, /*tp_as_mapping*/ |
| 9299 | 0, /*tp_hash*/ |
| 9300 | 0, /*tp_call*/ |
| 9301 | 0, /*tp_str*/ |
| 9302 | 0, /*tp_getattro*/ |
| 9303 | 0, /*tp_setattro*/ |
| 9304 | 0, /*tp_as_buffer*/ |
| 9305 | #if (PY_VERSION_HEX < 0x03000000) |
| 9306 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ |
| 9307 | #else |
| 9308 | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
| 9309 | #endif |
| 9310 | 0, /* tp_doc */ |
| 9311 | 0, /* tp_traverse */ |
| 9312 | 0, /* tp_clear */ |
| 9313 | 0, /* tp_richcompare */ |
| 9314 | offsetof(DBSiteObject, in_weakreflist), /* tp_weaklistoffset */ |
| 9315 | 0, /*tp_iter*/ |
| 9316 | 0, /*tp_iternext*/ |
| 9317 | DBSite_methods, /*tp_methods*/ |
| 9318 | 0, /*tp_members*/ |
| 9319 | }; |
| 9320 | #endif |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9321 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9322 | statichere PyTypeObject DBEnv_Type = { |
| 9323 | #if (PY_VERSION_HEX < 0x03000000) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9324 | PyObject_HEAD_INIT(NULL) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9325 | 0, /*ob_size*/ |
| 9326 | #else |
| 9327 | PyVarObject_HEAD_INIT(NULL, 0) |
| 9328 | #endif |
| 9329 | "DBEnv", /*tp_name*/ |
| 9330 | sizeof(DBEnvObject), /*tp_basicsize*/ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9331 | 0, /*tp_itemsize*/ |
| 9332 | /* methods */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9333 | (destructor)DBEnv_dealloc, /*tp_dealloc*/ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9334 | 0, /*tp_print*/ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9335 | 0, /*tp_getattr*/ |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9336 | 0, /*tp_setattr*/ |
| 9337 | 0, /*tp_compare*/ |
| 9338 | 0, /*tp_repr*/ |
| 9339 | 0, /*tp_as_number*/ |
| 9340 | 0, /*tp_as_sequence*/ |
| 9341 | 0, /*tp_as_mapping*/ |
| 9342 | 0, /*tp_hash*/ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9343 | 0, /* tp_call */ |
| 9344 | 0, /* tp_str */ |
| 9345 | 0, /* tp_getattro */ |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9346 | 0, /* tp_setattro */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9347 | 0, /* tp_as_buffer */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9348 | #if (PY_VERSION_HEX < 0x03000000) |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9349 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9350 | #else |
| 9351 | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
| 9352 | #endif |
| 9353 | 0, /* tp_doc */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9354 | 0, /* tp_traverse */ |
| 9355 | 0, /* tp_clear */ |
| 9356 | 0, /* tp_richcompare */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9357 | offsetof(DBEnvObject, in_weakreflist), /* tp_weaklistoffset */ |
| 9358 | 0, /* tp_iter */ |
| 9359 | 0, /* tp_iternext */ |
| 9360 | DBEnv_methods, /* tp_methods */ |
| 9361 | 0, /* tp_members */ |
| 9362 | DBEnv_getsets, /* tp_getsets */ |
| 9363 | }; |
| 9364 | |
| 9365 | statichere PyTypeObject DBTxn_Type = { |
| 9366 | #if (PY_VERSION_HEX < 0x03000000) |
| 9367 | PyObject_HEAD_INIT(NULL) |
| 9368 | 0, /*ob_size*/ |
| 9369 | #else |
| 9370 | PyVarObject_HEAD_INIT(NULL, 0) |
| 9371 | #endif |
| 9372 | "DBTxn", /*tp_name*/ |
| 9373 | sizeof(DBTxnObject), /*tp_basicsize*/ |
| 9374 | 0, /*tp_itemsize*/ |
| 9375 | /* methods */ |
| 9376 | (destructor)DBTxn_dealloc, /*tp_dealloc*/ |
| 9377 | 0, /*tp_print*/ |
| 9378 | 0, /*tp_getattr*/ |
| 9379 | 0, /*tp_setattr*/ |
| 9380 | 0, /*tp_compare*/ |
| 9381 | 0, /*tp_repr*/ |
| 9382 | 0, /*tp_as_number*/ |
| 9383 | 0, /*tp_as_sequence*/ |
| 9384 | 0, /*tp_as_mapping*/ |
| 9385 | 0, /*tp_hash*/ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9386 | 0, /* tp_call */ |
| 9387 | 0, /* tp_str */ |
| 9388 | 0, /* tp_getattro */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9389 | 0, /* tp_setattro */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9390 | 0, /* tp_as_buffer */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9391 | #if (PY_VERSION_HEX < 0x03000000) |
| 9392 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ |
| 9393 | #else |
| 9394 | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
| 9395 | #endif |
| 9396 | 0, /* tp_doc */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9397 | 0, /* tp_traverse */ |
| 9398 | 0, /* tp_clear */ |
| 9399 | 0, /* tp_richcompare */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9400 | offsetof(DBTxnObject, in_weakreflist), /* tp_weaklistoffset */ |
| 9401 | 0, /*tp_iter*/ |
| 9402 | 0, /*tp_iternext*/ |
| 9403 | DBTxn_methods, /*tp_methods*/ |
| 9404 | 0, /*tp_members*/ |
| 9405 | }; |
| 9406 | |
| 9407 | |
| 9408 | statichere PyTypeObject DBLock_Type = { |
| 9409 | #if (PY_VERSION_HEX < 0x03000000) |
| 9410 | PyObject_HEAD_INIT(NULL) |
| 9411 | 0, /*ob_size*/ |
| 9412 | #else |
| 9413 | PyVarObject_HEAD_INIT(NULL, 0) |
| 9414 | #endif |
| 9415 | "DBLock", /*tp_name*/ |
| 9416 | sizeof(DBLockObject), /*tp_basicsize*/ |
| 9417 | 0, /*tp_itemsize*/ |
| 9418 | /* methods */ |
| 9419 | (destructor)DBLock_dealloc, /*tp_dealloc*/ |
| 9420 | 0, /*tp_print*/ |
| 9421 | 0, /*tp_getattr*/ |
| 9422 | 0, /*tp_setattr*/ |
| 9423 | 0, /*tp_compare*/ |
| 9424 | 0, /*tp_repr*/ |
| 9425 | 0, /*tp_as_number*/ |
| 9426 | 0, /*tp_as_sequence*/ |
| 9427 | 0, /*tp_as_mapping*/ |
| 9428 | 0, /*tp_hash*/ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9429 | 0, /* tp_call */ |
| 9430 | 0, /* tp_str */ |
| 9431 | 0, /* tp_getattro */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9432 | 0, /* tp_setattro */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9433 | 0, /* tp_as_buffer */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9434 | #if (PY_VERSION_HEX < 0x03000000) |
| 9435 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ |
| 9436 | #else |
| 9437 | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
| 9438 | #endif |
| 9439 | 0, /* tp_doc */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9440 | 0, /* tp_traverse */ |
| 9441 | 0, /* tp_clear */ |
| 9442 | 0, /* tp_richcompare */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9443 | offsetof(DBLockObject, in_weakreflist), /* tp_weaklistoffset */ |
| 9444 | }; |
| 9445 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9446 | statichere PyTypeObject DBSequence_Type = { |
| 9447 | #if (PY_VERSION_HEX < 0x03000000) |
| 9448 | PyObject_HEAD_INIT(NULL) |
| 9449 | 0, /*ob_size*/ |
| 9450 | #else |
| 9451 | PyVarObject_HEAD_INIT(NULL, 0) |
| 9452 | #endif |
| 9453 | "DBSequence", /*tp_name*/ |
| 9454 | sizeof(DBSequenceObject), /*tp_basicsize*/ |
| 9455 | 0, /*tp_itemsize*/ |
| 9456 | /* methods */ |
| 9457 | (destructor)DBSequence_dealloc, /*tp_dealloc*/ |
| 9458 | 0, /*tp_print*/ |
| 9459 | 0, /*tp_getattr*/ |
| 9460 | 0, /*tp_setattr*/ |
| 9461 | 0, /*tp_compare*/ |
| 9462 | 0, /*tp_repr*/ |
| 9463 | 0, /*tp_as_number*/ |
| 9464 | 0, /*tp_as_sequence*/ |
| 9465 | 0, /*tp_as_mapping*/ |
| 9466 | 0, /*tp_hash*/ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9467 | 0, /* tp_call */ |
| 9468 | 0, /* tp_str */ |
| 9469 | 0, /* tp_getattro */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9470 | 0, /* tp_setattro */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9471 | 0, /* tp_as_buffer */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9472 | #if (PY_VERSION_HEX < 0x03000000) |
| 9473 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ |
| 9474 | #else |
| 9475 | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
| 9476 | #endif |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9477 | 0, /* tp_doc */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9478 | 0, /* tp_traverse */ |
| 9479 | 0, /* tp_clear */ |
| 9480 | 0, /* tp_richcompare */ |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9481 | offsetof(DBSequenceObject, in_weakreflist), /* tp_weaklistoffset */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9482 | 0, /*tp_iter*/ |
| 9483 | 0, /*tp_iternext*/ |
| 9484 | DBSequence_methods, /*tp_methods*/ |
| 9485 | 0, /*tp_members*/ |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9486 | }; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9487 | |
| 9488 | /* --------------------------------------------------------------------- */ |
| 9489 | /* Module-level functions */ |
| 9490 | |
| 9491 | static PyObject* |
| 9492 | DB_construct(PyObject* self, PyObject* args, PyObject* kwargs) |
| 9493 | { |
| 9494 | PyObject* dbenvobj = NULL; |
| 9495 | int flags = 0; |
Martin v. Löwis | 02cbf4a | 2006-02-27 17:20:04 +0000 | [diff] [blame] | 9496 | static char* kwnames[] = { "dbEnv", "flags", NULL}; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9497 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 9498 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Oi:DB", kwnames, |
| 9499 | &dbenvobj, &flags)) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9500 | return NULL; |
| 9501 | if (dbenvobj == Py_None) |
| 9502 | dbenvobj = NULL; |
| 9503 | else if (dbenvobj && !DBEnvObject_Check(dbenvobj)) { |
| 9504 | makeTypeError("DBEnv", dbenvobj); |
| 9505 | return NULL; |
| 9506 | } |
| 9507 | |
| 9508 | return (PyObject* )newDBObject((DBEnvObject*)dbenvobj, flags); |
| 9509 | } |
| 9510 | |
| 9511 | |
| 9512 | static PyObject* |
| 9513 | DBEnv_construct(PyObject* self, PyObject* args) |
| 9514 | { |
| 9515 | int flags = 0; |
| 9516 | if (!PyArg_ParseTuple(args, "|i:DbEnv", &flags)) return NULL; |
| 9517 | return (PyObject* )newDBEnvObject(flags); |
| 9518 | } |
| 9519 | |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9520 | static PyObject* |
| 9521 | DBSequence_construct(PyObject* self, PyObject* args, PyObject* kwargs) |
| 9522 | { |
Neal Norwitz | b4fcf8d | 2006-06-11 05:44:18 +0000 | [diff] [blame] | 9523 | PyObject* dbobj; |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9524 | int flags = 0; |
| 9525 | static char* kwnames[] = { "db", "flags", NULL}; |
| 9526 | |
| 9527 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:DBSequence", kwnames, &dbobj, &flags)) |
| 9528 | return NULL; |
Neal Norwitz | b4fcf8d | 2006-06-11 05:44:18 +0000 | [diff] [blame] | 9529 | if (!DBObject_Check(dbobj)) { |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9530 | makeTypeError("DB", dbobj); |
| 9531 | return NULL; |
| 9532 | } |
| 9533 | return (PyObject* )newDBSequenceObject((DBObject*)dbobj, flags); |
| 9534 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9535 | |
| 9536 | static char bsddb_version_doc[] = |
| 9537 | "Returns a tuple of major, minor, and patch release numbers of the\n\ |
| 9538 | underlying DB library."; |
| 9539 | |
| 9540 | static PyObject* |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9541 | bsddb_version(PyObject* self) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9542 | { |
| 9543 | int major, minor, patch; |
| 9544 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9545 | /* This should be instantaneous, no need to release the GIL */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9546 | db_version(&major, &minor, &patch); |
| 9547 | return Py_BuildValue("(iii)", major, minor, patch); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9548 | } |
| 9549 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9550 | #if (DBVER >= 50) |
| 9551 | static PyObject* |
| 9552 | bsddb_version_full(PyObject* self) |
| 9553 | { |
| 9554 | char *version_string; |
| 9555 | int family, release, major, minor, patch; |
| 9556 | |
| 9557 | /* This should be instantaneous, no need to release the GIL */ |
| 9558 | version_string = db_full_version(&family, &release, &major, &minor, &patch); |
| 9559 | return Py_BuildValue("(siiiii)", |
| 9560 | version_string, family, release, major, minor, patch); |
| 9561 | } |
| 9562 | #endif |
| 9563 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9564 | |
| 9565 | /* List of functions defined in the module */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9566 | static PyMethodDef bsddb_methods[] = { |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9567 | {"DB", (PyCFunction)DB_construct, METH_VARARGS | METH_KEYWORDS }, |
| 9568 | {"DBEnv", (PyCFunction)DBEnv_construct, METH_VARARGS}, |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 9569 | {"DBSequence", (PyCFunction)DBSequence_construct, METH_VARARGS | METH_KEYWORDS }, |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9570 | {"version", (PyCFunction)bsddb_version, METH_NOARGS, bsddb_version_doc}, |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9571 | #if (DBVER >= 50) |
| 9572 | {"full_version", (PyCFunction)bsddb_version_full, METH_NOARGS}, |
| 9573 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9574 | {NULL, NULL} /* sentinel */ |
| 9575 | }; |
| 9576 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9577 | |
Gregory P. Smith | 3925053 | 2007-10-09 06:02:21 +0000 | [diff] [blame] | 9578 | /* API structure */ |
| 9579 | static BSDDB_api bsddb_api; |
| 9580 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9581 | |
| 9582 | /* --------------------------------------------------------------------- */ |
| 9583 | /* Module initialization */ |
| 9584 | |
| 9585 | |
| 9586 | /* Convenience routine to export an integer value. |
| 9587 | * Errors are silently ignored, for better or for worse... |
| 9588 | */ |
| 9589 | #define ADD_INT(dict, NAME) _addIntToDict(dict, #NAME, NAME) |
| 9590 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9591 | /* |
| 9592 | ** We can rename the module at import time, so the string allocated |
| 9593 | ** must be big enough, and any use of the name must use this particular |
| 9594 | ** string. |
| 9595 | */ |
Gregory P. Smith | 41631e8 | 2003-09-21 00:08:14 +0000 | [diff] [blame] | 9596 | #define MODULE_NAME_MAX_LEN 11 |
| 9597 | static char _bsddbModuleName[MODULE_NAME_MAX_LEN+1] = "_bsddb"; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9598 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9599 | #if (PY_VERSION_HEX >= 0x03000000) |
| 9600 | static struct PyModuleDef bsddbmodule = { |
| 9601 | PyModuleDef_HEAD_INIT, |
| 9602 | _bsddbModuleName, /* Name of module */ |
| 9603 | NULL, /* module documentation, may be NULL */ |
| 9604 | -1, /* size of per-interpreter state of the module, |
| 9605 | or -1 if the module keeps state in global variables. */ |
| 9606 | bsddb_methods, |
| 9607 | NULL, /* Reload */ |
| 9608 | NULL, /* Traverse */ |
| 9609 | NULL, /* Clear */ |
| 9610 | NULL /* Free */ |
| 9611 | }; |
| 9612 | #endif |
| 9613 | |
| 9614 | |
| 9615 | #if (PY_VERSION_HEX < 0x03000000) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9616 | DL_EXPORT(void) init_bsddb(void) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9617 | #else |
| 9618 | PyMODINIT_FUNC PyInit__bsddb(void) /* Note the two underscores */ |
| 9619 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9620 | { |
| 9621 | PyObject* m; |
| 9622 | PyObject* d; |
Gregory P. Smith | 3925053 | 2007-10-09 06:02:21 +0000 | [diff] [blame] | 9623 | PyObject* py_api; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9624 | PyObject* pybsddb_version_s; |
| 9625 | PyObject* db_version_s; |
| 9626 | PyObject* cvsid_s; |
| 9627 | |
| 9628 | #if (PY_VERSION_HEX < 0x03000000) |
| 9629 | pybsddb_version_s = PyString_FromString(PY_BSDDB_VERSION); |
| 9630 | db_version_s = PyString_FromString(DB_VERSION_STRING); |
| 9631 | cvsid_s = PyString_FromString(rcs_id); |
| 9632 | #else |
| 9633 | /* This data should be ascii, so UTF-8 conversion is fine */ |
| 9634 | pybsddb_version_s = PyUnicode_FromString(PY_BSDDB_VERSION); |
| 9635 | db_version_s = PyUnicode_FromString(DB_VERSION_STRING); |
| 9636 | cvsid_s = PyUnicode_FromString(rcs_id); |
| 9637 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9638 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9639 | /* Initialize object types */ |
| 9640 | if ((PyType_Ready(&DB_Type) < 0) |
| 9641 | || (PyType_Ready(&DBCursor_Type) < 0) |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9642 | || (PyType_Ready(&DBLogCursor_Type) < 0) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9643 | || (PyType_Ready(&DBEnv_Type) < 0) |
| 9644 | || (PyType_Ready(&DBTxn_Type) < 0) |
| 9645 | || (PyType_Ready(&DBLock_Type) < 0) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9646 | || (PyType_Ready(&DBSequence_Type) < 0) |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9647 | #if (DBVER >= 52) |
| 9648 | || (PyType_Ready(&DBSite_Type) < 0) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9649 | #endif |
| 9650 | ) { |
| 9651 | #if (PY_VERSION_HEX < 0x03000000) |
| 9652 | return; |
| 9653 | #else |
| 9654 | return NULL; |
| 9655 | #endif |
| 9656 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9657 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9658 | /* Create the module and add the functions */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9659 | #if (PY_VERSION_HEX < 0x03000000) |
Gregory P. Smith | 41631e8 | 2003-09-21 00:08:14 +0000 | [diff] [blame] | 9660 | m = Py_InitModule(_bsddbModuleName, bsddb_methods); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9661 | #else |
| 9662 | m=PyModule_Create(&bsddbmodule); |
| 9663 | #endif |
| 9664 | if (m == NULL) { |
| 9665 | #if (PY_VERSION_HEX < 0x03000000) |
| 9666 | return; |
| 9667 | #else |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 9668 | return NULL; |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9669 | #endif |
| 9670 | } |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9671 | |
| 9672 | /* Add some symbolic constants to the module */ |
| 9673 | d = PyModule_GetDict(m); |
| 9674 | PyDict_SetItemString(d, "__version__", pybsddb_version_s); |
| 9675 | PyDict_SetItemString(d, "cvsid", cvsid_s); |
| 9676 | PyDict_SetItemString(d, "DB_VERSION_STRING", db_version_s); |
| 9677 | Py_DECREF(pybsddb_version_s); |
| 9678 | pybsddb_version_s = NULL; |
| 9679 | Py_DECREF(cvsid_s); |
| 9680 | cvsid_s = NULL; |
| 9681 | Py_DECREF(db_version_s); |
| 9682 | db_version_s = NULL; |
| 9683 | |
| 9684 | ADD_INT(d, DB_VERSION_MAJOR); |
| 9685 | ADD_INT(d, DB_VERSION_MINOR); |
| 9686 | ADD_INT(d, DB_VERSION_PATCH); |
| 9687 | |
| 9688 | ADD_INT(d, DB_MAX_PAGES); |
| 9689 | ADD_INT(d, DB_MAX_RECORDS); |
| 9690 | |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 9691 | #if (DBVER < 48) |
Gregory P. Smith | 41631e8 | 2003-09-21 00:08:14 +0000 | [diff] [blame] | 9692 | ADD_INT(d, DB_RPCCLIENT); |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 9693 | #endif |
| 9694 | |
| 9695 | #if (DBVER < 48) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9696 | ADD_INT(d, DB_XA_CREATE); |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 9697 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9698 | |
| 9699 | ADD_INT(d, DB_CREATE); |
| 9700 | ADD_INT(d, DB_NOMMAP); |
| 9701 | ADD_INT(d, DB_THREAD); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9702 | #if (DBVER >= 45) |
| 9703 | ADD_INT(d, DB_MULTIVERSION); |
| 9704 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9705 | |
| 9706 | ADD_INT(d, DB_FORCE); |
| 9707 | ADD_INT(d, DB_INIT_CDB); |
| 9708 | ADD_INT(d, DB_INIT_LOCK); |
| 9709 | ADD_INT(d, DB_INIT_LOG); |
| 9710 | ADD_INT(d, DB_INIT_MPOOL); |
| 9711 | ADD_INT(d, DB_INIT_TXN); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9712 | ADD_INT(d, DB_JOINENV); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9713 | |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 9714 | #if (DBVER >= 48) |
| 9715 | ADD_INT(d, DB_GID_SIZE); |
| 9716 | #else |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9717 | ADD_INT(d, DB_XIDDATASIZE); |
Matthias Klose | 54cc539 | 2010-03-15 12:46:18 +0000 | [diff] [blame] | 9718 | /* Allow new code to work in old BDB releases */ |
| 9719 | _addIntToDict(d, "DB_GID_SIZE", DB_XIDDATASIZE); |
| 9720 | #endif |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9721 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9722 | ADD_INT(d, DB_RECOVER); |
| 9723 | ADD_INT(d, DB_RECOVER_FATAL); |
| 9724 | ADD_INT(d, DB_TXN_NOSYNC); |
| 9725 | ADD_INT(d, DB_USE_ENVIRON); |
| 9726 | ADD_INT(d, DB_USE_ENVIRON_ROOT); |
| 9727 | |
| 9728 | ADD_INT(d, DB_LOCKDOWN); |
| 9729 | ADD_INT(d, DB_PRIVATE); |
| 9730 | ADD_INT(d, DB_SYSTEM_MEM); |
| 9731 | |
| 9732 | ADD_INT(d, DB_TXN_SYNC); |
| 9733 | ADD_INT(d, DB_TXN_NOWAIT); |
| 9734 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9735 | #if (DBVER >= 51) |
| 9736 | ADD_INT(d, DB_TXN_BULK); |
| 9737 | #endif |
| 9738 | |
| 9739 | #if (DBVER >= 48) |
| 9740 | ADD_INT(d, DB_CURSOR_BULK); |
| 9741 | #endif |
| 9742 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9743 | #if (DBVER >= 46) |
| 9744 | ADD_INT(d, DB_TXN_WAIT); |
| 9745 | #endif |
| 9746 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9747 | ADD_INT(d, DB_EXCL); |
| 9748 | ADD_INT(d, DB_FCNTL_LOCKING); |
| 9749 | ADD_INT(d, DB_ODDFILESIZE); |
| 9750 | ADD_INT(d, DB_RDWRMASTER); |
| 9751 | ADD_INT(d, DB_RDONLY); |
| 9752 | ADD_INT(d, DB_TRUNCATE); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9753 | ADD_INT(d, DB_EXTENT); |
| 9754 | ADD_INT(d, DB_CDB_ALLDB); |
| 9755 | ADD_INT(d, DB_VERIFY); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9756 | ADD_INT(d, DB_UPGRADE); |
| 9757 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9758 | ADD_INT(d, DB_PRINTABLE); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9759 | ADD_INT(d, DB_AGGRESSIVE); |
| 9760 | ADD_INT(d, DB_NOORDERCHK); |
| 9761 | ADD_INT(d, DB_ORDERCHKONLY); |
| 9762 | ADD_INT(d, DB_PR_PAGE); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9763 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9764 | ADD_INT(d, DB_PR_RECOVERYTEST); |
| 9765 | ADD_INT(d, DB_SALVAGE); |
| 9766 | |
| 9767 | ADD_INT(d, DB_LOCK_NORUN); |
| 9768 | ADD_INT(d, DB_LOCK_DEFAULT); |
| 9769 | ADD_INT(d, DB_LOCK_OLDEST); |
| 9770 | ADD_INT(d, DB_LOCK_RANDOM); |
| 9771 | ADD_INT(d, DB_LOCK_YOUNGEST); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9772 | ADD_INT(d, DB_LOCK_MAXLOCKS); |
| 9773 | ADD_INT(d, DB_LOCK_MINLOCKS); |
| 9774 | ADD_INT(d, DB_LOCK_MINWRITE); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9775 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9776 | ADD_INT(d, DB_LOCK_EXPIRE); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9777 | ADD_INT(d, DB_LOCK_MAXWRITE); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9778 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 9779 | _addIntToDict(d, "DB_LOCK_CONFLICT", 0); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9780 | |
| 9781 | ADD_INT(d, DB_LOCK_DUMP); |
| 9782 | ADD_INT(d, DB_LOCK_GET); |
| 9783 | ADD_INT(d, DB_LOCK_INHERIT); |
| 9784 | ADD_INT(d, DB_LOCK_PUT); |
| 9785 | ADD_INT(d, DB_LOCK_PUT_ALL); |
| 9786 | ADD_INT(d, DB_LOCK_PUT_OBJ); |
| 9787 | |
| 9788 | ADD_INT(d, DB_LOCK_NG); |
| 9789 | ADD_INT(d, DB_LOCK_READ); |
| 9790 | ADD_INT(d, DB_LOCK_WRITE); |
| 9791 | ADD_INT(d, DB_LOCK_NOWAIT); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9792 | ADD_INT(d, DB_LOCK_WAIT); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9793 | ADD_INT(d, DB_LOCK_IWRITE); |
| 9794 | ADD_INT(d, DB_LOCK_IREAD); |
| 9795 | ADD_INT(d, DB_LOCK_IWR); |
Gregory P. Smith | 29602d2 | 2006-01-24 09:46:48 +0000 | [diff] [blame] | 9796 | #if (DBVER < 44) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9797 | ADD_INT(d, DB_LOCK_DIRTY); |
Gregory P. Smith | 29602d2 | 2006-01-24 09:46:48 +0000 | [diff] [blame] | 9798 | #else |
| 9799 | ADD_INT(d, DB_LOCK_READ_UNCOMMITTED); /* renamed in 4.4 */ |
| 9800 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9801 | ADD_INT(d, DB_LOCK_WWRITE); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9802 | |
| 9803 | ADD_INT(d, DB_LOCK_RECORD); |
| 9804 | ADD_INT(d, DB_LOCK_UPGRADE); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9805 | ADD_INT(d, DB_LOCK_SWITCH); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9806 | ADD_INT(d, DB_LOCK_UPGRADE_WRITE); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9807 | |
| 9808 | ADD_INT(d, DB_LOCK_NOWAIT); |
| 9809 | ADD_INT(d, DB_LOCK_RECORD); |
| 9810 | ADD_INT(d, DB_LOCK_UPGRADE); |
| 9811 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9812 | ADD_INT(d, DB_LSTAT_ABORTED); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9813 | ADD_INT(d, DB_LSTAT_FREE); |
| 9814 | ADD_INT(d, DB_LSTAT_HELD); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 9815 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9816 | ADD_INT(d, DB_LSTAT_PENDING); |
| 9817 | ADD_INT(d, DB_LSTAT_WAITING); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9818 | |
| 9819 | ADD_INT(d, DB_ARCH_ABS); |
| 9820 | ADD_INT(d, DB_ARCH_DATA); |
| 9821 | ADD_INT(d, DB_ARCH_LOG); |
Gregory P. Smith | 3dd2002 | 2006-06-05 00:31:01 +0000 | [diff] [blame] | 9822 | ADD_INT(d, DB_ARCH_REMOVE); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9823 | |
| 9824 | ADD_INT(d, DB_BTREE); |
| 9825 | ADD_INT(d, DB_HASH); |
| 9826 | ADD_INT(d, DB_RECNO); |
| 9827 | ADD_INT(d, DB_QUEUE); |
| 9828 | ADD_INT(d, DB_UNKNOWN); |
| 9829 | |
| 9830 | ADD_INT(d, DB_DUP); |
| 9831 | ADD_INT(d, DB_DUPSORT); |
| 9832 | ADD_INT(d, DB_RECNUM); |
| 9833 | ADD_INT(d, DB_RENUMBER); |
| 9834 | ADD_INT(d, DB_REVSPLITOFF); |
| 9835 | ADD_INT(d, DB_SNAPSHOT); |
| 9836 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9837 | ADD_INT(d, DB_INORDER); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9838 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9839 | ADD_INT(d, DB_JOIN_NOSORT); |
| 9840 | |
| 9841 | ADD_INT(d, DB_AFTER); |
| 9842 | ADD_INT(d, DB_APPEND); |
| 9843 | ADD_INT(d, DB_BEFORE); |
Gregory P. Smith | 8b96a35 | 2007-01-05 01:59:42 +0000 | [diff] [blame] | 9844 | #if (DBVER < 45) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9845 | ADD_INT(d, DB_CACHED_COUNTS); |
Gregory P. Smith | 8b96a35 | 2007-01-05 01:59:42 +0000 | [diff] [blame] | 9846 | #endif |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 9847 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9848 | ADD_INT(d, DB_CONSUME); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9849 | ADD_INT(d, DB_CONSUME_WAIT); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9850 | ADD_INT(d, DB_CURRENT); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9851 | ADD_INT(d, DB_FAST_STAT); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9852 | ADD_INT(d, DB_FIRST); |
| 9853 | ADD_INT(d, DB_FLUSH); |
| 9854 | ADD_INT(d, DB_GET_BOTH); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9855 | ADD_INT(d, DB_GET_BOTH_RANGE); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9856 | ADD_INT(d, DB_GET_RECNO); |
| 9857 | ADD_INT(d, DB_JOIN_ITEM); |
| 9858 | ADD_INT(d, DB_KEYFIRST); |
| 9859 | ADD_INT(d, DB_KEYLAST); |
| 9860 | ADD_INT(d, DB_LAST); |
| 9861 | ADD_INT(d, DB_NEXT); |
| 9862 | ADD_INT(d, DB_NEXT_DUP); |
| 9863 | ADD_INT(d, DB_NEXT_NODUP); |
| 9864 | ADD_INT(d, DB_NODUPDATA); |
| 9865 | ADD_INT(d, DB_NOOVERWRITE); |
| 9866 | ADD_INT(d, DB_NOSYNC); |
| 9867 | ADD_INT(d, DB_POSITION); |
| 9868 | ADD_INT(d, DB_PREV); |
| 9869 | ADD_INT(d, DB_PREV_NODUP); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9870 | #if (DBVER >= 46) |
| 9871 | ADD_INT(d, DB_PREV_DUP); |
| 9872 | #endif |
Gregory P. Smith | 8b96a35 | 2007-01-05 01:59:42 +0000 | [diff] [blame] | 9873 | #if (DBVER < 45) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9874 | ADD_INT(d, DB_RECORDCOUNT); |
Gregory P. Smith | 8b96a35 | 2007-01-05 01:59:42 +0000 | [diff] [blame] | 9875 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9876 | ADD_INT(d, DB_SET); |
| 9877 | ADD_INT(d, DB_SET_RANGE); |
| 9878 | ADD_INT(d, DB_SET_RECNO); |
| 9879 | ADD_INT(d, DB_WRITECURSOR); |
| 9880 | |
| 9881 | ADD_INT(d, DB_OPFLAGS_MASK); |
| 9882 | ADD_INT(d, DB_RMW); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9883 | ADD_INT(d, DB_DIRTY_READ); |
| 9884 | ADD_INT(d, DB_MULTIPLE); |
| 9885 | ADD_INT(d, DB_MULTIPLE_KEY); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9886 | |
Gregory P. Smith | 29602d2 | 2006-01-24 09:46:48 +0000 | [diff] [blame] | 9887 | #if (DBVER >= 44) |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9888 | ADD_INT(d, DB_IMMUTABLE_KEY); |
Gregory P. Smith | 29602d2 | 2006-01-24 09:46:48 +0000 | [diff] [blame] | 9889 | ADD_INT(d, DB_READ_UNCOMMITTED); /* replaces DB_DIRTY_READ in 4.4 */ |
| 9890 | ADD_INT(d, DB_READ_COMMITTED); |
| 9891 | #endif |
| 9892 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9893 | #if (DBVER >= 44) |
| 9894 | ADD_INT(d, DB_FREELIST_ONLY); |
| 9895 | ADD_INT(d, DB_FREE_SPACE); |
| 9896 | #endif |
| 9897 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9898 | ADD_INT(d, DB_DONOTINDEX); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9899 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9900 | ADD_INT(d, DB_KEYEMPTY); |
| 9901 | ADD_INT(d, DB_KEYEXIST); |
| 9902 | ADD_INT(d, DB_LOCK_DEADLOCK); |
| 9903 | ADD_INT(d, DB_LOCK_NOTGRANTED); |
| 9904 | ADD_INT(d, DB_NOSERVER); |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9905 | #if (DBVER < 52) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9906 | ADD_INT(d, DB_NOSERVER_HOME); |
| 9907 | ADD_INT(d, DB_NOSERVER_ID); |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9908 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9909 | ADD_INT(d, DB_NOTFOUND); |
| 9910 | ADD_INT(d, DB_OLD_VERSION); |
| 9911 | ADD_INT(d, DB_RUNRECOVERY); |
| 9912 | ADD_INT(d, DB_VERIFY_BAD); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9913 | ADD_INT(d, DB_PAGE_NOTFOUND); |
| 9914 | ADD_INT(d, DB_SECONDARY_BAD); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 9915 | ADD_INT(d, DB_STAT_CLEAR); |
| 9916 | ADD_INT(d, DB_REGION_INIT); |
| 9917 | ADD_INT(d, DB_NOLOCKING); |
| 9918 | ADD_INT(d, DB_YIELDCPU); |
| 9919 | ADD_INT(d, DB_PANIC_ENVIRONMENT); |
| 9920 | ADD_INT(d, DB_NOPANIC); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9921 | ADD_INT(d, DB_OVERWRITE); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9922 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9923 | ADD_INT(d, DB_STAT_SUBSYSTEM); |
| 9924 | ADD_INT(d, DB_STAT_MEMP_HASH); |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9925 | ADD_INT(d, DB_STAT_LOCK_CONF); |
| 9926 | ADD_INT(d, DB_STAT_LOCK_LOCKERS); |
| 9927 | ADD_INT(d, DB_STAT_LOCK_OBJECTS); |
| 9928 | ADD_INT(d, DB_STAT_LOCK_PARAMS); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9929 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9930 | #if (DBVER >= 48) |
| 9931 | ADD_INT(d, DB_OVERWRITE_DUP); |
| 9932 | #endif |
| 9933 | |
| 9934 | #if (DBVER >= 47) |
| 9935 | ADD_INT(d, DB_FOREIGN_ABORT); |
| 9936 | ADD_INT(d, DB_FOREIGN_CASCADE); |
| 9937 | ADD_INT(d, DB_FOREIGN_NULLIFY); |
| 9938 | #endif |
| 9939 | |
| 9940 | #if (DBVER >= 44) |
Gregory P. Smith | aae141a | 2007-11-01 21:08:14 +0000 | [diff] [blame] | 9941 | ADD_INT(d, DB_REGISTER); |
| 9942 | #endif |
| 9943 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 9944 | ADD_INT(d, DB_EID_INVALID); |
| 9945 | ADD_INT(d, DB_EID_BROADCAST); |
| 9946 | |
Gregory P. Smith | 41631e8 | 2003-09-21 00:08:14 +0000 | [diff] [blame] | 9947 | ADD_INT(d, DB_TIME_NOTGRANTED); |
| 9948 | ADD_INT(d, DB_TXN_NOT_DURABLE); |
| 9949 | ADD_INT(d, DB_TXN_WRITE_NOSYNC); |
Gregory P. Smith | 41631e8 | 2003-09-21 00:08:14 +0000 | [diff] [blame] | 9950 | ADD_INT(d, DB_DIRECT_DB); |
| 9951 | ADD_INT(d, DB_INIT_REP); |
| 9952 | ADD_INT(d, DB_ENCRYPT); |
| 9953 | ADD_INT(d, DB_CHKSUM); |
Gregory P. Smith | 41631e8 | 2003-09-21 00:08:14 +0000 | [diff] [blame] | 9954 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9955 | #if (DBVER < 47) |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 9956 | ADD_INT(d, DB_LOG_AUTOREMOVE); |
| 9957 | ADD_INT(d, DB_DIRECT_LOG); |
| 9958 | #endif |
| 9959 | |
| 9960 | #if (DBVER >= 47) |
| 9961 | ADD_INT(d, DB_LOG_DIRECT); |
| 9962 | ADD_INT(d, DB_LOG_DSYNC); |
| 9963 | ADD_INT(d, DB_LOG_IN_MEMORY); |
| 9964 | ADD_INT(d, DB_LOG_AUTO_REMOVE); |
| 9965 | ADD_INT(d, DB_LOG_ZERO); |
| 9966 | #endif |
| 9967 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9968 | #if (DBVER >= 44) |
| 9969 | ADD_INT(d, DB_DSYNC_DB); |
| 9970 | #endif |
| 9971 | |
| 9972 | #if (DBVER >= 45) |
| 9973 | ADD_INT(d, DB_TXN_SNAPSHOT); |
| 9974 | #endif |
| 9975 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9976 | ADD_INT(d, DB_VERB_DEADLOCK); |
| 9977 | #if (DBVER >= 46) |
| 9978 | ADD_INT(d, DB_VERB_FILEOPS); |
| 9979 | ADD_INT(d, DB_VERB_FILEOPS_ALL); |
| 9980 | #endif |
| 9981 | ADD_INT(d, DB_VERB_RECOVERY); |
| 9982 | #if (DBVER >= 44) |
| 9983 | ADD_INT(d, DB_VERB_REGISTER); |
| 9984 | #endif |
| 9985 | ADD_INT(d, DB_VERB_REPLICATION); |
| 9986 | ADD_INT(d, DB_VERB_WAITSFOR); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 9987 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 9988 | #if (DBVER >= 50) |
| 9989 | ADD_INT(d, DB_VERB_REP_SYSTEM); |
| 9990 | #endif |
| 9991 | |
| 9992 | #if (DBVER >= 47) |
| 9993 | ADD_INT(d, DB_VERB_REP_ELECT); |
| 9994 | ADD_INT(d, DB_VERB_REP_LEASE); |
| 9995 | ADD_INT(d, DB_VERB_REP_MISC); |
| 9996 | ADD_INT(d, DB_VERB_REP_MSGS); |
| 9997 | ADD_INT(d, DB_VERB_REP_SYNC); |
| 9998 | ADD_INT(d, DB_VERB_REPMGR_CONNFAIL); |
| 9999 | ADD_INT(d, DB_VERB_REPMGR_MISC); |
| 10000 | #endif |
| 10001 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 10002 | #if (DBVER >= 45) |
| 10003 | ADD_INT(d, DB_EVENT_PANIC); |
| 10004 | ADD_INT(d, DB_EVENT_REP_CLIENT); |
| 10005 | #if (DBVER >= 46) |
| 10006 | ADD_INT(d, DB_EVENT_REP_ELECTED); |
| 10007 | #endif |
| 10008 | ADD_INT(d, DB_EVENT_REP_MASTER); |
| 10009 | ADD_INT(d, DB_EVENT_REP_NEWMASTER); |
| 10010 | #if (DBVER >= 46) |
| 10011 | ADD_INT(d, DB_EVENT_REP_PERM_FAILED); |
| 10012 | #endif |
| 10013 | ADD_INT(d, DB_EVENT_REP_STARTUPDONE); |
| 10014 | ADD_INT(d, DB_EVENT_WRITE_FAILED); |
| 10015 | #endif |
| 10016 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 10017 | #if (DBVER >= 50) |
| 10018 | ADD_INT(d, DB_REPMGR_CONF_ELECTIONS); |
| 10019 | ADD_INT(d, DB_EVENT_REP_MASTER_FAILURE); |
| 10020 | ADD_INT(d, DB_EVENT_REP_DUPMASTER); |
| 10021 | ADD_INT(d, DB_EVENT_REP_ELECTION_FAILED); |
| 10022 | #endif |
| 10023 | #if (DBVER >= 48) |
| 10024 | ADD_INT(d, DB_EVENT_REG_ALIVE); |
| 10025 | ADD_INT(d, DB_EVENT_REG_PANIC); |
| 10026 | #endif |
| 10027 | |
| 10028 | #if (DBVER >=52) |
| 10029 | ADD_INT(d, DB_EVENT_REP_SITE_ADDED); |
| 10030 | ADD_INT(d, DB_EVENT_REP_SITE_REMOVED); |
| 10031 | ADD_INT(d, DB_EVENT_REP_LOCAL_SITE_REMOVED); |
| 10032 | ADD_INT(d, DB_EVENT_REP_CONNECT_BROKEN); |
| 10033 | ADD_INT(d, DB_EVENT_REP_CONNECT_ESTD); |
| 10034 | ADD_INT(d, DB_EVENT_REP_CONNECT_TRY_FAILED); |
| 10035 | ADD_INT(d, DB_EVENT_REP_INIT_DONE); |
| 10036 | |
| 10037 | ADD_INT(d, DB_MEM_LOCK); |
| 10038 | ADD_INT(d, DB_MEM_LOCKOBJECT); |
| 10039 | ADD_INT(d, DB_MEM_LOCKER); |
| 10040 | ADD_INT(d, DB_MEM_LOGID); |
| 10041 | ADD_INT(d, DB_MEM_TRANSACTION); |
| 10042 | ADD_INT(d, DB_MEM_THREAD); |
| 10043 | |
| 10044 | ADD_INT(d, DB_BOOTSTRAP_HELPER); |
| 10045 | ADD_INT(d, DB_GROUP_CREATOR); |
| 10046 | ADD_INT(d, DB_LEGACY); |
| 10047 | ADD_INT(d, DB_LOCAL_SITE); |
| 10048 | ADD_INT(d, DB_REPMGR_PEER); |
| 10049 | #endif |
| 10050 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 10051 | ADD_INT(d, DB_REP_DUPMASTER); |
| 10052 | ADD_INT(d, DB_REP_HOLDELECTION); |
| 10053 | #if (DBVER >= 44) |
| 10054 | ADD_INT(d, DB_REP_IGNORE); |
| 10055 | ADD_INT(d, DB_REP_JOIN_FAILURE); |
| 10056 | #endif |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 10057 | ADD_INT(d, DB_REP_ISPERM); |
| 10058 | ADD_INT(d, DB_REP_NOTPERM); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 10059 | ADD_INT(d, DB_REP_NEWSITE); |
| 10060 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 10061 | ADD_INT(d, DB_REP_MASTER); |
| 10062 | ADD_INT(d, DB_REP_CLIENT); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10063 | |
| 10064 | ADD_INT(d, DB_REP_PERMANENT); |
| 10065 | |
| 10066 | #if (DBVER >= 44) |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 10067 | #if (DBVER >= 50) |
| 10068 | ADD_INT(d, DB_REP_CONF_AUTOINIT); |
| 10069 | #else |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10070 | ADD_INT(d, DB_REP_CONF_NOAUTOINIT); |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 10071 | #endif /* 5.0 */ |
| 10072 | #endif /* 4.4 */ |
| 10073 | #if (DBVER >= 44) |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10074 | ADD_INT(d, DB_REP_CONF_DELAYCLIENT); |
| 10075 | ADD_INT(d, DB_REP_CONF_BULK); |
| 10076 | ADD_INT(d, DB_REP_CONF_NOWAIT); |
| 10077 | ADD_INT(d, DB_REP_ANYWHERE); |
| 10078 | ADD_INT(d, DB_REP_REREQUEST); |
| 10079 | #endif |
| 10080 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10081 | ADD_INT(d, DB_REP_NOBUFFER); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10082 | |
| 10083 | #if (DBVER >= 46) |
| 10084 | ADD_INT(d, DB_REP_LEASE_EXPIRED); |
| 10085 | ADD_INT(d, DB_IGNORE_LEASE); |
| 10086 | #endif |
| 10087 | |
| 10088 | #if (DBVER >= 47) |
| 10089 | ADD_INT(d, DB_REP_CONF_LEASE); |
| 10090 | ADD_INT(d, DB_REPMGR_CONF_2SITE_STRICT); |
| 10091 | #endif |
| 10092 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 10093 | #if (DBVER >= 45) |
| 10094 | ADD_INT(d, DB_REP_ELECTION); |
| 10095 | |
| 10096 | ADD_INT(d, DB_REP_ACK_TIMEOUT); |
| 10097 | ADD_INT(d, DB_REP_CONNECTION_RETRY); |
| 10098 | ADD_INT(d, DB_REP_ELECTION_TIMEOUT); |
| 10099 | ADD_INT(d, DB_REP_ELECTION_RETRY); |
| 10100 | #endif |
| 10101 | #if (DBVER >= 46) |
| 10102 | ADD_INT(d, DB_REP_CHECKPOINT_DELAY); |
| 10103 | ADD_INT(d, DB_REP_FULL_ELECTION_TIMEOUT); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10104 | ADD_INT(d, DB_REP_LEASE_TIMEOUT); |
| 10105 | #endif |
| 10106 | #if (DBVER >= 47) |
| 10107 | ADD_INT(d, DB_REP_HEARTBEAT_MONITOR); |
| 10108 | ADD_INT(d, DB_REP_HEARTBEAT_SEND); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 10109 | #endif |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 10110 | |
| 10111 | #if (DBVER >= 45) |
| 10112 | ADD_INT(d, DB_REPMGR_PEER); |
| 10113 | ADD_INT(d, DB_REPMGR_ACKS_ALL); |
| 10114 | ADD_INT(d, DB_REPMGR_ACKS_ALL_PEERS); |
| 10115 | ADD_INT(d, DB_REPMGR_ACKS_NONE); |
| 10116 | ADD_INT(d, DB_REPMGR_ACKS_ONE); |
| 10117 | ADD_INT(d, DB_REPMGR_ACKS_ONE_PEER); |
| 10118 | ADD_INT(d, DB_REPMGR_ACKS_QUORUM); |
| 10119 | ADD_INT(d, DB_REPMGR_CONNECTED); |
| 10120 | ADD_INT(d, DB_REPMGR_DISCONNECTED); |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 10121 | ADD_INT(d, DB_STAT_ALL); |
| 10122 | #endif |
| 10123 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 10124 | #if (DBVER >= 51) |
| 10125 | ADD_INT(d, DB_REPMGR_ACKS_ALL_AVAILABLE); |
| 10126 | #endif |
| 10127 | |
| 10128 | #if (DBVER >= 48) |
| 10129 | ADD_INT(d, DB_REP_CONF_INMEM); |
| 10130 | #endif |
| 10131 | |
| 10132 | ADD_INT(d, DB_TIMEOUT); |
| 10133 | |
| 10134 | #if (DBVER >= 50) |
| 10135 | ADD_INT(d, DB_FORCESYNC); |
| 10136 | #endif |
| 10137 | |
| 10138 | #if (DBVER >= 48) |
| 10139 | ADD_INT(d, DB_FAILCHK); |
| 10140 | #endif |
| 10141 | |
| 10142 | #if (DBVER >= 51) |
| 10143 | ADD_INT(d, DB_HOTBACKUP_IN_PROGRESS); |
| 10144 | #endif |
| 10145 | |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 10146 | ADD_INT(d, DB_BUFFER_SMALL); |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 10147 | ADD_INT(d, DB_SEQ_DEC); |
| 10148 | ADD_INT(d, DB_SEQ_INC); |
| 10149 | ADD_INT(d, DB_SEQ_WRAP); |
Gregory P. Smith | 8b7e917 | 2004-12-13 09:51:23 +0000 | [diff] [blame] | 10150 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 10151 | #if (DBVER < 47) |
Jesus Cea | ca3939c | 2008-05-22 15:27:38 +0000 | [diff] [blame] | 10152 | ADD_INT(d, DB_LOG_INMEMORY); |
| 10153 | ADD_INT(d, DB_DSYNC_LOG); |
| 10154 | #endif |
| 10155 | |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 10156 | ADD_INT(d, DB_ENCRYPT_AES); |
| 10157 | ADD_INT(d, DB_AUTO_COMMIT); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10158 | ADD_INT(d, DB_PRIORITY_VERY_LOW); |
| 10159 | ADD_INT(d, DB_PRIORITY_LOW); |
| 10160 | ADD_INT(d, DB_PRIORITY_DEFAULT); |
| 10161 | ADD_INT(d, DB_PRIORITY_HIGH); |
| 10162 | ADD_INT(d, DB_PRIORITY_VERY_HIGH); |
| 10163 | |
| 10164 | #if (DBVER >= 46) |
| 10165 | ADD_INT(d, DB_PRIORITY_UNCHANGED); |
Barry Warsaw | 9a0d779 | 2002-12-30 20:53:52 +0000 | [diff] [blame] | 10166 | #endif |
| 10167 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10168 | ADD_INT(d, EINVAL); |
| 10169 | ADD_INT(d, EACCES); |
| 10170 | ADD_INT(d, ENOSPC); |
| 10171 | ADD_INT(d, ENOMEM); |
| 10172 | ADD_INT(d, EAGAIN); |
| 10173 | ADD_INT(d, EBUSY); |
| 10174 | ADD_INT(d, EEXIST); |
| 10175 | ADD_INT(d, ENOENT); |
| 10176 | ADD_INT(d, EPERM); |
| 10177 | |
Barry Warsaw | 1baa982 | 2003-03-31 19:51:29 +0000 | [diff] [blame] | 10178 | ADD_INT(d, DB_SET_LOCK_TIMEOUT); |
| 10179 | ADD_INT(d, DB_SET_TXN_TIMEOUT); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10180 | |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 10181 | #if (DBVER >= 48) |
| 10182 | ADD_INT(d, DB_SET_REG_TIMEOUT); |
| 10183 | #endif |
| 10184 | |
Gregory P. Smith | 7f5b6f4 | 2006-04-08 07:10:51 +0000 | [diff] [blame] | 10185 | /* The exception name must be correct for pickled exception * |
| 10186 | * objects to unpickle properly. */ |
| 10187 | #ifdef PYBSDDB_STANDALONE /* different value needed for standalone pybsddb */ |
| 10188 | #define PYBSDDB_EXCEPTION_BASE "bsddb3.db." |
| 10189 | #else |
| 10190 | #define PYBSDDB_EXCEPTION_BASE "bsddb.db." |
| 10191 | #endif |
| 10192 | |
| 10193 | /* All the rest of the exceptions derive only from DBError */ |
| 10194 | #define MAKE_EX(name) name = PyErr_NewException(PYBSDDB_EXCEPTION_BASE #name, DBError, NULL); \ |
| 10195 | PyDict_SetItemString(d, #name, name) |
| 10196 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10197 | /* The base exception class is DBError */ |
Gregory P. Smith | 7f5b6f4 | 2006-04-08 07:10:51 +0000 | [diff] [blame] | 10198 | DBError = NULL; /* used in MAKE_EX so that it derives from nothing */ |
| 10199 | MAKE_EX(DBError); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10200 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 10201 | #if (PY_VERSION_HEX < 0x03000000) |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 10202 | /* Some magic to make DBNotFoundError and DBKeyEmptyError derive |
| 10203 | * from both DBError and KeyError, since the API only supports |
| 10204 | * using one base class. */ |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10205 | PyDict_SetItemString(d, "KeyError", PyExc_KeyError); |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 10206 | PyRun_String("class DBNotFoundError(DBError, KeyError): pass\n" |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 10207 | "class DBKeyEmptyError(DBError, KeyError): pass", |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10208 | Py_file_input, d, d); |
| 10209 | DBNotFoundError = PyDict_GetItemString(d, "DBNotFoundError"); |
Gregory P. Smith | e947706 | 2005-06-04 06:46:59 +0000 | [diff] [blame] | 10210 | DBKeyEmptyError = PyDict_GetItemString(d, "DBKeyEmptyError"); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10211 | PyDict_DelItemString(d, "KeyError"); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 10212 | #else |
| 10213 | /* Since Python 2.5, PyErr_NewException() accepts a tuple, to be able to |
| 10214 | ** derive from several classes. We use this new API only for Python 3.0, |
| 10215 | ** though. |
| 10216 | */ |
| 10217 | { |
| 10218 | PyObject* bases; |
| 10219 | |
| 10220 | bases = PyTuple_Pack(2, DBError, PyExc_KeyError); |
| 10221 | |
| 10222 | #define MAKE_EX2(name) name = PyErr_NewException(PYBSDDB_EXCEPTION_BASE #name, bases, NULL); \ |
| 10223 | PyDict_SetItemString(d, #name, name) |
| 10224 | MAKE_EX2(DBNotFoundError); |
| 10225 | MAKE_EX2(DBKeyEmptyError); |
| 10226 | |
| 10227 | #undef MAKE_EX2 |
| 10228 | |
| 10229 | Py_XDECREF(bases); |
| 10230 | } |
| 10231 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10232 | |
Gregory P. Smith | e276717 | 2003-11-02 08:06:29 +0000 | [diff] [blame] | 10233 | MAKE_EX(DBCursorClosedError); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10234 | MAKE_EX(DBKeyExistError); |
| 10235 | MAKE_EX(DBLockDeadlockError); |
| 10236 | MAKE_EX(DBLockNotGrantedError); |
| 10237 | MAKE_EX(DBOldVersionError); |
| 10238 | MAKE_EX(DBRunRecoveryError); |
| 10239 | MAKE_EX(DBVerifyBadError); |
| 10240 | MAKE_EX(DBNoServerError); |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 10241 | #if (DBVER < 52) |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10242 | MAKE_EX(DBNoServerHomeError); |
| 10243 | MAKE_EX(DBNoServerIDError); |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 10244 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10245 | MAKE_EX(DBPageNotFoundError); |
| 10246 | MAKE_EX(DBSecondaryBadError); |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10247 | |
| 10248 | MAKE_EX(DBInvalidArgError); |
| 10249 | MAKE_EX(DBAccessError); |
| 10250 | MAKE_EX(DBNoSpaceError); |
| 10251 | MAKE_EX(DBNoMemoryError); |
| 10252 | MAKE_EX(DBAgainError); |
| 10253 | MAKE_EX(DBBusyError); |
| 10254 | MAKE_EX(DBFileExistsError); |
| 10255 | MAKE_EX(DBNoSuchFileError); |
| 10256 | MAKE_EX(DBPermissionsError); |
| 10257 | |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 10258 | MAKE_EX(DBRepHandleDeadError); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10259 | #if (DBVER >= 44) |
| 10260 | MAKE_EX(DBRepLockoutError); |
| 10261 | #endif |
Jesus Cea | ef9764f | 2008-05-13 18:45:46 +0000 | [diff] [blame] | 10262 | |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 10263 | MAKE_EX(DBRepUnavailError); |
| 10264 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10265 | #if (DBVER >= 46) |
| 10266 | MAKE_EX(DBRepLeaseExpiredError); |
| 10267 | #endif |
| 10268 | |
| 10269 | #if (DBVER >= 47) |
| 10270 | MAKE_EX(DBForeignConflictError); |
| 10271 | #endif |
| 10272 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10273 | #undef MAKE_EX |
| 10274 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10275 | /* Initialise the C API structure and add it to the module */ |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 10276 | bsddb_api.api_version = PYBSDDB_API_VERSION; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10277 | bsddb_api.db_type = &DB_Type; |
| 10278 | bsddb_api.dbcursor_type = &DBCursor_Type; |
| 10279 | bsddb_api.dblogcursor_type = &DBLogCursor_Type; |
| 10280 | bsddb_api.dbenv_type = &DBEnv_Type; |
| 10281 | bsddb_api.dbtxn_type = &DBTxn_Type; |
| 10282 | bsddb_api.dblock_type = &DBLock_Type; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10283 | bsddb_api.dbsequence_type = &DBSequence_Type; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10284 | bsddb_api.makeDBError = makeDBError; |
Gregory P. Smith | 3925053 | 2007-10-09 06:02:21 +0000 | [diff] [blame] | 10285 | |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10286 | /* |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 10287 | ** Capsules exist from Python 2.7 and 3.1. |
| 10288 | ** We don't support Python 3.0 anymore, so... |
| 10289 | ** #if (PY_VERSION_HEX < ((PY_MAJOR_VERSION < 3) ? 0x02070000 : 0x03020000)) |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10290 | */ |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 10291 | #if (PY_VERSION_HEX < 0x02070000) |
Gregory P. Smith | 3925053 | 2007-10-09 06:02:21 +0000 | [diff] [blame] | 10292 | py_api = PyCObject_FromVoidPtr((void*)&bsddb_api, NULL); |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10293 | #else |
| 10294 | { |
doko@ubuntu.com | 4950a3b | 2013-03-19 14:46:29 -0700 | [diff] [blame] | 10295 | /* |
| 10296 | ** The data must outlive the call!!. So, the static definition. |
| 10297 | ** The buffer must be big enough... |
| 10298 | */ |
| 10299 | static char py_api_name[MODULE_NAME_MAX_LEN+10]; |
Jesus Cea | 6557aac | 2010-03-22 14:22:26 +0000 | [diff] [blame] | 10300 | |
| 10301 | strcpy(py_api_name, _bsddbModuleName); |
| 10302 | strcat(py_api_name, ".api"); |
| 10303 | |
| 10304 | py_api = PyCapsule_New((void*)&bsddb_api, py_api_name, NULL); |
| 10305 | } |
| 10306 | #endif |
| 10307 | |
Jesus Cea | 84f2c32 | 2010-11-05 00:13:50 +0000 | [diff] [blame] | 10308 | /* Check error control */ |
| 10309 | /* |
| 10310 | ** PyErr_NoMemory(); |
| 10311 | ** py_api = NULL; |
| 10312 | */ |
| 10313 | |
| 10314 | if (py_api) { |
| 10315 | PyDict_SetItemString(d, "api", py_api); |
| 10316 | Py_DECREF(py_api); |
| 10317 | } else { /* Something bad happened */ |
| 10318 | PyErr_WriteUnraisable(m); |
Jesus Cea | bf088f8 | 2010-11-08 12:57:59 +0000 | [diff] [blame] | 10319 | if(PyErr_Warn(PyExc_RuntimeWarning, |
| 10320 | "_bsddb/_pybsddb C API will be not available")) { |
| 10321 | PyErr_WriteUnraisable(m); |
| 10322 | } |
Jesus Cea | 84f2c32 | 2010-11-05 00:13:50 +0000 | [diff] [blame] | 10323 | PyErr_Clear(); |
| 10324 | } |
Gregory P. Smith | 3925053 | 2007-10-09 06:02:21 +0000 | [diff] [blame] | 10325 | |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10326 | /* Check for errors */ |
| 10327 | if (PyErr_Occurred()) { |
| 10328 | PyErr_Print(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 10329 | Py_FatalError("can't initialize module _bsddb/_pybsddb"); |
| 10330 | Py_DECREF(m); |
| 10331 | m = NULL; |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10332 | } |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 10333 | #if (PY_VERSION_HEX < 0x03000000) |
| 10334 | return; |
| 10335 | #else |
| 10336 | return m; |
| 10337 | #endif |
Martin v. Löwis | 6aa4a1f | 2002-11-19 08:09:52 +0000 | [diff] [blame] | 10338 | } |
Gregory P. Smith | 41631e8 | 2003-09-21 00:08:14 +0000 | [diff] [blame] | 10339 | |
| 10340 | /* allow this module to be named _pybsddb so that it can be installed |
| 10341 | * and imported on top of python >= 2.3 that includes its own older |
| 10342 | * copy of the library named _bsddb without importing the old version. */ |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 10343 | #if (PY_VERSION_HEX < 0x03000000) |
Gregory P. Smith | 41631e8 | 2003-09-21 00:08:14 +0000 | [diff] [blame] | 10344 | DL_EXPORT(void) init_pybsddb(void) |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 10345 | #else |
| 10346 | PyMODINIT_FUNC PyInit__pybsddb(void) /* Note the two underscores */ |
| 10347 | #endif |
Gregory P. Smith | 41631e8 | 2003-09-21 00:08:14 +0000 | [diff] [blame] | 10348 | { |
| 10349 | strncpy(_bsddbModuleName, "_pybsddb", MODULE_NAME_MAX_LEN); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 10350 | #if (PY_VERSION_HEX < 0x03000000) |
Gregory P. Smith | 41631e8 | 2003-09-21 00:08:14 +0000 | [diff] [blame] | 10351 | init_bsddb(); |
Jesus Cea | c5a11fa | 2008-07-23 11:38:42 +0000 | [diff] [blame] | 10352 | #else |
| 10353 | return PyInit__bsddb(); /* Note the two underscores */ |
| 10354 | #endif |
Gregory P. Smith | 41631e8 | 2003-09-21 00:08:14 +0000 | [diff] [blame] | 10355 | } |