-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: serialize pointer- and padding-free objects in one write #14678
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -420,11 +420,15 @@ function serialize_any(s::SerializationState, x) | |
else | ||
t.mutable && serialize_cycle(s, x) && return | ||
serialize_type(s, t) | ||
for i in 1:nf | ||
if isdefined(x, i) | ||
serialize(s, getfield(x, i)) | ||
else | ||
writetag(s.io, UNDEFREF_TAG) | ||
if t.pointerfree && ccall(:jl_datatype_haspadding, Cint, (Any,), t)==0 | ||
write(s.io, pointer_from_objref(x), sizeof(x)) | ||
else | ||
for i in 1:nf | ||
if isdefined(x, i) | ||
serialize(s, getfield(x, i)) | ||
else | ||
writetag(s.io, UNDEFREF_TAG) | ||
end | ||
end | ||
end | ||
end | ||
|
@@ -674,6 +678,11 @@ function deserialize(s::SerializationState, t::DataType) | |
end | ||
if nf == 0 | ||
return ccall(:jl_new_struct, Any, (Any,Any...), t) | ||
elseif t.pointerfree && ccall(:jl_datatype_haspadding, Cint, (Any,), t)==0 | ||
x = ccall(:jl_new_struct_uninit, Any, (Any,), t) | ||
a_ = pointer_to_array(convert(Ptr{UInt8},pointer_from_objref(x)), sizeof(t)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is regrettable but there are no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i've thought they should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me. |
||
read!(s.io, a_) | ||
return x | ||
elseif isbits(t) | ||
if nf == 1 | ||
return ccall(:jl_new_struct, Any, (Any,Any...), t, deserialize(s)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the pointer returned here may be to a box that is not gc-rooted. in general,
pointer_from_objref
should never be called on something that isimmutable
andpointerfree
(I think we should make it an error)i'm looking into possible alternatives that would provide the same benefit, but doesn't require calling pointer_from_objref