#14059: Fix refcount/deallocation of integers
-----------------------------+----------------------------------------------
       Reporter:  SimonKing  |         Owner:  rlm     
           Type:  defect     |        Status:  new     
       Priority:  blocker    |     Milestone:  sage-5.7
      Component:  memleak    |    Resolution:          
       Keywords:             |   Work issues:          
Report Upstream:  N/A        |     Reviewers:          
        Authors:             |     Merged in:          
   Dependencies:             |      Stopgaps:          
-----------------------------+----------------------------------------------

Comment (by SimonKing):

 At least for educational purposes, the following comments have to change:
 {{{
         # We take the address 'new' and move mpz_t_offset bytes (chars)
         # to the address of 'value'. We treat that address as a pointer
         # to a mpz_t struct and allocate memory for the _mp_d element of
         # that struct. We allocate one limb.
         #
         # What is done here is potentially very dangerous as it reaches
         # deeply into the internal structure of GMP. Consequently things
         # may break if a new release of GMP changes some internals. To
         # emphasize this, this is what the GMP manual has to say about
         # the documentation for the struct we are using:
         #
         #  "This chapter is provided only for informational purposes and
 the
         #  various internals described here may change in future GMP
 releases.
         #  Applications expecting to be compatible with future releases
 should use
         #  only the documented interfaces described in previous chapters."
         #
         # If this line is used Sage is not such an application.
         #
         # The clean version of the following line is:
         #
         # mpz_init( <mpz_t>(<char *>new + mpz_t_offset) )
         #
         # We save time both by avoiding an extra function call and
         # because the rest of the mpz struct was already initialized
         # fully using the memcpy above.

         (<__mpz_struct *>( <char *>new + mpz_t_offset) )._mp_d =
 <mp_ptr>mpz_alloc(GMP_LIMB_BITS >> 3)
 }}}
 Namely, when I uncomment `mpz_init( <mpz_t>(<char *>new + mpz_t_offset) )`
 and comment the last line, then the module won't build:
 {{{
 sage/rings/integer.c: In function
 ‘__pyx_f_4sage_5rings_7integer_fast_tp_new’:
 sage/rings/integer.c:35637:18: error: cast specifies array type
 error: command 'gcc' failed with exit status 1
 Error installing modified sage library code.
 }}}

 So, the "clean version" doesn't even build.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14059#comment:11>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to