This package should implement custom methods for Serialization.serialize and deserialize of ArbFloat etcetera.
Right now, it uses the fallback methods, which just read and write the raw struct contents. This fails when the precision becomes sufficiently large, in which case the struct contents include C pointers, leading to errors in packages that rely on Julia serialization/deserialization such as Distributed.jl — see #74 and this discourse thread.
See also this discussion on Google Groups, in which the lead FLINT developer (Fredrik Johansson) recommends arb_dump_str and arb_load_str for serialization/deserialization.
For example, here is a rough draft of a serialize method for ArbFloat:
using Serialization
function Serialization.serialize(s::AbstractSerializer, x::ArbFloat)
serialize_type(s, typeof(x))
unsafestr = ccall(@libarb(arb_dump_str), Cstring, (Ref{ArbReal},), x)
len = Int64(ccall(:strlen, Csize_t, (Cstring,), unsafestr))
write(s.io, len)
unsafe_write(s.io, pointer(unsafestr), len)
ccall(@libflint(flint_free), Cvoid, (Cstring,), unsafestr)
return nothing
end
It uses unsafe_write, which allows it to directly write the arb_dump_str buffer contents to the serialization stream; I'm being a little low-level here because serialization is often performance-critical and so I want to avoid unnecessary copies of the string data. The inverse deserialize function should look something like:
function Serialization.deserialize(s::AbstractSerializer, ::Type{ArbFloat{P}}) where {P}
len = read(s.io, Int64)::Int64
str = Serialization.deserialize_string(s, Int(len))
# TODO: call arb_load_str to constuct arb_t from str
return nothing
end
This seems like it will require a new low-level constructor to use arb_load_str instead of arb_init.
This package should implement custom methods for
Serialization.serializeanddeserializeofArbFloatetcetera.Right now, it uses the fallback methods, which just read and write the raw
structcontents. This fails when the precision becomes sufficiently large, in which case thestructcontents include C pointers, leading to errors in packages that rely on Julia serialization/deserialization such as Distributed.jl — see #74 and this discourse thread.See also this discussion on Google Groups, in which the lead FLINT developer (Fredrik Johansson) recommends
arb_dump_strandarb_load_strfor serialization/deserialization.For example, here is a rough draft of a
serializemethod forArbFloat:It uses
unsafe_write, which allows it to directly write thearb_dump_strbuffer contents to the serialization stream; I'm being a little low-level here because serialization is often performance-critical and so I want to avoid unnecessary copies of the string data. The inversedeserializefunction should look something like:This seems like it will require a new low-level constructor to use
arb_load_strinstead ofarb_init.