#13901: Fix cython's deep C-stacks upon deallocation
------------------------------------------------------------------+---------
       Reporter:  nbruin                                          |         
Owner:  rlm     
           Type:  defect                                          |        
Status:  new     
       Priority:  major                                           |     
Milestone:  sage-5.6
      Component:  memleak                                         |    
Resolution:          
       Keywords:                                                  |   Work 
issues:          
Report Upstream:  Reported upstream. Developers acknowledge bug.  |     
Reviewers:          
        Authors:                                                  |     Merged 
in:          
   Dependencies:                                                  |      
Stopgaps:          
------------------------------------------------------------------+---------
Changes (by jpflori):

  * upstream:  Reported upstream. No feedback yet. => Reported upstream.
               Developers acknowledge bug.


Old description:

> Once you know about python's `trashcan` that is used in its dealloc
> methods and that cython does not make use of it, it's not hard to cause a
> crash in deallocation of a cython class:
> {{{
> cython("""
> cdef class A(object):
>     cdef object ref
>     def __init__(self,ref):
>         self.ref = ref
>
> """)
> }}}
> A long linked list of these will quickly exhaust the C-stack (set a
> ulimit on the stack if you have a lot of memory):
> {{{
> print "allocating a"
> a=A(None)
> for i in range(10**6):
>     a=A(a)
>
> print "deleting a"
> del a
> print "done deleting a"
> }}}
>
> Once you interleave with a python container type (tuple, for instance),
> the trashcan starts to kick in. The following runs without problem.
> {{{
> b=A(None)
> print "allocating b"
> for i in range(10**6):
>     b=A((b,))
>
> print "deleting b"
> del b
> print "done deleting b"
> }}}
> This issue came up as a side issue on #13896. The trashcan is a rather
> complicated thing to get working right. In particular, cython must take
> precautions to ensure that once deallocation is started on an object, it
> isn't put into the trashcan in deallocs of base types.

New description:

 Once you know about python's `trashcan` that is used in its dealloc
 methods and that cython does not make use of it, it's not hard to cause a
 crash in deallocation of a cython class:
 {{{
 cython("""
 cdef class A(object):
     cdef object ref
     def __init__(self,ref):
         self.ref = ref

 """)
 }}}
 A long linked list of these will quickly exhaust the C-stack (set a ulimit
 on the stack if you have a lot of memory):
 {{{
 print "allocating a"
 a=A(None)
 for i in range(10**6):
     a=A(a)

 print "deleting a"
 del a
 print "done deleting a"
 }}}

 Once you interleave with a python container type (tuple, for instance),
 the trashcan starts to kick in. The following runs without problem.
 {{{
 b=A(None)
 print "allocating b"
 for i in range(10**6):
     b=A((b,))

 print "deleting b"
 del b
 print "done deleting b"
 }}}
 This issue came up as a side issue on #13896. The trashcan is a rather
 complicated thing to get working right. In particular, cython must take
 precautions to ensure that once deallocation is started on an object, it
 isn't put into the trashcan in deallocs of base types.

 This is now upstream http://trac.cython.org/cython_trac/ticket/797

--

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