mirror of
https://github.com/python/cpython.git
synced 2025-12-18 06:41:40 +00:00
Add support for the iterator protocol to weakref proxy objects.
Part of fixing SF bug #591704.
This commit is contained in:
parent
ca3ac7f639
commit
f16c3dc81b
1 changed files with 64 additions and 38 deletions
|
|
@ -383,6 +383,24 @@ proxy_setitem(PyWeakReference *proxy, PyObject *key, PyObject *value)
|
||||||
return PyObject_SetItem(PyWeakref_GET_OBJECT(proxy), key, value);
|
return PyObject_SetItem(PyWeakref_GET_OBJECT(proxy), key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* iterator slots */
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
proxy_iter(PyWeakReference *proxy)
|
||||||
|
{
|
||||||
|
if (!proxy_checkref(proxy))
|
||||||
|
return NULL;
|
||||||
|
return PyObject_GetIter(PyWeakref_GET_OBJECT(proxy));
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
proxy_iternext(PyWeakReference *proxy)
|
||||||
|
{
|
||||||
|
if (!proxy_checkref(proxy))
|
||||||
|
return NULL;
|
||||||
|
return PyIter_Next(PyWeakref_GET_OBJECT(proxy));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyNumberMethods proxy_as_number = {
|
static PyNumberMethods proxy_as_number = {
|
||||||
(binaryfunc)proxy_add, /*nb_add*/
|
(binaryfunc)proxy_add, /*nb_add*/
|
||||||
|
|
@ -467,6 +485,10 @@ _PyWeakref_ProxyType = {
|
||||||
0, /* tp_doc */
|
0, /* tp_doc */
|
||||||
(traverseproc)gc_traverse, /* tp_traverse */
|
(traverseproc)gc_traverse, /* tp_traverse */
|
||||||
(inquiry)gc_clear, /* tp_clear */
|
(inquiry)gc_clear, /* tp_clear */
|
||||||
|
0, /* tp_richcompare */
|
||||||
|
0, /* tp_weaklistoffset */
|
||||||
|
(getiterfunc)proxy_iter, /* tp_iter */
|
||||||
|
(iternextfunc)proxy_iternext, /* tp_iternext */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -498,6 +520,10 @@ _PyWeakref_CallableProxyType = {
|
||||||
0, /* tp_doc */
|
0, /* tp_doc */
|
||||||
(traverseproc)gc_traverse, /* tp_traverse */
|
(traverseproc)gc_traverse, /* tp_traverse */
|
||||||
(inquiry)gc_clear, /* tp_clear */
|
(inquiry)gc_clear, /* tp_clear */
|
||||||
|
0, /* tp_richcompare */
|
||||||
|
0, /* tp_weaklistoffset */
|
||||||
|
(getiterfunc)proxy_iter, /* tp_iter */
|
||||||
|
(iternextfunc)proxy_iternext, /* tp_iternext */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue