#13447: Make libsingular multivariate polynomial rings collectable
----------------------------------------------------------------+-----------
       Reporter:  nbruin                                        |         
Owner:                                 
           Type:  defect                                        |        
Status:  needs_info                     
       Priority:  major                                         |     
Milestone:  sage-5.4                       
      Component:  memleak                                       |    
Resolution:                                 
       Keywords:                                                |   Work 
issues:  Input from a libsingular expert
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):

 Replying to [comment:51 nbruin]:
 > I'm not so sure that
 > {{{#!python
 >     currRingHdl = enterid("my_awesome_sage_ring", 0, RING_CMD, &IDROOT,
 1)
 >     currRingHdl.data.uring.ref += 1
 > }}}
 > is entirely safe.

 I am sure that it is not safe: One can't even call singular_ring_delete on
 it. That's why I removed it, unless `currRing==NULL`.


 > '''EDIT:''' `kernel/Number.h` contains uncommented definitions:
 > {{{#!C++
 > using namespace boost;
 > inline void intrusive_ptr_add_ref(ring r){
 >     r->ref++;
 >     //Print("ref count after add: %d", r->ref);
 > }
 > inline void intrusive_ptr_release(ring r){
 >     if (r->ref<=0) rDelete(r);
 >     else {
 >     r->ref--;
 >
 >     }
 >     //Print("ref count after release: %d", r->ref);
 > }
 > }}}
 > I find the `ptr_release` a little worrisome: Do the singular people
 believe that `r->ref ==0` means that there is still a reference?

 According to the code snipped, the ring is deleted if `r->ref==0`. So,
 apparently `r->ref==0` means that there is ''no'' reference.

 > this code all indicates that special action is required only if `ref<=0`
 'before' decreasing.

 If `ref<=0` then no reference is left, hence, the ring is deleted.
 Otherwise, the reference counter is decremented. I really don't understand
 the problem.

 > In that case we should probably ensure that `singular_ring_ref` and
 `singular_delete_ring` are somehow aliased to
 `boost::intrusive_ptr_add_ref` and `intrusive_ptr_release` from
 `kernel/Number.h`.

 Singular tests whether `ref<=0`; if it is, then the ring is deleted, but
 if it isn't then the counter is decremented.

 We first decrement the counter, and then test whether `ref<0`; if it is,
 then the ring is deleted, but if it isn't then no further action is taken.

 Isn't that logically the same?

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13447#comment:53>
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