Ticket #13145: 13145.patch

File 13145.patch, 3.1 KB (added by roed, 9 years ago)
  • sage/libs/singular/ring.pxd

    # HG changeset patch
    # User David Roe <roed.math@gmail.com>
    # Date 1340303091 14400
    # Node ID 2877d084a44d4907d9fd14120929578d23e6aa50
    # Parent  bb37f43b5feaf166b5835cfccf17235fe6fbd94c
    #13145: Add refcounting code in sage.rings.polynomial.plural.new_NRing and new_CRing.
    
    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
     58cdef 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  
    586586    """
    587587    cdef size_t addr = <size_t>currRing
    588588    print "DEBUG: currRing == "+str(hex(addr))
     589
     590def currRing_wrapper():
     591    """
     592    Returns a wrapper for the current ring, for use in debugging ring_refcount_dict.
     593
     594    EXAMPLES::
     595
     596        sage: from sage.libs.singular.ring import currRing_wrapper
     597        sage: currRing_wrapper()
     598        The ring pointer ...
     599    """
     600    return wrap_ring(currRing)
  • sage/rings/polynomial/plural.pyx

    diff --git a/sage/rings/polynomial/plural.pyx b/sage/rings/polynomial/plural.pyx
    a b  
    111111from sage.structure.parent_gens cimport ParentWithGens
    112112
    113113# singular rings
    114 from sage.libs.singular.ring cimport singular_ring_new, singular_ring_delete
     114from sage.libs.singular.ring cimport singular_ring_new, singular_ring_delete, wrap_ring
     115import sage.libs.singular.ring
    115116
    116117from sage.rings.integer cimport Integer
    117118from sage.structure.element cimport Element, ModuleElement
     
    27052706        sage: R = new_CRing(W, H.base_ring())
    27062707        sage: R # indirect doctest
    27072708        Multivariate Polynomial Ring in x, y, z over Rational Field
     2709
     2710    Check that #13145 has been resolved::
     2711
     2712        sage: h = hash(R.gen() + 1) # sets currRing
     2713        sage: from sage.libs.singular.ring import ring_refcount_dict, currRing_wrapper
     2714        sage: curcnt = ring_refcount_dict[currRing_wrapper()]
     2715        sage: newR = new_CRing(W, H.base_ring())
     2716        sage: ring_refcount_dict[currRing_wrapper()] - curcnt
     2717        1
    27082718    """
    27092719    assert( rw.is_commutative() )
    27102720       
    27112721    cdef MPolynomialRing_libsingular self = <MPolynomialRing_libsingular>PY_NEW(MPolynomialRing_libsingular)
    27122722       
    27132723    self._ring = rw._ring
     2724
     2725    wrapped_ring = wrap_ring(self._ring)
     2726    cur_refcnt = sage.libs.singular.ring.ring_refcount_dict.get(wrapped_ring, 0)
     2727    sage.libs.singular.ring.ring_refcount_dict[wrapped_ring] = cur_refcnt + 1
     2728
    27142729    self._ring.ShortOut = 0
    27152730       
    27162731    self.__ngens = rw.ngens()
     
    27732788   
    27742789    cdef NCPolynomialRing_plural self = <NCPolynomialRing_plural>PY_NEW(NCPolynomialRing_plural)
    27752790    self._ring = rw._ring
     2791
     2792    wrapped_ring = wrap_ring(self._ring)
     2793    cur_refcnt = sage.libs.singular.ring.ring_refcount_dict.get(wrapped_ring, 0)
     2794    sage.libs.singular.ring.ring_refcount_dict[wrapped_ring] = cur_refcnt + 1
     2795
    27762796    self._ring.ShortOut = 0
    27772797       
    27782798    self.__ngens = rw.ngens()