From f6a5c628540a78e8c070057e12b4064206f9850b Mon Sep 17 00:00:00 2001 From: Martin Stjernholm <mast@lysator.liu.se> Date: Wed, 2 Apr 2003 02:38:31 +0200 Subject: [PATCH] Fixed initialization of the int64/bignum pointers on systems where it apparently doesn't work to assign function pointers in other modules, e.g. NT. Rev: src/bignum.c:1.38 Rev: src/bignum.h:1.23 Rev: src/modules/Gmp/mpz_glue.c:1.138 --- src/bignum.c | 14 ++++++++++++-- src/bignum.h | 5 ++++- src/modules/Gmp/mpz_glue.c | 18 ++++++++---------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/bignum.c b/src/bignum.c index 7b1c70fba1..0facc6fc8e 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.37 2003/03/29 17:12:17 grubba Exp $ +|| $Id: bignum.c,v 1.38 2003/04/02 00:38:31 mast Exp $ */ #include "global.h" @@ -130,11 +130,21 @@ PMOD_EXPORT void bootstrap_push_int64 (INT64 i) push_int(DO_NOT_WARN((INT_TYPE)i)); } else - Pike_error ("Failed to convert large integer (Gmp.bignum not loaded).\n"); + Pike_fatal ("Failed to convert large integer (Gmp.bignum not loaded).\n"); } PMOD_EXPORT void (*push_int64) (INT64) = bootstrap_push_int64; PMOD_EXPORT int (*int64_from_bignum) (INT64 *, struct object *) = NULL; + +PMOD_EXPORT void hook_in_int64_funcs ( + void (*push_int64_val)(INT64), + int (*int64_from_bignum_val) (INT64 *, struct object *)) +{ + /* 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; +} #endif #endif /* AUTO_BIGNUM */ diff --git a/src/bignum.h b/src/bignum.h index 6e7bebf4b4..59e54b4ccc 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.22 2003/03/29 17:12:17 grubba Exp $ +|| $Id: bignum.h,v 1.23 2003/04/02 00:38:31 mast Exp $ */ #include "global.h" @@ -61,6 +61,9 @@ void convert_svalue_to_bignum(struct svalue *s); PMOD_EXPORT void bootstrap_push_int64(INT64 i); PMOD_EXPORT void (*push_int64)(INT64 i); PMOD_EXPORT int (*int64_from_bignum) (INT64 *i, struct object *bignum); +PMOD_EXPORT void hook_in_int64_funcs ( + void (*push_int64_val)(INT64), + int (*int64_from_bignum_val) (INT64 *, struct object *)); #else #define push_int64(i) push_int((INT_TYPE)(i)) #define int64_from_bignum(I,BIGNUM) 0 diff --git a/src/modules/Gmp/mpz_glue.c b/src/modules/Gmp/mpz_glue.c index 46347db4b1..848fb55c09 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.137 2003/03/29 17:14:22 grubba Exp $ +|| $Id: mpz_glue.c,v 1.138 2003/04/02 00:38:31 mast Exp $ */ #include "global.h" -RCSID("$Id: mpz_glue.c,v 1.137 2003/03/29 17:14:22 grubba Exp $"); +RCSID("$Id: mpz_glue.c,v 1.138 2003/04/02 00:38:31 mast Exp $"); #include "gmp_machine.h" #include "module.h" @@ -143,11 +143,11 @@ static void gmp_push_int64 (INT64 i) ((SIZEOF_INT64 + SIZEOF_LONG - 1) / SIZEOF_LONG - 1) /* The above is the position of the top unsigned long in the INT64. */ * ULONG_BITS; - mpz_set_ui (mpz, (i >> n) & ULONG_MAX); + mpz_set_ui (mpz, (unsigned long) (i >> n)); while (n) { n -= ULONG_BITS; mpz_mul_2exp (mpz, mpz, ULONG_BITS); - mpz_add_ui (mpz, mpz, (i >> n) & ULONG_MAX); + mpz_add_ui (mpz, mpz, (unsigned long) (i >> n)); } } #endif @@ -308,11 +308,11 @@ int get_new_mpz(MP_INT *tmp, struct svalue *s, ((SIZEOF_INT_TYPE + SIZEOF_LONG - 1) / SIZEOF_LONG - 1) /* The above is the position of the top unsigned long in the INT_TYPE. */ * ULONG_BITS; - mpz_set_ui (tmp, (i >> n) & ULONG_MAX); + mpz_set_ui (tmp, (unsigned long) (i >> n)); while (n) { n -= ULONG_BITS; mpz_mul_2exp (tmp, tmp, ULONG_BITS); - mpz_add_ui (tmp, tmp, (i >> n) & ULONG_MAX); + mpz_add_ui (tmp, tmp, (unsigned long) (i >> n)); } } #endif @@ -1724,8 +1724,7 @@ PIKE_MODULE_EXIT mpz_clear (mpz_int_type_min); #ifdef INT64 mpz_clear (mpz_int64_min); - push_int64 = bootstrap_push_int64; - int64_from_bignum = NULL; + hook_in_int64_funcs (NULL, NULL); #endif } #endif @@ -1886,8 +1885,7 @@ PIKE_MODULE_INIT mpz_init (mpz_int64_min); mpz_setbit (mpz_int64_min, INT64_BITS); mpz_neg (mpz_int64_min, mpz_int64_min); - push_int64 = gmp_push_int64; - int64_from_bignum = gmp_int64_from_bignum; + hook_in_int64_funcs (gmp_push_int64, gmp_int64_from_bignum); #endif #if 0 -- GitLab