Mercurial > cpython-lru_cache-weakref
annotate Modules/_dbmmodule.c @ 48715:48dddfd2fbf3
RPC_WSTR is not available Visual Studio 2003 or earlier.
(Maybe I should have defined RPC_WSTR on old compiler,
but uuidcreate() is only place using it, so I simply replaced
with unsigned short *)
| author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> |
|---|---|
| date | Sun, 17 Aug 2008 07:26:26 +0000 |
| parents | aa1fbe321acf |
| children | 8ffec372040e |
| rev | line source |
|---|---|
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 /* DBM module using dictionary interface */ |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
5 #include "Python.h" |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 #include <sys/types.h> |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 #include <sys/stat.h> |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 #include <fcntl.h> |
|
14550
7fa4302a5a08
Use the configure support to determine which ndbm.h header to include.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
10 |
|
7fa4302a5a08
Use the configure support to determine which ndbm.h header to include.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
11 /* Some Linux systems install gdbm/ndbm.h, but not ndbm.h. This supports |
|
7fa4302a5a08
Use the configure support to determine which ndbm.h header to include.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
12 * whichever configure was able to locate. |
|
7fa4302a5a08
Use the configure support to determine which ndbm.h header to include.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
13 */ |
|
7fa4302a5a08
Use the configure support to determine which ndbm.h header to include.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
14 #if defined(HAVE_NDBM_H) |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 #include <ndbm.h> |
|
22114
c454b76d51e7
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21313
diff
changeset
|
16 #if defined(PYOS_OS2) && !defined(PYCC_GCC) |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
17 static char *which_dbm = "ndbm"; |
|
22114
c454b76d51e7
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21313
diff
changeset
|
18 #else |
|
c454b76d51e7
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21313
diff
changeset
|
19 static char *which_dbm = "GNU gdbm"; /* EMX port of GDBM */ |
|
c454b76d51e7
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21313
diff
changeset
|
20 #endif |
|
14550
7fa4302a5a08
Use the configure support to determine which ndbm.h header to include.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
21 #elif defined(HAVE_GDBM_NDBM_H) |
|
7fa4302a5a08
Use the configure support to determine which ndbm.h header to include.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
22 #include <gdbm/ndbm.h> |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
23 static char *which_dbm = "GNU gdbm"; |
|
24490
0854524ece00
add #include branch for compilation with Berkeley DB
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
24 #elif defined(HAVE_BERKDB_H) |
|
0854524ece00
add #include branch for compilation with Berkeley DB
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
25 #include <db.h> |
|
0854524ece00
add #include branch for compilation with Berkeley DB
Skip Montanaro <skip@pobox.com>
parents:
24471
diff
changeset
|
26 static char *which_dbm = "Berkeley DB"; |
|
14550
7fa4302a5a08
Use the configure support to determine which ndbm.h header to include.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
27 #else |
|
7fa4302a5a08
Use the configure support to determine which ndbm.h header to include.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
28 #error "No ndbm.h available!" |
|
7fa4302a5a08
Use the configure support to determine which ndbm.h header to include.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
29 #endif |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 typedef struct { |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
32 PyObject_HEAD |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 int di_size; /* -1 means recompute */ |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 DBM *di_dbm; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 } dbmobject; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23867
diff
changeset
|
37 static PyTypeObject Dbmtype; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
43777
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:
4718
diff
changeset
|
40 #define check_dbmobject_open(v) if ((v)->di_dbm == NULL) \ |
|
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
4718
diff
changeset
|
41 { PyErr_SetString(DbmError, "DBM object has already been closed"); \ |
|
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
4718
diff
changeset
|
42 return NULL; } |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
44 static PyObject *DbmError; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
46 static PyObject * |
|
13515
cd7abb4feb1b
ANSI-fication, not really tested, but should (hopefully) compile
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
47 newdbmobject(char *file, int flags, int mode) |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 { |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 dbmobject *dp; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
51 dp = PyObject_New(dbmobject, &Dbmtype); |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 if (dp == NULL) |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 return NULL; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 dp->di_size = -1; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 if ( (dp->di_dbm = dbm_open(file, flags, mode)) == 0 ) { |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
56 PyErr_SetFromErrno(DbmError); |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
57 Py_DECREF(dp); |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
58 return NULL; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 } |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
60 return (PyObject *)dp; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 /* Methods */ |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 static void |
|
13515
cd7abb4feb1b
ANSI-fication, not really tested, but should (hopefully) compile
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
66 dbm_dealloc(register dbmobject *dp) |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 { |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 if ( dp->di_dbm ) |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
69 dbm_close(dp->di_dbm); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
70 PyObject_Del(dp); |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
73 static Py_ssize_t |
|
13515
cd7abb4feb1b
ANSI-fication, not really tested, but should (hopefully) compile
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
74 dbm_length(dbmobject *dp) |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 { |
|
5828
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
4718
diff
changeset
|
76 if (dp->di_dbm == NULL) { |
|
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
4718
diff
changeset
|
77 PyErr_SetString(DbmError, "DBM object has already been closed"); |
|
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
4718
diff
changeset
|
78 return -1; |
|
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
4718
diff
changeset
|
79 } |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 if ( dp->di_size < 0 ) { |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
81 datum key; |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
82 int size; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
84 size = 0; |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
85 for ( key=dbm_firstkey(dp->di_dbm); key.dptr; |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
86 key = dbm_nextkey(dp->di_dbm)) |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
87 size++; |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
88 dp->di_size = size; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 return dp->di_size; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
93 static PyObject * |
|
13515
cd7abb4feb1b
ANSI-fication, not really tested, but should (hopefully) compile
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
94 dbm_subscript(dbmobject *dp, register PyObject *key) |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 { |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 datum drec, krec; |
|
41895
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
97 Py_ssize_t tmp_size; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 |
|
26360
8236d5288412
Fix SF # 640557, '64-bit' systems and the dbm module
Neal Norwitz <nnorwitz@gmail.com>
parents:
24490
diff
changeset
|
99 if (!PyArg_Parse(key, "s#", &krec.dptr, &tmp_size) ) |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 return NULL; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 |
|
26360
8236d5288412
Fix SF # 640557, '64-bit' systems and the dbm module
Neal Norwitz <nnorwitz@gmail.com>
parents:
24490
diff
changeset
|
102 krec.dsize = tmp_size; |
|
5828
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
4718
diff
changeset
|
103 check_dbmobject_open(dp); |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 drec = dbm_fetch(dp->di_dbm, krec); |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 if ( drec.dptr == 0 ) { |
|
42467
81a3803f43cf
Quick fixes for assert failures in dbm wrapper code.
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
106 PyErr_SetObject(PyExc_KeyError, key); |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
107 return NULL; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 if ( dbm_error(dp->di_dbm) ) { |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
110 dbm_clearerr(dp->di_dbm); |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
111 PyErr_SetString(DbmError, ""); |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
112 return NULL; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 } |
|
47300
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
47285
diff
changeset
|
114 return PyByteArray_FromStringAndSize(drec.dptr, drec.dsize); |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 static int |
|
13515
cd7abb4feb1b
ANSI-fication, not really tested, but should (hopefully) compile
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
118 dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w) |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 { |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 datum krec, drec; |
|
41895
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
121 Py_ssize_t tmp_size; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 |
|
26360
8236d5288412
Fix SF # 640557, '64-bit' systems and the dbm module
Neal Norwitz <nnorwitz@gmail.com>
parents:
24490
diff
changeset
|
123 if ( !PyArg_Parse(v, "s#", &krec.dptr, &tmp_size) ) { |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
124 PyErr_SetString(PyExc_TypeError, |
|
41895
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
125 "dbm mappings have string keys only"); |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
126 return -1; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 } |
|
26360
8236d5288412
Fix SF # 640557, '64-bit' systems and the dbm module
Neal Norwitz <nnorwitz@gmail.com>
parents:
24490
diff
changeset
|
128 krec.dsize = tmp_size; |
|
5828
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
4718
diff
changeset
|
129 if (dp->di_dbm == NULL) { |
|
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
4718
diff
changeset
|
130 PyErr_SetString(DbmError, "DBM object has already been closed"); |
|
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
4718
diff
changeset
|
131 return -1; |
|
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
4718
diff
changeset
|
132 } |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 dp->di_size = -1; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 if (w == NULL) { |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
135 if ( dbm_delete(dp->di_dbm, krec) < 0 ) { |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
136 dbm_clearerr(dp->di_dbm); |
|
42487
c8a091b842d6
Fix a type error in a previous patch I made to this module.
Guido van Rossum <guido@python.org>
parents:
42467
diff
changeset
|
137 PyErr_SetObject(PyExc_KeyError, v); |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
138 return -1; |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
139 } |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 } else { |
|
26360
8236d5288412
Fix SF # 640557, '64-bit' systems and the dbm module
Neal Norwitz <nnorwitz@gmail.com>
parents:
24490
diff
changeset
|
141 if ( !PyArg_Parse(w, "s#", &drec.dptr, &tmp_size) ) { |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
142 PyErr_SetString(PyExc_TypeError, |
|
41895
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
143 "dbm mappings have byte string elements only"); |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
144 return -1; |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
145 } |
|
26360
8236d5288412
Fix SF # 640557, '64-bit' systems and the dbm module
Neal Norwitz <nnorwitz@gmail.com>
parents:
24490
diff
changeset
|
146 drec.dsize = tmp_size; |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
147 if ( dbm_store(dp->di_dbm, krec, drec, DBM_REPLACE) < 0 ) { |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
148 dbm_clearerr(dp->di_dbm); |
|
4718
1834654bebe3
Opps, fixed a couple of newly introduced wrapping problems.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4717
diff
changeset
|
149 PyErr_SetString(DbmError, |
| 15318 | 150 "cannot add item to database"); |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
151 return -1; |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
152 } |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 if ( dbm_error(dp->di_dbm) ) { |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
155 dbm_clearerr(dp->di_dbm); |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
156 PyErr_SetString(DbmError, ""); |
|
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
157 return -1; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 return 0; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
162 static PyMappingMethods dbm_as_mapping = { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
163 (lenfunc)dbm_length, /*mp_length*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
164 (binaryfunc)dbm_subscript, /*mp_subscript*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
165 (objobjargproc)dbm_ass_sub, /*mp_ass_subscript*/ |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 }; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
168 static PyObject * |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
169 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:
2268
diff
changeset
|
170 { |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
171 if (dp->di_dbm) |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
172 dbm_close(dp->di_dbm); |
|
2805
b7a06db85caf
normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents:
2268
diff
changeset
|
173 dp->di_dbm = NULL; |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
174 Py_INCREF(Py_None); |
|
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
175 return Py_None; |
|
2805
b7a06db85caf
normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents:
2268
diff
changeset
|
176 } |
|
b7a06db85caf
normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents:
2268
diff
changeset
|
177 |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
178 static PyObject * |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
179 dbm_keys(register dbmobject *dp, PyObject *unused) |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 { |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
181 register PyObject *v, *item; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 datum key; |
|
2268
ac6f69b1e993
plug leak and improve error handling in dbm_keys()
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
183 int err; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 |
|
5828
9fa2bd8a2b78
Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents:
4718
diff
changeset
|
185 check_dbmobject_open(dp); |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
186 v = PyList_New(0); |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 if (v == NULL) |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 return NULL; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 for (key = dbm_firstkey(dp->di_dbm); key.dptr; |
|
2268
ac6f69b1e993
plug leak and improve error handling in dbm_keys()
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
190 key = dbm_nextkey(dp->di_dbm)) { |
|
47300
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
47285
diff
changeset
|
191 item = PyByteArray_FromStringAndSize(key.dptr, key.dsize); |
|
2268
ac6f69b1e993
plug leak and improve error handling in dbm_keys()
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
192 if (item == NULL) { |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
193 Py_DECREF(v); |
|
2268
ac6f69b1e993
plug leak and improve error handling in dbm_keys()
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
194 return NULL; |
|
ac6f69b1e993
plug leak and improve error handling in dbm_keys()
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
195 } |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
196 err = PyList_Append(v, item); |
|
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
197 Py_DECREF(item); |
|
2268
ac6f69b1e993
plug leak and improve error handling in dbm_keys()
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
198 if (err != 0) { |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
199 Py_DECREF(v); |
|
2268
ac6f69b1e993
plug leak and improve error handling in dbm_keys()
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
200 return NULL; |
|
ac6f69b1e993
plug leak and improve error handling in dbm_keys()
Guido van Rossum <guido@python.org>
parents:
2061
diff
changeset
|
201 } |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 return v; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 |
|
39593
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
206 static int |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
207 dbm_contains(PyObject *self, PyObject *arg) |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 { |
|
39593
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
209 dbmobject *dp = (dbmobject *)self; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 datum key, val; |
|
39593
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
211 |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
212 if ((dp)->di_dbm == NULL) { |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
213 PyErr_SetString(DbmError, |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
214 "DBM object has already been closed"); |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
215 return -1; |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
216 } |
|
41895
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
217 if (PyUnicode_Check(arg)) { |
|
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
218 arg = _PyUnicode_AsDefaultEncodedString(arg, NULL); |
|
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
219 if (arg == NULL) |
|
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
220 return -1; |
|
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
221 } |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
222 if (!PyBytes_Check(arg)) { |
|
39593
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
223 PyErr_Format(PyExc_TypeError, |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
224 "dbm key must be string, not %.100s", |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
225 arg->ob_type->tp_name); |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
226 return -1; |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
227 } |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
228 key.dptr = PyBytes_AS_STRING(arg); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
229 key.dsize = PyBytes_GET_SIZE(arg); |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 val = dbm_fetch(dp->di_dbm, key); |
|
39593
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
231 return val.dptr != NULL; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
232 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 |
|
39593
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
234 static PySequenceMethods dbm_as_sequence = { |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
235 0, /* sq_length */ |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
236 0, /* sq_concat */ |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
237 0, /* sq_repeat */ |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
238 0, /* sq_item */ |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
239 0, /* sq_slice */ |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
240 0, /* sq_ass_item */ |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
241 0, /* sq_ass_slice */ |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
242 dbm_contains, /* sq_contains */ |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
243 0, /* sq_inplace_concat */ |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
244 0, /* sq_inplace_repeat */ |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
245 }; |
|
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
246 |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
247 static PyObject * |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
248 dbm_get(register dbmobject *dp, PyObject *args) |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
249 { |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
250 datum key, val; |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
251 PyObject *defvalue = Py_None; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39593
diff
changeset
|
252 char *tmp_ptr; |
|
41895
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
253 Py_ssize_t tmp_size; |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
254 |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
255 if (!PyArg_ParseTuple(args, "s#|O:get", |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39593
diff
changeset
|
256 &tmp_ptr, &tmp_size, &defvalue)) |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
257 return NULL; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39593
diff
changeset
|
258 key.dptr = tmp_ptr; |
|
26360
8236d5288412
Fix SF # 640557, '64-bit' systems and the dbm module
Neal Norwitz <nnorwitz@gmail.com>
parents:
24490
diff
changeset
|
259 key.dsize = tmp_size; |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
260 check_dbmobject_open(dp); |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
261 val = dbm_fetch(dp->di_dbm, key); |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
262 if (val.dptr != NULL) |
|
47300
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
47285
diff
changeset
|
263 return PyByteArray_FromStringAndSize(val.dptr, val.dsize); |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
264 else { |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
265 Py_INCREF(defvalue); |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
266 return defvalue; |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
267 } |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
268 } |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
269 |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
270 static PyObject * |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
271 dbm_setdefault(register dbmobject *dp, PyObject *args) |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
272 { |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
273 datum key, val; |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
274 PyObject *defvalue = NULL; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39593
diff
changeset
|
275 char *tmp_ptr; |
|
41895
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
276 Py_ssize_t tmp_size; |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
277 |
|
41895
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
278 if (!PyArg_ParseTuple(args, "s#|O:setdefault", |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39593
diff
changeset
|
279 &tmp_ptr, &tmp_size, &defvalue)) |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
280 return NULL; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39593
diff
changeset
|
281 key.dptr = tmp_ptr; |
|
26360
8236d5288412
Fix SF # 640557, '64-bit' systems and the dbm module
Neal Norwitz <nnorwitz@gmail.com>
parents:
24490
diff
changeset
|
282 key.dsize = tmp_size; |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
283 check_dbmobject_open(dp); |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
284 val = dbm_fetch(dp->di_dbm, key); |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
285 if (val.dptr != NULL) |
|
47300
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
47285
diff
changeset
|
286 return PyByteArray_FromStringAndSize(val.dptr, val.dsize); |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
287 if (defvalue == NULL) { |
|
47300
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
47285
diff
changeset
|
288 defvalue = PyByteArray_FromStringAndSize(NULL, 0); |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
289 if (defvalue == NULL) |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
290 return NULL; |
|
41895
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
291 val.dptr = NULL; |
|
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
292 val.dsize = 0; |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
293 } |
|
41895
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
294 else { |
|
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
295 if ( !PyArg_Parse(defvalue, "s#", &val.dptr, &tmp_size) ) { |
|
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
296 PyErr_SetString(PyExc_TypeError, |
|
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
297 "dbm mappings have byte string elements only"); |
|
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
298 return NULL; |
|
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
299 } |
|
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
300 val.dsize = tmp_size; |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
301 Py_INCREF(defvalue); |
|
41895
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
302 } |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
303 if (dbm_store(dp->di_dbm, key, val, DBM_INSERT) < 0) { |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
304 dbm_clearerr(dp->di_dbm); |
| 15318 | 305 PyErr_SetString(DbmError, "cannot add item to database"); |
|
41895
3fda9e6a0b6d
Modernize. Values are now bytes.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
306 Py_DECREF(defvalue); |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
307 return NULL; |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
308 } |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
309 return defvalue; |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
310 } |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
311 |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
312 static PyMethodDef dbm_methods[] = { |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
313 {"close", (PyCFunction)dbm__close, METH_NOARGS, |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
314 "close()\nClose the database."}, |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
315 {"keys", (PyCFunction)dbm_keys, METH_NOARGS, |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
316 "keys() -> list\nReturn a list of all keys in the database."}, |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
317 {"get", (PyCFunction)dbm_get, METH_VARARGS, |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
318 "get(key[, default]) -> value\n" |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
319 "Return the value for key if present, otherwise default."}, |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
320 {"setdefault", (PyCFunction)dbm_setdefault, METH_VARARGS, |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
321 "setdefault(key[, default]) -> value\n" |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
322 "Return the value for key if present, otherwise default. If key\n" |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
323 "is not in the database, it is inserted with default as the value."}, |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
324 {NULL, NULL} /* sentinel */ |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
325 }; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
326 |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
327 static PyTypeObject Dbmtype = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
41895
diff
changeset
|
328 PyVarObject_HEAD_INIT(NULL, 0) |
|
47285
afbde360dd1a
Create the dbm package from PEP 3108. #2881.
Georg Brandl <georg@python.org>
parents:
45534
diff
changeset
|
329 "_dbm.dbm", |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
330 sizeof(dbmobject), |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
331 0, |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
332 (destructor)dbm_dealloc, /*tp_dealloc*/ |
|
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
333 0, /*tp_print*/ |
|
48418
aa1fbe321acf
#3247: get rid of Py_FindMethod
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
334 0, /*tp_getattr*/ |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
335 0, /*tp_setattr*/ |
|
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
336 0, /*tp_compare*/ |
|
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
337 0, /*tp_repr*/ |
|
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
338 0, /*tp_as_number*/ |
|
39593
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
339 &dbm_as_sequence, /*tp_as_sequence*/ |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
340 &dbm_as_mapping, /*tp_as_mapping*/ |
|
45534
7afef8f43e4a
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61064,61066-61080 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
341 0, /*tp_hash*/ |
|
7afef8f43e4a
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61064,61066-61080 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
342 0, /*tp_call*/ |
|
7afef8f43e4a
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61064,61066-61080 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
343 0, /*tp_str*/ |
|
7afef8f43e4a
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61064,61066-61080 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
344 0, /*tp_getattro*/ |
|
7afef8f43e4a
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61064,61066-61080 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
345 0, /*tp_setattro*/ |
|
7afef8f43e4a
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61064,61066-61080 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
346 0, /*tp_as_buffer*/ |
|
48418
aa1fbe321acf
#3247: get rid of Py_FindMethod
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
347 Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
|
aa1fbe321acf
#3247: get rid of Py_FindMethod
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
348 0, /*tp_doc*/ |
|
aa1fbe321acf
#3247: get rid of Py_FindMethod
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
349 0, /*tp_traverse*/ |
|
aa1fbe321acf
#3247: get rid of Py_FindMethod
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
350 0, /*tp_clear*/ |
|
aa1fbe321acf
#3247: get rid of Py_FindMethod
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
351 0, /*tp_richcompare*/ |
|
aa1fbe321acf
#3247: get rid of Py_FindMethod
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
352 0, /*tp_weaklistoffset*/ |
|
aa1fbe321acf
#3247: get rid of Py_FindMethod
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
353 0, /*tp_iter*/ |
|
aa1fbe321acf
#3247: get rid of Py_FindMethod
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
354 0, /*tp_iternext*/ |
|
aa1fbe321acf
#3247: get rid of Py_FindMethod
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
355 dbm_methods, /*tp_methods*/ |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
356 }; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
357 |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 /* ----------------------------------------------------------------- */ |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
360 static PyObject * |
|
13515
cd7abb4feb1b
ANSI-fication, not really tested, but should (hopefully) compile
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
361 dbmopen(PyObject *self, PyObject *args) |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 { |
|
2805
b7a06db85caf
normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents:
2268
diff
changeset
|
363 char *name; |
|
b7a06db85caf
normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents:
2268
diff
changeset
|
364 char *flags = "r"; |
|
b7a06db85caf
normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents:
2268
diff
changeset
|
365 int iflags; |
|
b7a06db85caf
normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents:
2268
diff
changeset
|
366 int mode = 0666; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
368 if ( !PyArg_ParseTuple(args, "s|si:open", &name, &flags, &mode) ) |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
369 return NULL; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 if ( strcmp(flags, "r") == 0 ) |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
371 iflags = O_RDONLY; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
372 else if ( strcmp(flags, "w") == 0 ) |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
373 iflags = O_RDWR; |
|
2805
b7a06db85caf
normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents:
2268
diff
changeset
|
374 else if ( strcmp(flags, "rw") == 0 ) /* B/W compat */ |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
375 iflags = O_RDWR|O_CREAT; |
|
2805
b7a06db85caf
normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents:
2268
diff
changeset
|
376 else if ( strcmp(flags, "c") == 0 ) |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
377 iflags = O_RDWR|O_CREAT; |
|
2805
b7a06db85caf
normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents:
2268
diff
changeset
|
378 else if ( strcmp(flags, "n") == 0 ) |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
379 iflags = O_RDWR|O_CREAT|O_TRUNC; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 else { |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
381 PyErr_SetString(DbmError, |
| 15318 | 382 "arg 2 to open should be 'r', 'w', 'c', or 'n'"); |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
383 return NULL; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
384 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 return newdbmobject(name, iflags, mode); |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 } |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
387 |
|
4648
6dd851445c7d
renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
388 static PyMethodDef dbmmodule_methods[] = { |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
389 { "open", (PyCFunction)dbmopen, METH_VARARGS, |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
390 "open(path[, flag[, mode]]) -> mapping\n" |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
391 "Return a database object."}, |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
392 { 0, 0 }, |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 }; |
|
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
395 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
396 static struct PyModuleDef _dbmmodule = { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
397 PyModuleDef_HEAD_INIT, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
398 "_dbm", |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
399 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
400 -1, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
401 dbmmodule_methods, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
402 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
403 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
404 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
405 NULL |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
406 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
407 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24280
diff
changeset
|
408 PyMODINIT_FUNC |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
409 PyInit__dbm(void) { |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
410 PyObject *m, *d, *s; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
411 |
|
39593
599abc31f770
Fix this right for has_key(). This required adding tp_as_sequence.
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
412 if (PyType_Ready(&Dbmtype) < 0) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
413 return NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
414 m = PyModule_Create(&_dbmmodule); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
26360
diff
changeset
|
415 if (m == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
416 return NULL; |
|
4717
12154d091316
Reindented via GvR recomendation ala Bwarsaw cppy-style.el
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4648
diff
changeset
|
417 d = PyModule_GetDict(m); |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
418 if (DbmError == NULL) |
|
47357
b97dd5889246
Make db modules' error classes inherit IOError.
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
419 DbmError = PyErr_NewException("_dbm.error", |
|
b97dd5889246
Make db modules' error classes inherit IOError.
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
420 PyExc_IOError, NULL); |
|
42588
b7bd4a2689c1
The dbm module should use bytes for keys. This makes test_shelve pass.
Guido van Rossum <guido@python.org>
parents:
42487
diff
changeset
|
421 s = PyUnicode_FromString(which_dbm); |
|
14608
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
422 if (s != NULL) { |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
423 PyDict_SetItemString(d, "library", s); |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
424 Py_DECREF(s); |
|
142a90eea8f4
Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents:
14577
diff
changeset
|
425 } |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5828
diff
changeset
|
426 if (DbmError != NULL) |
|
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5828
diff
changeset
|
427 PyDict_SetItemString(d, "error", DbmError); |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
428 if (PyErr_Occurred()) { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
429 Py_DECREF(m); |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
430 m = NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
431 } |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47357
diff
changeset
|
432 return m; |
|
906
63798cde582c
Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
433 } |
