New issue 2023: cpyext: PyDict_Keys/Values/Items() does not call type method 
but instance method
https://bitbucket.org/pypy/pypy/issue/2023/cpyext-pydict_keys-values-items-does-not

sbehnel:

This is a somewhat special test case in Cython. Here is the code:

```
#!cython

class DictPySubtype(dict):
    def keys(self):
        """
        >>> d = DictPySubtype(one=42, two=17, three=0)
        >>> for v in sorted(d.keys()):
        ...     print(v)
        three
        two
        """
        for key in dict.keys(self):
            if key != 'one':
                yield key
```

When executed in PyPy 2.5.1, I get an infinite recursion crash with C stack 
traces like this:

```
#1111 0x00007ffff5887c02 in PyPyIter_Next () from 
/home/stefan/ablage/software/Python/pypy-2.5.1-linux64/bin/libpypy-c.so
#1112 0x00007ffff000f211 in 
__pyx_gb_27builtin_subtype_methods_cy3_13DictPySubtype_8generator2 
(__pyx_generator=0x16653e0, __pyx_sent_value=0x7ffff6b6a0b0 <_PyPy_NoneStruct>) 
at builtin_subtype_methods_cy3.c:1471
#1113 0x00007ffff0015ec0 in __Pyx_Generator_SendEx (self=0x16653e0, 
value=0x7ffff6b6a0b0 <_PyPy_NoneStruct>) at builtin_subtype_methods_cy3.c:4768
#1114 0x00007ffff0016078 in __Pyx_Generator_Next (self=0x16653e0) at 
builtin_subtype_methods_cy3.c:4811
```

This is because Cython translates "dict.keys(self)" into the CPython 2.x 
equivalent "PyDict_Keys(self)". However, cpyext does not implement this C-API 
function as "dict.keys(self)" but as "self.keys()", which then calls the 
overridden method again and ends up in infinite recursion.

This might apply to other cpyext functions as well that delegate to methods of 
builtin types.



_______________________________________________
pypy-issue mailing list
pypy-issue@python.org
https://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to