Skip to content

Commit

Permalink
Fix mutable_copy(::BigFloat) in Julia v1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Oct 10, 2024
1 parent 93c7e3b commit be48c0b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/implementations/BigFloat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be48c0b

Please sign in to comment.