ยปCore Development>Code coverage>Modules/_gdbmmodule.c

Python code coverage for Modules/_gdbmmodule.c

#countcontent
1n/a
2n/a/* DBM module using dictionary interface */
3n/a/* Author: Anthony Baxter, after dbmmodule.c */
4n/a/* Doc strings: Mitch Chapman */
5n/a
6n/a
7n/a#include "Python.h"
8n/a
9n/a#include <sys/types.h>
10n/a#include <sys/stat.h>
11n/a#include <fcntl.h>
12n/a#include "gdbm.h"
13n/a
14n/a#if defined(WIN32) && !defined(__CYGWIN__)
15n/a#include "gdbmerrno.h"
16n/aextern const char * gdbm_strerror(gdbm_error);
17n/a#endif
18n/a
19n/a/*[clinic input]
20n/amodule _gdbm
21n/aclass _gdbm.gdbm "dbmobject *" "&Dbmtype"
22n/a[clinic start generated code]*/
23n/a/*[clinic end generated code: output=da39a3ee5e6b4b0d input=113927c6170729b2]*/
24n/a
25n/aPyDoc_STRVAR(gdbmmodule__doc__,
26n/a"This module provides an interface to the GNU DBM (GDBM) library.\n\
27n/a\n\
28n/aThis module is quite similar to the dbm module, but uses GDBM instead to\n\
29n/aprovide some additional functionality. Please note that the file formats\n\
30n/acreated by GDBM and dbm are incompatible.\n\
31n/a\n\
32n/aGDBM objects behave like mappings (dictionaries), except that keys and\n\
33n/avalues are always immutable bytes-like objects or strings. Printing\n\
34n/aa GDBM object doesn't print the keys and values, and the items() and\n\
35n/avalues() methods are not supported.");
36n/a
37n/atypedef struct {
38n/a PyObject_HEAD
39n/a int di_size; /* -1 means recompute */
40n/a GDBM_FILE di_dbm;
41n/a} dbmobject;
42n/a
43n/astatic PyTypeObject Dbmtype;
44n/a
45n/a#include "clinic/_gdbmmodule.c.h"
46n/a
47n/a#define is_dbmobject(v) (Py_TYPE(v) == &Dbmtype)
48n/a#define check_dbmobject_open(v) if ((v)->di_dbm == NULL) \
49n/a { PyErr_SetString(DbmError, "GDBM object has already been closed"); \
50n/a return NULL; }
51n/a
52n/a
53n/a
54n/astatic PyObject *DbmError;
55n/a
56n/aPyDoc_STRVAR(gdbm_object__doc__,
57n/a"This object represents a GDBM database.\n\
58n/aGDBM objects behave like mappings (dictionaries), except that keys and\n\
59n/avalues are always immutable bytes-like objects or strings. Printing\n\
60n/aa GDBM object doesn't print the keys and values, and the items() and\n\
61n/avalues() methods are not supported.\n\
62n/a\n\
63n/aGDBM objects also support additional operations such as firstkey,\n\
64n/anextkey, reorganize, and sync.");
65n/a
66n/astatic PyObject *
67n/anewdbmobject(const char *file, int flags, int mode)
68n/a{
69n/a dbmobject *dp;
70n/a
71n/a dp = PyObject_New(dbmobject, &Dbmtype);
72n/a if (dp == NULL)
73n/a return NULL;
74n/a dp->di_size = -1;
75n/a errno = 0;
76n/a if ((dp->di_dbm = gdbm_open((char *)file, 0, flags, mode, NULL)) == 0) {
77n/a if (errno != 0)
78n/a PyErr_SetFromErrno(DbmError);
79n/a else
80n/a PyErr_SetString(DbmError, gdbm_strerror(gdbm_errno));
81n/a Py_DECREF(dp);
82n/a return NULL;
83n/a }
84n/a return (PyObject *)dp;
85n/a}
86n/a
87n/a/* Methods */
88n/a
89n/astatic void
90n/adbm_dealloc(dbmobject *dp)
91n/a{
92n/a if (dp->di_dbm)
93n/a gdbm_close(dp->di_dbm);
94n/a PyObject_Del(dp);
95n/a}
96n/a
97n/astatic Py_ssize_t
98n/adbm_length(dbmobject *dp)
99n/a{
100n/a if (dp->di_dbm == NULL) {
101n/a PyErr_SetString(DbmError, "GDBM object has already been closed");
102n/a return -1;
103n/a }
104n/a if (dp->di_size < 0) {
105n/a datum key,okey;
106n/a int size;
107n/a okey.dsize=0;
108n/a okey.dptr=NULL;
109n/a
110n/a size = 0;
111n/a for (key=gdbm_firstkey(dp->di_dbm); key.dptr;
112n/a key = gdbm_nextkey(dp->di_dbm,okey)) {
113n/a size++;
114n/a if(okey.dsize) free(okey.dptr);
115n/a okey=key;
116n/a }
117n/a dp->di_size = size;
118n/a }
119n/a return dp->di_size;
120n/a}
121n/a
122n/astatic PyObject *
123n/adbm_subscript(dbmobject *dp, PyObject *key)
124n/a{
125n/a PyObject *v;
126n/a datum drec, krec;
127n/a
128n/a if (!PyArg_Parse(key, "s#", &krec.dptr, &krec.dsize) )
129n/a return NULL;
130n/a
131n/a if (dp->di_dbm == NULL) {
132n/a PyErr_SetString(DbmError,
133n/a "GDBM object has already been closed");
134n/a return NULL;
135n/a }
136n/a drec = gdbm_fetch(dp->di_dbm, krec);
137n/a if (drec.dptr == 0) {
138n/a PyErr_SetObject(PyExc_KeyError, key);
139n/a return NULL;
140n/a }
141n/a v = PyBytes_FromStringAndSize(drec.dptr, drec.dsize);
142n/a free(drec.dptr);
143n/a return v;
144n/a}
145n/a
146n/a/*[clinic input]
147n/a_gdbm.gdbm.get
148n/a
149n/a key: object
150n/a default: object = None
151n/a /
152n/a
153n/aGet the value for key, or default if not present.
154n/a[clinic start generated code]*/
155n/a
156n/astatic PyObject *
157n/a_gdbm_gdbm_get_impl(dbmobject *self, PyObject *key, PyObject *default_value)
158n/a/*[clinic end generated code: output=19b7c585ad4f554a input=a9c20423f34c17b6]*/
159n/a{
160n/a PyObject *res;
161n/a
162n/a res = dbm_subscript(self, key);
163n/a if (res == NULL && PyErr_ExceptionMatches(PyExc_KeyError)) {
164n/a PyErr_Clear();
165n/a Py_INCREF(default_value);
166n/a return default_value;
167n/a }
168n/a return res;
169n/a}
170n/a
171n/astatic int
172n/adbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w)
173n/a{
174n/a datum krec, drec;
175n/a
176n/a if (!PyArg_Parse(v, "s#", &krec.dptr, &krec.dsize) ) {
177n/a PyErr_SetString(PyExc_TypeError,
178n/a "gdbm mappings have bytes or string indices only");
179n/a return -1;
180n/a }
181n/a if (dp->di_dbm == NULL) {
182n/a PyErr_SetString(DbmError,
183n/a "GDBM object has already been closed");
184n/a return -1;
185n/a }
186n/a dp->di_size = -1;
187n/a if (w == NULL) {
188n/a if (gdbm_delete(dp->di_dbm, krec) < 0) {
189n/a PyErr_SetObject(PyExc_KeyError, v);
190n/a return -1;
191n/a }
192n/a }
193n/a else {
194n/a if (!PyArg_Parse(w, "s#", &drec.dptr, &drec.dsize)) {
195n/a PyErr_SetString(PyExc_TypeError,
196n/a "gdbm mappings have byte or string elements only");
197n/a return -1;
198n/a }
199n/a errno = 0;
200n/a if (gdbm_store(dp->di_dbm, krec, drec, GDBM_REPLACE) < 0) {
201n/a if (errno != 0)
202n/a PyErr_SetFromErrno(DbmError);
203n/a else
204n/a PyErr_SetString(DbmError,
205n/a gdbm_strerror(gdbm_errno));
206n/a return -1;
207n/a }
208n/a }
209n/a return 0;
210n/a}
211n/a
212n/a/*[clinic input]
213n/a_gdbm.gdbm.setdefault
214n/a
215n/a key: object
216n/a default: object = None
217n/a /
218n/a
219n/aGet value for key, or set it to default and return default if not present.
220n/a[clinic start generated code]*/
221n/a
222n/astatic PyObject *
223n/a_gdbm_gdbm_setdefault_impl(dbmobject *self, PyObject *key,
224n/a PyObject *default_value)
225n/a/*[clinic end generated code: output=88760ee520329012 input=0db46b69e9680171]*/
226n/a{
227n/a PyObject *res;
228n/a
229n/a res = dbm_subscript(self, key);
230n/a if (res == NULL && PyErr_ExceptionMatches(PyExc_KeyError)) {
231n/a PyErr_Clear();
232n/a if (dbm_ass_sub(self, key, default_value) < 0)
233n/a return NULL;
234n/a return dbm_subscript(self, key);
235n/a }
236n/a return res;
237n/a}
238n/a
239n/astatic PyMappingMethods dbm_as_mapping = {
240n/a (lenfunc)dbm_length, /*mp_length*/
241n/a (binaryfunc)dbm_subscript, /*mp_subscript*/
242n/a (objobjargproc)dbm_ass_sub, /*mp_ass_subscript*/
243n/a};
244n/a
245n/a/*[clinic input]
246n/a_gdbm.gdbm.close
247n/a
248n/aClose the database.
249n/a[clinic start generated code]*/
250n/a
251n/astatic PyObject *
252n/a_gdbm_gdbm_close_impl(dbmobject *self)
253n/a/*[clinic end generated code: output=23512a594598b563 input=0a203447379b45fd]*/
254n/a{
255n/a if (self->di_dbm)
256n/a gdbm_close(self->di_dbm);
257n/a self->di_dbm = NULL;
258n/a Py_RETURN_NONE;
259n/a}
260n/a
261n/a/* XXX Should return a set or a set view */
262n/a/*[clinic input]
263n/a_gdbm.gdbm.keys
264n/a
265n/aGet a list of all keys in the database.
266n/a[clinic start generated code]*/
267n/a
268n/astatic PyObject *
269n/a_gdbm_gdbm_keys_impl(dbmobject *self)
270n/a/*[clinic end generated code: output=cb4b1776c3645dcc input=1832ee0a3132cfaf]*/
271n/a{
272n/a PyObject *v, *item;
273n/a datum key, nextkey;
274n/a int err;
275n/a
276n/a if (self == NULL || !is_dbmobject(self)) {
277n/a PyErr_BadInternalCall();
278n/a return NULL;
279n/a }
280n/a check_dbmobject_open(self);
281n/a
282n/a v = PyList_New(0);
283n/a if (v == NULL)
284n/a return NULL;
285n/a
286n/a key = gdbm_firstkey(self->di_dbm);
287n/a while (key.dptr) {
288n/a item = PyBytes_FromStringAndSize(key.dptr, key.dsize);
289n/a if (item == NULL) {
290n/a free(key.dptr);
291n/a Py_DECREF(v);
292n/a return NULL;
293n/a }
294n/a err = PyList_Append(v, item);
295n/a Py_DECREF(item);
296n/a if (err != 0) {
297n/a free(key.dptr);
298n/a Py_DECREF(v);
299n/a return NULL;
300n/a }
301n/a nextkey = gdbm_nextkey(self->di_dbm, key);
302n/a free(key.dptr);
303n/a key = nextkey;
304n/a }
305n/a return v;
306n/a}
307n/a
308n/astatic int
309n/adbm_contains(PyObject *self, PyObject *arg)
310n/a{
311n/a dbmobject *dp = (dbmobject *)self;
312n/a datum key;
313n/a Py_ssize_t size;
314n/a
315n/a if ((dp)->di_dbm == NULL) {
316n/a PyErr_SetString(DbmError,
317n/a "GDBM object has already been closed");
318n/a return -1;
319n/a }
320n/a if (PyUnicode_Check(arg)) {
321n/a key.dptr = (char *)PyUnicode_AsUTF8AndSize(arg, &size);
322n/a key.dsize = size;
323n/a if (key.dptr == NULL)
324n/a return -1;
325n/a }
326n/a else if (!PyBytes_Check(arg)) {
327n/a PyErr_Format(PyExc_TypeError,
328n/a "gdbm key must be bytes or string, not %.100s",
329n/a arg->ob_type->tp_name);
330n/a return -1;
331n/a }
332n/a else {
333n/a key.dptr = PyBytes_AS_STRING(arg);
334n/a key.dsize = PyBytes_GET_SIZE(arg);
335n/a }
336n/a return gdbm_exists(dp->di_dbm, key);
337n/a}
338n/a
339n/astatic PySequenceMethods dbm_as_sequence = {
340n/a 0, /* sq_length */
341n/a 0, /* sq_concat */
342n/a 0, /* sq_repeat */
343n/a 0, /* sq_item */
344n/a 0, /* sq_slice */
345n/a 0, /* sq_ass_item */
346n/a 0, /* sq_ass_slice */
347n/a dbm_contains, /* sq_contains */
348n/a 0, /* sq_inplace_concat */
349n/a 0, /* sq_inplace_repeat */
350n/a};
351n/a
352n/a/*[clinic input]
353n/a_gdbm.gdbm.firstkey
354n/a
355n/aReturn the starting key for the traversal.
356n/a
357n/aIt's possible to loop over every key in the database using this method
358n/aand the nextkey() method. The traversal is ordered by GDBM's internal
359n/ahash values, and won't be sorted by the key values.
360n/a[clinic start generated code]*/
361n/a
362n/astatic PyObject *
363n/a_gdbm_gdbm_firstkey_impl(dbmobject *self)
364n/a/*[clinic end generated code: output=9ff85628d84b65d2 input=0dbd6a335d69bba0]*/
365n/a{
366n/a PyObject *v;
367n/a datum key;
368n/a
369n/a check_dbmobject_open(self);
370n/a key = gdbm_firstkey(self->di_dbm);
371n/a if (key.dptr) {
372n/a v = PyBytes_FromStringAndSize(key.dptr, key.dsize);
373n/a free(key.dptr);
374n/a return v;
375n/a }
376n/a else {
377n/a Py_RETURN_NONE;
378n/a }
379n/a}
380n/a
381n/a/*[clinic input]
382n/a_gdbm.gdbm.nextkey
383n/a
384n/a key: str(accept={str, robuffer}, zeroes=True)
385n/a /
386n/a
387n/aReturns the key that follows key in the traversal.
388n/a
389n/aThe following code prints every key in the database db, without having
390n/ato create a list in memory that contains them all:
391n/a
392n/a k = db.firstkey()
393n/a while k != None:
394n/a print(k)
395n/a k = db.nextkey(k)
396n/a[clinic start generated code]*/
397n/a
398n/astatic PyObject *
399n/a_gdbm_gdbm_nextkey_impl(dbmobject *self, const char *key,
400n/a Py_ssize_clean_t key_length)
401n/a/*[clinic end generated code: output=192ab892de6eb2f6 input=1f1606943614e36f]*/
402n/a{
403n/a PyObject *v;
404n/a datum dbm_key, nextkey;
405n/a
406n/a dbm_key.dptr = (char *)key;
407n/a dbm_key.dsize = key_length;
408n/a check_dbmobject_open(self);
409n/a nextkey = gdbm_nextkey(self->di_dbm, dbm_key);
410n/a if (nextkey.dptr) {
411n/a v = PyBytes_FromStringAndSize(nextkey.dptr, nextkey.dsize);
412n/a free(nextkey.dptr);
413n/a return v;
414n/a }
415n/a else {
416n/a Py_RETURN_NONE;
417n/a }
418n/a}
419n/a
420n/a/*[clinic input]
421n/a_gdbm.gdbm.reorganize
422n/a
423n/aReorganize the database.
424n/a
425n/aIf you have carried out a lot of deletions and would like to shrink
426n/athe space used by the GDBM file, this routine will reorganize the
427n/adatabase. GDBM will not shorten the length of a database file except
428n/aby using this reorganization; otherwise, deleted file space will be
429n/akept and reused as new (key,value) pairs are added.
430n/a[clinic start generated code]*/
431n/a
432n/astatic PyObject *
433n/a_gdbm_gdbm_reorganize_impl(dbmobject *self)
434n/a/*[clinic end generated code: output=38d9624df92e961d input=f6bea85bcfd40dd2]*/
435n/a{
436n/a check_dbmobject_open(self);
437n/a errno = 0;
438n/a if (gdbm_reorganize(self->di_dbm) < 0) {
439n/a if (errno != 0)
440n/a PyErr_SetFromErrno(DbmError);
441n/a else
442n/a PyErr_SetString(DbmError, gdbm_strerror(gdbm_errno));
443n/a return NULL;
444n/a }
445n/a Py_RETURN_NONE;
446n/a}
447n/a
448n/a/*[clinic input]
449n/a_gdbm.gdbm.sync
450n/a
451n/aFlush the database to the disk file.
452n/a
453n/aWhen the database has been opened in fast mode, this method forces
454n/aany unwritten data to be written to the disk.
455n/a[clinic start generated code]*/
456n/a
457n/astatic PyObject *
458n/a_gdbm_gdbm_sync_impl(dbmobject *self)
459n/a/*[clinic end generated code: output=488b15f47028f125 input=2a47d2c9e153ab8a]*/
460n/a{
461n/a check_dbmobject_open(self);
462n/a gdbm_sync(self->di_dbm);
463n/a Py_RETURN_NONE;
464n/a}
465n/a
466n/astatic PyObject *
467n/adbm__enter__(PyObject *self, PyObject *args)
468n/a{
469n/a Py_INCREF(self);
470n/a return self;
471n/a}
472n/a
473n/astatic PyObject *
474n/adbm__exit__(PyObject *self, PyObject *args)
475n/a{
476n/a _Py_IDENTIFIER(close);
477n/a return _PyObject_CallMethodId(self, &PyId_close, NULL);
478n/a}
479n/a
480n/astatic PyMethodDef dbm_methods[] = {
481n/a _GDBM_GDBM_CLOSE_METHODDEF
482n/a _GDBM_GDBM_KEYS_METHODDEF
483n/a _GDBM_GDBM_FIRSTKEY_METHODDEF
484n/a _GDBM_GDBM_NEXTKEY_METHODDEF
485n/a _GDBM_GDBM_REORGANIZE_METHODDEF
486n/a _GDBM_GDBM_SYNC_METHODDEF
487n/a _GDBM_GDBM_GET_METHODDEF
488n/a _GDBM_GDBM_GET_METHODDEF
489n/a _GDBM_GDBM_SETDEFAULT_METHODDEF
490n/a {"__enter__", dbm__enter__, METH_NOARGS, NULL},
491n/a {"__exit__", dbm__exit__, METH_VARARGS, NULL},
492n/a {NULL, NULL} /* sentinel */
493n/a};
494n/a
495n/astatic PyTypeObject Dbmtype = {
496n/a PyVarObject_HEAD_INIT(0, 0)
497n/a "_gdbm.gdbm",
498n/a sizeof(dbmobject),
499n/a 0,
500n/a (destructor)dbm_dealloc, /*tp_dealloc*/
501n/a 0, /*tp_print*/
502n/a 0, /*tp_getattr*/
503n/a 0, /*tp_setattr*/
504n/a 0, /*tp_reserved*/
505n/a 0, /*tp_repr*/
506n/a 0, /*tp_as_number*/
507n/a &dbm_as_sequence, /*tp_as_sequence*/
508n/a &dbm_as_mapping, /*tp_as_mapping*/
509n/a 0, /*tp_hash*/
510n/a 0, /*tp_call*/
511n/a 0, /*tp_str*/
512n/a 0, /*tp_getattro*/
513n/a 0, /*tp_setattro*/
514n/a 0, /*tp_as_buffer*/
515n/a Py_TPFLAGS_DEFAULT, /*tp_xxx4*/
516n/a gdbm_object__doc__, /*tp_doc*/
517n/a 0, /*tp_traverse*/
518n/a 0, /*tp_clear*/
519n/a 0, /*tp_richcompare*/
520n/a 0, /*tp_weaklistoffset*/
521n/a 0, /*tp_iter*/
522n/a 0, /*tp_iternext*/
523n/a dbm_methods, /*tp_methods*/
524n/a};
525n/a
526n/a/* ----------------------------------------------------------------- */
527n/a
528n/a/*[clinic input]
529n/a_gdbm.open as dbmopen
530n/a filename as name: str
531n/a flags: str="r"
532n/a mode: int(py_default="0o666") = 0o666
533n/a /
534n/a
535n/aOpen a dbm database and return a dbm object.
536n/a
537n/aThe filename argument is the name of the database file.
538n/a
539n/aThe optional flags argument can be 'r' (to open an existing database
540n/afor reading only -- default), 'w' (to open an existing database for
541n/areading and writing), 'c' (which creates the database if it doesn't
542n/aexist), or 'n' (which always creates a new empty database).
543n/a
544n/aSome versions of gdbm support additional flags which must be
545n/aappended to one of the flags described above. The module constant
546n/a'open_flags' is a string of valid additional flags. The 'f' flag
547n/aopens the database in fast mode; altered data will not automatically
548n/abe written to the disk after every change. This results in faster
549n/awrites to the database, but may result in an inconsistent database
550n/aif the program crashes while the database is still open. Use the
551n/async() method to force any unwritten data to be written to the disk.
552n/aThe 's' flag causes all database operations to be synchronized to
553n/adisk. The 'u' flag disables locking of the database file.
554n/a
555n/aThe optional mode argument is the Unix mode of the file, used only
556n/awhen the database has to be created. It defaults to octal 0o666.
557n/a[clinic start generated code]*/
558n/a
559n/astatic PyObject *
560n/adbmopen_impl(PyObject *module, const char *name, const char *flags, int mode)
561n/a/*[clinic end generated code: output=31aa1bafdf5da688 input=55563cd60e51984a]*/
562n/a{
563n/a int iflags;
564n/a
565n/a switch (flags[0]) {
566n/a case 'r':
567n/a iflags = GDBM_READER;
568n/a break;
569n/a case 'w':
570n/a iflags = GDBM_WRITER;
571n/a break;
572n/a case 'c':
573n/a iflags = GDBM_WRCREAT;
574n/a break;
575n/a case 'n':
576n/a iflags = GDBM_NEWDB;
577n/a break;
578n/a default:
579n/a PyErr_SetString(DbmError,
580n/a "First flag must be one of 'r', 'w', 'c' or 'n'");
581n/a return NULL;
582n/a }
583n/a for (flags++; *flags != '\0'; flags++) {
584n/a char buf[40];
585n/a switch (*flags) {
586n/a#ifdef GDBM_FAST
587n/a case 'f':
588n/a iflags |= GDBM_FAST;
589n/a break;
590n/a#endif
591n/a#ifdef GDBM_SYNC
592n/a case 's':
593n/a iflags |= GDBM_SYNC;
594n/a break;
595n/a#endif
596n/a#ifdef GDBM_NOLOCK
597n/a case 'u':
598n/a iflags |= GDBM_NOLOCK;
599n/a break;
600n/a#endif
601n/a default:
602n/a PyOS_snprintf(buf, sizeof(buf), "Flag '%c' is not supported.",
603n/a *flags);
604n/a PyErr_SetString(DbmError, buf);
605n/a return NULL;
606n/a }
607n/a }
608n/a
609n/a return newdbmobject(name, iflags, mode);
610n/a}
611n/a
612n/astatic const char dbmmodule_open_flags[] = "rwcn"
613n/a#ifdef GDBM_FAST
614n/a "f"
615n/a#endif
616n/a#ifdef GDBM_SYNC
617n/a "s"
618n/a#endif
619n/a#ifdef GDBM_NOLOCK
620n/a "u"
621n/a#endif
622n/a ;
623n/a
624n/astatic PyMethodDef dbmmodule_methods[] = {
625n/a DBMOPEN_METHODDEF
626n/a { 0, 0 },
627n/a};
628n/a
629n/a
630n/astatic struct PyModuleDef _gdbmmodule = {
631n/a PyModuleDef_HEAD_INIT,
632n/a "_gdbm",
633n/a gdbmmodule__doc__,
634n/a -1,
635n/a dbmmodule_methods,
636n/a NULL,
637n/a NULL,
638n/a NULL,
639n/a NULL
640n/a};
641n/a
642n/aPyMODINIT_FUNC
643n/aPyInit__gdbm(void) {
644n/a PyObject *m, *d, *s;
645n/a
646n/a if (PyType_Ready(&Dbmtype) < 0)
647n/a return NULL;
648n/a m = PyModule_Create(&_gdbmmodule);
649n/a if (m == NULL)
650n/a return NULL;
651n/a d = PyModule_GetDict(m);
652n/a DbmError = PyErr_NewException("_gdbm.error", PyExc_IOError, NULL);
653n/a if (DbmError != NULL) {
654n/a PyDict_SetItemString(d, "error", DbmError);
655n/a s = PyUnicode_FromString(dbmmodule_open_flags);
656n/a PyDict_SetItemString(d, "open_flags", s);
657n/a Py_DECREF(s);
658n/a }
659n/a return m;
660n/a}