Branch: Tag:

2003-10-12

2003-10-12 18:49:59 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added cut off at 1MB for pow() too.

Rev: src/modules/Gmp/mpz_glue.c:1.154

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: mpz_glue.c,v 1.153 2003/10/11 16:35:17 grubba Exp $ + || $Id: mpz_glue.c,v 1.154 2003/10/12 18:49:59 grubba Exp $   */      #include "global.h" - RCSID("$Id: mpz_glue.c,v 1.153 2003/10/11 16:35:17 grubba Exp $"); + RCSID("$Id: mpz_glue.c,v 1.154 2003/10/12 18:49:59 grubba Exp $");   #include "gmp_machine.h"   #include "module.h"   
1711:    if (sp[-1].type == T_INT) {    if (sp[-1].u.integer < 0)    SIMPLE_ARG_ERROR ("Gmp.mpz->pow", 1, "Negative exponent."); - #ifdef BIG_PIKE_INT -  if (!FITS_ULONG (sp[-1].u.integer)) +  /* Cut off at 1 MB. */ +  if ((mpz_size(THIS)*sp[-1].u.integer>(0x100000/sizeof(mp_limb_t))))    if(mpz_cmp_si(THIS, -1)<0 || mpz_cmp_si(THIS, 1)>0)    goto too_large; - #endif +     res = fast_clone_object(THIS_PROGRAM);    mpz_pow_ui(OBTOMPZ(res), THIS, sp[-1].u.integer);    } else { - #ifdef BIG_PIKE_INT +    too_large: - #endif +     mi = get_mpz(sp-1, 1, "Gmp.mpz->pow", 1, 1);    if(mpz_sgn(mi)<0)    SIMPLE_ARG_ERROR ("Gmp.mpz->pow", 1, "Negative exponent.");    i=mpz_get_si(mi); -  if(mpz_cmp_si(mi, i)) +  /* Cut off at 1 MB. */ +  if(mpz_cmp_si(mi, i) || +  (mpz_size(THIS)*i>(0x100000/sizeof(mp_limb_t))))    {    if(mpz_cmp_si(THIS, -1)<0 || mpz_cmp_si(THIS, 1)>0)    SIMPLE_ARG_ERROR ("Gmp.mpz->pow", 1, "Exponent too large.");