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

Fix BigFloat for Julia v1.12 #307

Merged
merged 11 commits into from
Oct 13, 2024
Merged
Changes from 3 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
20 changes: 14 additions & 6 deletions src/implementations/BigFloat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@

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′)
# These methods are copied from `deepcopy_internal` in `base/mpfr.jl`. We don't
# use `mutable_copy(x) = deepcopy(x)` because this creates an empty `IdDict()`
# which costs some extra allocations. We don't need the IdDict case because we
# never call `mutable_copy` recursively.
@static if VERSION >= v"1.12.0-DEV.1343"
mutable_copy(x::BigFloat) = Base.MPFR._BigFloat(copy(getfield(x, :d)))
odow marked this conversation as resolved.
Show resolved Hide resolved
else
function mutable_copy(x::BigFloat)
d = x._d
GC.@preserve d begin
d′ = unsafe_string(pointer(d), sizeof(d))
return Base.MPFR._BigFloat(x.prec, x.sign, x.exp, d′)
end
end
end

const _MPFRRoundingMode = Base.MPFR.MPFRRoundingMode
Expand Down
Loading