[pypy-dev] crash in cpyext dict iteration

Stefan Behnel stefan_ml at behnel.de
Sat Feb 25 18:10:10 CET 2012


Hi,

I've rewritten Cython's dict iteration code to use normal PyIter_Next()
iteration on PyPy, but now I get a crash in one of the tests. Apparently,
the iterator fails to raise an exception when the dict is being resized
during iteration. The test goes like this:

'''
def iterdict_change_size(dict d):
    """
    >>> count, i = 0, -1
    >>> d = {1:2, 10:20}
    >>> for i in d:
    ...     d[i+1] = 5
    ...     count += 1
    ...     if count > 5:
    ...         break # safety
    Traceback (most recent call last):
    RuntimeError: dictionary changed size during iteration

    >>> iterdict_change_size({1:2, 10:20})
    Traceback (most recent call last):
    RuntimeError: dictionary changed size during iteration
    >>> print( iterdict_change_size({}) )
    DONE
    """
    cdef int count = 0
    i = -1
    for i in d:
        d[i+1] = 5
        count += 1
        if count > 5:
            break # safety
    return "DONE"
'''

It's supposed to raise an exception when starting the second iteration, but
in PyPy, it crashes at that point instead.

Stefan



More information about the pypy-dev mailing list