Ticket #12313: trac_12313-safe_callback.patch

File trac_12313-safe_callback.patch, 1.5 KB (added by SimonKing, 7 years ago)

Making sure Python attributes exist in a weakref callback

  • sage/structure/coerce_dict.pyx

    # HG changeset patch
    # User Simon King <simon.king@uni-jena.de>
    # Date 1358514053 -3600
    # Node ID de5914a402e912bdf4bfc24cf9c071e2f9441bdb
    # Parent  98521ef1da2cd4002909ce651459eb69de36c650
    #12313: Make sure that Python attributes still exist in weakref callback
    
    diff --git a/sage/structure/coerce_dict.pyx b/sage/structure/coerce_dict.pyx
    a b  
    119119        if D is None:
    120120            return
    121121        cdef size_t k = r.key
    122         cdef size_t h = k % PyList_GET_SIZE(D.buckets)
    123         cdef list bucket = <object>PyList_GET_ITEM(D.buckets,h)
     122        cdef list buckets = D.buckets
     123        if buckets is None:
     124            return
     125        cdef size_t h = k % PyList_GET_SIZE(buckets)
     126        cdef list bucket = <object>PyList_GET_ITEM(buckets,h)
    124127        cdef Py_ssize_t i
    125128        for i from 0 <= i < PyList_GET_SIZE(bucket) by 2:
    126129            if <size_t><object>PyList_GET_ITEM(bucket,i)==k:
     
    211214        cdef TripleDict D = self.D()
    212215        if D is None:
    213216            return
     217        cdef buckets = D.buckets
     218        if buckets is None:
     219            return
    214220        k1,k2,k3 = r.key
    215221        cdef size_t h = (k1 + 13*k2 ^ 503*k3)
    216         cdef list bucket = <object>PyList_GET_ITEM(D.buckets, h % PyList_GET_SIZE(D.buckets))
     222        cdef list bucket = <object>PyList_GET_ITEM(buckets, h % PyList_GET_SIZE(buckets))
    217223        cdef Py_ssize_t i
    218224        for i from 0 <= i < PyList_GET_SIZE(bucket) by 4:
    219225            if <size_t><object>PyList_GET_ITEM(bucket, i)==k1 and \