summaryrefslogtreecommitdiffstats
path: root/Modules/gdbmmodule.c
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-02-26 08:18:11 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-02-26 08:18:11 (GMT)
commitaa0ef52ea1b48773799812d388f0efd5d29b1819 (patch)
treee57c194fdc20d1e071b96b6935a277b078706d77 /Modules/gdbmmodule.c
parent75992edfaebbe08966746c7179b5c8ff8da8caeb (diff)
downloadcpython-aa0ef52ea1b48773799812d388f0efd5d29b1819.zip
cpython-aa0ef52ea1b48773799812d388f0efd5d29b1819.tar.gz
cpython-aa0ef52ea1b48773799812d388f0efd5d29b1819.tar.bz2
The contains function raised a gcc warning. The new code is copied straight from py3k.
Diffstat (limited to 'Modules/gdbmmodule.c')
-rw-r--r--Modules/gdbmmodule.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/Modules/gdbmmodule.c b/Modules/gdbmmodule.c
index 8d3e048..04b3332 100644
--- a/Modules/gdbmmodule.c
+++ b/Modules/gdbmmodule.c
@@ -179,16 +179,23 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w)
}
static int
-dbm_contains(register dbmobject *dp, PyObject *v)
+dbm_contains(register dbmobject *dp, PyObject *arg)
{
datum key;
- if (PyString_AsStringAndSize(v, &key.dptr, &key.dsize)) {
+ if ((dp)->di_dbm == NULL) {
+ PyErr_SetString(DbmError,
+ "GDBM object has already been closed");
return -1;
}
-
- check_dbmobject_open(dp);
-
+ if (!PyString_Check(arg)) {
+ PyErr_Format(PyExc_TypeError,
+ "gdbm key must be string, not %.100s",
+ arg->ob_type->tp_name);
+ return -1;
+ }
+ key.dptr = PyString_AS_STRING(arg);
+ key.dsize = PyString_GET_SIZE(arg);
return gdbm_exists(dp->di_dbm, key);
}