#13447: Make libsingular multivariate polynomial rings collectable
----------------------------------------------------------------+-----------
       Reporter:  nbruin                                        |         
Owner:                                                                          
 
           Type:  defect                                        |        
Status:  needs_work                                                             
  
       Priority:  major                                         |     
Milestone:  sage-5.4                                                            
     
      Component:  memleak                                       |    
Resolution:                                                                     
      
       Keywords:                                                |   Work 
issues:  Understand why sometimes `new_RingWrap` needs an incref and sometimes 
not
Report Upstream:  None of the above - read trac for reasoning.  |     
Reviewers:  Simon King                                                          
     
        Authors:  Nils Bruin, Simon King                        |     Merged 
in:                                                                           
   Dependencies:  #11521                                        |      
Stopgaps:                                                                       
    
----------------------------------------------------------------+-----------

Comment (by SimonKing):

 Some suggestions:

 The singular function `rKill` seems to do what we want in
 `singular_ring_delete`. Hence, to keep it simple, `singular_ring_delete`
 should call `rKill`, and nothing more (unless we want a sanity test, such
 as printing a warning if `singular_ring_delete` is called on NULL).

 `rKill` only takes action if `r->ref` is zero when it is called. Indeed,
 according to Hans, `r->ref` is the number of interpreter variables
 pointing to a ring, minus one. In order to avoid confusion, we should
 follow the same idea.

 So, what means "interpreter variables" for us? I think this should be "any
 Sage object whose deallocation needs the libsingular ring being alive".
 This is every polynomial ring, every Gröbner strategy, and any element of
 a polynomial ring.

 Since ref is -1 based, when a Sage ring R is created then ref shall be
 zero, so that the underlying libsingular ring can be properly deleted if R
 is deallocated. And if any element or Gröbner strategy on that ring is
 created, ref needs to be incremented. The deallocation of an element or
 Gröbner strategy must involve a call to `singular_ring_delete`.

 A complication arises when calling a singular_function. When we call a
 Singular interpreter function, then we should have ref>0, again according
 to Hans. Hence, at the begin of a call, ref must be incremented, and
 decremented when leaving it.

 Special care needs to be taken on `currRingHdl`. According to Hans,
 `rKill` can make it NULL, and it should be NULL if and only if `currRing`
 is NULL. Currently, we create `currRingHdl` when we ''create'' a Singular
 function, but we only use it when we ''call'' a Singular function. That's
 asking for trouble. Hence, we should move the creation of currRingHdl to
 `SingularFunction.__call__`, where we also set the correct `currRing`.
 `SingularFunction.__init__` is not the right place.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13447#comment:69>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to