From 42fd6b1879a26cdd75b383f3061da75ffbc61611 Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Wed, 3 Dec 2014 09:33:10 +0530 Subject: [PATCH] small fixup for rand(::BigInt) and update docs Now the runtime version of GMP is checked against the compile time version, as suggested by @JeffBezanson. He also noted that the limbs field of RangeGeneratorBigInt was not specific enough. --- base/gmp.jl | 12 ++++++++++-- base/random.jl | 2 +- doc/stdlib/base.rst | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/base/gmp.jl b/base/gmp.jl index ccc491657acf06..ea30a3c38eb134 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -18,8 +18,11 @@ else end typealias CdoubleMax Union(Float16, Float32, Float64) -const GMP_VERSION = VersionNumber(bytestring(unsafe_load(cglobal((:__gmp_version, :libgmp), Ptr{Cchar})))) -const GMP_BITS_PER_LIMB = Int(unsafe_load(cglobal((:__gmp_bits_per_limb, :libgmp), Cint))) +gmp_version() = VersionNumber(bytestring(unsafe_load(cglobal((:__gmp_version, :libgmp), Ptr{Cchar})))) +gmp_bits_per_limb() = Int(unsafe_load(cglobal((:__gmp_bits_per_limb, :libgmp), Cint))) + +const GMP_VERSION = gmp_version() +const GMP_BITS_PER_LIMB = gmp_bits_per_limb() # GMP's mp_limb_t is by default a typedef of `unsigned long`, but can also be configured to be either # `unsigned int` or `unsigned long long int`. The correct unsigned type is here named Limb, and must @@ -49,6 +52,11 @@ _gmp_clear_func = C_NULL _mpfr_clear_func = C_NULL function __init__() + if gmp_version() != GMP_VERSION || gmp_bits_per_limb() != GMP_BITS_PER_LIMB + error(string("the dynamically loaded GMP library (version $(gmp_version()) with __gmp_bits_per_limb == $(gmp_bits_per_limb()))\n", + "does not correspond to the compile time version (version $GMP_VERSION with __gmp_bits_per_limb == $GMP_BITS_PER_LIMB)")) + end + global _gmp_clear_func = cglobal((:__gmpz_clear, :libgmp)) global _mpfr_clear_func = cglobal((:mpfr_clear, :libmpfr)) ccall((:__gmp_set_memory_functions, :libgmp), Void, diff --git a/base/random.jl b/base/random.jl index 025b4f7012bdc0..ec4d09687b0ec7 100644 --- a/base/random.jl +++ b/base/random.jl @@ -399,7 +399,7 @@ else immutable RangeGeneratorBigInt <: RangeGenerator a::BigInt # first m::BigInt # range length - 1 - limbs::Array{Limb} # buffer to be copied into generated BigInt's + limbs::Vector{Limb} # buffer to be copied into generated BigInt's mask::Limb # applied to the highest limb RangeGeneratorBigInt(a, m, nlimbs, mask) = new(a, m, Array(Limb, nlimbs), mask) diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index 3ab5822e46ca18..7ea4e7f80fe73b 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -4083,7 +4083,7 @@ Random number generation in Julia uses the `Mersenne Twister library