diff --git a/gmp-h.in b/gmp-h.in index 58fc571f..cab0a3b9 100644 --- a/gmp-h.in +++ b/gmp-h.in @@ -224,6 +224,10 @@ typedef __gmp_const mp_limb_t * mp_srcptr; #define __GMP_MP_SIZE_T_INT 1 typedef int mp_size_t; typedef int mp_exp_t; +#elif defined( _MSC_VER ) +#define __GMP_MP_SIZE_T_INT 2 +typedef intptr_t mp_size_t; +typedef intptr_t mp_exp_t; #else #define __GMP_MP_SIZE_T_INT 0 typedef long int mp_size_t; diff --git a/gmp-impl.h b/gmp-impl.h index ffbc0390..592297b0 100644 --- a/gmp-impl.h +++ b/gmp-impl.h @@ -51,7 +51,7 @@ MA 02110-1301, USA. */ reference, int can be 46 or 64 bits, whereas uint is always 64 bits; and short can be 24, 32, 46 or 64 bits, and different for ushort. */ -#if defined _CRAY +#if defined _CRAY || defined _MSC_VER #include #endif @@ -551,7 +551,15 @@ void __gmp_tmp_debug_free _PROTO ((const char *, int, int, #define SHRT_MAX ((short) (-(SHRT_MIN+1))) #endif -#if __GMP_MP_SIZE_T_INT +#if __GMP_MP_SIZE_T_INT == 2 +# ifdef _WIN64 +# define MP_SIZE_T_MAX _I64_MAX +# define MP_SIZE_T_MIN _I64_MIN +# else +# define MP_SIZE_T_MAX LONG_MAX +# define MP_SIZE_T_MIN LONG_MIN +# endif +#elif __GMP_MP_SIZE_T_INT #define MP_SIZE_T_MAX INT_MAX #define MP_SIZE_T_MIN INT_MIN #else diff --git a/memory.c b/memory.c index d91de689..7be3ce71 100644 --- a/memory.c +++ b/memory.c @@ -46,7 +46,11 @@ __gmp_default_allocate (size_t size) ret = malloc (size); if (ret == 0) { +#if defined _MSC_VER && defined _WIN64 + fprintf (stderr, "GNU MP: Cannot allocate memory (size=%llu)\n", size); +#else fprintf (stderr, "GNU MP: Cannot allocate memory (size=%u)\n", size); +#endif abort (); } @@ -94,7 +98,11 @@ __gmp_default_reallocate (void *oldptr, size_t old_size, size_t new_size) ret = realloc (oldptr, new_size); if (ret == 0) { - fprintf (stderr, "GNU MP: Cannot reallocate memory (old_size=%u new_size=%u)\n", old_size, new_size); +#if defined _MSC_VER && defined _WIN64 + fprintf (stderr, "GNU MP: Cannot reallocate memory (old_size=%llu new_size=%llu)\n", old_size, new_size); +#else + fprintf (stderr, "GNU MP: Cannot reallocate memory (old_size=%u new_size=%u)\n", old_size, new_size); +#endif abort (); } diff --git a/mpz/inp_raw.c b/mpz/inp_raw.c index c82b0b83..cf8e0232 100644 --- a/mpz/inp_raw.c +++ b/mpz/inp_raw.c @@ -79,7 +79,7 @@ mpz_inp_raw (mpz_ptr x, FILE *fp) Could write "csize -= ((csize & 0x80000000L) << 1)", but that tickles a bug in gcc 3.0 for powerpc64 on AIX. */ if (sizeof (csize) > 4 && csize & 0x80000000L) - csize -= 0x80000000L << 1; + csize |= (mp_size_t)(-1) << 32; abs_csize = ABS (csize);