Ticket #13447: trac_13447-refcount_cleanup.patch

File trac_13447-refcount_cleanup.patch, 4.6 KB (added by nbruin, 7 years ago)

clean up final bits in refcounting of singular rings

  • sage/libs/singular/function.pyx

    # HG changeset patch
    # User Nils Bruin <nbruin@sfu.ca>
    # Date 1347918130 25200
    # Node ID 160adcc9bf1362ef8f248a0911dc4ecbd9b7e04c
    # Parent  a7f30893564305802ffc89a4fbdc8cffbe73ea82
    #13447: Cleanup of singular_ring refcounting:
    remove now unused class ring_wrapper_Py and associated functions
    add deletion in one more spot where refcount can hit zero
    
    diff --git a/sage/libs/singular/function.pyx b/sage/libs/singular/function.pyx
    a b  
    14091409
    14101410    if currRingHdl.data.uring!= currRing:
    14111411        currRingHdl.data.uring.ref -= 1
     1412        if currRingHdl.data.uring.ref == 0:
     1413            rDelete(currRingHdl.data.uring)
    14121414        currRingHdl.data.uring = currRing # ref counting?
    14131415        currRingHdl.data.uring.ref += 1
    14141416
  • sage/libs/singular/ring.pxd

    diff --git a/sage/libs/singular/ring.pxd b/sage/libs/singular/ring.pxd
    a b  
    5353
    5454# carefully delete a ring once its refcount is zero
    5555cdef void singular_ring_delete(ring *doomed)
    56 
    57 # Used internally for reference counting
    58 cdef wrap_ring(ring* R)
  • sage/libs/singular/ring.pyx

    diff --git a/sage/libs/singular/ring.pyx b/sage/libs/singular/ring.pyx
    a b  
    326326    _ring.ref=1
    327327    return _ring
    328328
    329 
    330329#############################################################################
    331 
    332 cdef class ring_wrapper_Py(object):
    333     r"""
    334     Python object wrapping the ring pointer.
    335 
    336     This is useful to store ring pointers in Python containers.
    337 
    338     You must not construct instances of this class yourself, use
    339     :func:`wrap_ring` instead.
    340 
    341     EXAMPLES::
    342 
    343         sage: from sage.libs.singular.ring import ring_wrapper_Py
    344         sage: ring_wrapper_Py
    345         <type 'sage.libs.singular.ring.ring_wrapper_Py'>
    346     """
    347 
    348     cdef ring* _ring
    349 
    350     def __cinit__(self):
    351         """
    352         The Cython constructor.
    353        
    354         EXAMPLES::
    355        
    356             sage: from sage.libs.singular.ring import ring_wrapper_Py
    357             sage: t = ring_wrapper_Py(); t
    358             The ring pointer 0x0
    359             sage: TestSuite(t).run()
    360         """
    361         self._ring = NULL
    362 
    363     def __hash__(self):
    364         """
    365         Return a hash value so that instances can be used as dictionary keys.
    366 
    367         OUTPUT:
    368        
    369         Integer.
    370        
    371         EXAMPLES::
    372 
    373             sage: from sage.libs.singular.ring import ring_wrapper_Py
    374             sage: t = ring_wrapper_Py()
    375             sage: t.__hash__()
    376             0
    377         """
    378         return <long>(self._ring)
    379 
    380     def __repr__(self):
    381         """
    382         Return a string representation.
    383 
    384         OUTPUT:
    385 
    386         String.
    387 
    388         EXAMPLES::
    389 
    390             sage: from sage.libs.singular.ring import ring_wrapper_Py
    391             sage: t = ring_wrapper_Py()
    392             sage: t
    393             The ring pointer 0x0
    394             sage: t.__repr__()
    395             'The ring pointer 0x0'
    396         """
    397         return 'The ring pointer '+hex(self.__hash__())
    398 
    399     def __cmp__(ring_wrapper_Py left, ring_wrapper_Py right):
    400         """
    401         Compare ``left`` and ``right`` so that instances can be used as dictionary keys.
    402        
    403         INPUT:
    404 
    405         - ``right`` -- a :class:`ring_wrapper_Py`
    406        
    407         OUTPUT:
    408 
    409         -1, 0, or +1 depending on whether ``left`` and ``right`` are
    410          less than, equal, or greather than.
    411 
    412         EXAMPLES::
    413 
    414             sage: from sage.libs.singular.ring import ring_wrapper_Py
    415             sage: t = ring_wrapper_Py()
    416             sage: t.__cmp__(t)
    417             0
    418         """
    419         if left._ring < right._ring:
    420             return -1
    421         if left._ring > right._ring:
    422             return +1
    423         return 0
    424 
    425 
    426 cdef wrap_ring(ring* R):
    427     """
    428     Wrap a C ring pointer into a Python object.
    429 
    430     INPUT:
    431 
    432     - ``R`` -- a singular ring (a C datastructure).
    433 
    434     OUTPUT:
    435 
    436     A Python object :class:`ring_wrapper_Py` wrapping the C pointer.
    437     """
    438     cdef ring_wrapper_Py W = ring_wrapper_Py()
    439     W._ring = R
    440     return W
    441 
    442 
    443330cdef ring *singular_ring_reference(ring *existing_ring) except NULL:
    444331    """
    445332    Refcount the ring ``existing_ring``.
     
    589476    cdef size_t addr = <size_t>currRing
    590477    print "DEBUG: currRing == "+str(hex(addr))
    591478
    592 def currRing_wrapper():
    593     """
    594     Returns a wrapper for the current ring, for use in debugging ring_refcount_dict.
    595 
    596     EXAMPLES::
    597 
    598         sage: from sage.libs.singular.ring import currRing_wrapper
    599         sage: currRing_wrapper()
    600         The ring pointer ...
    601     """
    602     return wrap_ring(currRing)