From 7a4fe54c26332c21cd95b01cc07bd74714d060ae Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 18 Sep 2017 14:38:26 +0000 Subject: Finish libtommath's constification work. All done (hopefully). And make sure that C preprocessor directives have the '#' as first character on the line. --- generic/tclTomMath.h | 8 ++++---- libtommath/bn_fast_s_mp_mul_high_digs.c | 2 +- libtommath/bn_mp_prime_fermat.c | 2 +- libtommath/bn_mp_prime_is_divisible.c | 2 +- libtommath/bn_mp_prime_is_prime.c | 2 +- libtommath/bn_mp_prime_miller_rabin.c | 2 +- libtommath/bn_s_mp_mul_high_digs.c | 2 +- libtommath/tommath.h | 8 ++++---- libtommath/tommath_private.h | 8 +++----- win/tclAppInit.c | 4 ++-- win/tclWinPipe.c | 12 ++++++------ 11 files changed, 25 insertions(+), 27 deletions(-) diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h index 1f22d6f..c8b2a87 100644 --- a/generic/tclTomMath.h +++ b/generic/tclTomMath.h @@ -663,21 +663,21 @@ MODULE_SCOPE const mp_digit ltm_prime_tab[PRIME_SIZE]; /* result=1 if a is divisible by one of the first PRIME_SIZE primes */ /* -int mp_prime_is_divisible(mp_int *a, int *result); +int mp_prime_is_divisible(const mp_int *a, int *result); */ /* performs one Fermat test of "a" using base "b". * Sets result to 0 if composite or 1 if probable prime */ /* -int mp_prime_fermat(mp_int *a, mp_int *b, int *result); +int mp_prime_fermat(const mp_int *a, const mp_int *b, int *result); */ /* performs one Miller-Rabin test of "a" using base "b". * Sets result to 0 if composite or 1 if probable prime */ /* -int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result); +int mp_prime_miller_rabin(const mp_int *a, const mp_int *b, int *result); */ /* This gives [for a given bit size] the number of trials required @@ -695,7 +695,7 @@ int mp_prime_rabin_miller_trials(int size); * Sets result to 1 if probably prime, 0 otherwise */ /* -int mp_prime_is_prime(mp_int *a, int t, int *result); +int mp_prime_is_prime(const mp_int *a, int t, int *result); */ /* finds the next prime after the number "a" using "t" trials diff --git a/libtommath/bn_fast_s_mp_mul_high_digs.c b/libtommath/bn_fast_s_mp_mul_high_digs.c index 588d80b..8b662ed 100644 --- a/libtommath/bn_fast_s_mp_mul_high_digs.c +++ b/libtommath/bn_fast_s_mp_mul_high_digs.c @@ -24,7 +24,7 @@ * * Based on Algorithm 14.12 on pp.595 of HAC. */ -int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs) +int fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) { int olduse, res, pa, ix, iz; mp_digit W[MP_WARRAY]; diff --git a/libtommath/bn_mp_prime_fermat.c b/libtommath/bn_mp_prime_fermat.c index 37ad6ec..9c15435 100644 --- a/libtommath/bn_mp_prime_fermat.c +++ b/libtommath/bn_mp_prime_fermat.c @@ -23,7 +23,7 @@ * * Sets result to 1 if the congruence holds, or zero otherwise. */ -int mp_prime_fermat(mp_int *a, mp_int *b, int *result) +int mp_prime_fermat(const mp_int *a, const mp_int *b, int *result) { mp_int t; int err; diff --git a/libtommath/bn_mp_prime_is_divisible.c b/libtommath/bn_mp_prime_is_divisible.c index 92af330..c1e1158 100644 --- a/libtommath/bn_mp_prime_is_divisible.c +++ b/libtommath/bn_mp_prime_is_divisible.c @@ -20,7 +20,7 @@ * * sets result to 0 if not, 1 if yes */ -int mp_prime_is_divisible(mp_int *a, int *result) +int mp_prime_is_divisible(const mp_int *a, int *result) { int err, ix; mp_digit res; diff --git a/libtommath/bn_mp_prime_is_prime.c b/libtommath/bn_mp_prime_is_prime.c index 20a7d1f..e97712d 100644 --- a/libtommath/bn_mp_prime_is_prime.c +++ b/libtommath/bn_mp_prime_is_prime.c @@ -22,7 +22,7 @@ * * Sets result to 1 if probably prime, 0 otherwise */ -int mp_prime_is_prime(mp_int *a, int t, int *result) +int mp_prime_is_prime(const mp_int *a, int t, int *result) { mp_int b; int ix, err, res; diff --git a/libtommath/bn_mp_prime_miller_rabin.c b/libtommath/bn_mp_prime_miller_rabin.c index 917dc01..5de5f05 100644 --- a/libtommath/bn_mp_prime_miller_rabin.c +++ b/libtommath/bn_mp_prime_miller_rabin.c @@ -22,7 +22,7 @@ * Randomly the chance of error is no more than 1/4 and often * very much lower. */ -int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result) +int mp_prime_miller_rabin(const mp_int *a, const mp_int *b, int *result) { mp_int n1, y, r; int s, j, err; diff --git a/libtommath/bn_s_mp_mul_high_digs.c b/libtommath/bn_s_mp_mul_high_digs.c index 44d0d21..0a829b9 100644 --- a/libtommath/bn_s_mp_mul_high_digs.c +++ b/libtommath/bn_s_mp_mul_high_digs.c @@ -19,7 +19,7 @@ * [meant to get the higher part of the product] */ int -s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs) +s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) { mp_int t; int res, pa, pb, ix, iy; diff --git a/libtommath/tommath.h b/libtommath/tommath.h index 513b5b9..dee7ab5 100644 --- a/libtommath/tommath.h +++ b/libtommath/tommath.h @@ -464,17 +464,17 @@ int mp_exptmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d); extern const mp_digit ltm_prime_tab[PRIME_SIZE]; /* result=1 if a is divisible by one of the first PRIME_SIZE primes */ -int mp_prime_is_divisible(mp_int *a, int *result); +int mp_prime_is_divisible(const mp_int *a, int *result); /* performs one Fermat test of "a" using base "b". * Sets result to 0 if composite or 1 if probable prime */ -int mp_prime_fermat(mp_int *a, mp_int *b, int *result); +int mp_prime_fermat(const mp_int *a, const mp_int *b, int *result); /* performs one Miller-Rabin test of "a" using base "b". * Sets result to 0 if composite or 1 if probable prime */ -int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result); +int mp_prime_miller_rabin(const mp_int *a, const mp_int *b, int *result); /* This gives [for a given bit size] the number of trials required * such that Miller-Rabin gives a prob of failure lower than 2^-96 @@ -488,7 +488,7 @@ int mp_prime_rabin_miller_trials(int size); * * Sets result to 1 if probably prime, 0 otherwise */ -int mp_prime_is_prime(mp_int *a, int t, int *result); +int mp_prime_is_prime(const mp_int *a, int t, int *result); /* finds the next prime after the number "a" using "t" trials * of Miller-Rabin. diff --git a/libtommath/tommath_private.h b/libtommath/tommath_private.h index 58846bf..be065cd 100644 --- a/libtommath/tommath_private.h +++ b/libtommath/tommath_private.h @@ -40,21 +40,19 @@ extern "C" { #endif /* define heap macros */ -#if 0 #ifndef XMALLOC /* default to libc stuff */ # define XMALLOC malloc # define XFREE free # define XREALLOC realloc # define XCALLOC calloc -#else +#elif 0 /* prototypes for our heap functions */ extern void *XMALLOC(size_t n); extern void *XREALLOC(void *p, size_t n); extern void *XCALLOC(size_t n, size_t s); extern void XFREE(void *p); #endif -#endif /* lowlevel functions, do not call! */ int s_mp_add(const mp_int *a, const mp_int *b, mp_int *c); @@ -62,8 +60,8 @@ int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c); #define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1) int fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); int s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); -int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs); -int s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs); +int fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); +int s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); int fast_s_mp_sqr(const mp_int *a, mp_int *b); int s_mp_sqr(const mp_int *a, mp_int *b); int mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c); diff --git a/win/tclAppInit.c b/win/tclAppInit.c index e06eaf5..ef9f98b 100644 --- a/win/tclAppInit.c +++ b/win/tclAppInit.c @@ -263,8 +263,8 @@ setargv( } /* Make sure we don't call ckalloc through the (not yet initialized) stub table */ - #undef Tcl_Alloc - #undef Tcl_DbCkalloc +# undef Tcl_Alloc +# undef Tcl_DbCkalloc argSpace = ckalloc(size * sizeof(char *) + (_tcslen(cmdLine) * sizeof(TCHAR)) + sizeof(TCHAR)); diff --git a/win/tclWinPipe.c b/win/tclWinPipe.c index 4b372a5..5f1aa70 100644 --- a/win/tclWinPipe.c +++ b/win/tclWinPipe.c @@ -3392,11 +3392,11 @@ TclPipeThreadStop( SetEvent(pipeTI->evWakeUp); } CloseHandle(pipeTI->evControl); - #ifndef _PTI_USE_CKALLOC +# ifndef _PTI_USE_CKALLOC free(pipeTI); - #else +# else ckfree(pipeTI); - #endif +# endif } } @@ -3440,13 +3440,13 @@ TclPipeThreadExit( if (pipeTI->evWakeUp) { SetEvent(pipeTI->evWakeUp); } - #ifndef _PTI_USE_CKALLOC +# ifndef _PTI_USE_CKALLOC free(pipeTI); - #else +# else ckfree(pipeTI); /* be sure all subsystems used are finalized */ Tcl_FinalizeThread(); - #endif +# endif } } -- cgit v0.12