diff src/if_py_both.h @ 4698:2db005052371 v7.3.1096

updated for version 7.3.1096 Problem: Python: popitem() was not defined in a standard way. Solution: Remove the argument from popitem(). (ZyX)
author Bram Moolenaar <bram@vim.org>
date Sun, 02 Jun 2013 17:41:54 +0200
parents 9e7ef781d494
children 26f2dbea7443
line wrap: on
line diff
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -1061,17 +1061,6 @@ DictionaryLength(DictionaryObject *self)
 	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, Py
 }
 
     static PyObject *
-DictionaryPopItem(DictionaryObject *self, PyObject *args)
-{
-    PyObject	*keyObject;
-
-    if (!PyArg_ParseTuple(args, "O", &keyObject))
+DictionaryPopItem(DictionaryObject *self)
+{
+    hashitem_T	*hi;
+    PyObject	*r;
+    PyObject	*valObject;
+    dictitem_T	*di;
+
+    if (self->dict->dv_hashtab.ht_used == 0)
+    {
+	PyErr_SetNone(PyExc_KeyError);
 	return NULL;
-
-    return _DictionaryItem(self, keyObject,
-			    DICT_FLAG_POP|DICT_FLAG_RETURN_PAIR);
+    }
+
+    hi = self->dict->dv_hashtab.ht_array;
+    while (HASHITEM_EMPTY(hi))
+	++hi;
+
+    di = dict_lookup(hi);
+
+    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 DictionaryMeth
     {"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}