summaryrefslogtreecommitdiff
path: root/Modules/_dbmmodule.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2011-09-28 07:41:54 +0200
committerMartin v. Löwis <martin@v.loewis.de>2011-09-28 07:41:54 +0200
commitd1d013c01c268d869597b35cbcd8b5d7c5baf2ae (patch)
treeac42dafc2067cce1d896e613738a7bd263601d36 /Modules/_dbmmodule.c
parent5292805e03b80f41e608ea20ce6bc3f64d6566dd (diff)
downloadcpython-d1d013c01c268d869597b35cbcd8b5d7c5baf2ae.tar.gz
Implement PEP 393.
Diffstat (limited to 'Modules/_dbmmodule.c')
-rw-r--r--Modules/_dbmmodule.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c
index 69a7112e7d..327b8730c2 100644
--- a/Modules/_dbmmodule.c
+++ b/Modules/_dbmmodule.c
@@ -212,6 +212,7 @@ dbm_contains(PyObject *self, PyObject *arg)
{
dbmobject *dp = (dbmobject *)self;
datum key, val;
+ Py_ssize_t size;
if ((dp)->di_dbm == NULL) {
PyErr_SetString(DbmError,
@@ -219,8 +220,9 @@ dbm_contains(PyObject *self, PyObject *arg)
return -1;
}
if (PyUnicode_Check(arg)) {
- arg = _PyUnicode_AsDefaultEncodedString(arg);
- if (arg == NULL)
+ key.dptr = PyUnicode_AsUTF8AndSize(arg, &size);
+ key.dsize = size;
+ if (key.dptr == NULL)
return -1;
}
if (!PyBytes_Check(arg)) {
@@ -229,8 +231,10 @@ dbm_contains(PyObject *self, PyObject *arg)
arg->ob_type->tp_name);
return -1;
}
- key.dptr = PyBytes_AS_STRING(arg);
- key.dsize = PyBytes_GET_SIZE(arg);
+ else {
+ key.dptr = PyBytes_AS_STRING(arg);
+ key.dsize = PyBytes_GET_SIZE(arg);
+ }
val = dbm_fetch(dp->di_dbm, key);
return val.dptr != NULL;
}