summaryrefslogtreecommitdiff
path: root/Modules/_collectionsmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2013-10-01 01:00:59 -0700
committerRaymond Hettinger <python@rcn.com>2013-10-01 01:00:59 -0700
commitc13516b0a0fd3142b29e1f354c2080cd52948213 (patch)
treec457578d34b0dc1edf54535d83244b1636b3b87a /Modules/_collectionsmodule.c
parent65870835a006ad613b111fe4579bd7e3354585b7 (diff)
parent2ff2190b6293966f76633d810dfbe2d232ff5973 (diff)
downloadcpython-git-c13516b0a0fd3142b29e1f354c2080cd52948213.tar.gz
merge
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r--Modules/_collectionsmodule.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index e5dfdb4242..113abc965f 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1763,10 +1763,16 @@ Count elements in the iterable, updating the mappping");
static PyObject *
_count_elements(PyObject *self, PyObject *args)
{
+ _Py_IDENTIFIER(__getitem__);
+ _Py_IDENTIFIER(__setitem__);
PyObject *it, *iterable, *mapping, *oldval;
PyObject *newval = NULL;
PyObject *key = NULL;
PyObject *one = NULL;
+ PyObject *mapping_getitem;
+ PyObject *mapping_setitem;
+ PyObject *dict_getitem;
+ PyObject *dict_setitem;
if (!PyArg_UnpackTuple(args, "_count_elements", 2, 2, &mapping, &iterable))
return NULL;
@@ -1781,7 +1787,15 @@ _count_elements(PyObject *self, PyObject *args)
return NULL;
}
- if (PyDict_CheckExact(mapping)) {
+ mapping_getitem = _PyType_LookupId(Py_TYPE(mapping), &PyId___getitem__);
+ dict_getitem = _PyType_LookupId(&PyDict_Type, &PyId___getitem__);
+ mapping_setitem = _PyType_LookupId(Py_TYPE(mapping), &PyId___setitem__);
+ dict_setitem = _PyType_LookupId(&PyDict_Type, &PyId___setitem__);
+
+ if (mapping_getitem != NULL &&
+ mapping_getitem == dict_getitem &&
+ mapping_setitem != NULL &&
+ mapping_setitem == dict_setitem) {
while (1) {
key = PyIter_Next(it);
if (key == NULL)