summaryrefslogtreecommitdiff
path: root/src/if_py_both.h
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2013-06-02 17:41:54 +0200
committerBram Moolenaar <Bram@vim.org>2013-06-02 17:41:54 +0200
commitde71b5658f780e1fac29b1ef8b58af3dd42e65ad (patch)
treecdcf529e0fca413b18415513673940763cbd9460 /src/if_py_both.h
parent525666f28201c313825065d49b98606c8cade457 (diff)
downloadvim-de71b5658f780e1fac29b1ef8b58af3dd42e65ad.zip
updated for version 7.3.1096
Problem: Python: popitem() was not defined in a standard way. Solution: Remove the argument from popitem(). (ZyX)
Diffstat (limited to 'src/if_py_both.h')
-rw-r--r--src/if_py_both.h46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/if_py_both.h b/src/if_py_both.h
index 4c80d2e30..eedbf1ca2 100644
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -1061,17 +1061,6 @@ _DictionaryItem(DictionaryObject *self, PyObject *args, int flags)
dictitem_free(di);
}
- if (flags & DICT_FLAG_RETURN_PAIR)
- {
- PyObject *tmp = r;
-
- if (!(r = Py_BuildValue("(" Py_bytes_fmt "O)", hi->hi_key, tmp)))
- {
- Py_DECREF(tmp);
- return NULL;
- }
- }
-
return r;
}
@@ -1457,15 +1446,38 @@ DictionaryPop(DictionaryObject *self, PyObject *args)
}
static PyObject *
-DictionaryPopItem(DictionaryObject *self, PyObject *args)
+DictionaryPopItem(DictionaryObject *self)
{
- PyObject *keyObject;
+ hashitem_T *hi;
+ PyObject *r;
+ PyObject *valObject;
+ dictitem_T *di;
- if (!PyArg_ParseTuple(args, "O", &keyObject))
+ if (self->dict->dv_hashtab.ht_used == 0)
+ {
+ PyErr_SetNone(PyExc_KeyError);
return NULL;
+ }
+
+ hi = self->dict->dv_hashtab.ht_array;
+ while (HASHITEM_EMPTY(hi))
+ ++hi;
+
+ di = dict_lookup(hi);
- return _DictionaryItem(self, keyObject,
- DICT_FLAG_POP|DICT_FLAG_RETURN_PAIR);
+ if (!(valObject = ConvertToPyObject(&di->di_tv)))
+ return NULL;
+
+ if (!(r = Py_BuildValue("(" Py_bytes_fmt "O)", hi->hi_key, valObject)))
+ {
+ Py_DECREF(valObject);
+ return NULL;
+ }
+
+ hash_remove(&self->dict->dv_hashtab, hi);
+ dictitem_free(di);
+
+ return r;
}
static PyObject *
@@ -1505,7 +1517,7 @@ static struct PyMethodDef DictionaryMethods[] = {
{"update", (PyCFunction)DictionaryUpdate, METH_VARARGS|METH_KEYWORDS, ""},
{"get", (PyCFunction)DictionaryGet, METH_VARARGS, ""},
{"pop", (PyCFunction)DictionaryPop, METH_VARARGS, ""},
- {"popitem", (PyCFunction)DictionaryPopItem, METH_VARARGS, ""},
+ {"popitem", (PyCFunction)DictionaryPopItem, METH_NOARGS, ""},
{"has_key", (PyCFunction)DictionaryHasKey, METH_VARARGS, ""},
{"__dir__", (PyCFunction)DictionaryDir, METH_NOARGS, ""},
{ NULL, NULL, 0, NULL}