source: python/trunk/Modules/bsddb.h@ 380

Last change on this file since 380 was 132, checked in by Yuri Dario, 15 years ago

python: backported bdb 4.8.x code from Python 2.7

  • Property svn:eol-style set to native
File size: 9.9 KB
Line 
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,
38 * written to replace a SWIG-generated file. It has since been updated
39 * to compile with Berkeley DB versions 3.2 through 4.2.
40 *
41 * This module was started by Andrew Kuchling to remove the dependency
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.
45 *
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 *
51 * Gregory P. Smith <greg@krypto.org> is once again the maintainer.
52 *
53 * Use the pybsddb-users@lists.sf.net mailing list for all questions.
54 * Things can change faster than the header of this file is updated. This
55 * file is shared with the PyBSDDB project at SourceForge:
56 *
57 * http://pybsddb.sf.net
58 *
59 * This file should remain backward compatible with Python 2.1, but see PEP
60 * 291 for the most current backward compatibility requirements:
61 *
62 * http://www.python.org/peps/pep-0291.html
63 *
64 * This module contains 6 types:
65 *
66 * DB (Database)
67 * DBCursor (Database Cursor)
68 * DBEnv (database environment)
69 * DBTxn (An explicit database transaction)
70 * DBLock (A lock handle)
71 * DBSequence (Sequence)
72 *
73 * New datatypes:
74 *
75 * DBLogCursor (Log Cursor)
76 *
77 */
78
79/* --------------------------------------------------------------------- */
80
81/*
82 * Portions of this module, associated unit tests and build scripts are the
83 * result of a contract with The Written Word (http://thewrittenword.com/)
84 * Many thanks go out to them for causing me to raise the bar on quality and
85 * functionality, resulting in a better bsddb3 package for all of us to use.
86 *
87 * --Robin
88 */
89
90/* --------------------------------------------------------------------- */
91
92/*
93 * Work to split it up into a separate header and to add a C API was
94 * contributed by Duncan Grisby <duncan@tideway.com>. See here:
95 * http://sourceforge.net/tracker/index.php?func=detail&aid=1551895&group_id=13900&atid=313900
96 */
97
98/* --------------------------------------------------------------------- */
99
100#ifndef _BSDDB_H_
101#define _BSDDB_H_
102
103#include <db.h>
104
105
106/* 40 = 4.0, 33 = 3.3; this will break if the minor revision is > 9 */
107#define DBVER (DB_VERSION_MAJOR * 10 + DB_VERSION_MINOR)
108#if DB_VERSION_MINOR > 9
109#error "eek! DBVER can't handle minor versions > 9"
110#endif
111
112#define PY_BSDDB_VERSION "4.8.4"
113
114/* Python object definitions */
115
116struct behaviourFlags {
117 /* What is the default behaviour when DB->get or DBCursor->get returns a
118 DB_NOTFOUND || DB_KEYEMPTY error? Return None or raise an exception? */
119 unsigned int getReturnsNone : 1;
120 /* What is the default behaviour for DBCursor.set* methods when DBCursor->get
121 * returns a DB_NOTFOUND || DB_KEYEMPTY error? Return None or raise? */
122 unsigned int cursorSetReturnsNone : 1;
123};
124
125
126
127struct DBObject; /* Forward declaration */
128struct DBCursorObject; /* Forward declaration */
129struct DBLogCursorObject; /* Forward declaration */
130struct DBTxnObject; /* Forward declaration */
131struct DBSequenceObject; /* Forward declaration */
132
133typedef struct {
134 PyObject_HEAD
135 DB_ENV* db_env;
136 u_int32_t flags; /* saved flags from open() */
137 int closed;
138 struct behaviourFlags moduleFlags;
139 PyObject* event_notifyCallback;
140 struct DBObject *children_dbs;
141 struct DBTxnObject *children_txns;
142 struct DBLogCursorObject *children_logcursors;
143 PyObject *private_obj;
144 PyObject *rep_transport;
145 PyObject *in_weakreflist; /* List of weak references */
146} DBEnvObject;
147
148typedef struct DBObject {
149 PyObject_HEAD
150 DB* db;
151 DBEnvObject* myenvobj; /* PyObject containing the DB_ENV */
152 u_int32_t flags; /* saved flags from open() */
153 u_int32_t setflags; /* saved flags from set_flags() */
154 struct behaviourFlags moduleFlags;
155 struct DBTxnObject *txn;
156 struct DBCursorObject *children_cursors;
157#if (DBVER >=43)
158 struct DBSequenceObject *children_sequences;
159#endif
160 struct DBObject **sibling_prev_p;
161 struct DBObject *sibling_next;
162 struct DBObject **sibling_prev_p_txn;
163 struct DBObject *sibling_next_txn;
164 PyObject* associateCallback;
165 PyObject* btCompareCallback;
166 int primaryDBType;
167 PyObject *private_obj;
168 PyObject *in_weakreflist; /* List of weak references */
169} DBObject;
170
171
172typedef struct DBCursorObject {
173 PyObject_HEAD
174 DBC* dbc;
175 struct DBCursorObject **sibling_prev_p;
176 struct DBCursorObject *sibling_next;
177 struct DBCursorObject **sibling_prev_p_txn;
178 struct DBCursorObject *sibling_next_txn;
179 DBObject* mydb;
180 struct DBTxnObject *txn;
181 PyObject *in_weakreflist; /* List of weak references */
182} DBCursorObject;
183
184
185typedef struct DBTxnObject {
186 PyObject_HEAD
187 DB_TXN* txn;
188 DBEnvObject* env;
189 int flag_prepare;
190 struct DBTxnObject *parent_txn;
191 struct DBTxnObject **sibling_prev_p;
192 struct DBTxnObject *sibling_next;
193 struct DBTxnObject *children_txns;
194 struct DBObject *children_dbs;
195 struct DBSequenceObject *children_sequences;
196 struct DBCursorObject *children_cursors;
197 PyObject *in_weakreflist; /* List of weak references */
198} DBTxnObject;
199
200
201typedef struct DBLogCursorObject {
202 PyObject_HEAD
203 DB_LOGC* logc;
204 DBEnvObject* env;
205 struct DBLogCursorObject **sibling_prev_p;
206 struct DBLogCursorObject *sibling_next;
207 PyObject *in_weakreflist; /* List of weak references */
208} DBLogCursorObject;
209
210
211typedef struct {
212 PyObject_HEAD
213 DB_LOCK lock;
214 int lock_initialized; /* Signal if we actually have a lock */
215 PyObject *in_weakreflist; /* List of weak references */
216} DBLockObject;
217
218
219#if (DBVER >= 43)
220typedef struct DBSequenceObject {
221 PyObject_HEAD
222 DB_SEQUENCE* sequence;
223 DBObject* mydb;
224 struct DBTxnObject *txn;
225 struct DBSequenceObject **sibling_prev_p;
226 struct DBSequenceObject *sibling_next;
227 struct DBSequenceObject **sibling_prev_p_txn;
228 struct DBSequenceObject *sibling_next_txn;
229 PyObject *in_weakreflist; /* List of weak references */
230} DBSequenceObject;
231#endif
232
233
234/* API structure for use by C code */
235
236/* To access the structure from an external module, use code like the
237 following (error checking missed out for clarity):
238
239 // If you are using Python before 3.2:
240 BSDDB_api* bsddb_api;
241 PyObject* mod;
242 PyObject* cobj;
243
244 mod = PyImport_ImportModule("bsddb._bsddb");
245 // Use "bsddb3._pybsddb" if you're using the standalone pybsddb add-on.
246 cobj = PyObject_GetAttrString(mod, "api");
247 api = (BSDDB_api*)PyCObject_AsVoidPtr(cobj);
248 Py_DECREF(cobj);
249 Py_DECREF(mod);
250
251
252 // If you are using Python 3.2 or up:
253 BSDDB_api* bsddb_api;
254
255 // Use "bsddb3._pybsddb.api" if you're using
256 // the standalone pybsddb add-on.
257 bsddb_api = (void **)PyCapsule_Import("bsddb._bsddb.api", 1);
258
259
260 The structure's members must not be changed.
261*/
262
263typedef struct {
264 /* Type objects */
265 PyTypeObject* db_type;
266 PyTypeObject* dbcursor_type;
267 PyTypeObject* dblogcursor_type;
268 PyTypeObject* dbenv_type;
269 PyTypeObject* dbtxn_type;
270 PyTypeObject* dblock_type;
271#if (DBVER >= 43)
272 PyTypeObject* dbsequence_type;
273#endif
274
275 /* Functions */
276 int (*makeDBError)(int err);
277} BSDDB_api;
278
279
280#ifndef COMPILING_BSDDB_C
281
282/* If not inside _bsddb.c, define type check macros that use the api
283 structure. The calling code must have a value named bsddb_api
284 pointing to the api structure.
285*/
286
287#define DBObject_Check(v) ((v)->ob_type == bsddb_api->db_type)
288#define DBCursorObject_Check(v) ((v)->ob_type == bsddb_api->dbcursor_type)
289#define DBEnvObject_Check(v) ((v)->ob_type == bsddb_api->dbenv_type)
290#define DBTxnObject_Check(v) ((v)->ob_type == bsddb_api->dbtxn_type)
291#define DBLockObject_Check(v) ((v)->ob_type == bsddb_api->dblock_type)
292#if (DBVER >= 43)
293#define DBSequenceObject_Check(v) ((v)->ob_type == bsddb_api->dbsequence_type)
294#endif
295
296#endif /* COMPILING_BSDDB_C */
297
298
299#endif /* _BSDDB_H_ */
Note: See TracBrowser for help on using the repository browser.