pike.git / src / bignum.c

version» Context lines:

pike.git/src/bignum.c:1:   /*   || 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.27 2002/10/11 01:39:28 nilsson Exp $ + || $Id: bignum.c,v 1.28 2003/01/11 01:52:55 mast Exp $   */      #include "global.h"      #ifdef AUTO_BIGNUM      #include "interpret.h"   #include "program.h"   #include "object.h"   #include "svalue.h"
pike.git/src/bignum.c:20:   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) + void init_auto_bignum(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);   }      void exit_auto_bignum(void)   {    free_svalue(&auto_bignum_program);    auto_bignum_program.type=T_INT;   }      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");   }      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");   }      int is_bignum_object(struct object *o)   {    /* Note:    * This function should *NOT* try to resolv Gmp.mpz unless    * it is already loaded into memory.    * /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);   }      PMOD_EXPORT int is_bignum_object_in_svalue(struct svalue *sv)   {    return sv->type == T_OBJECT && is_bignum_object(sv->u.object);   }      PMOD_EXPORT struct object *make_bignum_object(void)   {
pike.git/src/bignum.c:153: Inside #if defined(INT64)
   }    else    {    unsigned int neg = 0;    if( i < 0 )    {    i = -i;    neg = 1;    }    -  resolve_auto_bignum_program(); -  +    #if PIKE_BYTEORDER == 1234    {    char digits[8];    char *ledigits = (char *)&i;    digits[7] = ledigits[ 0 ]; digits[6] = ledigits[ 1 ];    digits[5] = ledigits[ 2 ]; digits[4] = ledigits[ 3 ];    digits[3] = ledigits[ 4 ]; digits[2] = ledigits[ 5 ];    digits[1] = ledigits[ 6 ]; digits[0] = ledigits[ 7 ];    push_string( make_shared_binary_string( digits, 8 ) );    }