From aa0ef52ea1b48773799812d388f0efd5d29b1819 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Tue, 26 Feb 2008 08:18:11 +0000 Subject: [PATCH] The contains function raised a gcc warning. The new code is copied straight from py3k. --- Modules/gdbmmodule.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Modules/gdbmmodule.c b/Modules/gdbmmodule.c index 8d3e048dff5..04b3332bb89 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); }