Skip to content

Commit

Permalink
Make the __init__ in GMP more statically compilable (#55012)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeff Bezanson <jeff.bezanson@gmail.com>
  • Loading branch information
gbaraldi and JeffBezanson committed Jul 4, 2024
1 parent 8083506 commit c388382
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ else
const libgmp = "libgmp.so.10"
end

version() = VersionNumber(unsafe_string(unsafe_load(cglobal((:__gmp_version, libgmp), Ptr{Cchar}))))
_version() = unsafe_string(unsafe_load(cglobal((:__gmp_version, libgmp), Ptr{Cchar})))
version() = VersionNumber(_version())
major_version() = _version()[1]
bits_per_limb() = Int(unsafe_load(cglobal((:__gmp_bits_per_limb, libgmp), Cint)))

const VERSION = version()
const MAJOR_VERSION = major_version()
const BITS_PER_LIMB = bits_per_limb()

# GMP's mp_limb_t is by default a typedef of `unsigned long`, but can also be configured to be either
Expand Down Expand Up @@ -102,7 +105,7 @@ const ALLOC_OVERFLOW_FUNCTION = Ref(false)

function __init__()
try
if version().major != VERSION.major || bits_per_limb() != BITS_PER_LIMB
if major_version() != MAJOR_VERSION || bits_per_limb() != BITS_PER_LIMB
msg = """The dynamically loaded GMP library (v\"$(version())\" with __gmp_bits_per_limb == $(bits_per_limb()))
does not correspond to the compile time version (v\"$VERSION\" with __gmp_bits_per_limb == $BITS_PER_LIMB).
Please rebuild Julia."""
Expand Down

0 comments on commit c388382

Please sign in to comment.