Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion stdlib/Serialization/src/Serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ end
function deserialize(s::AbstractSerializer, X::Type{MemoryRef{T}} where T)
x = Core.memoryref(deserialize(s))::X
i = deserialize(s)::Int
i == 2 || (x = Core.memoryref(x, i, true))
i == 2 || (x = Core.memoryrefnew(x, i, true))
return x::X
end

Expand Down
31 changes: 31 additions & 0 deletions stdlib/Serialization/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -687,3 +687,34 @@ if Int === Int64
@test @invokelatest(Main.f111_to_112(16)) == 256
end
end

@testset "MemoryRef" begin
old_m = Memory{Int}(undef, 10)
for i in 1:10
old_m[i] = i^2
end
old_x = memoryref(old_m, 5)
@test old_x[] == 25
old_d = Dict(:x => old_x)

old_str = sprint(serialize, old_d)
new_d = deserialize(IOBuffer(old_str))

@test new_d[:x] isa MemoryRef
@test new_d[:x][] == 25
end

@testset "Memory" begin
old_m = Memory{Int}(undef, 10)
for i in 1:10
old_m[i] = i^3
end
@test old_m[5] == 125
old_d = Dict(:m => old_m)

old_str = sprint(serialize, old_d)
new_d = deserialize(IOBuffer(old_str))

@test new_d[:m] isa Memory
@test new_d[:m][5] == 125
end
Loading