/Modules/bsddb.h

http://unladen-swallow.googlecode.com/ · C Header · 273 lines · 117 code · 40 blank · 116 comment · 6 complexity · 89e483757fc807a0f1d24efc049f87d4 MD5 · raw file

  1. /*----------------------------------------------------------------------
  2. Copyright (c) 1999-2001, Digital Creations, Fredericksburg, VA, USA
  3. and Andrew Kuchling. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. o Redistributions of source code must retain the above copyright
  8. notice, this list of conditions, and the disclaimer that follows.
  9. o Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions, and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. o Neither the name of Digital Creations nor the names of its
  14. contributors may be used to endorse or promote products derived
  15. from this software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS
  17. IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  18. TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  19. PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
  20. CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  22. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  23. OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  25. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  26. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  27. DAMAGE.
  28. ------------------------------------------------------------------------*/
  29. /*
  30. * Handwritten code to wrap version 3.x of the Berkeley DB library,
  31. * written to replace a SWIG-generated file. It has since been updated
  32. * to compile with Berkeley DB versions 3.2 through 4.2.
  33. *
  34. * This module was started by Andrew Kuchling to remove the dependency
  35. * on SWIG in a package by Gregory P. Smith who based his work on a
  36. * similar package by Robin Dunn <robin@alldunn.com> which wrapped
  37. * Berkeley DB 2.7.x.
  38. *
  39. * Development of this module then returned full circle back to Robin Dunn
  40. * who worked on behalf of Digital Creations to complete the wrapping of
  41. * the DB 3.x API and to build a solid unit test suite. Robin has
  42. * since gone onto other projects (wxPython).
  43. *
  44. * Gregory P. Smith <greg@krypto.org> is once again the maintainer.
  45. *
  46. * Use the pybsddb-users@lists.sf.net mailing list for all questions.
  47. * Things can change faster than the header of this file is updated. This
  48. * file is shared with the PyBSDDB project at SourceForge:
  49. *
  50. * http://pybsddb.sf.net
  51. *
  52. * This file should remain backward compatible with Python 2.1, but see PEP
  53. * 291 for the most current backward compatibility requirements:
  54. *
  55. * http://www.python.org/peps/pep-0291.html
  56. *
  57. * This module contains 6 types:
  58. *
  59. * DB (Database)
  60. * DBCursor (Database Cursor)
  61. * DBEnv (database environment)
  62. * DBTxn (An explicit database transaction)
  63. * DBLock (A lock handle)
  64. * DBSequence (Sequence)
  65. *
  66. */
  67. /* --------------------------------------------------------------------- */
  68. /*
  69. * Portions of this module, associated unit tests and build scripts are the
  70. * result of a contract with The Written Word (http://thewrittenword.com/)
  71. * Many thanks go out to them for causing me to raise the bar on quality and
  72. * functionality, resulting in a better bsddb3 package for all of us to use.
  73. *
  74. * --Robin
  75. */
  76. /* --------------------------------------------------------------------- */
  77. /*
  78. * Work to split it up into a separate header and to add a C API was
  79. * contributed by Duncan Grisby <duncan@tideway.com>. See here:
  80. * http://sourceforge.net/tracker/index.php?func=detail&aid=1551895&group_id=13900&atid=313900
  81. */
  82. /* --------------------------------------------------------------------- */
  83. #ifndef _BSDDB_H_
  84. #define _BSDDB_H_
  85. #include <db.h>
  86. /* 40 = 4.0, 33 = 3.3; this will break if the minor revision is > 9 */
  87. #define DBVER (DB_VERSION_MAJOR * 10 + DB_VERSION_MINOR)
  88. #if DB_VERSION_MINOR > 9
  89. #error "eek! DBVER can't handle minor versions > 9"
  90. #endif
  91. #define PY_BSDDB_VERSION "4.7.3"
  92. /* Python object definitions */
  93. struct behaviourFlags {
  94. /* What is the default behaviour when DB->get or DBCursor->get returns a
  95. DB_NOTFOUND || DB_KEYEMPTY error? Return None or raise an exception? */
  96. unsigned int getReturnsNone : 1;
  97. /* What is the default behaviour for DBCursor.set* methods when DBCursor->get
  98. * returns a DB_NOTFOUND || DB_KEYEMPTY error? Return None or raise? */
  99. unsigned int cursorSetReturnsNone : 1;
  100. };
  101. struct DBObject; /* Forward declaration */
  102. struct DBCursorObject; /* Forward declaration */
  103. struct DBTxnObject; /* Forward declaration */
  104. struct DBSequenceObject; /* Forward declaration */
  105. typedef struct {
  106. PyObject_HEAD
  107. DB_ENV* db_env;
  108. u_int32_t flags; /* saved flags from open() */
  109. int closed;
  110. struct behaviourFlags moduleFlags;
  111. PyObject* event_notifyCallback;
  112. struct DBObject *children_dbs;
  113. struct DBTxnObject *children_txns;
  114. PyObject *private_obj;
  115. PyObject *rep_transport;
  116. PyObject *in_weakreflist; /* List of weak references */
  117. } DBEnvObject;
  118. typedef struct DBObject {
  119. PyObject_HEAD
  120. DB* db;
  121. DBEnvObject* myenvobj; /* PyObject containing the DB_ENV */
  122. u_int32_t flags; /* saved flags from open() */
  123. u_int32_t setflags; /* saved flags from set_flags() */
  124. int haveStat;
  125. struct behaviourFlags moduleFlags;
  126. struct DBTxnObject *txn;
  127. struct DBCursorObject *children_cursors;
  128. #if (DBVER >=43)
  129. struct DBSequenceObject *children_sequences;
  130. #endif
  131. struct DBObject **sibling_prev_p;
  132. struct DBObject *sibling_next;
  133. struct DBObject **sibling_prev_p_txn;
  134. struct DBObject *sibling_next_txn;
  135. PyObject* associateCallback;
  136. PyObject* btCompareCallback;
  137. int primaryDBType;
  138. PyObject *private_obj;
  139. PyObject *in_weakreflist; /* List of weak references */
  140. } DBObject;
  141. typedef struct DBCursorObject {
  142. PyObject_HEAD
  143. DBC* dbc;
  144. struct DBCursorObject **sibling_prev_p;
  145. struct DBCursorObject *sibling_next;
  146. struct DBCursorObject **sibling_prev_p_txn;
  147. struct DBCursorObject *sibling_next_txn;
  148. DBObject* mydb;
  149. struct DBTxnObject *txn;
  150. PyObject *in_weakreflist; /* List of weak references */
  151. } DBCursorObject;
  152. typedef struct DBTxnObject {
  153. PyObject_HEAD
  154. DB_TXN* txn;
  155. DBEnvObject* env;
  156. int flag_prepare;
  157. struct DBTxnObject *parent_txn;
  158. struct DBTxnObject **sibling_prev_p;
  159. struct DBTxnObject *sibling_next;
  160. struct DBTxnObject *children_txns;
  161. struct DBObject *children_dbs;
  162. struct DBSequenceObject *children_sequences;
  163. struct DBCursorObject *children_cursors;
  164. PyObject *in_weakreflist; /* List of weak references */
  165. } DBTxnObject;
  166. typedef struct {
  167. PyObject_HEAD
  168. DB_LOCK lock;
  169. PyObject *in_weakreflist; /* List of weak references */
  170. } DBLockObject;
  171. #if (DBVER >= 43)
  172. typedef struct DBSequenceObject {
  173. PyObject_HEAD
  174. DB_SEQUENCE* sequence;
  175. DBObject* mydb;
  176. struct DBTxnObject *txn;
  177. struct DBSequenceObject **sibling_prev_p;
  178. struct DBSequenceObject *sibling_next;
  179. struct DBSequenceObject **sibling_prev_p_txn;
  180. struct DBSequenceObject *sibling_next_txn;
  181. PyObject *in_weakreflist; /* List of weak references */
  182. } DBSequenceObject;
  183. #endif
  184. /* API structure for use by C code */
  185. /* To access the structure from an external module, use code like the
  186. following (error checking missed out for clarity):
  187. BSDDB_api* bsddb_api;
  188. PyObject* mod;
  189. PyObject* cobj;
  190. mod = PyImport_ImportModule("bsddb._bsddb");
  191. // Use "bsddb3._pybsddb" if you're using the standalone pybsddb add-on.
  192. cobj = PyObject_GetAttrString(mod, "api");
  193. api = (BSDDB_api*)PyCObject_AsVoidPtr(cobj);
  194. Py_DECREF(cobj);
  195. Py_DECREF(mod);
  196. The structure's members must not be changed.
  197. */
  198. typedef struct {
  199. /* Type objects */
  200. PyTypeObject* db_type;
  201. PyTypeObject* dbcursor_type;
  202. PyTypeObject* dbenv_type;
  203. PyTypeObject* dbtxn_type;
  204. PyTypeObject* dblock_type;
  205. #if (DBVER >= 43)
  206. PyTypeObject* dbsequence_type;
  207. #endif
  208. /* Functions */
  209. int (*makeDBError)(int err);
  210. } BSDDB_api;
  211. #ifndef COMPILING_BSDDB_C
  212. /* If not inside _bsddb.c, define type check macros that use the api
  213. structure. The calling code must have a value named bsddb_api
  214. pointing to the api structure.
  215. */
  216. #define DBObject_Check(v) ((v)->ob_type == bsddb_api->db_type)
  217. #define DBCursorObject_Check(v) ((v)->ob_type == bsddb_api->dbcursor_type)
  218. #define DBEnvObject_Check(v) ((v)->ob_type == bsddb_api->dbenv_type)
  219. #define DBTxnObject_Check(v) ((v)->ob_type == bsddb_api->dbtxn_type)
  220. #define DBLockObject_Check(v) ((v)->ob_type == bsddb_api->dblock_type)
  221. #if (DBVER >= 43)
  222. #define DBSequenceObject_Check(v) ((v)->ob_type == bsddb_api->dbsequence_type)
  223. #endif
  224. #endif /* COMPILING_BSDDB_C */
  225. #endif /* _BSDDB_H_ */