diff --git a/src/bignum.c b/src/bignum.c index 7d5d1abd7b52223a7b0ed8f2d0f5f60b900434d7..0156143e4bfdab23293220b1ba95e99c38933442 100644 --- a/src/bignum.c +++ b/src/bignum.c @@ -2,7 +2,7 @@ || 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.39 2003/04/02 20:54:00 mast Exp $ +|| $Id: bignum.c,v 1.40 2003/11/15 17:25:05 mast Exp $ */ #include "global.h" @@ -135,15 +135,18 @@ static void bootstrap_push_int64 (INT64 i) PMOD_EXPORT void (*push_int64) (INT64) = bootstrap_push_int64; PMOD_EXPORT int (*int64_from_bignum) (INT64 *, struct object *) = NULL; +PMOD_EXPORT void (*reduce_stack_top_bignum) (void) = NULL; PMOD_EXPORT void hook_in_int64_funcs ( void (*push_int64_val)(INT64), - int (*int64_from_bignum_val) (INT64 *, struct object *)) + int (*int64_from_bignum_val) (INT64 *, struct object *), + void (*reduce_stack_top_bignum_val) (void)) { /* Assigning the pointers above directly from the Gmp module doesn't * work in some cases, e.g. NT. */ push_int64 = push_int64_val ? push_int64_val : bootstrap_push_int64; int64_from_bignum = int64_from_bignum_val; + reduce_stack_top_bignum = reduce_stack_top_bignum_val; } #endif diff --git a/src/bignum.h b/src/bignum.h index f6524b86da0152a499d3ab53d6c73b936beb6e02..d31057c404babd338db1adc673f6a72ce1a18cdb 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -2,7 +2,7 @@ || 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.h,v 1.25 2003/08/22 15:57:52 tomas Exp $ +|| $Id: bignum.h,v 1.26 2003/11/15 17:25:05 mast Exp $ */ #include "global.h" @@ -60,9 +60,11 @@ void convert_svalue_to_bignum(struct svalue *s); #ifdef INT64 PMOD_EXPORT extern void (*push_int64)(INT64 i); PMOD_EXPORT extern int (*int64_from_bignum) (INT64 *i, struct object *bignum); +PMOD_EXPORT extern void (*reduce_stack_top_bignum) (void); PMOD_EXPORT void hook_in_int64_funcs ( void (*push_int64_val)(INT64), - int (*int64_from_bignum_val) (INT64 *, struct object *)); + int (*int64_from_bignum_val) (INT64 *, struct object *), + void (*reduce_stack_top_bignum_val) (void)); #else #define push_int64(i) push_int((INT_TYPE)(i)) #define int64_from_bignum(I,BIGNUM) 0 diff --git a/src/encode.c b/src/encode.c index 82959c7e96dedc23e67a92157749dd75052b041c..a4531c443dcd4e310e69d4966e55a987636e2428 100644 --- a/src/encode.c +++ b/src/encode.c @@ -2,7 +2,7 @@ || 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: encode.c,v 1.198 2003/11/14 00:41:27 mast Exp $ +|| $Id: encode.c,v 1.199 2003/11/15 17:25:05 mast Exp $ */ #include "global.h" @@ -30,7 +30,7 @@ #include "pikecode.h" #include "pike_types.h" -RCSID("$Id: encode.c,v 1.198 2003/11/14 00:41:27 mast Exp $"); +RCSID("$Id: encode.c,v 1.199 2003/11/15 17:25:05 mast Exp $"); /* #define ENCODE_DEBUG */ @@ -2508,6 +2508,9 @@ static void decode_value2(struct decode_data *data) */ push_int(36); convert_stack_top_with_base_to_bignum(); +#if SIZEOF_INT_TYPE > 4 + reduce_stack_top_bignum(); +#endif break; } diff --git a/src/modules/Gmp/mpz_glue.c b/src/modules/Gmp/mpz_glue.c index ea2d2cd9797930f12dbdcce3695a4334247566bd..45ab8d4504fc16c934dc1d79419a9b05c829d114 100644 --- a/src/modules/Gmp/mpz_glue.c +++ b/src/modules/Gmp/mpz_glue.c @@ -2,11 +2,11 @@ || 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.155 2003/11/14 10:26:43 mast Exp $ +|| $Id: mpz_glue.c,v 1.156 2003/11/15 17:25:05 mast Exp $ */ #include "global.h" -RCSID("$Id: mpz_glue.c,v 1.155 2003/11/14 10:26:43 mast Exp $"); +RCSID("$Id: mpz_glue.c,v 1.156 2003/11/15 17:25:05 mast Exp $"); #include "gmp_machine.h" #include "module.h" @@ -116,6 +116,7 @@ overflow: else push_object (o); } + #define PUSH_REDUCED(o) do { struct object *reducetmp__=(o); \ if(THIS_PROGRAM == bignum_program) \ mpzmod_reduce(reducetmp__); \ @@ -125,6 +126,18 @@ overflow: #ifdef INT64 +static void gmp_reduce_stack_top_bignum (void) +{ + struct object *o; +#ifdef PIKE_DEBUG + if (sp[-1].type != T_OBJECT || sp[-1].u.object->prog != bignum_program) + Pike_fatal ("Not a Gmp.bignum.\n"); +#endif + o = (--sp)->u.object; + debug_malloc_touch (o); + mpzmod_reduce (o); +} + static void gmp_push_int64 (INT64 i) { if(i == DO_NOT_WARN((INT_TYPE)i)) @@ -1890,7 +1903,7 @@ PIKE_MODULE_EXIT mpz_clear (mpz_int_type_min); #ifdef INT64 mpz_clear (mpz_int64_min); - hook_in_int64_funcs (NULL, NULL); + hook_in_int64_funcs (NULL, NULL, NULL); #endif } #endif @@ -2050,7 +2063,8 @@ PIKE_MODULE_INIT mpz_init (mpz_int64_min); mpz_setbit (mpz_int64_min, INT64_BITS); mpz_neg (mpz_int64_min, mpz_int64_min); - hook_in_int64_funcs (gmp_push_int64, gmp_int64_from_bignum); + hook_in_int64_funcs (gmp_push_int64, gmp_int64_from_bignum, + gmp_reduce_stack_top_bignum); #endif #if 0