annotate Modules/dbmmodule.c @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents fd25030223b0
children 53da3bad8554
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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";
50048
dd5e1a042dba issue 4483 - dbm build failures on systems with gdbm_compat lib.
Skip Montanaro <skip@pobox.com>
parents: 47527
diff changeset
24 #elif defined(HAVE_GDBM_DASH_NDBM_H)
dd5e1a042dba issue 4483 - dbm build failures on systems with gdbm_compat lib.
Skip Montanaro <skip@pobox.com>
parents: 47527
diff changeset
25 #include <gdbm-ndbm.h>
dd5e1a042dba issue 4483 - dbm build failures on systems with gdbm_compat lib.
Skip Montanaro <skip@pobox.com>
parents: 47527
diff changeset
26 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
27 #elif defined(HAVE_BERKDB_H)
0854524ece00 add #include branch for compilation with Berkeley DB
Skip Montanaro <skip@pobox.com>
parents: 24471
diff changeset
28 #include <db.h>
0854524ece00 add #include branch for compilation with Berkeley DB
Skip Montanaro <skip@pobox.com>
parents: 24471
diff changeset
29 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
30 #else
7fa4302a5a08 Use the configure support to determine which ndbm.h header to include.
Fred Drake <fdrake@acm.org>
parents: 14375
diff changeset
31 #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
32 #endif
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 typedef struct {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
35 PyObject_HEAD
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
36 int di_size; /* -1 means recompute */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
37 DBM *di_dbm;
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 } dbmobject;
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
24280
1598a1e473e2 staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23867
diff changeset
40 static PyTypeObject Dbmtype;
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
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
42 #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
43 #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
44 { 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
45 return NULL; }
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
4648
6dd851445c7d renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4600
diff changeset
47 static PyObject *DbmError;
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
4648
6dd851445c7d renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4600
diff changeset
49 static PyObject *
13515
cd7abb4feb1b ANSI-fication, not really tested, but should (hopefully) compile
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
50 newdbmobject(char *file, int flags, int mode)
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
52 dbmobject *dp;
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
54 dp = PyObject_New(dbmobject, &Dbmtype);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
55 if (dp == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
56 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
57 dp->di_size = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
58 if ( (dp->di_dbm = dbm_open(file, flags, mode)) == 0 ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
59 PyErr_SetFromErrno(DbmError);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
60 Py_DECREF(dp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
61 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
62 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
63 return (PyObject *)dp;
906
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
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 /* Methods */
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 static void
13515
cd7abb4feb1b ANSI-fication, not really tested, but should (hopefully) compile
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
69 dbm_dealloc(register dbmobject *dp)
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
71 if ( dp->di_dbm )
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
72 dbm_close(dp->di_dbm);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
73 PyObject_Del(dp);
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 }
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
76 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
77 dbm_length(dbmobject *dp)
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
79 if (dp->di_dbm == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
80 PyErr_SetString(DbmError, "DBM object has already been closed");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
81 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
82 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
83 if ( dp->di_size < 0 ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
84 datum key;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
85 int size;
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
87 size = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
88 for ( key=dbm_firstkey(dp->di_dbm); key.dptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
89 key = dbm_nextkey(dp->di_dbm))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
90 size++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
91 dp->di_size = size;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
92 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
93 return dp->di_size;
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 }
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95
4648
6dd851445c7d renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4600
diff changeset
96 static PyObject *
13515
cd7abb4feb1b ANSI-fication, not really tested, but should (hopefully) compile
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
97 dbm_subscript(dbmobject *dp, register PyObject *key)
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
99 datum drec, krec;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
100 int tmp_size;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
101
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
102 if (!PyArg_Parse(key, "s#", &krec.dptr, &tmp_size) )
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
103 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
104
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
105 krec.dsize = tmp_size;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
106 check_dbmobject_open(dp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
107 drec = dbm_fetch(dp->di_dbm, krec);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
108 if ( drec.dptr == 0 ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
109 PyErr_SetString(PyExc_KeyError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
110 PyString_AS_STRING((PyStringObject *)key));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
111 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
112 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
113 if ( dbm_error(dp->di_dbm) ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
114 dbm_clearerr(dp->di_dbm);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
115 PyErr_SetString(DbmError, "");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
116 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
117 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
118 return PyString_FromStringAndSize(drec.dptr, drec.dsize);
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
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 static int
13515
cd7abb4feb1b ANSI-fication, not really tested, but should (hopefully) compile
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
122 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
123 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
124 datum krec, drec;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
125 int tmp_size;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
126
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
127 if ( !PyArg_Parse(v, "s#", &krec.dptr, &tmp_size) ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
128 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
129 "dbm mappings have string indices only");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
130 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
131 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
132 krec.dsize = tmp_size;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
133 if (dp->di_dbm == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
134 PyErr_SetString(DbmError, "DBM object has already been closed");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
135 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
136 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
137 dp->di_size = -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
138 if (w == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
139 if ( dbm_delete(dp->di_dbm, krec) < 0 ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
140 dbm_clearerr(dp->di_dbm);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
141 PyErr_SetString(PyExc_KeyError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
142 PyString_AS_STRING((PyStringObject *)v));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
143 return -1;
5828
9fa2bd8a2b78 Patches by AMK to check that the db is still open.
Guido van Rossum <guido@python.org>
parents: 4718
diff changeset
144 }
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
145 } else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
146 if ( !PyArg_Parse(w, "s#", &drec.dptr, &tmp_size) ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
147 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
148 "dbm mappings have string elements only");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
149 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
150 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
151 drec.dsize = tmp_size;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
152 if ( dbm_store(dp->di_dbm, krec, drec, DBM_REPLACE) < 0 ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
153 dbm_clearerr(dp->di_dbm);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
154 PyErr_SetString(DbmError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
155 "cannot add item to database");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
156 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
157 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
158 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
159 if ( dbm_error(dp->di_dbm) ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
160 dbm_clearerr(dp->di_dbm);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
161 PyErr_SetString(DbmError, "");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
162 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
163 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
164 return 0;
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 }
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166
45523
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
167 static int
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
168 dbm_contains(register dbmobject *dp, PyObject *v)
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
169 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
170 datum key, val;
45523
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
171
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
172 if (PyString_AsStringAndSize(v, (char **)&key.dptr,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
173 (Py_ssize_t *)&key.dsize)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
174 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
175 }
45523
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
176
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
177 /* Expand check_dbmobject_open to return -1 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
178 if (dp->di_dbm == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
179 PyErr_SetString(DbmError, "DBM object has already been closed");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
180 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
181 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
182 val = dbm_fetch(dp->di_dbm, key);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
183 return val.dptr != NULL;
45523
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
184 }
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
185
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
186 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
187 (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
188 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
189 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
190 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
191 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
192 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
193 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
194 (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
195 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
196 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
197 };
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
198
4648
6dd851445c7d renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4600
diff changeset
199 static PyMappingMethods dbm_as_mapping = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
200 (lenfunc)dbm_length, /*mp_length*/
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
201 (binaryfunc)dbm_subscript, /*mp_subscript*/
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
202 (objobjargproc)dbm_ass_sub, /*mp_ass_subscript*/
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 };
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
204
4648
6dd851445c7d renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4600
diff changeset
205 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36501
diff changeset
206 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
207 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
208 if (dp->di_dbm)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
209 dbm_close(dp->di_dbm);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
210 dp->di_dbm = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
211 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
212 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
213 }
b7a06db85caf normalized flag arg and made flag, mode default args; minor cosmetics
Guido van Rossum <guido@python.org>
parents: 2268
diff changeset
214
4648
6dd851445c7d renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4600
diff changeset
215 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36501
diff changeset
216 dbm_keys(register dbmobject *dp, PyObject *unused)
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
218 register PyObject *v, *item;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
219 datum key;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
220 int err;
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
222 check_dbmobject_open(dp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
223 v = PyList_New(0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
224 if (v == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
225 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
226 for (key = dbm_firstkey(dp->di_dbm); key.dptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
227 key = dbm_nextkey(dp->di_dbm)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
228 item = PyString_FromStringAndSize(key.dptr, key.dsize);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
229 if (item == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
230 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
231 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
232 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
233 err = PyList_Append(v, item);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
234 Py_DECREF(item);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
235 if (err != 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
236 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
237 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
238 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
239 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
240 return v;
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 }
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
242
4648
6dd851445c7d renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4600
diff changeset
243 static PyObject *
13515
cd7abb4feb1b ANSI-fication, not really tested, but should (hopefully) compile
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
244 dbm_has_key(register dbmobject *dp, PyObject *args)
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
246 char *tmp_ptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
247 datum key, val;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
248 int tmp_size;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
249
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
250 if (!PyArg_ParseTuple(args, "s#:has_key", &tmp_ptr, &tmp_size))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
251 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
252 key.dptr = tmp_ptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
253 key.dsize = tmp_size;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
254 check_dbmobject_open(dp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
255 val = dbm_fetch(dp->di_dbm, key);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
256 return PyInt_FromLong(val.dptr != NULL);
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 }
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
258
14608
142a90eea8f4 Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents: 14577
diff changeset
259 static PyObject *
142a90eea8f4 Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents: 14577
diff changeset
260 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
261 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
262 datum key, val;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
263 PyObject *defvalue = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
264 char *tmp_ptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
265 int 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
266
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
267 if (!PyArg_ParseTuple(args, "s#|O:get",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
268 &tmp_ptr, &tmp_size, &defvalue))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
269 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
270 key.dptr = tmp_ptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
271 key.dsize = tmp_size;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
272 check_dbmobject_open(dp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
273 val = dbm_fetch(dp->di_dbm, key);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
274 if (val.dptr != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
275 return PyString_FromStringAndSize(val.dptr, val.dsize);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
276 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
277 Py_INCREF(defvalue);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
278 return defvalue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
279 }
14608
142a90eea8f4 Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents: 14577
diff changeset
280 }
142a90eea8f4 Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents: 14577
diff changeset
281
142a90eea8f4 Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents: 14577
diff changeset
282 static PyObject *
142a90eea8f4 Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents: 14577
diff changeset
283 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
284 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
285 datum key, val;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
286 PyObject *defvalue = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
287 char *tmp_ptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
288 int 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
289
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
290 if (!PyArg_ParseTuple(args, "s#|S:setdefault",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
291 &tmp_ptr, &tmp_size, &defvalue))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
292 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
293 key.dptr = tmp_ptr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
294 key.dsize = tmp_size;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
295 check_dbmobject_open(dp);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
296 val = dbm_fetch(dp->di_dbm, key);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
297 if (val.dptr != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
298 return PyString_FromStringAndSize(val.dptr, val.dsize);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
299 if (defvalue == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
300 defvalue = PyString_FromStringAndSize(NULL, 0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
301 if (defvalue == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
302 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
303 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
304 else
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
305 Py_INCREF(defvalue);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
306 val.dptr = PyString_AS_STRING(defvalue);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
307 val.dsize = PyString_GET_SIZE(defvalue);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
308 if (dbm_store(dp->di_dbm, key, val, DBM_INSERT) < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
309 dbm_clearerr(dp->di_dbm);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
310 PyErr_SetString(DbmError, "cannot add item to database");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
311 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
312 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
313 return defvalue;
14608
142a90eea8f4 Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents: 14577
diff changeset
314 }
142a90eea8f4 Add a constant "library" to the module which names the library used,
Fred Drake <fdrake@acm.org>
parents: 14577
diff changeset
315
4648
6dd851445c7d renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4600
diff changeset
316 static PyMethodDef dbm_methods[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
317 {"close", (PyCFunction)dbm__close, METH_NOARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
318 "close()\nClose the database."},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
319 {"keys", (PyCFunction)dbm_keys, METH_NOARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
320 "keys() -> list\nReturn a list of all keys in the database."},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
321 {"has_key", (PyCFunction)dbm_has_key, METH_VARARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
322 "has_key(key} -> boolean\nReturn true iff key is in the database."},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
323 {"get", (PyCFunction)dbm_get, METH_VARARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
324 "get(key[, default]) -> value\n"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
325 "Return the value for key if present, otherwise default."},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
326 {"setdefault", (PyCFunction)dbm_setdefault, METH_VARARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
327 "setdefault(key[, default]) -> value\n"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
328 "Return the value for key if present, otherwise default. If key\n"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
329 "is not in the database, it is inserted with default as the value."},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
330 {NULL, NULL} /* sentinel */
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 };
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
332
4648
6dd851445c7d renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4600
diff changeset
333 static PyObject *
13515
cd7abb4feb1b ANSI-fication, not really tested, but should (hopefully) compile
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
334 dbm_getattr(dbmobject *dp, char *name)
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
336 return Py_FindMethod(dbm_methods, (PyObject *)dp, name);
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 }
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
338
4648
6dd851445c7d renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4600
diff changeset
339 static PyTypeObject Dbmtype = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
340 PyVarObject_HEAD_INIT(NULL, 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
341 "dbm.dbm",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
342 sizeof(dbmobject),
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
343 0,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
344 (destructor)dbm_dealloc, /*tp_dealloc*/
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
345 0, /*tp_print*/
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
346 (getattrfunc)dbm_getattr, /*tp_getattr*/
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
347 0, /*tp_setattr*/
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
348 0, /*tp_compare*/
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
349 0, /*tp_repr*/
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
350 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
351 &dbm_as_sequence, /*tp_as_sequence*/
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
352 &dbm_as_mapping, /*tp_as_mapping*/
45523
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
353 0, /*tp_hash*/
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
354 0, /*tp_call*/
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
355 0, /*tp_str*/
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
356 0, /*tp_getattro*/
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
357 0, /*tp_setattro*/
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
358 0, /*tp_as_buffer*/
4f639af58a19 Issue 2168. gdbm and dbm needs to be iterable; this fixes a
Facundo Batista <facundobatista@gmail.com>
parents: 44350
diff changeset
359 Py_TPFLAGS_DEFAULT, /*tp_xxx4*/
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 };
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
361
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 /* ----------------------------------------------------------------- */
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
363
4648
6dd851445c7d renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4600
diff changeset
364 static PyObject *
13515
cd7abb4feb1b ANSI-fication, not really tested, but should (hopefully) compile
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
365 dbmopen(PyObject *self, PyObject *args)
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
367 char *name;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
368 char *flags = "r";
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
369 int iflags;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
370 int mode = 0666;
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
371
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
372 if ( !PyArg_ParseTuple(args, "s|si:open", &name, &flags, &mode) )
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
373 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
374 if ( strcmp(flags, "r") == 0 )
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
375 iflags = O_RDONLY;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
376 else if ( strcmp(flags, "w") == 0 )
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
377 iflags = O_RDWR;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
378 else if ( strcmp(flags, "rw") == 0 ) /* B/W compat */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
379 iflags = O_RDWR|O_CREAT;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
380 else if ( strcmp(flags, "c") == 0 )
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
381 iflags = O_RDWR|O_CREAT;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
382 else if ( strcmp(flags, "n") == 0 )
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
383 iflags = O_RDWR|O_CREAT|O_TRUNC;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
384 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
385 PyErr_SetString(DbmError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
386 "arg 2 to open should be 'r', 'w', 'c', or 'n'");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
387 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
388 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
389 return newdbmobject(name, iflags, mode);
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 }
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
391
4648
6dd851445c7d renamed in a grand fashion.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4600
diff changeset
392 static PyMethodDef dbmmodule_methods[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
393 { "open", (PyCFunction)dbmopen, METH_VARARGS,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
394 "open(path[, flag[, mode]]) -> mapping\n"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
395 "Return a database object."},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
396 { 0, 0 },
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 };
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
398
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24280
diff changeset
399 PyMODINIT_FUNC
13690
c09c0171474f ANSIfy some more forward declarations.
Thomas Wouters <thomas@python.org>
parents: 13515
diff changeset
400 initdbm(void) {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
401 PyObject *m, *d, *s;
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
402
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
403 Dbmtype.ob_type = &PyType_Type;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
404 m = Py_InitModule("dbm", dbmmodule_methods);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
405 if (m == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
406 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
407 d = PyModule_GetDict(m);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
408 if (DbmError == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
409 DbmError = PyErr_NewException("dbm.error", NULL, NULL);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
410 s = PyString_FromString(which_dbm);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
411 if (s != NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
412 PyDict_SetItemString(d, "library", s);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
413 Py_DECREF(s);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
414 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
415 if (DbmError != NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50048
diff changeset
416 PyDict_SetItemString(d, "error", DbmError);
906
63798cde582c Added qgetfd() to cstubs for GL.
Guido van Rossum <guido@python.org>
parents:
diff changeset
417 }