Branch: Tag:

2003-02-21

2003-02-21 17:42:21 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Backported new bignum bootstrap from Pike 7.5.

Rev: lib/master.pike.in:1.240
Rev: src/bignum.c:1.29
Rev: src/bignum.h:1.17
Rev: src/modules/Gmp/mpz_glue.c:1.116

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: bignum.c,v 1.28 2003/02/14 19:19:57 mast Exp $ + || $Id: bignum.c,v 1.29 2003/02/21 17:42:21 grubba Exp $   */      #include "global.h"
17:      #define sp Pike_sp    - struct svalue auto_bignum_program = { + PMOD_EXPORT struct svalue auto_bignum_program = {    T_INT, 0,   #ifdef HAVE_UNION_INIT    {0}, /* Only to avoid warnings. */   #endif   };    - PMOD_EXPORT int gmp_library_loaded=0; - int gmp_library_resolving=0; -  - static void resolve_auto_bignum_program(void) - { -  if(auto_bignum_program.type == T_INT) -  { -  if(gmp_library_resolving) -  Pike_fatal("Recursive GMP resolving!\n"); -  -  gmp_library_resolving=1; -  push_text("Gmp.bignum"); -  SAFE_APPLY_MASTER("resolv", 1); -  -  if(sp[-1].type != T_FUNCTION && sp[-1].type != T_PROGRAM) -  Pike_error("Failed to resolv Gmp.mpz!\n"); -  -  auto_bignum_program=sp[-1]; -  sp--; -  dmalloc_touch_svalue(sp); -  gmp_library_resolving=0; -  } - } -  +    PMOD_EXPORT struct program *get_auto_bignum_program(void)   { -  resolve_auto_bignum_program(); +     return program_from_function(&auto_bignum_program);   }      PMOD_EXPORT struct program *get_auto_bignum_program_or_zero(void)   { -  if(!gmp_library_loaded || -  gmp_library_resolving || -  !master_object) return 0; -  resolve_auto_bignum_program(); +  if (auto_bignum_program.type == T_INT) +  return 0;    return program_from_function(&auto_bignum_program);   }   
71:      PMOD_EXPORT void convert_stack_top_to_bignum(void)   { -  resolve_auto_bignum_program(); +     apply_svalue(&auto_bignum_program, 1);    -  if(sp[-1].type != T_OBJECT) -  Pike_error("Gmp.mpz conversion failed.\n"); +  if(sp[-1].type != T_OBJECT) { +  if (auto_bignum_program.type!=T_PROGRAM) +  Pike_error("Gmp.mpz conversion failed (Gmp.bignum not loaded).\n"); +  else +  Pike_error("Gmp.mpz conversion failed (unknown error).\n");    } -  + }      PMOD_EXPORT void convert_stack_top_with_base_to_bignum(void)   { -  resolve_auto_bignum_program(); +     apply_svalue(&auto_bignum_program, 2);    -  if(sp[-1].type != T_OBJECT) -  Pike_error("Gmp.mpz conversion failed.\n"); +  if(sp[-1].type != T_OBJECT) { +  if (auto_bignum_program.type!=T_PROGRAM) +  Pike_error("Gmp.mpz conversion failed (Gmp.bignum not loaded).\n"); +  else +  Pike_error("Gmp.mpz conversion failed (unknown error).\n");    } -  + }      int is_bignum_object(struct object *o)   {
95:    * /Hubbe    */    -  if(!gmp_library_loaded || -  gmp_library_resolving || -  !master_object) +  if (auto_bignum_program.type == T_INT)    return 0; /* not possible */    -  resolve_auto_bignum_program(); +     return o->prog == program_from_svalue(&auto_bignum_program);   }   
160: Inside #if defined(INT64)
   neg = 1;    }    -  resolve_auto_bignum_program(); -  +    #if PIKE_BYTEORDER == 1234    {    char digits[8];