[Python-checkins] r61072 - python/trunk/Modules/dbmmodule.c python/trunk/Modules/gdbmmodule.c

skip at pobox.com skip at pobox.com
Tue Feb 26 13:57:43 CET 2008


    facundo> Issue 2168. gdbm and dbm needs to be iterable; this fixes a
    facundo> failure in the shelve module.  Thanks Thomas Herve.

    ...
 
    facundo> +static int
    facundo> +dbm_contains(register dbmobject *dp, PyObject *v)
    facundo> +{
    facundo> +    datum key, val;
    facundo> +
    facundo> +    if (PyString_AsStringAndSize(v, &key.dptr, &key.dsize)) {
    facundo> +        return -1;
    facundo> +    }
    facundo> +
    facundo> +    /* Expand check_dbmobject_open to return -1 */
    facundo> +    if (dp->di_dbm == NULL) {
    facundo> +        PyErr_SetString(DbmError, "DBM object has already been closed");
    facundo> +        return -1;
    facundo> +    }
    facundo> +  val = dbm_fetch(dp->di_dbm, key);
    facundo> +  return val.dptr != NULL;
    facundo> +}

    ...

I realize it's not a very long function, but couldn't (shouldn't?) this be
written in terms of dbm_has_key (or vice versa) to avoid code duplication
(physical or logical)?

Skip


More information about the Python-checkins mailing list