Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 1 | /* Berkeley DB interface. |
| 2 | Author: Michael McLay |
| 3 | Hacked: Guido van Rossum |
| 4 | Btree and Recno additions plus sequence methods: David Ely |
| 5 | |
| 6 | XXX To do: |
| 7 | - provide interface to the B-tree and record libraries too |
| 8 | - provide a way to access the various hash functions |
| 9 | - support more open flags |
Guido van Rossum | 675e994 | 1999-09-20 13:28:18 +0000 | [diff] [blame] | 10 | |
| 11 | The windows port of the Berkeley DB code is hard to find on the web: |
| 12 | www.nightmare.com/software.html |
| 13 | */ |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 14 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 15 | #include "Python.h" |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 16 | #ifdef WITH_THREAD |
Guido van Rossum | 49b5606 | 1998-10-01 20:42:43 +0000 | [diff] [blame] | 17 | #include "pythread.h" |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 18 | #endif |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 19 | |
| 20 | #include <sys/types.h> |
| 21 | #include <sys/stat.h> |
| 22 | #include <fcntl.h> |
Fred Drake | c9cb847 | 2000-08-31 16:11:07 +0000 | [diff] [blame] | 23 | #ifdef HAVE_DB_185_H |
| 24 | #include <db_185.h> |
| 25 | #else |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 26 | #include <db.h> |
Fred Drake | c9cb847 | 2000-08-31 16:11:07 +0000 | [diff] [blame] | 27 | #endif |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 28 | /* Please don't include internal header files of the Berkeley db package |
| 29 | (it messes up the info required in the Setup file) */ |
| 30 | |
| 31 | typedef struct { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 32 | PyObject_HEAD |
| 33 | DB *di_bsddb; |
| 34 | int di_size; /* -1 means recompute */ |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 35 | #ifdef WITH_THREAD |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 36 | PyThread_type_lock di_lock; |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 37 | #endif |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 38 | } bsddbobject; |
| 39 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 40 | staticforward PyTypeObject Bsddbtype; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 41 | |
| 42 | #define is_bsddbobject(v) ((v)->ob_type == &Bsddbtype) |
Guido van Rossum | 77eecfa | 1997-07-17 22:56:01 +0000 | [diff] [blame] | 43 | #define check_bsddbobject_open(v) if ((v)->di_bsddb == NULL) \ |
Fred Drake | c9f7c26 | 2001-02-19 21:16:00 +0000 | [diff] [blame] | 44 | { PyErr_SetString(BsddbError, \ |
| 45 | "BSDDB object has already been closed"); \ |
Guido van Rossum | 77eecfa | 1997-07-17 22:56:01 +0000 | [diff] [blame] | 46 | return NULL; } |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 47 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 48 | static PyObject *BsddbError; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 49 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 50 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 51 | newdbhashobject(char *file, int flags, int mode, |
Fred Drake | c9f7c26 | 2001-02-19 21:16:00 +0000 | [diff] [blame] | 52 | int bsize, int ffactor, int nelem, int cachesize, |
| 53 | int hash, int lorder) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 54 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 55 | bsddbobject *dp; |
| 56 | HASHINFO info; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 57 | |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 58 | if ((dp = PyObject_New(bsddbobject, &Bsddbtype)) == NULL) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 59 | return NULL; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 60 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 61 | info.bsize = bsize; |
| 62 | info.ffactor = ffactor; |
| 63 | info.nelem = nelem; |
| 64 | info.cachesize = cachesize; |
| 65 | info.hash = NULL; /* XXX should derive from hash argument */ |
| 66 | info.lorder = lorder; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 67 | |
Guido van Rossum | 6beb479 | 1996-09-11 23:22:25 +0000 | [diff] [blame] | 68 | #ifdef O_BINARY |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 69 | flags |= O_BINARY; |
Guido van Rossum | 6beb479 | 1996-09-11 23:22:25 +0000 | [diff] [blame] | 70 | #endif |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 71 | Py_BEGIN_ALLOW_THREADS |
| 72 | dp->di_bsddb = dbopen(file, flags, mode, DB_HASH, &info); |
| 73 | Py_END_ALLOW_THREADS |
| 74 | if (dp->di_bsddb == NULL) { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 75 | PyErr_SetFromErrno(BsddbError); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 76 | #ifdef WITH_THREAD |
| 77 | dp->di_lock = NULL; |
| 78 | #endif |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 79 | Py_DECREF(dp); |
| 80 | return NULL; |
| 81 | } |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 82 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 83 | dp->di_size = -1; |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 84 | #ifdef WITH_THREAD |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 85 | dp->di_lock = PyThread_allocate_lock(); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 86 | if (dp->di_lock == NULL) { |
| 87 | PyErr_SetString(BsddbError, "can't allocate lock"); |
| 88 | Py_DECREF(dp); |
| 89 | return NULL; |
| 90 | } |
| 91 | #endif |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 92 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 93 | return (PyObject *)dp; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 96 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 97 | newdbbtobject(char *file, int flags, int mode, |
Fred Drake | c9f7c26 | 2001-02-19 21:16:00 +0000 | [diff] [blame] | 98 | int btflags, int cachesize, int maxkeypage, |
| 99 | int minkeypage, int psize, int lorder) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 100 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 101 | bsddbobject *dp; |
| 102 | BTREEINFO info; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 103 | |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 104 | if ((dp = PyObject_New(bsddbobject, &Bsddbtype)) == NULL) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 105 | return NULL; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 106 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 107 | info.flags = btflags; |
| 108 | info.cachesize = cachesize; |
| 109 | info.maxkeypage = maxkeypage; |
| 110 | info.minkeypage = minkeypage; |
| 111 | info.psize = psize; |
| 112 | info.lorder = lorder; |
| 113 | info.compare = 0; /* Use default comparison functions, for now..*/ |
| 114 | info.prefix = 0; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 115 | |
Guido van Rossum | 6beb479 | 1996-09-11 23:22:25 +0000 | [diff] [blame] | 116 | #ifdef O_BINARY |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 117 | flags |= O_BINARY; |
Guido van Rossum | 6beb479 | 1996-09-11 23:22:25 +0000 | [diff] [blame] | 118 | #endif |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 119 | Py_BEGIN_ALLOW_THREADS |
| 120 | dp->di_bsddb = dbopen(file, flags, mode, DB_BTREE, &info); |
| 121 | Py_END_ALLOW_THREADS |
| 122 | if (dp->di_bsddb == NULL) { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 123 | PyErr_SetFromErrno(BsddbError); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 124 | #ifdef WITH_THREAD |
| 125 | dp->di_lock = NULL; |
| 126 | #endif |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 127 | Py_DECREF(dp); |
| 128 | return NULL; |
| 129 | } |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 130 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 131 | dp->di_size = -1; |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 132 | #ifdef WITH_THREAD |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 133 | dp->di_lock = PyThread_allocate_lock(); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 134 | if (dp->di_lock == NULL) { |
| 135 | PyErr_SetString(BsddbError, "can't allocate lock"); |
| 136 | Py_DECREF(dp); |
| 137 | return NULL; |
| 138 | } |
| 139 | #endif |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 140 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 141 | return (PyObject *)dp; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 144 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 145 | newdbrnobject(char *file, int flags, int mode, |
Fred Drake | c9f7c26 | 2001-02-19 21:16:00 +0000 | [diff] [blame] | 146 | int rnflags, int cachesize, int psize, int lorder, |
| 147 | size_t reclen, u_char bval, char *bfname) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 148 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 149 | bsddbobject *dp; |
| 150 | RECNOINFO info; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 151 | |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 152 | if ((dp = PyObject_New(bsddbobject, &Bsddbtype)) == NULL) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 153 | return NULL; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 154 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 155 | info.flags = rnflags; |
| 156 | info.cachesize = cachesize; |
| 157 | info.psize = psize; |
| 158 | info.lorder = lorder; |
| 159 | info.reclen = reclen; |
| 160 | info.bval = bval; |
| 161 | info.bfname = bfname; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 162 | |
Guido van Rossum | 6beb479 | 1996-09-11 23:22:25 +0000 | [diff] [blame] | 163 | #ifdef O_BINARY |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 164 | flags |= O_BINARY; |
Guido van Rossum | 6beb479 | 1996-09-11 23:22:25 +0000 | [diff] [blame] | 165 | #endif |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 166 | Py_BEGIN_ALLOW_THREADS |
| 167 | dp->di_bsddb = dbopen(file, flags, mode, DB_RECNO, &info); |
| 168 | Py_END_ALLOW_THREADS |
| 169 | if (dp->di_bsddb == NULL) { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 170 | PyErr_SetFromErrno(BsddbError); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 171 | #ifdef WITH_THREAD |
| 172 | dp->di_lock = NULL; |
| 173 | #endif |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 174 | Py_DECREF(dp); |
| 175 | return NULL; |
| 176 | } |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 177 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 178 | dp->di_size = -1; |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 179 | #ifdef WITH_THREAD |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 180 | dp->di_lock = PyThread_allocate_lock(); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 181 | if (dp->di_lock == NULL) { |
| 182 | PyErr_SetString(BsddbError, "can't allocate lock"); |
| 183 | Py_DECREF(dp); |
| 184 | return NULL; |
| 185 | } |
| 186 | #endif |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 187 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 188 | return (PyObject *)dp; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 191 | static void |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 192 | bsddb_dealloc(bsddbobject *dp) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 193 | { |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 194 | #ifdef WITH_THREAD |
| 195 | if (dp->di_lock) { |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 196 | PyThread_acquire_lock(dp->di_lock, 0); |
| 197 | PyThread_release_lock(dp->di_lock); |
| 198 | PyThread_free_lock(dp->di_lock); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 199 | dp->di_lock = NULL; |
| 200 | } |
| 201 | #endif |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 202 | if (dp->di_bsddb != NULL) { |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 203 | int status; |
| 204 | Py_BEGIN_ALLOW_THREADS |
| 205 | status = (dp->di_bsddb->close)(dp->di_bsddb); |
| 206 | Py_END_ALLOW_THREADS |
| 207 | if (status != 0) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 208 | fprintf(stderr, |
| 209 | "Python bsddb: close errno %d in dealloc\n", |
| 210 | errno); |
| 211 | } |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 212 | PyObject_Del(dp); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 215 | #ifdef WITH_THREAD |
Fred Drake | c9f7c26 | 2001-02-19 21:16:00 +0000 | [diff] [blame] | 216 | #define BSDDB_BGN_SAVE(_dp) \ |
| 217 | Py_BEGIN_ALLOW_THREADS PyThread_acquire_lock(_dp->di_lock,1); |
| 218 | #define BSDDB_END_SAVE(_dp) \ |
| 219 | PyThread_release_lock(_dp->di_lock); Py_END_ALLOW_THREADS |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 220 | #else |
| 221 | #define BSDDB_BGN_SAVE(_dp) Py_BEGIN_ALLOW_THREADS |
| 222 | #define BSDDB_END_SAVE(_dp) Py_END_ALLOW_THREADS |
| 223 | #endif |
| 224 | |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 225 | static int |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 226 | bsddb_length(bsddbobject *dp) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 227 | { |
Guido van Rossum | 77eecfa | 1997-07-17 22:56:01 +0000 | [diff] [blame] | 228 | if (dp->di_bsddb == NULL) { |
Fred Drake | c9f7c26 | 2001-02-19 21:16:00 +0000 | [diff] [blame] | 229 | PyErr_SetString(BsddbError, |
| 230 | "BSDDB object has already been closed"); |
Guido van Rossum | 77eecfa | 1997-07-17 22:56:01 +0000 | [diff] [blame] | 231 | return -1; |
| 232 | } |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 233 | if (dp->di_size < 0) { |
| 234 | DBT krec, drec; |
| 235 | int status; |
| 236 | int size = 0; |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 237 | BSDDB_BGN_SAVE(dp) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 238 | for (status = (dp->di_bsddb->seq)(dp->di_bsddb, |
| 239 | &krec, &drec,R_FIRST); |
| 240 | status == 0; |
| 241 | status = (dp->di_bsddb->seq)(dp->di_bsddb, |
| 242 | &krec, &drec, R_NEXT)) |
| 243 | size++; |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 244 | BSDDB_END_SAVE(dp) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 245 | if (status < 0) { |
| 246 | PyErr_SetFromErrno(BsddbError); |
| 247 | return -1; |
| 248 | } |
| 249 | dp->di_size = size; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 250 | } |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 251 | return dp->di_size; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 254 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 255 | bsddb_subscript(bsddbobject *dp, PyObject *key) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 256 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 257 | int status; |
| 258 | DBT krec, drec; |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 259 | char *data,buf[4096]; |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 260 | int size; |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 261 | PyObject *result; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 262 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 263 | if (!PyArg_Parse(key, "s#", &data, &size)) |
| 264 | return NULL; |
Guido van Rossum | 77eecfa | 1997-07-17 22:56:01 +0000 | [diff] [blame] | 265 | check_bsddbobject_open(dp); |
| 266 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 267 | krec.data = data; |
| 268 | krec.size = size; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 269 | |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 270 | BSDDB_BGN_SAVE(dp) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 271 | status = (dp->di_bsddb->get)(dp->di_bsddb, &krec, &drec, 0); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 272 | if (status == 0) { |
| 273 | if (drec.size > sizeof(buf)) data = malloc(drec.size); |
| 274 | else data = buf; |
Andrew M. Kuchling | 2e09530 | 2000-12-15 00:59:32 +0000 | [diff] [blame] | 275 | if (data!=NULL) memcpy(data,drec.data,drec.size); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 276 | } |
| 277 | BSDDB_END_SAVE(dp) |
Andrew M. Kuchling | 2e09530 | 2000-12-15 00:59:32 +0000 | [diff] [blame] | 278 | if (data==NULL) return PyErr_NoMemory(); |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 279 | if (status != 0) { |
| 280 | if (status < 0) |
| 281 | PyErr_SetFromErrno(BsddbError); |
| 282 | else |
| 283 | PyErr_SetObject(PyExc_KeyError, key); |
| 284 | return NULL; |
| 285 | } |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 286 | |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 287 | result = PyString_FromStringAndSize(data, (int)drec.size); |
| 288 | if (data != buf) free(data); |
| 289 | return result; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | static int |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 293 | bsddb_ass_sub(bsddbobject *dp, PyObject *key, PyObject *value) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 294 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 295 | int status; |
| 296 | DBT krec, drec; |
| 297 | char *data; |
| 298 | int size; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 299 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 300 | if (!PyArg_Parse(key, "s#", &data, &size)) { |
| 301 | PyErr_SetString(PyExc_TypeError, |
| 302 | "bsddb key type must be string"); |
| 303 | return -1; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 304 | } |
Guido van Rossum | 77eecfa | 1997-07-17 22:56:01 +0000 | [diff] [blame] | 305 | if (dp->di_bsddb == NULL) { |
Fred Drake | c9f7c26 | 2001-02-19 21:16:00 +0000 | [diff] [blame] | 306 | PyErr_SetString(BsddbError, |
| 307 | "BSDDB object has already been closed"); |
Guido van Rossum | 77eecfa | 1997-07-17 22:56:01 +0000 | [diff] [blame] | 308 | return -1; |
| 309 | } |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 310 | krec.data = data; |
| 311 | krec.size = size; |
| 312 | dp->di_size = -1; |
| 313 | if (value == NULL) { |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 314 | BSDDB_BGN_SAVE(dp) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 315 | status = (dp->di_bsddb->del)(dp->di_bsddb, &krec, 0); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 316 | BSDDB_END_SAVE(dp) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 317 | } |
| 318 | else { |
| 319 | if (!PyArg_Parse(value, "s#", &data, &size)) { |
| 320 | PyErr_SetString(PyExc_TypeError, |
| 321 | "bsddb value type must be string"); |
| 322 | return -1; |
| 323 | } |
| 324 | drec.data = data; |
| 325 | drec.size = size; |
| 326 | #if 0 |
| 327 | /* For RECNO, put fails with 'No space left on device' |
| 328 | after a few short records are added?? Looks fine |
| 329 | to this point... linked with 1.85 on Solaris Intel |
| 330 | Roger E. Masse 1/16/97 |
| 331 | */ |
| 332 | printf("before put data: '%s', size: %d\n", |
| 333 | drec.data, drec.size); |
| 334 | printf("before put key= '%s', size= %d\n", |
| 335 | krec.data, krec.size); |
| 336 | #endif |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 337 | BSDDB_BGN_SAVE(dp) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 338 | status = (dp->di_bsddb->put)(dp->di_bsddb, &krec, &drec, 0); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 339 | BSDDB_END_SAVE(dp) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 340 | } |
| 341 | if (status != 0) { |
| 342 | if (status < 0) |
| 343 | PyErr_SetFromErrno(BsddbError); |
| 344 | else |
| 345 | PyErr_SetObject(PyExc_KeyError, key); |
| 346 | return -1; |
| 347 | } |
| 348 | return 0; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 351 | static PyMappingMethods bsddb_as_mapping = { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 352 | (inquiry)bsddb_length, /*mp_length*/ |
| 353 | (binaryfunc)bsddb_subscript, /*mp_subscript*/ |
| 354 | (objobjargproc)bsddb_ass_sub, /*mp_ass_subscript*/ |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 355 | }; |
| 356 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 357 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 358 | bsddb_close(bsddbobject *dp, PyObject *args) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 359 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 360 | if (!PyArg_NoArgs(args)) |
| 361 | return NULL; |
| 362 | if (dp->di_bsddb != NULL) { |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 363 | int status; |
| 364 | BSDDB_BGN_SAVE(dp) |
| 365 | status = (dp->di_bsddb->close)(dp->di_bsddb); |
| 366 | BSDDB_END_SAVE(dp) |
| 367 | if (status != 0) { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 368 | dp->di_bsddb = NULL; |
| 369 | PyErr_SetFromErrno(BsddbError); |
| 370 | return NULL; |
| 371 | } |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 372 | } |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 373 | dp->di_bsddb = NULL; |
| 374 | Py_INCREF(Py_None); |
| 375 | return Py_None; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 378 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 379 | bsddb_keys(bsddbobject *dp, PyObject *args) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 380 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 381 | PyObject *list, *item; |
| 382 | DBT krec, drec; |
Guido van Rossum | 730806d | 1998-04-10 22:27:42 +0000 | [diff] [blame] | 383 | char *data=NULL,buf[4096]; |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 384 | int status; |
| 385 | int err; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 386 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 387 | if (!PyArg_NoArgs(args)) |
| 388 | return NULL; |
Guido van Rossum | 77eecfa | 1997-07-17 22:56:01 +0000 | [diff] [blame] | 389 | check_bsddbobject_open(dp); |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 390 | list = PyList_New(0); |
| 391 | if (list == NULL) |
| 392 | return NULL; |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 393 | BSDDB_BGN_SAVE(dp) |
| 394 | status = (dp->di_bsddb->seq)(dp->di_bsddb, &krec, &drec, R_FIRST); |
| 395 | if (status == 0) { |
| 396 | if (krec.size > sizeof(buf)) data = malloc(krec.size); |
| 397 | else data = buf; |
Andrew M. Kuchling | 2e09530 | 2000-12-15 00:59:32 +0000 | [diff] [blame] | 398 | if (data!=NULL) memcpy(data,krec.data,krec.size); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 399 | } |
| 400 | BSDDB_END_SAVE(dp) |
Andrew M. Kuchling | 2e09530 | 2000-12-15 00:59:32 +0000 | [diff] [blame] | 401 | if (data==NULL) return PyErr_NoMemory(); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 402 | while (status == 0) { |
| 403 | item = PyString_FromStringAndSize(data, (int)krec.size); |
| 404 | if (data != buf) free(data); |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 405 | if (item == NULL) { |
| 406 | Py_DECREF(list); |
| 407 | return NULL; |
| 408 | } |
| 409 | err = PyList_Append(list, item); |
| 410 | Py_DECREF(item); |
| 411 | if (err != 0) { |
| 412 | Py_DECREF(list); |
| 413 | return NULL; |
| 414 | } |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 415 | BSDDB_BGN_SAVE(dp) |
Fred Drake | c9f7c26 | 2001-02-19 21:16:00 +0000 | [diff] [blame] | 416 | status = (dp->di_bsddb->seq) |
| 417 | (dp->di_bsddb, &krec, &drec, R_NEXT); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 418 | if (status == 0) { |
Fred Drake | c9f7c26 | 2001-02-19 21:16:00 +0000 | [diff] [blame] | 419 | if (krec.size > sizeof(buf)) |
| 420 | data = malloc(krec.size); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 421 | else data = buf; |
Fred Drake | c9f7c26 | 2001-02-19 21:16:00 +0000 | [diff] [blame] | 422 | if (data != NULL) |
| 423 | memcpy(data,krec.data,krec.size); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 424 | } |
| 425 | BSDDB_END_SAVE(dp) |
Fred Drake | c9f7c26 | 2001-02-19 21:16:00 +0000 | [diff] [blame] | 426 | if (data == NULL) return PyErr_NoMemory(); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 427 | } |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 428 | if (status < 0) { |
| 429 | PyErr_SetFromErrno(BsddbError); |
| 430 | Py_DECREF(list); |
| 431 | return NULL; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 432 | } |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 433 | if (dp->di_size < 0) |
| 434 | dp->di_size = PyList_Size(list); /* We just did the work */ |
| 435 | return list; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 438 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 439 | bsddb_has_key(bsddbobject *dp, PyObject *args) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 440 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 441 | DBT krec, drec; |
| 442 | int status; |
| 443 | char *data; |
| 444 | int size; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 445 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 446 | if (!PyArg_Parse(args, "s#", &data, &size)) |
| 447 | return NULL; |
Guido van Rossum | 77eecfa | 1997-07-17 22:56:01 +0000 | [diff] [blame] | 448 | check_bsddbobject_open(dp); |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 449 | krec.data = data; |
| 450 | krec.size = size; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 451 | |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 452 | BSDDB_BGN_SAVE(dp) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 453 | status = (dp->di_bsddb->get)(dp->di_bsddb, &krec, &drec, 0); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 454 | BSDDB_END_SAVE(dp) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 455 | if (status < 0) { |
| 456 | PyErr_SetFromErrno(BsddbError); |
| 457 | return NULL; |
| 458 | } |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 459 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 460 | return PyInt_FromLong(status == 0); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 463 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 464 | bsddb_set_location(bsddbobject *dp, PyObject *key) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 465 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 466 | int status; |
| 467 | DBT krec, drec; |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 468 | char *data,buf[4096]; |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 469 | int size; |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 470 | PyObject *result; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 471 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 472 | if (!PyArg_Parse(key, "s#", &data, &size)) |
| 473 | return NULL; |
Guido van Rossum | 77eecfa | 1997-07-17 22:56:01 +0000 | [diff] [blame] | 474 | check_bsddbobject_open(dp); |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 475 | krec.data = data; |
| 476 | krec.size = size; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 477 | |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 478 | BSDDB_BGN_SAVE(dp) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 479 | status = (dp->di_bsddb->seq)(dp->di_bsddb, &krec, &drec, R_CURSOR); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 480 | if (status == 0) { |
| 481 | if (drec.size > sizeof(buf)) data = malloc(drec.size); |
| 482 | else data = buf; |
Andrew M. Kuchling | 2e09530 | 2000-12-15 00:59:32 +0000 | [diff] [blame] | 483 | if (data!=NULL) memcpy(data,drec.data,drec.size); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 484 | } |
| 485 | BSDDB_END_SAVE(dp) |
Andrew M. Kuchling | 2e09530 | 2000-12-15 00:59:32 +0000 | [diff] [blame] | 486 | if (data==NULL) return PyErr_NoMemory(); |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 487 | if (status != 0) { |
| 488 | if (status < 0) |
| 489 | PyErr_SetFromErrno(BsddbError); |
| 490 | else |
| 491 | PyErr_SetObject(PyExc_KeyError, key); |
| 492 | return NULL; |
| 493 | } |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 494 | |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 495 | result = Py_BuildValue("s#s#", krec.data, krec.size, data, drec.size); |
| 496 | if (data != buf) free(data); |
| 497 | return result; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 500 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 501 | bsddb_seq(bsddbobject *dp, PyObject *args, int sequence_request) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 502 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 503 | int status; |
| 504 | DBT krec, drec; |
Guido van Rossum | 730806d | 1998-04-10 22:27:42 +0000 | [diff] [blame] | 505 | char *kdata=NULL,kbuf[4096]; |
| 506 | char *ddata=NULL,dbuf[4096]; |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 507 | PyObject *result; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 508 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 509 | if (!PyArg_NoArgs(args)) |
| 510 | return NULL; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 511 | |
Guido van Rossum | 77eecfa | 1997-07-17 22:56:01 +0000 | [diff] [blame] | 512 | check_bsddbobject_open(dp); |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 513 | krec.data = 0; |
| 514 | krec.size = 0; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 515 | |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 516 | BSDDB_BGN_SAVE(dp) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 517 | status = (dp->di_bsddb->seq)(dp->di_bsddb, &krec, |
| 518 | &drec, sequence_request); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 519 | if (status == 0) { |
| 520 | if (krec.size > sizeof(kbuf)) kdata = malloc(krec.size); |
| 521 | else kdata = kbuf; |
Andrew M. Kuchling | 2e09530 | 2000-12-15 00:59:32 +0000 | [diff] [blame] | 522 | if (kdata!=NULL) memcpy(kdata,krec.data,krec.size); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 523 | if (drec.size > sizeof(dbuf)) ddata = malloc(drec.size); |
| 524 | else ddata = dbuf; |
Andrew M. Kuchling | 2e09530 | 2000-12-15 00:59:32 +0000 | [diff] [blame] | 525 | if (ddata!=NULL) memcpy(ddata,drec.data,drec.size); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 526 | } |
| 527 | BSDDB_END_SAVE(dp) |
Andrew M. Kuchling | 2e09530 | 2000-12-15 00:59:32 +0000 | [diff] [blame] | 528 | if (status == 0) { |
| 529 | if ((kdata==NULL) || (ddata==NULL)) |
| 530 | return PyErr_NoMemory(); |
| 531 | } |
| 532 | else { |
| 533 | /* (status != 0) */ |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 534 | if (status < 0) |
| 535 | PyErr_SetFromErrno(BsddbError); |
| 536 | else |
| 537 | PyErr_SetObject(PyExc_KeyError, args); |
| 538 | return NULL; |
| 539 | } |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 540 | |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 541 | result = Py_BuildValue("s#s#", kdata, krec.size, ddata, drec.size); |
| 542 | if (kdata != kbuf) free(kdata); |
| 543 | if (ddata != dbuf) free(ddata); |
| 544 | return result; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 547 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 548 | bsddb_next(bsddbobject *dp, PyObject *key) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 549 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 550 | return bsddb_seq(dp, key, R_NEXT); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 551 | } |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 552 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 553 | bsddb_previous(bsddbobject *dp, PyObject *key) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 554 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 555 | return bsddb_seq(dp, key, R_PREV); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 556 | } |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 557 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 558 | bsddb_first(bsddbobject *dp, PyObject *key) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 559 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 560 | return bsddb_seq(dp, key, R_FIRST); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 561 | } |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 562 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 563 | bsddb_last(bsddbobject *dp, PyObject *key) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 564 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 565 | return bsddb_seq(dp, key, R_LAST); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 566 | } |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 567 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 568 | bsddb_sync(bsddbobject *dp, PyObject *args) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 569 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 570 | int status; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 571 | |
Guido van Rossum | 77eecfa | 1997-07-17 22:56:01 +0000 | [diff] [blame] | 572 | if (!PyArg_NoArgs(args)) |
| 573 | return NULL; |
| 574 | check_bsddbobject_open(dp); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 575 | BSDDB_BGN_SAVE(dp) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 576 | status = (dp->di_bsddb->sync)(dp->di_bsddb, 0); |
Guido van Rossum | 4f199ea | 1998-04-09 20:56:35 +0000 | [diff] [blame] | 577 | BSDDB_END_SAVE(dp) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 578 | if (status != 0) { |
| 579 | PyErr_SetFromErrno(BsddbError); |
| 580 | return NULL; |
| 581 | } |
| 582 | return PyInt_FromLong(status = 0); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 583 | } |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 584 | static PyMethodDef bsddb_methods[] = { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 585 | {"close", (PyCFunction)bsddb_close}, |
| 586 | {"keys", (PyCFunction)bsddb_keys}, |
| 587 | {"has_key", (PyCFunction)bsddb_has_key}, |
| 588 | {"set_location", (PyCFunction)bsddb_set_location}, |
| 589 | {"next", (PyCFunction)bsddb_next}, |
| 590 | {"previous", (PyCFunction)bsddb_previous}, |
| 591 | {"first", (PyCFunction)bsddb_first}, |
| 592 | {"last", (PyCFunction)bsddb_last}, |
| 593 | {"sync", (PyCFunction)bsddb_sync}, |
| 594 | {NULL, NULL} /* sentinel */ |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 595 | }; |
| 596 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 597 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 598 | bsddb_getattr(PyObject *dp, char *name) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 599 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 600 | return Py_FindMethod(bsddb_methods, dp, name); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 603 | static PyTypeObject Bsddbtype = { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 604 | PyObject_HEAD_INIT(NULL) |
| 605 | 0, |
| 606 | "bsddb", |
| 607 | sizeof(bsddbobject), |
| 608 | 0, |
| 609 | (destructor)bsddb_dealloc, /*tp_dealloc*/ |
| 610 | 0, /*tp_print*/ |
| 611 | (getattrfunc)bsddb_getattr, /*tp_getattr*/ |
| 612 | 0, /*tp_setattr*/ |
| 613 | 0, /*tp_compare*/ |
| 614 | 0, /*tp_repr*/ |
| 615 | 0, /*tp_as_number*/ |
| 616 | 0, /*tp_as_sequence*/ |
| 617 | &bsddb_as_mapping, /*tp_as_mapping*/ |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 618 | }; |
| 619 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 620 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 621 | bsdhashopen(PyObject *self, PyObject *args) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 622 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 623 | char *file; |
| 624 | char *flag = NULL; |
| 625 | int flags = O_RDONLY; |
| 626 | int mode = 0666; |
| 627 | int bsize = 0; |
| 628 | int ffactor = 0; |
| 629 | int nelem = 0; |
| 630 | int cachesize = 0; |
| 631 | int hash = 0; /* XXX currently ignored */ |
| 632 | int lorder = 0; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 633 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 634 | if (!PyArg_ParseTuple(args, "s|siiiiiii:hashopen", |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 635 | &file, &flag, &mode, |
| 636 | &bsize, &ffactor, &nelem, &cachesize, |
| 637 | &hash, &lorder)) |
| 638 | return NULL; |
| 639 | if (flag != NULL) { |
| 640 | /* XXX need to pass O_EXCL, O_EXLOCK, O_NONBLOCK, O_SHLOCK */ |
| 641 | if (flag[0] == 'r') |
| 642 | flags = O_RDONLY; |
| 643 | else if (flag[0] == 'w') |
| 644 | flags = O_RDWR; |
| 645 | else if (flag[0] == 'c') |
| 646 | flags = O_RDWR|O_CREAT; |
| 647 | else if (flag[0] == 'n') |
| 648 | flags = O_RDWR|O_CREAT|O_TRUNC; |
| 649 | else { |
| 650 | PyErr_SetString(BsddbError, |
| 651 | "Flag should begin with 'r', 'w', 'c' or 'n'"); |
| 652 | return NULL; |
| 653 | } |
| 654 | if (flag[1] == 'l') { |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 655 | #if defined(O_EXLOCK) && defined(O_SHLOCK) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 656 | if (flag[0] == 'r') |
| 657 | flags |= O_SHLOCK; |
| 658 | else |
| 659 | flags |= O_EXLOCK; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 660 | #else |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 661 | PyErr_SetString(BsddbError, |
| 662 | "locking not supported on this platform"); |
| 663 | return NULL; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 664 | #endif |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 665 | } |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 666 | } |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 667 | return newdbhashobject(file, flags, mode, |
| 668 | bsize, ffactor, nelem, cachesize, hash, lorder); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 671 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 672 | bsdbtopen(PyObject *self, PyObject *args) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 673 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 674 | char *file; |
| 675 | char *flag = NULL; |
| 676 | int flags = O_RDONLY; |
| 677 | int mode = 0666; |
| 678 | int cachesize = 0; |
| 679 | int maxkeypage = 0; |
| 680 | int minkeypage = 0; |
| 681 | int btflags = 0; |
| 682 | unsigned int psize = 0; |
| 683 | int lorder = 0; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 684 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 685 | if (!PyArg_ParseTuple(args, "s|siiiiiii:btopen", |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 686 | &file, &flag, &mode, |
| 687 | &btflags, &cachesize, &maxkeypage, &minkeypage, |
| 688 | &psize, &lorder)) |
| 689 | return NULL; |
| 690 | if (flag != NULL) { |
| 691 | /* XXX need to pass O_EXCL, O_EXLOCK, O_NONBLOCK, O_SHLOCK */ |
| 692 | if (flag[0] == 'r') |
| 693 | flags = O_RDONLY; |
| 694 | else if (flag[0] == 'w') |
| 695 | flags = O_RDWR; |
| 696 | else if (flag[0] == 'c') |
| 697 | flags = O_RDWR|O_CREAT; |
| 698 | else if (flag[0] == 'n') |
| 699 | flags = O_RDWR|O_CREAT|O_TRUNC; |
| 700 | else { |
| 701 | PyErr_SetString(BsddbError, |
| 702 | "Flag should begin with 'r', 'w', 'c' or 'n'"); |
| 703 | return NULL; |
| 704 | } |
| 705 | if (flag[1] == 'l') { |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 706 | #if defined(O_EXLOCK) && defined(O_SHLOCK) |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 707 | if (flag[0] == 'r') |
| 708 | flags |= O_SHLOCK; |
| 709 | else |
| 710 | flags |= O_EXLOCK; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 711 | #else |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 712 | PyErr_SetString(BsddbError, |
| 713 | "locking not supported on this platform"); |
| 714 | return NULL; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 715 | #endif |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 716 | } |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 717 | } |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 718 | return newdbbtobject(file, flags, mode, |
| 719 | btflags, cachesize, maxkeypage, minkeypage, |
| 720 | psize, lorder); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 721 | } |
Guido van Rossum | dd96ca7 | 1996-05-23 22:57:54 +0000 | [diff] [blame] | 722 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 723 | static PyObject * |
Peter Schneider-Kamp | cb27c35 | 2000-07-10 17:06:38 +0000 | [diff] [blame] | 724 | bsdrnopen(PyObject *self, PyObject *args) |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 725 | { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 726 | char *file; |
| 727 | char *flag = NULL; |
| 728 | int flags = O_RDONLY; |
| 729 | int mode = 0666; |
| 730 | int cachesize = 0; |
| 731 | int rnflags = 0; |
| 732 | unsigned int psize = 0; |
| 733 | int lorder = 0; |
| 734 | size_t reclen = 0; |
| 735 | char *bval = ""; |
| 736 | char *bfname = NULL; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 737 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 738 | if (!PyArg_ParseTuple(args, "s|siiiiiiss:rnopen", |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 739 | &file, &flag, &mode, |
| 740 | &rnflags, &cachesize, &psize, &lorder, |
| 741 | &reclen, &bval, &bfname)) |
| 742 | return NULL; |
| 743 | |
| 744 | # if 0 |
| 745 | printf("file: %s\n", file); |
| 746 | printf("flag: %s\n", flag); |
| 747 | printf("mode: %d\n", mode); |
| 748 | printf("rnflags: 0x%x\n", rnflags); |
| 749 | printf("cachesize: %d\n", cachesize); |
| 750 | printf("psize: %d\n", psize); |
| 751 | printf("lorder: %d\n", 0); |
| 752 | printf("reclen: %d\n", reclen); |
| 753 | printf("bval: %c\n", bval[0]); |
| 754 | printf("bfname %s\n", bfname); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 755 | #endif |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 756 | |
| 757 | if (flag != NULL) { |
| 758 | /* XXX need to pass O_EXCL, O_EXLOCK, O_NONBLOCK, O_SHLOCK */ |
| 759 | if (flag[0] == 'r') |
| 760 | flags = O_RDONLY; |
| 761 | else if (flag[0] == 'w') |
| 762 | flags = O_RDWR; |
| 763 | else if (flag[0] == 'c') |
| 764 | flags = O_RDWR|O_CREAT; |
| 765 | else if (flag[0] == 'n') |
| 766 | flags = O_RDWR|O_CREAT|O_TRUNC; |
| 767 | else { |
| 768 | PyErr_SetString(BsddbError, |
| 769 | "Flag should begin with 'r', 'w', 'c' or 'n'"); |
| 770 | return NULL; |
| 771 | } |
| 772 | if (flag[1] == 'l') { |
| 773 | #if defined(O_EXLOCK) && defined(O_SHLOCK) |
| 774 | if (flag[0] == 'r') |
| 775 | flags |= O_SHLOCK; |
| 776 | else |
| 777 | flags |= O_EXLOCK; |
| 778 | #else |
| 779 | PyErr_SetString(BsddbError, |
| 780 | "locking not supported on this platform"); |
| 781 | return NULL; |
| 782 | #endif |
| 783 | } |
| 784 | else if (flag[1] != '\0') { |
| 785 | PyErr_SetString(BsddbError, |
| 786 | "Flag char 2 should be 'l' or absent"); |
| 787 | return NULL; |
| 788 | } |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 789 | } |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 790 | return newdbrnobject(file, flags, mode, rnflags, cachesize, |
| 791 | psize, lorder, reclen, bval[0], bfname); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Guido van Rossum | dfe8ad9 | 1996-07-24 00:51:20 +0000 | [diff] [blame] | 794 | static PyMethodDef bsddbmodule_methods[] = { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 795 | {"hashopen", (PyCFunction)bsdhashopen, 1}, |
| 796 | {"btopen", (PyCFunction)bsdbtopen, 1}, |
| 797 | {"rnopen", (PyCFunction)bsdrnopen, 1}, |
| 798 | {0, 0}, |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 799 | }; |
| 800 | |
Guido van Rossum | 3886bb6 | 1998-12-04 18:50:17 +0000 | [diff] [blame] | 801 | DL_EXPORT(void) |
Thomas Wouters | 58d0510 | 2000-07-24 14:43:35 +0000 | [diff] [blame] | 802 | initbsddb(void) { |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 803 | PyObject *m, *d; |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 804 | |
Roger E. Masse | d9240d1 | 1997-01-16 22:05:33 +0000 | [diff] [blame] | 805 | Bsddbtype.ob_type = &PyType_Type; |
| 806 | m = Py_InitModule("bsddb", bsddbmodule_methods); |
| 807 | d = PyModule_GetDict(m); |
Guido van Rossum | 0cb96de | 1997-10-01 04:29:29 +0000 | [diff] [blame] | 808 | BsddbError = PyErr_NewException("bsddb.error", NULL, NULL); |
| 809 | if (BsddbError != NULL) |
| 810 | PyDict_SetItemString(d, "error", BsddbError); |
Guido van Rossum | 1100dca | 1995-08-30 23:43:03 +0000 | [diff] [blame] | 811 | } |