Ticket #11468: trac_11468-memleaks_singular.patch

File trac_11468-memleaks_singular.patch, 6.1 KB (added by jpflori, 10 years ago)

New version with correct commit message and copyright.

  • sage/libs/singular/singular.pyx

    # HG changeset patch
    # User Jean-Pierre Flori <flori@enst.fr>
    # Date 1308174730 -7200
    # Node ID 1aa412d3f4dcfeb7f607db667e334282aa21cacd
    # Parent  96c0d07e46bcf1dbea7aeae1e1521d3f139ed44d
    Trac 11468: fixes memleaks in singular.pyx
    
    diff -r 96c0d07e46bc -r 1aa412d3f4dc sage/libs/singular/singular.pyx
    a b  
    11"""
    22libSingular conversion routines and initialisation.
    33
    4 AUTHOR: 
     4AUTHOR:
    55
    66- Martin Albrecht <malb@informatik.uni-bremen.de>
    77"""
    88###############################################################################
    9 #   Sage: System for Algebra and Geometry Experimentation   
    109#       Copyright (C) 2005, 2006 William Stein <wstein@gmail.com>
     10#
    1111#  Distributed under the terms of the GNU General Public License (GPL)
    12 #  The full text of the GPL is available at:
     12#  as published by the Free Software Foundation; either version 2 of
     13#  the License, or (at your option) any later version.
    1314#                  http://www.gnu.org/licenses/
    1415###############################################################################
    1516
     
    2627from sage.misc.misc_c import is_64_bit
    2728
    2829from sage.libs.singular.decl cimport intvec
    29 from sage.libs.singular.decl cimport SR_HDL, SR_INT, SR_TO_INT, singular_options, singular_verbose_options
     30from sage.libs.singular.decl cimport SR_HDL, SR_INT, SR_TO_INT
     31from sage.libs.singular.decl cimport singular_options, singular_verbose_options
    3032from sage.libs.singular.decl cimport On, Off, SW_USE_NTL, SW_USE_NTL_GCD_0, SW_USE_EZGCD, SW_USE_NTL_SORT, SW_USE_NTL_GCD_P
    3133from sage.libs.singular.decl cimport napoly, lnumber, Sy_bit, OPT_REDSB, OPT_INTSTRATEGY, OPT_REDTAIL, OPT_REDTHROUGH
    3234from sage.libs.singular.decl cimport nlGetNumerator, nlGetDenom, nlDelete, nlInit2gmp
     
    7880    mpq_init(_z)
    7981
    8082    ##  Immediate integers handles carry the tag 'SR_INT', i.e. the last bit is 1.
    81     ##  This distinguishes immediate integers from other handles which  point to
    82     ##  structures aligned on 4 byte boundaries and therefor have last bit  zero.
    83     ##  (The second bit is reserved as tag to allow extensions of  this scheme.)
     83    ##  This distinguishes immediate integers from other handles which point to
     84    ##  structures aligned on 4 byte boundaries and therefor have last bit zero.
     85    ##  (The second bit is reserved as tag to allow extensions of this scheme.)
    8486    ##  Using immediates as pointers and dereferencing them gives address errors.
    8587    nom = nlGetNumerator(n, _ring)
    8688    mpz_init(nom_z)
     
    231233        if e == 0:
    232234            ret = ret + c
    233235        elif c != 0:
    234             ret = ret  + c * a**e 
     236            ret = ret  + c * a**e
    235237        z = <napoly*>pNext(<poly*>z)
    236238    return base(ret)
    237239
     
    269271        if e == 0:
    270272            ret = ret + coeff
    271273        elif coeff != 0:
    272             ret = ret  + coeff * a**e
     274            ret = ret + coeff * a**e
    273275        z = <napoly*>pNext(<poly*>z)
    274276    return base(ret)
    275277
     
    300302        4294967295
    301303
    302304        sage: P(3).lc()
    303         3       
     305        3
    304306
    305307        sage: P.<x,y,z> = Integers(17^20)[]
    306308        sage: P(17^19 + 3).lc()
    307309        239072435685151324847156
    308310
    309311        sage: P(3)
    310         3       
     312        3
    311313    """
    312314    cdef Integer ret
    313315    if _ring.ringtype == 1:
     
    342344    cdef int b
    343345
    344346    rChangeCurrRing(_ring)
    345     b   = - _ring.ch;
     347    b = - _ring.ch;
    346348
    347349    a = naPar(1)
    348350
     
    353355        coeff = naInit(quo%b, _ring)
    354356
    355357        if not naIsZero(coeff):
    356             n2 = naAdd( naMult(coeff, apow1),  n1)
    357             naDelete(&n1, _ring);
    358             n1= n2
     358            apow2 = naMult(coeff, apow1)
     359            n2 = naAdd(apow2, n1)
     360            naDelete(&apow2, _ring)
     361            naDelete(&n1, _ring)
     362            n1 = n2
    359363
    360364        apow2 = naMult(apow1, a)
    361365        naDelete(&apow1, _ring)
     
    387391            coeff = naInit(GF2_conv_to_long(GF2X_coeff(rep,i)), _ring)
    388392
    389393            if not naIsZero(coeff):
    390                 n2 = naAdd( naMult(coeff, apow1),  n1)
     394                apow2 = naMult(coeff, apow1)
     395                n2 = naAdd(apow2, n1)
     396                naDelete(&apow2, _ring)
    391397                naDelete(&n1, _ring);
    392                 n1= n2
     398                n1 = n2
    393399
    394400            apow2 = naMult(apow1, a)
    395401            naDelete(&apow1, _ring)
     
    400406        naDelete(&apow1, _ring)
    401407        naDelete(&a, _ring)
    402408    else:
    403        n1 = naInit(GF2_conv_to_long(GF2X_coeff(rep,0)), _ring)
     409        n1 = naInit(GF2_conv_to_long(GF2X_coeff(rep,0)), _ring)
    404410
    405411    return n1
    406412
     
    424430            coeff = naInit(int(elem[i]), _ring)
    425431
    426432            if not naIsZero(coeff):
    427                 n2 = naAdd( naMult(coeff, apow1),  n1)
     433                apow2 = naMult(coeff, apow1)
     434                n2 = naAdd(apow2, n1)
     435                naDelete(&apow2, _ring)
    428436                naDelete(&n1, _ring);
    429                 n1= n2
     437                n1 = n2
    430438
    431439            apow2 = naMult(apow1, a)
    432440            naDelete(&apow1, _ring)
     
    461469        nlDelete(&nlCoeff, _ring)
    462470
    463471        # faster would be to assign the coefficient directly
    464         n2 = naAdd( naMult(naCoeff, apow1),  n1)
     472        apow2 = naMult(naCoeff, apow1)
     473        n2 = naAdd(apow2, n1)
     474        naDelete(&apow2, _ring)
    465475        naDelete(&n1, _ring);
    466476        naDelete(&naCoeff, _ring)
    467477        n1 = n2
     
    520530        4294967295
    521531
    522532        sage: P(3)
    523         3       
     533        3
    524534
    525535        sage: P.<x,y,z> = Integers(17^20)[]
    526536        sage: P(17^19 + 3)
    527537        239072435685151324847156
    528538
    529539        sage: P(3)
    530         3       
     540        3
    531541    """
    532542    nr2mModul = d.parent().characteristic()
    533543    cdef int _d
     
    630640    """
    631641    if unlikely(e > max_exponent_size):
    632642        raise OverflowError("Exponent overflow (%d)."%(e))
    633     return 0;
     643    return 0
    634644
    635645# Our attempt at avoiding exponent overflows.
    636646cdef unsigned int max_exponent_size
     
    701711cdef void libsingular_error_callback(const_char_ptr s):
    702712    _s = s
    703713    error_messages.append(_s)
    704