Mercurial > cpython-lru_cache-weakref
annotate Modules/gdbmmodule.c @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 52294af4b663 |
| children |
| rev | line source |
|---|---|
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 /* DBM module using dictionary interface */ |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
3 /* Author: Anthony Baxter, after dbmmodule.c */ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
4 /* Doc strings: Mitch Chapman */ |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
7 #include "Python.h" |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 #include <sys/types.h> |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 #include <sys/stat.h> |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 #include <fcntl.h> |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 #include "gdbm.h" |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 |
|
16837
0e6a3da4f956
SF patch 404928: Support for next Cygwin gcc (2.95.2-8)
Tim Peters <tim.peters@gmail.com>
parents:
15601
diff
changeset
|
14 #if defined(WIN32) && !defined(__CYGWIN__) |
|
9230
38c07ba4b8e4
Win32 port. Patches by Milton L. Hankins.
Guido van Rossum <guido@python.org>
parents:
8037
diff
changeset
|
15 #include "gdbmerrno.h" |
|
38c07ba4b8e4
Win32 port. Patches by Milton L. Hankins.
Guido van Rossum <guido@python.org>
parents:
8037
diff
changeset
|
16 extern const char * gdbm_strerror(gdbm_error); |
|
38c07ba4b8e4
Win32 port. Patches by Milton L. Hankins.
Guido van Rossum <guido@python.org>
parents:
8037
diff
changeset
|
17 #endif |
|
38c07ba4b8e4
Win32 port. Patches by Milton L. Hankins.
Guido van Rossum <guido@python.org>
parents:
8037
diff
changeset
|
18 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
19 PyDoc_STRVAR(gdbmmodule__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
20 "This module provides an interface to the GNU DBM (GDBM) library.\n\ |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
21 \n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
22 This module is quite similar to the dbm module, but uses GDBM instead to\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
23 provide some additional functionality. Please note that the file formats\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
24 created by GDBM and dbm are incompatible. \n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
25 \n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
26 GDBM objects behave like mappings (dictionaries), except that keys and\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
27 values are always strings. Printing a GDBM object doesn't print the\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
28 keys and values, and the items() and values() methods are not\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
29 supported."); |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
30 |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 typedef struct { |
| 13425 | 32 PyObject_HEAD |
| 33 int di_size; /* -1 means recompute */ | |
| 34 GDBM_FILE di_dbm; | |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 } dbmobject; |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
37 static PyTypeObject Dbmtype; |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42333
diff
changeset
|
39 #define is_dbmobject(v) (Py_TYPE(v) == &Dbmtype) |
|
5828
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
5214
diff
changeset
|
40 #define check_dbmobject_open(v) if ((v)->di_dbm == NULL) \ |
| 13425 | 41 { PyErr_SetString(DbmError, "GDBM object has already been closed"); \ |
| 42 return NULL; } | |
|
5828
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
5214
diff
changeset
|
43 |
|
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
5214
diff
changeset
|
44 |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
46 static PyObject *DbmError; |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
48 PyDoc_STRVAR(gdbm_object__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
49 "This object represents a GDBM database.\n\ |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
50 GDBM objects behave like mappings (dictionaries), except that keys and\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
51 values are always strings. Printing a GDBM object doesn't print the\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
52 keys and values, and the items() and values() methods are not\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
53 supported.\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
54 \n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
55 GDBM objects also support additional operations such as firstkey,\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
56 nextkey, reorganize, and sync."); |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
57 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
58 static PyObject * |
| 13425 | 59 newdbmobject(char *file, int flags, int mode) |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 { |
| 13425 | 61 dbmobject *dp; |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 |
| 13425 | 63 dp = PyObject_New(dbmobject, &Dbmtype); |
| 64 if (dp == NULL) | |
| 65 return NULL; | |
| 66 dp->di_size = -1; | |
| 67 errno = 0; | |
| 68 if ((dp->di_dbm = gdbm_open(file, 0, flags, mode, NULL)) == 0) { | |
| 69 if (errno != 0) | |
| 70 PyErr_SetFromErrno(DbmError); | |
| 71 else | |
| 72 PyErr_SetString(DbmError, gdbm_strerror(gdbm_errno)); | |
| 73 Py_DECREF(dp); | |
| 74 return NULL; | |
| 75 } | |
| 76 return (PyObject *)dp; | |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 } |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 /* Methods */ |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 static void |
| 13425 | 82 dbm_dealloc(register dbmobject *dp) |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 { |
| 13425 | 84 if (dp->di_dbm) |
| 85 gdbm_close(dp->di_dbm); | |
| 86 PyObject_Del(dp); | |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 } |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
89 static Py_ssize_t |
| 13425 | 90 dbm_length(dbmobject *dp) |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 { |
| 13425 | 92 if (dp->di_dbm == NULL) { |
| 93 PyErr_SetString(DbmError, "GDBM object has already been closed"); | |
| 94 return -1; | |
| 95 } | |
| 96 if (dp->di_size < 0) { | |
| 97 datum key,okey; | |
| 98 int size; | |
| 99 okey.dsize=0; | |
|
36787
0cc58dbd87fe
Fix gcc (4.0.x) warning about use of uninitialized variable.
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
100 okey.dptr=NULL; |
| 13425 | 101 |
| 102 size = 0; | |
| 103 for (key=gdbm_firstkey(dp->di_dbm); key.dptr; | |
| 104 key = gdbm_nextkey(dp->di_dbm,okey)) { | |
| 105 size++; | |
| 106 if(okey.dsize) free(okey.dptr); | |
| 107 okey=key; | |
|
5828
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
5214
diff
changeset
|
108 } |
| 13425 | 109 dp->di_size = size; |
| 110 } | |
| 111 return dp->di_size; | |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 } |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
114 static PyObject * |
| 13425 | 115 dbm_subscript(dbmobject *dp, register PyObject *key) |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 { |
| 13425 | 117 PyObject *v; |
| 118 datum drec, krec; | |
| 119 | |
| 120 if (!PyArg_Parse(key, "s#", &krec.dptr, &krec.dsize) ) | |
| 121 return NULL; | |
|
11718
1163a7a1cc67
Protect against core dumps in gdbm: don't allow access by key once the
Fred Drake <fdrake@acm.org>
parents:
9588
diff
changeset
|
122 |
| 13425 | 123 if (dp->di_dbm == NULL) { |
| 124 PyErr_SetString(DbmError, | |
| 125 "GDBM object has already been closed"); | |
| 126 return NULL; | |
| 127 } | |
| 128 drec = gdbm_fetch(dp->di_dbm, krec); | |
| 129 if (drec.dptr == 0) { | |
| 130 PyErr_SetString(PyExc_KeyError, | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
131 PyString_AS_STRING((PyStringObject *)key)); |
| 13425 | 132 return NULL; |
| 133 } | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
134 v = PyString_FromStringAndSize(drec.dptr, drec.dsize); |
| 13425 | 135 free(drec.dptr); |
| 136 return v; | |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 } |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 static int |
| 13425 | 140 dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w) |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 { |
| 13425 | 142 datum krec, drec; |
| 143 | |
| 144 if (!PyArg_Parse(v, "s#", &krec.dptr, &krec.dsize) ) { | |
| 145 PyErr_SetString(PyExc_TypeError, | |
| 146 "gdbm mappings have string indices only"); | |
| 147 return -1; | |
| 148 } | |
| 149 if (dp->di_dbm == NULL) { | |
| 150 PyErr_SetString(DbmError, | |
| 151 "GDBM object has already been closed"); | |
| 152 return -1; | |
| 153 } | |
| 154 dp->di_size = -1; | |
| 155 if (w == NULL) { | |
| 156 if (gdbm_delete(dp->di_dbm, krec) < 0) { | |
| 157 PyErr_SetString(PyExc_KeyError, | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
158 PyString_AS_STRING((PyStringObject *)v)); |
| 13425 | 159 return -1; |
|
5828
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
5214
diff
changeset
|
160 } |
| 13425 | 161 } |
| 162 else { | |
| 163 if (!PyArg_Parse(w, "s#", &drec.dptr, &drec.dsize)) { | |
| 164 PyErr_SetString(PyExc_TypeError, | |
| 165 "gdbm mappings have string elements only"); | |
| 166 return -1; | |
| 167 } | |
| 168 errno = 0; | |
| 169 if (gdbm_store(dp->di_dbm, krec, drec, GDBM_REPLACE) < 0) { | |
| 170 if (errno != 0) | |
| 171 PyErr_SetFromErrno(DbmError); | |
| 172 else | |
| 173 PyErr_SetString(DbmError, | |
| 174 gdbm_strerror(gdbm_errno)); | |
| 175 return -1; | |
| 176 } | |
| 177 } | |
| 178 return 0; | |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 } |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 |
|
45523
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
181 static int |
|
45533
fe7394bc79d6
The contains function raised a gcc warning. The new code is copied straight from py3k.
Christian Heimes <christian@cheimes.de>
parents:
45523
diff
changeset
|
182 dbm_contains(register dbmobject *dp, PyObject *arg) |
|
45523
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
183 { |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
184 datum key; |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
185 |
|
45533
fe7394bc79d6
The contains function raised a gcc warning. The new code is copied straight from py3k.
Christian Heimes <christian@cheimes.de>
parents:
45523
diff
changeset
|
186 if ((dp)->di_dbm == NULL) { |
|
fe7394bc79d6
The contains function raised a gcc warning. The new code is copied straight from py3k.
Christian Heimes <christian@cheimes.de>
parents:
45523
diff
changeset
|
187 PyErr_SetString(DbmError, |
|
fe7394bc79d6
The contains function raised a gcc warning. The new code is copied straight from py3k.
Christian Heimes <christian@cheimes.de>
parents:
45523
diff
changeset
|
188 "GDBM object has already been closed"); |
|
45523
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
189 return -1; |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
190 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
191 if (!PyString_Check(arg)) { |
|
45533
fe7394bc79d6
The contains function raised a gcc warning. The new code is copied straight from py3k.
Christian Heimes <christian@cheimes.de>
parents:
45523
diff
changeset
|
192 PyErr_Format(PyExc_TypeError, |
|
fe7394bc79d6
The contains function raised a gcc warning. The new code is copied straight from py3k.
Christian Heimes <christian@cheimes.de>
parents:
45523
diff
changeset
|
193 "gdbm key must be string, not %.100s", |
|
fe7394bc79d6
The contains function raised a gcc warning. The new code is copied straight from py3k.
Christian Heimes <christian@cheimes.de>
parents:
45523
diff
changeset
|
194 arg->ob_type->tp_name); |
|
fe7394bc79d6
The contains function raised a gcc warning. The new code is copied straight from py3k.
Christian Heimes <christian@cheimes.de>
parents:
45523
diff
changeset
|
195 return -1; |
|
fe7394bc79d6
The contains function raised a gcc warning. The new code is copied straight from py3k.
Christian Heimes <christian@cheimes.de>
parents:
45523
diff
changeset
|
196 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
197 key.dptr = PyString_AS_STRING(arg); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
198 key.dsize = PyString_GET_SIZE(arg); |
|
45523
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
199 return gdbm_exists(dp->di_dbm, key); |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
200 } |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
201 |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
202 static PySequenceMethods dbm_as_sequence = { |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
203 (lenfunc)dbm_length, /*_length*/ |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
204 0, /*sq_concat*/ |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
205 0, /*sq_repeat*/ |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
206 0, /*sq_item*/ |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
207 0, /*sq_slice*/ |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
208 0, /*sq_ass_item*/ |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
209 0, /*sq_ass_slice*/ |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
210 (objobjproc)dbm_contains, /*sq_contains*/ |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
211 0, /*sq_inplace_concat*/ |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
212 0 /*sq_inplace_repeat*/ |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
213 }; |
|
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
214 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
215 static PyMappingMethods dbm_as_mapping = { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
216 (lenfunc)dbm_length, /*mp_length*/ |
| 13425 | 217 (binaryfunc)dbm_subscript, /*mp_subscript*/ |
| 218 (objobjargproc)dbm_ass_sub, /*mp_ass_subscript*/ | |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 }; |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
221 PyDoc_STRVAR(dbm_close__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
222 "close() -> None\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
223 Closes the database."); |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
224 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
225 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36787
diff
changeset
|
226 dbm_close(register dbmobject *dp, PyObject *unused) |
|
2805
b7a06db85caf
normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents:
2567
diff
changeset
|
227 { |
| 13425 | 228 if (dp->di_dbm) |
| 229 gdbm_close(dp->di_dbm); | |
| 230 dp->di_dbm = NULL; | |
| 231 Py_INCREF(Py_None); | |
| 232 return Py_None; | |
|
2805
b7a06db85caf
normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents:
2567
diff
changeset
|
233 } |
|
b7a06db85caf
normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents:
2567
diff
changeset
|
234 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
235 PyDoc_STRVAR(dbm_keys__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
236 "keys() -> list_of_keys\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
237 Get a list of all keys in the database."); |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
238 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
239 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36787
diff
changeset
|
240 dbm_keys(register dbmobject *dp, PyObject *unused) |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
241 { |
| 13425 | 242 register PyObject *v, *item; |
| 243 datum key, nextkey; | |
| 244 int err; | |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
245 |
| 13425 | 246 if (dp == NULL || !is_dbmobject(dp)) { |
| 247 PyErr_BadInternalCall(); | |
| 248 return NULL; | |
| 249 } | |
| 250 check_dbmobject_open(dp); | |
|
3772
c8d0f78221cc
Rewritten keys() and has_key() to avoid memory leaks.
Guido van Rossum <guido@python.org>
parents:
3367
diff
changeset
|
251 |
| 13425 | 252 v = PyList_New(0); |
| 253 if (v == NULL) | |
| 254 return NULL; | |
|
3772
c8d0f78221cc
Rewritten keys() and has_key() to avoid memory leaks.
Guido van Rossum <guido@python.org>
parents:
3367
diff
changeset
|
255 |
| 13425 | 256 key = gdbm_firstkey(dp->di_dbm); |
| 257 while (key.dptr) { | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
258 item = PyString_FromStringAndSize(key.dptr, key.dsize); |
| 13425 | 259 if (item == NULL) { |
| 260 free(key.dptr); | |
| 261 Py_DECREF(v); | |
| 262 return NULL; | |
| 263 } | |
| 264 err = PyList_Append(v, item); | |
| 265 Py_DECREF(item); | |
| 266 if (err != 0) { | |
| 267 free(key.dptr); | |
| 268 Py_DECREF(v); | |
| 269 return NULL; | |
| 270 } | |
| 271 nextkey = gdbm_nextkey(dp->di_dbm, key); | |
| 272 free(key.dptr); | |
| 273 key = nextkey; | |
| 274 } | |
| 275 return v; | |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 } |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
278 PyDoc_STRVAR(dbm_has_key__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
279 "has_key(key) -> boolean\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
280 Find out whether or not the database contains a given key."); |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
281 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
282 static PyObject * |
| 13425 | 283 dbm_has_key(register dbmobject *dp, PyObject *args) |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 { |
| 13425 | 285 datum key; |
| 286 | |
| 287 if (!PyArg_ParseTuple(args, "s#:has_key", &key.dptr, &key.dsize)) | |
| 288 return NULL; | |
| 289 check_dbmobject_open(dp); | |
| 290 return PyInt_FromLong((long) gdbm_exists(dp->di_dbm, key)); | |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 } |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
293 PyDoc_STRVAR(dbm_firstkey__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
294 "firstkey() -> key\n\ |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
295 It's possible to loop over every key in the database using this method\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
296 and the nextkey() method. The traversal is ordered by GDBM's internal\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
297 hash values, and won't be sorted by the key values. This method\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
298 returns the starting key."); |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
299 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
300 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36787
diff
changeset
|
301 dbm_firstkey(register dbmobject *dp, PyObject *unused) |
|
2567
b5963c4b639a
added firstkey(), nextkey(), reorganize() methods
Guido van Rossum <guido@python.org>
parents:
2531
diff
changeset
|
302 { |
| 13425 | 303 register PyObject *v; |
| 304 datum key; | |
|
2567
b5963c4b639a
added firstkey(), nextkey(), reorganize() methods
Guido van Rossum <guido@python.org>
parents:
2531
diff
changeset
|
305 |
| 13425 | 306 check_dbmobject_open(dp); |
| 307 key = gdbm_firstkey(dp->di_dbm); | |
| 308 if (key.dptr) { | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
309 v = PyString_FromStringAndSize(key.dptr, key.dsize); |
| 13425 | 310 free(key.dptr); |
| 311 return v; | |
| 312 } | |
| 313 else { | |
| 314 Py_INCREF(Py_None); | |
| 315 return Py_None; | |
| 316 } | |
|
2567
b5963c4b639a
added firstkey(), nextkey(), reorganize() methods
Guido van Rossum <guido@python.org>
parents:
2531
diff
changeset
|
317 } |
|
b5963c4b639a
added firstkey(), nextkey(), reorganize() methods
Guido van Rossum <guido@python.org>
parents:
2531
diff
changeset
|
318 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
319 PyDoc_STRVAR(dbm_nextkey__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
320 "nextkey(key) -> next_key\n\ |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
321 Returns the key that follows key in the traversal.\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
322 The following code prints every key in the database db, without having\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
323 to create a list in memory that contains them all:\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
324 \n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
325 k = db.firstkey()\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
326 while k != None:\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
327 print k\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
328 k = db.nextkey(k)"); |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
329 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
330 static PyObject * |
| 13425 | 331 dbm_nextkey(register dbmobject *dp, PyObject *args) |
|
2567
b5963c4b639a
added firstkey(), nextkey(), reorganize() methods
Guido van Rossum <guido@python.org>
parents:
2531
diff
changeset
|
332 { |
| 13425 | 333 register PyObject *v; |
| 334 datum key, nextkey; | |
|
2567
b5963c4b639a
added firstkey(), nextkey(), reorganize() methods
Guido van Rossum <guido@python.org>
parents:
2531
diff
changeset
|
335 |
| 13425 | 336 if (!PyArg_ParseTuple(args, "s#:nextkey", &key.dptr, &key.dsize)) |
| 337 return NULL; | |
| 338 check_dbmobject_open(dp); | |
| 339 nextkey = gdbm_nextkey(dp->di_dbm, key); | |
| 340 if (nextkey.dptr) { | |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
341 v = PyString_FromStringAndSize(nextkey.dptr, nextkey.dsize); |
| 13425 | 342 free(nextkey.dptr); |
| 343 return v; | |
| 344 } | |
| 345 else { | |
| 346 Py_INCREF(Py_None); | |
| 347 return Py_None; | |
| 348 } | |
|
2567
b5963c4b639a
added firstkey(), nextkey(), reorganize() methods
Guido van Rossum <guido@python.org>
parents:
2531
diff
changeset
|
349 } |
|
b5963c4b639a
added firstkey(), nextkey(), reorganize() methods
Guido van Rossum <guido@python.org>
parents:
2531
diff
changeset
|
350 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
351 PyDoc_STRVAR(dbm_reorganize__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
352 "reorganize() -> None\n\ |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
353 If you have carried out a lot of deletions and would like to shrink\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
354 the space used by the GDBM file, this routine will reorganize the\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
355 database. GDBM will not shorten the length of a database file except\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
356 by using this reorganization; otherwise, deleted file space will be\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
357 kept and reused as new (key,value) pairs are added."); |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
358 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
359 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36787
diff
changeset
|
360 dbm_reorganize(register dbmobject *dp, PyObject *unused) |
|
2567
b5963c4b639a
added firstkey(), nextkey(), reorganize() methods
Guido van Rossum <guido@python.org>
parents:
2531
diff
changeset
|
361 { |
| 13425 | 362 check_dbmobject_open(dp); |
| 363 errno = 0; | |
| 364 if (gdbm_reorganize(dp->di_dbm) < 0) { | |
| 365 if (errno != 0) | |
| 366 PyErr_SetFromErrno(DbmError); | |
| 367 else | |
| 368 PyErr_SetString(DbmError, gdbm_strerror(gdbm_errno)); | |
| 369 return NULL; | |
| 370 } | |
| 371 Py_INCREF(Py_None); | |
| 372 return Py_None; | |
|
2567
b5963c4b639a
added firstkey(), nextkey(), reorganize() methods
Guido van Rossum <guido@python.org>
parents:
2531
diff
changeset
|
373 } |
|
b5963c4b639a
added firstkey(), nextkey(), reorganize() methods
Guido van Rossum <guido@python.org>
parents:
2531
diff
changeset
|
374 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
375 PyDoc_STRVAR(dbm_sync__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
376 "sync() -> None\n\ |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
377 When the database has been opened in fast mode, this method forces\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
378 any unwritten data to be written to the disk."); |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
379 |
|
5214
9c16bdf160ff
As per GvR recomendation, added support for a 'sync' attribute for the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4761
diff
changeset
|
380 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36787
diff
changeset
|
381 dbm_sync(register dbmobject *dp, PyObject *unused) |
|
5214
9c16bdf160ff
As per GvR recomendation, added support for a 'sync' attribute for the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4761
diff
changeset
|
382 { |
| 13425 | 383 check_dbmobject_open(dp); |
| 384 gdbm_sync(dp->di_dbm); | |
| 385 Py_INCREF(Py_None); | |
| 386 return Py_None; | |
|
5214
9c16bdf160ff
As per GvR recomendation, added support for a 'sync' attribute for the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4761
diff
changeset
|
387 } |
|
9c16bdf160ff
As per GvR recomendation, added support for a 'sync' attribute for the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4761
diff
changeset
|
388 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
389 static PyMethodDef dbm_methods[] = { |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36787
diff
changeset
|
390 {"close", (PyCFunction)dbm_close, METH_NOARGS, dbm_close__doc__}, |
|
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36787
diff
changeset
|
391 {"keys", (PyCFunction)dbm_keys, METH_NOARGS, dbm_keys__doc__}, |
| 13425 | 392 {"has_key", (PyCFunction)dbm_has_key, METH_VARARGS, dbm_has_key__doc__}, |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36787
diff
changeset
|
393 {"firstkey", (PyCFunction)dbm_firstkey,METH_NOARGS, dbm_firstkey__doc__}, |
| 13425 | 394 {"nextkey", (PyCFunction)dbm_nextkey, METH_VARARGS, dbm_nextkey__doc__}, |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36787
diff
changeset
|
395 {"reorganize",(PyCFunction)dbm_reorganize,METH_NOARGS, dbm_reorganize__doc__}, |
|
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36787
diff
changeset
|
396 {"sync", (PyCFunction)dbm_sync, METH_NOARGS, dbm_sync__doc__}, |
| 13425 | 397 {NULL, NULL} /* sentinel */ |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
398 }; |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
399 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
400 static PyObject * |
| 13425 | 401 dbm_getattr(dbmobject *dp, char *name) |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 { |
| 13425 | 403 return Py_FindMethod(dbm_methods, (PyObject *)dp, name); |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 } |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
405 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
406 static PyTypeObject Dbmtype = { |
|
42333
6620a510e9a9
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
407 PyVarObject_HEAD_INIT(0, 0) |
|
21313
91dd223829c6
Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents:
21073
diff
changeset
|
408 "gdbm.gdbm", |
| 13425 | 409 sizeof(dbmobject), |
| 410 0, | |
| 411 (destructor)dbm_dealloc, /*tp_dealloc*/ | |
| 412 0, /*tp_print*/ | |
| 413 (getattrfunc)dbm_getattr, /*tp_getattr*/ | |
| 414 0, /*tp_setattr*/ | |
| 415 0, /*tp_compare*/ | |
| 416 0, /*tp_repr*/ | |
| 417 0, /*tp_as_number*/ | |
|
45523
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
418 &dbm_as_sequence, /*tp_as_sequence*/ |
| 13425 | 419 &dbm_as_mapping, /*tp_as_mapping*/ |
| 420 0, /*tp_hash*/ | |
| 421 0, /*tp_call*/ | |
| 422 0, /*tp_str*/ | |
| 423 0, /*tp_getattro*/ | |
| 424 0, /*tp_setattro*/ | |
| 425 0, /*tp_as_buffer*/ | |
|
45523
4f639af58a19
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents:
44350
diff
changeset
|
426 Py_TPFLAGS_DEFAULT, /*tp_xxx4*/ |
| 13425 | 427 gdbm_object__doc__, /*tp_doc*/ |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
428 }; |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
429 |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
430 /* ----------------------------------------------------------------- */ |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
431 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
432 PyDoc_STRVAR(dbmopen__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
433 "open(filename, [flags, [mode]]) -> dbm_object\n\ |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
434 Open a dbm database and return a dbm object. The filename argument is\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
435 the name of the database file.\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
436 \n\ |
|
15601
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
437 The optional flags argument can be 'r' (to open an existing database\n\ |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
438 for reading only -- default), 'w' (to open an existing database for\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
439 reading and writing), 'c' (which creates the database if it doesn't\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
440 exist), or 'n' (which always creates a new empty database).\n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
441 \n\ |
|
15601
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
442 Some versions of gdbm support additional flags which must be\n\ |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
443 appended to one of the flags described above. The module constant\n\ |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
444 'open_flags' is a string of valid additional flags. The 'f' flag\n\ |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
445 opens the database in fast mode; altered data will not automatically\n\ |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
446 be written to the disk after every change. This results in faster\n\ |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
447 writes to the database, but may result in an inconsistent database\n\ |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
448 if the program crashes while the database is still open. Use the\n\ |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
449 sync() method to force any unwritten data to be written to the disk.\n\ |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
450 The 's' flag causes all database operations to be synchronized to\n\ |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
451 disk. The 'u' flag disables locking of the database file.\n\ |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
452 \n\ |
|
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
453 The optional mode argument is the Unix mode of the file, used only\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
454 when the database has to be created. It defaults to octal 0666. "); |
|
7528
3caf2397c508
Doc strings added by Mitch Chapman.
Guido van Rossum <guido@python.org>
parents:
6367
diff
changeset
|
455 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
456 static PyObject * |
| 13425 | 457 dbmopen(PyObject *self, PyObject *args) |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
458 { |
| 13425 | 459 char *name; |
|
32523
da63e2d6eb8a
[Bug #982806] The default argument for opening GDBM files is bogus. Patch #984672 by James Lamanna
Andrew M. Kuchling <amk@amk.ca>
parents:
24471
diff
changeset
|
460 char *flags = "r"; |
| 13425 | 461 int iflags; |
| 462 int mode = 0666; | |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
463 |
| 13425 | 464 if (!PyArg_ParseTuple(args, "s|si:open", &name, &flags, &mode)) |
| 465 return NULL; | |
| 466 switch (flags[0]) { | |
| 467 case 'r': | |
| 468 iflags = GDBM_READER; | |
| 469 break; | |
| 470 case 'w': | |
| 471 iflags = GDBM_WRITER; | |
| 472 break; | |
| 473 case 'c': | |
| 474 iflags = GDBM_WRCREAT; | |
| 475 break; | |
| 476 case 'n': | |
| 477 iflags = GDBM_NEWDB; | |
| 478 break; | |
| 479 default: | |
| 480 PyErr_SetString(DbmError, | |
|
15601
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
481 "First flag must be one of 'r', 'w', 'c' or 'n'"); |
| 13425 | 482 return NULL; |
| 483 } | |
|
15601
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
484 for (flags++; *flags != '\0'; flags++) { |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
485 char buf[40]; |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
486 switch (*flags) { |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
487 #ifdef GDBM_FAST |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
488 case 'f': |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
489 iflags |= GDBM_FAST; |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
490 break; |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
491 #endif |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
492 #ifdef GDBM_SYNC |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
493 case 's': |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
494 iflags |= GDBM_SYNC; |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
495 break; |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
496 #endif |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
497 #ifdef GDBM_NOLOCK |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
498 case 'u': |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
499 iflags |= GDBM_NOLOCK; |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
500 break; |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
501 #endif |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
502 default: |
|
21073
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
20955
diff
changeset
|
503 PyOS_snprintf(buf, sizeof(buf), "Flag '%c' is not supported.", |
|
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
20955
diff
changeset
|
504 *flags); |
|
15601
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
505 PyErr_SetString(DbmError, buf); |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
506 return NULL; |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
507 } |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
508 } |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
509 |
| 13425 | 510 return newdbmobject(name, iflags, mode); |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
511 } |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
512 |
|
15601
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
513 static char dbmmodule_open_flags[] = "rwcn" |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
514 #ifdef GDBM_FAST |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
515 "f" |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
516 #endif |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
517 #ifdef GDBM_SYNC |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
518 "s" |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
519 #endif |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
520 #ifdef GDBM_NOLOCK |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
521 "u" |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
522 #endif |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
523 ; |
|
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
524 |
|
4761
d7eea694cd3a
Renamed in a grand-ee-ous way!
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4503
diff
changeset
|
525 static PyMethodDef dbmmodule_methods[] = { |
| 13425 | 526 { "open", (PyCFunction)dbmopen, METH_VARARGS, dbmopen__doc__}, |
| 527 { 0, 0 }, | |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
528 }; |
|
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
529 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24280
diff
changeset
|
530 PyMODINIT_FUNC |
|
13690
c09c0171474f
ANSIfy some more forward declarations.
Thomas Wouters <thomas@python.org>
parents:
13425
diff
changeset
|
531 initgdbm(void) { |
|
20955
615a4f560268
Patch in bug report #477700: Fix memory leaks in gdbm & curses.
Martin v. Löwis <martin@v.loewis.de>
parents:
16837
diff
changeset
|
532 PyObject *m, *d, *s; |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
533 |
| 13425 | 534 Dbmtype.ob_type = &PyType_Type; |
| 535 m = Py_InitModule4("gdbm", dbmmodule_methods, | |
| 536 gdbmmodule__doc__, (PyObject *)NULL, | |
| 537 PYTHON_API_VERSION); | |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
32523
diff
changeset
|
538 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
32523
diff
changeset
|
539 return; |
| 13425 | 540 d = PyModule_GetDict(m); |
| 541 DbmError = PyErr_NewException("gdbm.error", NULL, NULL); | |
|
15601
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
542 if (DbmError != NULL) { |
| 13425 | 543 PyDict_SetItemString(d, "error", DbmError); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
544 s = PyString_FromString(dbmmodule_open_flags); |
|
20955
615a4f560268
Patch in bug report #477700: Fix memory leaks in gdbm & curses.
Martin v. Löwis <martin@v.loewis.de>
parents:
16837
diff
changeset
|
545 PyDict_SetItemString(d, "open_flags", s); |
|
615a4f560268
Patch in bug report #477700: Fix memory leaks in gdbm & curses.
Martin v. Löwis <martin@v.loewis.de>
parents:
16837
diff
changeset
|
546 Py_DECREF(s); |
|
15601
53423ec0a728
Add support for gdbm2 open flags ('s' and 'u'). Add module constant
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14375
diff
changeset
|
547 } |
|
1766
6e9130460288
* Modules/{Setup.in, gdbmmodule.c}, Doc/{lib,libgdbm}.tex: added
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
548 } |
