diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-04-08 19:06:57 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-04-08 19:06:57 (GMT) |
commit | bb3ef949858f5fa0190e37b1b7642dc29369e152 (patch) | |
tree | c5a4adb58d37c94899c477464aba5e5ad1ba6c6f | |
parent | 4865914200b6c412220d621f3cce4f355ad38554 (diff) | |
parent | 0305f67f8865a7b2e60d80e0dd4bfb2b4d30e024 (diff) | |
download | tcl-bb3ef949858f5fa0190e37b1b7642dc29369e152.zip tcl-bb3ef949858f5fa0190e37b1b7642dc29369e152.tar.gz tcl-bb3ef949858f5fa0190e37b1b7642dc29369e152.tar.bz2 |
Merge 8.7. Intended operation completed for mingw-w64 (but not yet for other compilers/platforms)
-rw-r--r-- | .travis.yml | 31 | ||||
-rw-r--r-- | generic/tclStubInit.c | 94 | ||||
-rw-r--r-- | generic/tclTomMath.h | 11 | ||||
-rw-r--r-- | generic/tclTomMathDecls.h | 174 | ||||
-rw-r--r-- | generic/tclVar.c | 11 | ||||
-rw-r--r-- | libtommath/bn_mp_get_long_long.c | 4 | ||||
-rw-r--r-- | libtommath/bn_mp_prime_strong_lucas_selfridge.c | 2 | ||||
-rw-r--r-- | libtommath/bn_mp_set_double.c | 4 | ||||
-rw-r--r-- | libtommath/makefile.mingw | 6 | ||||
-rw-r--r-- | libtommath/tommath.h | 29 | ||||
-rwxr-xr-x | libtommath/win32/libtommath.dll | bin | 0 -> 66560 bytes | |||
-rw-r--r-- | libtommath/win32/tommath.lib | bin | 0 -> 88136 bytes | |||
-rwxr-xr-x | libtommath/win64/libtommath.dll | bin | 0 -> 75264 bytes | |||
-rw-r--r-- | libtommath/win64/libtommath.dll.a | bin | 0 -> 86060 bytes | |||
-rw-r--r-- | tests/cmdMZ.test | 17 | ||||
-rw-r--r-- | win/Makefile.in | 29 | ||||
-rwxr-xr-x | win/configure | 35 | ||||
-rw-r--r-- | win/configure.ac | 11 |
18 files changed, 343 insertions, 115 deletions
diff --git a/.travis.yml b/.travis.yml index 3770e07..59b52eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -160,6 +160,22 @@ matrix: - wine env: - BUILD_DIR=win + - CFGOPT="--host=i686-w64-mingw32 --disable-shared" + - NO_DIRECT_TEST=1 + - os: linux + dist: xenial + compiler: i686-w64-mingw32-gcc + addons: + apt: + packages: + - gcc-mingw-w64-base + - binutils-mingw-w64-i686 + - gcc-mingw-w64-i686 + - gcc-mingw-w64 + - gcc-multilib + - wine + env: + - BUILD_DIR=win - CFGOPT="--host=i686-w64-mingw32 CFLAGS=-DTCL_UTF_MAX=6" - NO_DIRECT_TEST=1 - os: linux @@ -223,6 +239,21 @@ matrix: - wine env: - BUILD_DIR=win + - CFGOPT="--host=x86_64-w64-mingw32 --enable-64bit --disable-shared" + - NO_DIRECT_TEST=1 + - os: linux + dist: xenial + compiler: x86_64-w64-mingw32-gcc + addons: + apt: + packages: + - gcc-mingw-w64-base + - binutils-mingw-w64-x86-64 + - gcc-mingw-w64-x86-64 + - gcc-mingw-w64 + - wine + env: + - BUILD_DIR=win - CFGOPT="--host=x86_64-w64-mingw32 --enable-64bit CFLAGS=-DTCL_UTF_MAX=6" - NO_DIRECT_TEST=1 - os: linux diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index 197ed84..06f251a 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -10,7 +10,7 @@ */ #include "tclInt.h" -#include "tommath.h" +#include "tclTomMath.h" #ifdef __CYGWIN__ # include <wchar.h> @@ -61,6 +61,98 @@ #undef Tcl_BackgroundError #define TclStaticPackage Tcl_StaticPackage +#define TclBN_mp_add mp_add +#define TclBN_mp_add_d mp_add_d +#define TclBN_mp_and mp_and +#define TclBN_mp_clamp mp_clamp +#define TclBN_mp_clear mp_clear +#define TclBN_mp_clear_multi mp_clear_multi +#define TclBN_mp_cmp mp_cmp +#define TclBN_mp_cmp_d mp_cmp_d +#define TclBN_mp_cmp_mag mp_cmp_mag +#define TclBN_mp_cnt_lsb mp_cnt_lsb +#define TclBN_mp_copy mp_copy +#define TclBN_mp_count_bits mp_count_bits +#define TclBN_mp_div mp_div +#define TclBN_mp_div_2 mp_div_2 +#define TclBN_mp_div_2d mp_div_2d +#define TclBN_mp_div_3 mp_div_3 +#define TclBN_mp_div_d mp_div_d +#define TclBN_mp_exch mp_exch +#define TclBN_mp_expt_d mp_expt_d +#define TclBN_mp_expt_d_ex mp_expt_d_ex +#define TclBN_mp_get_bit mp_get_bit +#define TclBN_mp_get_int mp_get_int +#define TclBN_mp_get_long mp_get_long +#define TclBN_mp_get_long_long mp_get_long_long +#define TclBN_mp_grow mp_grow +#define TclBN_mp_init mp_init +#define TclBN_mp_init_copy mp_init_copy +#define TclBN_mp_init_multi mp_init_multi +#define TclBN_mp_init_set mp_init_set +#define TclBN_mp_init_set_int mp_init_set_int +#define TclBN_mp_init_size mp_init_size +#define TclBN_mp_karatsuba_mul mp_karatsuba_mul +#define TclBN_mp_karatsuba_sqr mp_karatsuba_sqr +#define TclBN_mp_lshd mp_lshd +#define TclBN_mp_mod mp_mod +#define TclBN_mp_mod_2d mp_mod_2d +#define TclBN_mp_mul mp_mul +#define TclBN_mp_mul_2 mp_mul_2 +#define TclBN_mp_mul_2d mp_mul_2d +#define TclBN_mp_mul_d mp_mul_d +#define TclBN_mp_neg mp_neg +#define TclBN_mp_or mp_or +#define TclBN_mp_radix_size mp_radix_size +#define TclBN_mp_read_radix mp_read_radix +#define TclBN_mp_rshd mp_rshd +#define TclBN_mp_set mp_set +#define TclBN_mp_set_int mp_set_int +#define TclBN_mp_set_long mp_set_long +#define TclBN_mp_set_long_long mp_set_long_long +#define TclBN_mp_shrink mp_shrink +#define TclBN_mp_sqr mp_sqr +#define TclBN_mp_sqrt mp_sqrt +#define TclBN_mp_sub mp_sub +#define TclBN_mp_sub_d mp_sub_d +#define TclBN_mp_tc_and mp_tc_and +#define TclBN_mp_tc_div_2d mp_tc_div_2d +#define TclBN_mp_tc_or mp_tc_or +#define TclBN_mp_tc_xor mp_tc_xor +#define TclBN_mp_to_unsigned_bin mp_to_unsigned_bin +#define TclBN_mp_to_unsigned_bin_n mp_to_unsigned_bin_n +#define TclBN_mp_toom_mul mp_toom_mul +#define TclBN_mp_toom_sqr mp_toom_sqr +#define TclBN_mp_toradix_n mp_toradix_n +#define TclBN_mp_unsigned_bin_size mp_unsigned_bin_size +#define TclBN_mp_xor mp_xor +#define TclBN_mp_zero mp_zero +#define TclBN_reverse bn_reverse +#define TclBN_fast_s_mp_mul_digs fast_s_mp_mul_digs +#define TclBN_fast_s_mp_sqr fast_s_mp_sqr +#define TclBN_mp_karatsuba_mul mp_karatsuba_mul +#define TclBN_mp_karatsuba_sqr mp_karatsuba_sqr +#define TclBN_mp_toom_mul mp_toom_mul +#define TclBN_mp_toom_sqr mp_toom_sqr +#define TclBN_s_mp_add s_mp_add +#define TclBN_s_mp_mul_digs s_mp_mul_digs +#define TclBN_s_mp_sqr s_mp_sqr +#define TclBN_s_mp_sub s_mp_sub +#define TclBN_mp_init_set_int mp_init_set_int +#define TclBN_mp_set_int mp_set_int +#define TclBN_mp_cnt_lsb mp_cnt_lsb +#define TclBN_mp_expt_d_ex mp_expt_d_ex +#define TclBN_mp_set_long_long mp_set_long_long +#define TclBN_mp_get_long_long mp_get_long_long +#define TclBN_mp_set_long mp_set_long +#define TclBN_mp_get_long mp_get_long +#define TclBN_mp_get_int mp_get_int +#define TclBN_mp_tc_and mp_tc_and +#define TclBN_mp_tc_or mp_tc_or +#define TclBN_mp_tc_xor mp_tc_xor +#define TclBN_mp_tc_div_2d mp_tc_div_2d +#define TclBN_mp_get_bit mp_get_bit + /* See bug 510001: TclSockMinimumBuffers needs plat imp */ #if defined(_WIN64) || defined(TCL_NO_DEPRECATED) || TCL_MAJOR_VERSION > 8 # define TclSockMinimumBuffersOld 0 diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h index bf541d8..2fbe6a2 100644 --- a/generic/tclTomMath.h +++ b/generic/tclTomMath.h @@ -23,7 +23,7 @@ extern "C" { #endif /* MS Visual C++ doesn't have a 128bit type for words, so fall back to 32bit MPI's (where words are 64bit) */ -#if defined(_WIN32) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__) +#if (defined(_MSC_VER) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__)) && !defined(MP_64BIT) # define MP_32BIT #endif @@ -34,7 +34,7 @@ extern "C" { defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__) || \ defined(__ia64) || defined(__ia64__) || defined(__itanium__) || defined(_M_IA64) || \ defined(__LP64__) || defined(_LP64) || defined(__64BIT__) -# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT)) +# if !(defined(MP_64BIT) || defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT)) # if defined(__GNUC__) /* we support 128bit integers only via: __attribute__((mode(TI))) */ # define MP_64BIT @@ -65,8 +65,11 @@ typedef unsigned short mp_digit; # error You must not define DIGIT_BIT when using MP_16BIT # endif #elif defined(MP_64BIT) -/* for GCC only on supported platforms */ +# ifdef _WIN32 +typedef unsigned __int64 mp_digit; +# else typedef unsigned long long mp_digit; +# endif # define DIGIT_BIT 60 #else /* this is the default case, 28-bit digits */ @@ -89,9 +92,7 @@ typedef unsigned int mp_digit; # define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */ #endif -#define MP_DIGIT_BIT DIGIT_BIT #define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1)) -#define MP_DIGIT_MAX MP_MASK /* equalities */ #define MP_LT -1 /* less than */ diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h index 165e3b7..afe704f 100644 --- a/generic/tclTomMathDecls.h +++ b/generic/tclTomMathDecls.h @@ -41,82 +41,108 @@ #define XFREE(mem, size) TclBNFree(mem) #define XREALLOC(mem, oldsize, newsize) TclBNRealloc(mem, newsize) - +#ifndef MODULE_SCOPE +# define MODULE_SCOPE extern +#endif /* Rename the global symbols in libtommath to avoid linkage conflicts */ -#define bn_reverse TclBN_reverse -#define fast_s_mp_mul_digs TclBN_fast_s_mp_mul_digs -#define fast_s_mp_sqr TclBN_fast_s_mp_sqr -#define mp_add TclBN_mp_add -#define mp_add_d TclBN_mp_add_d -#define mp_and TclBN_mp_and -#define mp_clamp TclBN_mp_clamp -#define mp_clear TclBN_mp_clear -#define mp_clear_multi TclBN_mp_clear_multi -#define mp_cmp TclBN_mp_cmp -#define mp_cmp_d TclBN_mp_cmp_d -#define mp_cmp_mag TclBN_mp_cmp_mag -#define mp_cnt_lsb TclBN_mp_cnt_lsb -#define mp_copy TclBN_mp_copy -#define mp_count_bits TclBN_mp_count_bits -#define mp_div TclBN_mp_div -#define mp_div_2 TclBN_mp_div_2 -#define mp_div_2d TclBN_mp_div_2d -#define mp_div_3 TclBN_mp_div_3 -#define mp_div_d TclBN_mp_div_d -#define mp_exch TclBN_mp_exch -#define mp_expt_d TclBN_mp_expt_d -#define mp_expt_d_ex TclBN_mp_expt_d_ex -#define mp_get_bit TclBN_mp_get_bit -#define mp_get_int TclBN_mp_get_int -#define mp_get_long TclBN_mp_get_long -#define mp_get_long_long TclBN_mp_get_long_long -#define mp_grow TclBN_mp_grow -#define mp_init TclBN_mp_init -#define mp_init_copy TclBN_mp_init_copy -#define mp_init_multi TclBN_mp_init_multi -#define mp_init_set TclBN_mp_init_set -#define mp_init_set_int TclBN_mp_init_set_int -#define mp_init_size TclBN_mp_init_size -#define mp_karatsuba_mul TclBN_mp_karatsuba_mul -#define mp_karatsuba_sqr TclBN_mp_karatsuba_sqr -#define mp_lshd TclBN_mp_lshd -#define mp_mod TclBN_mp_mod -#define mp_mod_2d TclBN_mp_mod_2d -#define mp_mul TclBN_mp_mul -#define mp_mul_2 TclBN_mp_mul_2 -#define mp_mul_2d TclBN_mp_mul_2d -#define mp_mul_d TclBN_mp_mul_d -#define mp_neg TclBN_mp_neg -#define mp_or TclBN_mp_or -#define mp_radix_size TclBN_mp_radix_size -#define mp_read_radix TclBN_mp_read_radix -#define mp_rshd TclBN_mp_rshd -#define mp_set TclBN_mp_set -#define mp_set_int TclBN_mp_set_int -#define mp_set_long TclBN_mp_set_long -#define mp_set_long_long TclBN_mp_set_long_long -#define mp_shrink TclBN_mp_shrink -#define mp_sqr TclBN_mp_sqr -#define mp_sqrt TclBN_mp_sqrt -#define mp_sub TclBN_mp_sub -#define mp_sub_d TclBN_mp_sub_d -#define mp_tc_and TclBN_mp_tc_and -#define mp_tc_div_2d TclBN_mp_tc_div_2d -#define mp_tc_or TclBN_mp_tc_or -#define mp_tc_xor TclBN_mp_tc_xor -#define mp_to_unsigned_bin TclBN_mp_to_unsigned_bin -#define mp_to_unsigned_bin_n TclBN_mp_to_unsigned_bin_n -#define mp_toom_mul TclBN_mp_toom_mul -#define mp_toom_sqr TclBN_mp_toom_sqr -#define mp_toradix_n TclBN_mp_toradix_n -#define mp_unsigned_bin_size TclBN_mp_unsigned_bin_size -#define mp_xor TclBN_mp_xor -#define mp_zero TclBN_mp_zero -#define s_mp_add TclBN_s_mp_add -#define s_mp_mul_digs TclBN_s_mp_mul_digs -#define s_mp_sqr TclBN_s_mp_sqr -#define s_mp_sub TclBN_s_mp_sub +MODULE_SCOPE int mp_add(const mp_int *a, const mp_int *b, + mp_int *c); +MODULE_SCOPE int mp_add_d(const mp_int *a, mp_digit b, + mp_int *c); +MODULE_SCOPE int mp_and(const mp_int *a, const mp_int *b, + mp_int *c); +MODULE_SCOPE void mp_clamp(mp_int *a); +MODULE_SCOPE void mp_clear(mp_int *a); +MODULE_SCOPE void mp_clear_multi(mp_int *a, ...); +MODULE_SCOPE int mp_cmp(const mp_int *a, const mp_int *b); +MODULE_SCOPE int mp_cmp_d(const mp_int *a, mp_digit b); +MODULE_SCOPE int mp_cmp_mag(const mp_int *a, const mp_int *b); +MODULE_SCOPE int mp_copy(const mp_int *a, mp_int *b); +MODULE_SCOPE int mp_count_bits(const mp_int *a); +MODULE_SCOPE int mp_div(const mp_int *a, const mp_int *b, + mp_int *q, mp_int *r); +MODULE_SCOPE int mp_div_d(const mp_int *a, mp_digit b, + mp_int *q, mp_digit *r); +MODULE_SCOPE int mp_div_2(const mp_int *a, mp_int *q); +MODULE_SCOPE int mp_div_2d(const mp_int *a, int b, mp_int *q, + mp_int *r); +MODULE_SCOPE int mp_div_3(const mp_int *a, mp_int *q, + mp_digit *r); +MODULE_SCOPE void mp_exch(mp_int *a, mp_int *b); +MODULE_SCOPE int mp_expt_d(const mp_int *a, mp_digit b, + mp_int *c); +MODULE_SCOPE int mp_grow(mp_int *a, int size); +MODULE_SCOPE int mp_init(mp_int *a); +MODULE_SCOPE int mp_init_copy(mp_int *a, const mp_int *b); +MODULE_SCOPE int mp_init_multi(mp_int *a, ...); +MODULE_SCOPE int mp_init_set(mp_int *a, mp_digit b); +MODULE_SCOPE int mp_init_size(mp_int *a, int size); +MODULE_SCOPE int mp_lshd(mp_int *a, int shift); +MODULE_SCOPE int mp_mod(const mp_int *a, const mp_int *b, + mp_int *r); +MODULE_SCOPE int mp_mod_2d(const mp_int *a, int b, mp_int *r); +MODULE_SCOPE int mp_mul(const mp_int *a, const mp_int *b, + mp_int *p); +MODULE_SCOPE int mp_mul_d(const mp_int *a, mp_digit b, + mp_int *p); +MODULE_SCOPE int mp_mul_2(const mp_int *a, mp_int *p); +MODULE_SCOPE int mp_mul_2d(const mp_int *a, int d, mp_int *p); +MODULE_SCOPE int mp_neg(const mp_int *a, mp_int *b); +MODULE_SCOPE int mp_or(const mp_int *a, const mp_int *b, + mp_int *c); +MODULE_SCOPE int mp_radix_size(const mp_int *a, int radix, + int *size); +MODULE_SCOPE int mp_read_radix(mp_int *a, const char *str, + int radix); +MODULE_SCOPE void mp_rshd(mp_int *a, int shift); +MODULE_SCOPE int mp_shrink(mp_int *a); +MODULE_SCOPE void mp_set(mp_int *a, mp_digit b); +MODULE_SCOPE int mp_sqr(const mp_int *a, mp_int *b); +MODULE_SCOPE int mp_sqrt(const mp_int *a, mp_int *b); +MODULE_SCOPE int mp_sub(const mp_int *a, const mp_int *b, + mp_int *c); +MODULE_SCOPE int mp_sub_d(const mp_int *a, mp_digit b, + mp_int *c); +MODULE_SCOPE int mp_to_unsigned_bin(const mp_int *a, + unsigned char *b); +MODULE_SCOPE int mp_to_unsigned_bin_n(const mp_int *a, + unsigned char *b, unsigned long *outlen); +MODULE_SCOPE int mp_toradix_n(const mp_int *a, char *str, + int radix, int maxlen); +MODULE_SCOPE int mp_unsigned_bin_size(const mp_int *a); +MODULE_SCOPE int mp_xor(const mp_int *a, const mp_int *b, + mp_int *c); +MODULE_SCOPE void mp_zero(mp_int *a); +MODULE_SCOPE void bn_reverse(unsigned char *s, int len); +MODULE_SCOPE int fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); +MODULE_SCOPE int fast_s_mp_sqr(const mp_int *a, mp_int *b); +MODULE_SCOPE int mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c); +MODULE_SCOPE int mp_karatsuba_sqr(const mp_int *a, mp_int *b); +MODULE_SCOPE int mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c); +MODULE_SCOPE int mp_toom_sqr(const mp_int *a, mp_int *b); +MODULE_SCOPE int s_mp_add(const mp_int *a, const mp_int *b, mp_int *c); +MODULE_SCOPE int s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); +MODULE_SCOPE int s_mp_sqr(const mp_int *a, mp_int *b); +MODULE_SCOPE int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c); +MODULE_SCOPE int mp_init_set_int(mp_int *a, unsigned long i); +MODULE_SCOPE int mp_set_int(mp_int *a, unsigned long i); +MODULE_SCOPE int mp_cnt_lsb(const mp_int *a); +MODULE_SCOPE int mp_expt_d_ex(const mp_int *a, mp_digit b, + mp_int *c, int fast); +MODULE_SCOPE int mp_set_long_long(mp_int *a, Tcl_WideUInt i); +MODULE_SCOPE Tcl_WideUInt mp_get_long_long(const mp_int *a); +MODULE_SCOPE int mp_set_long(mp_int *a, unsigned long i); +MODULE_SCOPE unsigned long mp_get_long(const mp_int *a); +MODULE_SCOPE unsigned long mp_get_int(const mp_int *a); +MODULE_SCOPE int mp_tc_and(const mp_int *a, const mp_int *b, + mp_int *c); +MODULE_SCOPE int mp_tc_or(const mp_int *a, const mp_int *b, + mp_int *c); +MODULE_SCOPE int mp_tc_xor(const mp_int *a, const mp_int *b, + mp_int *c); +MODULE_SCOPE int mp_tc_div_2d(const mp_int *a, int b, mp_int *c); +MODULE_SCOPE int mp_get_bit(const mp_int *a, int b); #undef TCL_STORAGE_CLASS #ifdef BUILD_tcl diff --git a/generic/tclVar.c b/generic/tclVar.c index 3271935..affc848 100644 --- a/generic/tclVar.c +++ b/generic/tclVar.c @@ -722,7 +722,7 @@ TclObjLookupVarEx( Tcl_Obj *cachedNamePtr = localName(varFramePtr, index); if (part1Ptr == cachedNamePtr) { - cachedNamePtr = NULL; + LocalSetIntRep(part1Ptr, index, NULL); } else { /* * [80304238ac] Trickiness here. We will store and incr the @@ -735,6 +735,14 @@ TclObjLookupVarEx( * cachedNamePtr and leave it as string only. This is * radical and destructive, so a better idea would be welcome. */ + + /* + * Firstly set cached local var reference (avoid free before set, + * see [45b9faf103f2]) + */ + LocalSetIntRep(part1Ptr, index, cachedNamePtr); + + /* Then wipe it */ TclFreeIntRep(cachedNamePtr); /* @@ -744,7 +752,6 @@ TclObjLookupVarEx( */ LocalSetIntRep(cachedNamePtr, index, NULL); } - LocalSetIntRep(part1Ptr, index, cachedNamePtr); } else { /* * At least mark part1Ptr as already parsed. diff --git a/libtommath/bn_mp_get_long_long.c b/libtommath/bn_mp_get_long_long.c index 49a0208..333c6d1 100644 --- a/libtommath/bn_mp_get_long_long.c +++ b/libtommath/bn_mp_get_long_long.c @@ -26,11 +26,11 @@ Tcl_WideUInt mp_get_long_long(const mp_int *a) i = MIN(a->used, (((CHAR_BIT * (int)sizeof(Tcl_WideUInt)) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; /* get most significant digit of result */ - res = (unsigned long long)a->dp[i]; + res = (Tcl_WideUInt)a->dp[i]; #if DIGIT_BIT < 64 while (--i >= 0) { - res = (res << DIGIT_BIT) | (unsigned long long)a->dp[i]; + res = (res << DIGIT_BIT) | (Tcl_WideUInt)a->dp[i]; } #endif return res; diff --git a/libtommath/bn_mp_prime_strong_lucas_selfridge.c b/libtommath/bn_mp_prime_strong_lucas_selfridge.c index 5a94f8e..d20b4d7 100644 --- a/libtommath/bn_mp_prime_strong_lucas_selfridge.c +++ b/libtommath/bn_mp_prime_strong_lucas_selfridge.c @@ -80,7 +80,7 @@ int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result) /* CZ TODO: choose better variable names! */ mp_int Dz, gcd, Np1, Uz, Vz, U2mz, V2mz, Qmz, Q2mz, Qkdz, T1z, T2z, T3z, T4z, Q2kdz; /* CZ TODO: Some of them need the full 32 bit, hence the (temporary) exclusion of MP_8BIT */ - int32_t D, Ds, J, sign, P, Q, r, s, u, Nbits; + int D, Ds, J, sign, P, Q, r, s, u, Nbits; int e; int isset, oddness; diff --git a/libtommath/bn_mp_set_double.c b/libtommath/bn_mp_set_double.c index c96a3b3..51badbe 100644 --- a/libtommath/bn_mp_set_double.c +++ b/libtommath/bn_mp_set_double.c @@ -15,11 +15,11 @@ #if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559) int mp_set_double(mp_int *a, double b) { - uint64_t frac; + Tcl_WideUInt frac; int exp, res; union { double dbl; - uint64_t bits; + Tcl_WideUInt bits; } cast; cast.dbl = b; diff --git a/libtommath/makefile.mingw b/libtommath/makefile.mingw index ec0de2b..222b1b6 100644 --- a/libtommath/makefile.mingw +++ b/libtommath/makefile.mingw @@ -11,7 +11,7 @@ #The following can be overridden from command line e.g. make -f makefile.mingw CC=gcc ARFLAGS=rcs PREFIX = c:\mingw -CC = gcc +CC = i686-w64-mingw32-gcc AR = ar ARFLAGS = r RANLIB = ranlib @@ -21,7 +21,7 @@ LDFLAGS = #Compilation flags LTM_CFLAGS = -I. $(CFLAGS) -LTM_LDFLAGS = $(LDFLAGS) +LTM_LDFLAGS = $(LDFLAGS) -static-libgcc #Libraries to be created LIBMAIN_S =libtommath.a @@ -54,7 +54,7 @@ bn_mp_sub_d.o bn_mp_submod.o bn_mp_tc_and.o bn_mp_tc_div_2d.o bn_mp_tc_or.o bn_m bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o \ bn_mp_toom_mul.o bn_mp_toom_sqr.o bn_mp_toradix.o bn_mp_toradix_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o \ bn_mp_zero.o bn_prime_tab.o bn_reverse.o bn_s_mp_add.o bn_s_mp_exptmod.o bn_s_mp_mul_digs.o \ -bn_s_mp_mul_high_digs.o bn_s_mp_sqr.o bn_s_mp_sub.o bncore.o +bn_s_mp_mul_high_digs.o bn_s_mp_sqr.o bn_s_mp_sub.o HEADERS_PUB=tommath.h tommath_class.h tommath_superclass.h diff --git a/libtommath/tommath.h b/libtommath/tommath.h index 66e2d8c..5c0a186 100644 --- a/libtommath/tommath.h +++ b/libtommath/tommath.h @@ -12,10 +12,13 @@ #ifndef BN_H_ #define BN_H_ -#include <stdio.h> #include <stdlib.h> #include <limits.h> +#ifndef LTM_NO_FILE +# include <stdio.h> +#endif + #include "tommath_class.h" #ifdef __cplusplus @@ -23,7 +26,7 @@ extern "C" { #endif /* MS Visual C++ doesn't have a 128bit type for words, so fall back to 32bit MPI's (where words are 64bit) */ -#if defined(_WIN32) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__) +#if (defined(_MSC_VER) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__)) && !defined(MP_64BIT) # define MP_32BIT #endif @@ -34,7 +37,7 @@ extern "C" { defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__) || \ defined(__ia64) || defined(__ia64__) || defined(__itanium__) || defined(_M_IA64) || \ defined(__LP64__) || defined(_LP64) || defined(__64BIT__) -# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT)) +# if !(defined(MP_64BIT) || defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT)) # if defined(__GNUC__) /* we support 128bit integers only via: __attribute__((mode(TI))) */ # define MP_64BIT @@ -45,8 +48,6 @@ extern "C" { # endif #endif -typedef unsigned long long Tcl_WideUInt; - /* some default configurations. * * A "mp_digit" must be able to hold DIGIT_BIT + 1 bits @@ -67,8 +68,11 @@ typedef unsigned short mp_digit; # error You must not define DIGIT_BIT when using MP_16BIT # endif #elif defined(MP_64BIT) -/* for GCC only on supported platforms */ +# ifdef _WIN32 +typedef unsigned __int64 mp_digit; +# else typedef unsigned long long mp_digit; +# endif # define DIGIT_BIT 60 #else /* this is the default case, 28-bit digits */ @@ -86,6 +90,11 @@ typedef unsigned int mp_digit; # endif #endif +/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */ +#ifndef DIGIT_BIT +# define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */ +#endif + #define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1)) /* equalities */ @@ -125,10 +134,14 @@ typedef int mp_err; #endif /* the infamous mp_int structure */ -typedef struct { +#ifndef MP_INT_DECLARED +#define MP_INT_DECLARED +typedef struct mp_int mp_int; +#endif +struct mp_int { int used, alloc, sign; mp_digit *dp; -} mp_int; +}; /* callback for mp_prime_random, should fill dst with random bytes and return how many read [upto len] */ typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat); diff --git a/libtommath/win32/libtommath.dll b/libtommath/win32/libtommath.dll Binary files differnew file mode 100755 index 0000000..4497517 --- /dev/null +++ b/libtommath/win32/libtommath.dll diff --git a/libtommath/win32/tommath.lib b/libtommath/win32/tommath.lib Binary files differnew file mode 100644 index 0000000..8628471 --- /dev/null +++ b/libtommath/win32/tommath.lib diff --git a/libtommath/win64/libtommath.dll b/libtommath/win64/libtommath.dll Binary files differnew file mode 100755 index 0000000..77d685b --- /dev/null +++ b/libtommath/win64/libtommath.dll diff --git a/libtommath/win64/libtommath.dll.a b/libtommath/win64/libtommath.dll.a Binary files differnew file mode 100644 index 0000000..54a76d7 --- /dev/null +++ b/libtommath/win64/libtommath.dll.a diff --git a/tests/cmdMZ.test b/tests/cmdMZ.test index d79e9f6..80258dc 100644 --- a/tests/cmdMZ.test +++ b/tests/cmdMZ.test @@ -409,6 +409,23 @@ test cmdMZ-6.10 {Tcl_TimeRateObjCmd: huge overhead cause 0us result} { [expr {[lindex $m1 6] <= 0.001}] } {1 1 1 1} +test cmdMZ-try-1.0 { + + fix for issue 45b9faf103f2 + + [try] interaction with local variable names produces segmentation violation + +} -body { + ::apply {{} { + set cmd try + $cmd { + lindex 5 + } on ok res {} + set res + }} +} -result 5 + + # The tests for Tcl_WhileObjCmd are in while.test # cleanup diff --git a/win/Makefile.in b/win/Makefile.in index faf4b77..be1ef9d 100644 --- a/win/Makefile.in +++ b/win/Makefile.in @@ -98,11 +98,11 @@ SRC_DIR = @srcdir@ ROOT_DIR = @srcdir@/.. TOP_DIR = $(shell cd @srcdir@/..; pwd -P) GENERIC_DIR = $(TOP_DIR)/generic -TOMMATH_DIR = $(TOP_DIR)/libtommath WIN_DIR = $(TOP_DIR)/win COMPAT_DIR = $(TOP_DIR)/compat PKGS_DIR = $(TOP_DIR)/pkgs ZLIB_DIR = $(COMPAT_DIR)/zlib +TOMMATH_DIR = $(TOP_DIR)/libtommath # Converts a POSIX path to a Windows native path. CYGPATH = @CYGPATH@ @@ -113,15 +113,11 @@ includedir_native = $(shell $(CYGPATH) '$(includedir)') mandir_native = $(shell $(CYGPATH) '$(mandir)') TCL_LIBRARY_NATIVE = $(shell $(CYGPATH) '$(TCL_LIBRARY)') GENERIC_DIR_NATIVE = $(shell $(CYGPATH) '$(GENERIC_DIR)') -TOMMATH_DIR_NATIVE = $(shell $(CYGPATH) '$(TOMMATH_DIR)') WIN_DIR_NATIVE = $(shell $(CYGPATH) '$(WIN_DIR)') ROOT_DIR_NATIVE = $(shell $(CYGPATH) '$(ROOT_DIR)') ROOT_DIR_WIN_NATIVE = $(shell cd '$(ROOT_DIR)' ; pwd -W || pwd -P) ZLIB_DIR_NATIVE = $(shell $(CYGPATH) '$(ZLIB_DIR)') -#GENERIC_DIR_NATIVE = $(GENERIC_DIR) -#TOMMATH_DIR_NATIVE = $(TOMMATH_DIR) -#WIN_DIR_NATIVE = $(WIN_DIR) -#ROOT_DIR_NATIVE = $(ROOT_DIR) +TOMMATH_DIR_NATIVE = $(shell $(CYGPATH) '$(TOMMATH_DIR)') # Fully qualify library path so that `make test` # does not depend on the current directory. @@ -159,8 +155,9 @@ TEST_LOAD_PRMS = lappend ::auto_path {$(ROOT_DIR_WIN_NATIVE)/tests};\ TEST_LOAD_FACILITIES = package ifneeded Tcltest ${VERSION}@TCL_PATCH_LEVEL@ [list load [file normalize ${TEST_DLL_FILE}] Tcltest];\ $(TEST_LOAD_PRMS) ZLIB_DLL_FILE = zlib1.dll +TOMMATH_DLL_FILE = libtommath.dll -SHARED_LIBRARIES = $(TCL_DLL_FILE) @ZLIB_DLL_FILE@ +SHARED_LIBRARIES = $(TCL_DLL_FILE) @ZLIB_DLL_FILE@ @TOMMATH_DLL_FILE@ STATIC_LIBRARIES = $(TCL_LIB_FILE) TCLSH = tclsh$(VER)${EXESUFFIX} @@ -180,7 +177,7 @@ TCL_EXE = @TCL_EXE@ # Setting the VPATH variable to a list of paths will cause the Makefile to # look into these paths when resolving .c to .obj dependencies. -VPATH = $(GENERIC_DIR):$(TOMMATH_DIR):$(WIN_DIR):$(COMPAT_DIR):$(ZLIB_DIR) +VPATH = $(GENERIC_DIR):$(WIN_DIR):$(COMPAT_DIR):$(ZLIB_DIR):$(TOMMATH_DIR) AR = @AR@ RANLIB = @RANLIB@ @@ -201,7 +198,7 @@ SHLIB_LD = @SHLIB_LD@ SHLIB_LD_LIBS = @SHLIB_LD_LIBS@ SHLIB_CFLAGS = @SHLIB_CFLAGS@ SHLIB_SUFFIX = @SHLIB_SUFFIX@ -LIBS = @LIBS@ $(shell $(CYGPATH) '@ZLIB_LIBS@') +LIBS = @LIBS@ $(shell $(CYGPATH) '@ZLIB_LIBS@') $(shell $(CYGPATH) '@TOMMATH_LIBS@') RMDIR = rm -rf MKDIR = mkdir -p @@ -477,7 +474,7 @@ ZLIB_OBJS = \ uncompr.$(OBJEXT) \ zutil.$(OBJEXT) -TCL_OBJS = ${GENERIC_OBJS} $(TOMMATH_OBJS) ${WIN_OBJS} @ZLIB_OBJS@ +TCL_OBJS = ${GENERIC_OBJS} ${WIN_OBJS} @ZLIB_OBJS@ @TOMMATH_OBJS@ TCL_DOCS = "$(ROOT_DIR_NATIVE)"/doc/*.[13n] @@ -567,7 +564,7 @@ ${TCL_STUB_LIB_FILE}: ${STUB_OBJS} @MAKE_STUB_LIB@ ${STUB_OBJS} @POST_MAKE_LIB@ -${TCL_DLL_FILE}: ${TCL_OBJS} tcl.$(RES) @ZLIB_DLL_FILE@ ${TCL_ZIP_FILE} +${TCL_DLL_FILE}: ${TCL_OBJS} tcl.$(RES) @ZLIB_DLL_FILE@ @TOMMATH_DLL_FILE@ ${TCL_ZIP_FILE} @$(RM) ${TCL_DLL_FILE} $(TCL_LIB_FILE) @MAKE_DLL@ ${TCL_OBJS} tcl.$(RES) $(SHLIB_LD_LIBS) @VC_MANIFEST_EMBED_DLL@ @@ -605,6 +602,14 @@ ${ZLIB_DLL_FILE}: ${TCL_STUB_LIB_FILE} $(COPY) $(ZLIB_DIR)/win32/${ZLIB_DLL_FILE} ${ZLIB_DLL_FILE}; \ fi; +# use pre-built libtommath.dll +${TOMMATH_DLL_FILE}: ${TCL_STUB_LIB_FILE} + @if test "@TOMMATH_LIBS@set" != "${TOMMATH_DIR_NATIVE}/win32/tommath.libset" ; then \ + $(COPY) $(TOMMATH_DIR)/win64/${TOMMATH_DLL_FILE} ${TOMMATH_DLL_FILE}; \ + else \ + $(COPY) $(TOMMATH_DIR)/win32/${TOMMATH_DLL_FILE} ${TOMMATH_DLL_FILE}; \ + fi; + # Add the object extension to the implicit rules. By default .obj is not # automatically added. @@ -790,7 +795,7 @@ install-binaries: binaries else true; \ fi; \ done; - @for i in $(TCL_DLL_FILE) $(ZLIB_DLL_FILE) $(TCLSH); \ + @for i in $(TCL_DLL_FILE) $(ZLIB_DLL_FILE) $(TOMMATH_DLL_FILE) $(TCLSH); \ do \ if [ -f $$i ]; then \ echo "Installing $$i to $(BIN_INSTALL_DIR)/"; \ diff --git a/win/configure b/win/configure index 982f96a..716cf98 100755 --- a/win/configure +++ b/win/configure @@ -710,8 +710,11 @@ ZIP_PROG TCLSH_PROG EXEEXT_FOR_BUILD CC_FOR_BUILD +TOMMATH_OBJS ZLIB_OBJS +TOMMATH_LIBS ZLIB_LIBS +TOMMATH_DLL_FILE ZLIB_DLL_FILE CFLAGS_WARNING CFLAGS_OPTIMIZE @@ -753,6 +756,7 @@ infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir @@ -830,6 +834,7 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE}' @@ -1082,6 +1087,15 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1219,7 +1233,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1372,6 +1386,7 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -4561,8 +4576,9 @@ case ${host_alias} in esac #------------------------------------------------------------------------ -# Add stuff for zlib; note that this is mostly done in the makefile now -# as we just assume that the platform hasn't got a usable z.lib +# Add stuff for zlib/libtommath; note that this is mostly done in the +# makefile now as we just assume that the platform hasn't got usable +# z.lib/tommath.lib #------------------------------------------------------------------------ if test "${enable_shared+set}" = "set"; then : @@ -4579,17 +4595,26 @@ if test "$tcl_ok" = "yes"; then : ZLIB_DLL_FILE=\${ZLIB_DLL_FILE} + TOMMATH_DLL_FILE=\${TOMMATH_DLL_FILE} + if test "$do64bit" != "no"; then : + +$as_echo "#define MD_64BIT 1" >>confdefs.h + if test "$GCC" == "yes"; then : ZLIB_LIBS=\${ZLIB_DIR_NATIVE}/win64/libz.dll.a + TOMMATH_LIBS=\${TOMMATH_DIR_NATIVE}/win64/libtommath.dll.a + else ZLIB_LIBS=\${ZLIB_DIR_NATIVE}/win64/zdll.lib + TOMMATH_LIBS=\${TOMMATH_DIR_NATIVE}/win64/tommath.lib + fi @@ -4597,6 +4622,8 @@ else ZLIB_LIBS=\${ZLIB_DIR_NATIVE}/win32/zdll.lib + TOMMATH_LIBS=\${TOMMATH_DIR_NATIVE}/win32/tommath.lib + fi @@ -4604,6 +4631,8 @@ else ZLIB_OBJS=\${ZLIB_OBJS} + TOMMATH_OBJS=\${TOMMATH_OBJS} + fi diff --git a/win/configure.ac b/win/configure.ac index 7b63c61..3edfe78 100644 --- a/win/configure.ac +++ b/win/configure.ac @@ -110,8 +110,9 @@ case ${host_alias} in esac #------------------------------------------------------------------------ -# Add stuff for zlib; note that this is mostly done in the makefile now -# as we just assume that the platform hasn't got a usable z.lib +# Add stuff for zlib/libtommath; note that this is mostly done in the +# makefile now as we just assume that the platform hasn't got usable +# z.lib/tommath.lib #------------------------------------------------------------------------ AS_IF([test "${enable_shared+set}" = "set"], [ @@ -122,17 +123,23 @@ AS_IF([test "${enable_shared+set}" = "set"], [ ]) AS_IF([test "$tcl_ok" = "yes"], [ AC_SUBST(ZLIB_DLL_FILE,[\${ZLIB_DLL_FILE}]) + AC_SUBST(TOMMATH_DLL_FILE,[\${TOMMATH_DLL_FILE}]) AS_IF([test "$do64bit" != "no"], [ + AC_DEFINE(MD_64BIT, 1, [Using libtommath.dll in 64-bit mode]) AS_IF([test "$GCC" == "yes"],[ AC_SUBST(ZLIB_LIBS,[\${ZLIB_DIR_NATIVE}/win64/libz.dll.a]) + AC_SUBST(TOMMATH_LIBS,[\${TOMMATH_DIR_NATIVE}/win64/libtommath.dll.a]) ], [ AC_SUBST(ZLIB_LIBS,[\${ZLIB_DIR_NATIVE}/win64/zdll.lib]) + AC_SUBST(TOMMATH_LIBS,[\${TOMMATH_DIR_NATIVE}/win64/tommath.lib]) ]) ], [ AC_SUBST(ZLIB_LIBS,[\${ZLIB_DIR_NATIVE}/win32/zdll.lib]) + AC_SUBST(TOMMATH_LIBS,[\${TOMMATH_DIR_NATIVE}/win32/tommath.lib]) ]) ], [ AC_SUBST(ZLIB_OBJS,[\${ZLIB_OBJS}]) + AC_SUBST(TOMMATH_OBJS,[\${TOMMATH_OBJS}]) ]) AC_DEFINE(HAVE_ZLIB, 1, [Is there an installed zlib?]) |