From be48c0b4c17240654d180fde380696122c2cc13b Mon Sep 17 00:00:00 2001 From: odow Date: Fri, 11 Oct 2024 09:54:41 +1300 Subject: [PATCH] Fix mutable_copy(::BigFloat) in Julia v1.12 --- src/implementations/BigFloat.jl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/implementations/BigFloat.jl b/src/implementations/BigFloat.jl index 442abed2..43e1b401 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