summaryrefslogtreecommitdiffstats
path: root/Modules/gdbmmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-07-07 22:37:11 (GMT)
committerGuido van Rossum <guido@python.org>1995-07-07 22:37:11 (GMT)
commit807b7bec0646eec137e23dc8cd08c2cf679b9d01 (patch)
treea9b8fe1702fb3cd4f8b7b082c4d18e698ea72f2f /Modules/gdbmmodule.c
parent55ea8a7b5bc39370103e7ceb51595765054cbadf (diff)
downloadcpython-807b7bec0646eec137e23dc8cd08c2cf679b9d01.zip
cpython-807b7bec0646eec137e23dc8cd08c2cf679b9d01.tar.gz
cpython-807b7bec0646eec137e23dc8cd08c2cf679b9d01.tar.bz2
normalized flag arg and made flag, mode default args; minor cosmetics
Diffstat (limited to 'Modules/gdbmmodule.c')
-rw-r--r--Modules/gdbmmodule.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/Modules/gdbmmodule.c b/Modules/gdbmmodule.c
index 632846f..021531c 100644
--- a/Modules/gdbmmodule.c
+++ b/Modules/gdbmmodule.c
@@ -68,7 +68,7 @@ newdbmobject(file, flags, mode)
else
err_setstr(DbmError, (char *) gdbm_strerror(gdbm_errno));
DECREF(dp);
- return 0;
+ return NULL;
}
return (object *)dp;
}
@@ -119,7 +119,7 @@ dbm_subscript(dp, key)
drec = gdbm_fetch(dp->di_dbm, krec);
if ( drec.dptr == 0 ) {
err_setstr(KeyError, GETSTRINGVALUE((stringobject *)key));
- return 0;
+ return NULL;
}
v = newsizedstringobject(drec.dptr, drec.dsize);
free(drec.dptr);
@@ -168,6 +168,21 @@ static mapping_methods dbm_as_mapping = {
};
static object *
+dbm_close(dp, args)
+ register dbmobject *dp;
+ object *args;
+{
+ if ( !getnoarg(args) )
+ return NULL;
+ if ( dp->di_dbm )
+ gdbm_close(dp->di_dbm);
+ dp->di_dbm = NULL;
+ DEL(dp);
+ INCREF(None);
+ return None;
+}
+
+static object *
dbm_keys(dp, args)
register dbmobject *dp;
object *args;
@@ -271,6 +286,7 @@ dbm_reorganize(dp, args)
}
static struct methodlist dbm_methods[] = {
+ {"close", (method)dbm_close},
{"keys", (method)dbm_keys},
{"has_key", (method)dbm_has_key},
{"firstkey", (method)dbm_firstkey},
@@ -290,7 +306,7 @@ dbm_getattr(dp, name)
static typeobject Dbmtype = {
OB_HEAD_INIT(&Typetype)
0,
- "Gdbm_dictionary",
+ "gdbm",
sizeof(dbmobject),
0,
(destructor)dbm_dealloc, /*tp_dealloc*/
@@ -311,12 +327,14 @@ dbmopen(self, args)
object *self;
object *args;
{
- char *name, *flags;
- int iflags, mode;
+ char *name;
+ char *flags = "r";
+ int iflags;
+ int mode = 0666;
/* XXXX add other flags */
- if ( !getargs(args, "(ssi)", &name, &flags, &mode) )
- return 0;
+ if ( !newgetargs(args, "s|si", &name, &flags, &mode) )
+ return NULL;
if ( strcmp(flags, "r") == 0 )
iflags = GDBM_READER;
else if ( strcmp(flags, "w") == 0 )
@@ -328,13 +346,13 @@ dbmopen(self, args)
else {
err_setstr(DbmError,
"Flags should be one of 'r', 'w', 'c' or 'n'");
- return 0;
+ return NULL;
}
return newdbmobject(name, iflags, mode);
}
static struct methodlist dbmmodule_methods[] = {
- { "open", (method)dbmopen },
+ { "open", (method)dbmopen, 1 },
{ 0, 0 },
};