diff --git a/src/implementations/BigFloat.jl b/src/implementations/BigFloat.jl index 442abed..43e1b40 100644 --- a/src/implementations/BigFloat.jl +++ b/src/implementations/BigFloat.jl @@ -9,12 +9,18 @@ mutability(::Type{BigFloat}) = IsMutable() -# Copied from `deepcopy_internal` implementation in Julia: -# https://github.com/JuliaLang/julia/blob/7d41d1eb610cad490cbaece8887f9bbd2a775021/base/mpfr.jl#L1041-L1050 -function mutable_copy(x::BigFloat) - d = x._d - d′ = GC.@preserve d unsafe_string(pointer(d), sizeof(d)) # creates a definitely-new String - return Base.MPFR._BigFloat(x.prec, x.sign, x.exp, d′) +@static if VERSION >= v"1.12" + function mutable_copy(x::BigFloat) + return Base.MPFR._BigFloat(copy(getfield(x, :d))) + end +else + # Copied from `deepcopy_internal` implementation in Julia: + # https://github.com/JuliaLang/julia/blob/7d41d1eb610cad490cbaece8887f9bbd2a775021/base/mpfr.jl#L1041-L1050 + function mutable_copy(x::BigFloat) + d = x._d + d′ = GC.@preserve d unsafe_string(pointer(d), sizeof(d)) # creates a definitely-new String + return Base.MPFR._BigFloat(x.prec, x.sign, x.exp, d′) + end end const _MPFRRoundingMode = Base.MPFR.MPFRRoundingMode