From c2a577d609e9c213788ef9ada92707c79e709e42 Mon Sep 17 00:00:00 2001 From: Marius Gerbershagen Date: Sat, 4 Jan 2020 18:03:47 +0100 Subject: [PATCH] bignums: prevent bignum registers from growing too big We had this code before, but it made non-functional in commit 20f4c8931e26e231934a19c9c0578d61058fddab and got removed with commit 749b97d06c7be58ac36d9864aa736c8fabfac93b. --- src/c/big.d | 5 ++++- src/h/number.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/c/big.d b/src/c/big.d index 782a227e5..0026e6c48 100644 --- a/src/c/big.d +++ b/src/c/big.d @@ -46,7 +46,10 @@ void _ecl_big_register_free(cl_object x) { - return; + /* We only need to free the integer when it gets too large */ + if (ECL_BIGNUM_DIM(x) > 4 * ECL_BIG_REGISTER_SIZE) { + _ecl_big_realloc2(x, ECL_BIG_REGISTER_SIZE); + } } static cl_object diff --git a/src/h/number.h b/src/h/number.h index 2a0e94ce5..e2fe43a2f 100644 --- a/src/h/number.h +++ b/src/h/number.h @@ -45,6 +45,7 @@ extern ECL_API _ecl_big_binary_op _ecl_big_boole_operator(int op); #define _ecl_big_set_index(x, f) mpz_set_ui((x)->big.big_num,(f)) #endif #define _ecl_big_init2(x,size) mpz_init2((x)->big.big_num,(size)*GMP_LIMB_BITS) +#define _ecl_big_realloc2(x,size) mpz_realloc2((x)->big.big_num,(size)*GMP_LIMB_BITS) #define _ecl_big_clear(x) mpz_clear((x)->big.big_num) #define _ecl_big_set(x,y) mpz_set((x)->big.big_num,(y)->big.big_num) #define _ecl_big_odd_p(x) ((mpz_get_ui(x->big.big_num) & 1) != 0)