Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy initialize gmp and mpfr finalizers #17010

Merged
merged 1 commit into from
Jun 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@ type BigInt <: Integer
function BigInt()
b = new(zero(Cint), zero(Cint), C_NULL)
ccall((:__gmpz_init,:libgmp), Void, (Ptr{BigInt},), &b)
finalizer(b, _gmp_clear_func)
finalizer(b, cglobal((:__gmpz_clear, :libgmp)))
return b
end
end

_gmp_clear_func = C_NULL
_mpfr_clear_func = C_NULL

function __init__()
try
if gmp_version().major != GMP_VERSION.major || gmp_bits_per_limb() != GMP_BITS_PER_LIMB
Expand All @@ -60,8 +57,6 @@ function __init__()
"Please rebuild Julia."))
end

global _gmp_clear_func = cglobal((:__gmpz_clear, :libgmp))
global _mpfr_clear_func = cglobal((:mpfr_clear, :libmpfr))
ccall((:__gmp_set_memory_functions, :libgmp), Void,
(Ptr{Void},Ptr{Void},Ptr{Void}),
cglobal(:jl_gc_counted_malloc),
Expand Down
4 changes: 2 additions & 2 deletions base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type BigFloat <: AbstractFloat
N = precision(BigFloat)
z = new(zero(Clong), zero(Cint), zero(Clong), C_NULL)
ccall((:mpfr_init2,:libmpfr), Void, (Ptr{BigFloat}, Clong), &z, N)
finalizer(z, Base.GMP._mpfr_clear_func)
finalizer(z, cglobal((:mpfr_clear, :libmpfr)))
return z
end
# Not recommended for general use
Expand Down Expand Up @@ -887,7 +887,7 @@ function Base.deepcopy_internal(x::BigFloat, stackdict::ObjectIdDict)
N = precision(x)
y = BigFloat(zero(Clong), zero(Cint), zero(Clong), C_NULL)
ccall((:mpfr_init2,:libmpfr), Void, (Ptr{BigFloat}, Clong), &y, N)
finalizer(y, Base.GMP._mpfr_clear_func)
finalizer(y, cglobal((:mpfr_clear, :libmpfr)))
ccall((:mpfr_set, :libmpfr), Int32, (Ptr{BigFloat}, Ptr{BigFloat}, Int32),
&y, &x, ROUNDING_MODE[end])
stackdict[x] = y
Expand Down