#11339: Illegal use of __deallocate__ in cython (pyx) code
-----------------------+----------------------------------------------------
   Reporter:  gagern   |          Owner:  drkirkby
       Type:  defect   |         Status:  new     
   Priority:  major    |      Milestone:  sage-4.7
  Component:  porting  |       Keywords:          
Work_issues:           |       Upstream:  N/A     
   Reviewer:           |         Author:          
     Merged:           |   Dependencies:          
-----------------------+----------------------------------------------------

Comment(by vbraun):

 The documentation is fairly clear, you are only allowed to touch C data
 structures in `__dealloc__`:
 http://docs.cython.org/src/userguide/special_methods.html#finalization-
 method-dealloc

 Really, this shows the difference between the C++ and the Python object
 model. In Python, executing constructors/destructors in derived classes is
 optional and leaves a lot of freedom to the programmer. Because of the
 garbage collection you can allocate resources wherever you want. By
 comparison, C++ is very strict and essentially forces you to use RAII.
 This is why there is no try/finally in C++. Which is why there is
 necessarily some tension in Cython between C++ and Python object
 instantiation/finalization.

 Having said that, it seems like the cleanest solution would be if Cython
 would also call the Python destructor `__del__` according to the normal
 Python rules (why `__clear__`?). Then the Python and C++ object model
 could just peacefully coexist. The lifetime of a cdef class would be

 {{{
 __cinit__()    # always called
 __init__()     # not necessarily called for derived classes
 ... do something ...
 __del__()      # not necessarily called for derived classes
 __dealloc__()  # always called
 }}}

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