JuliaIO / BSON.jl

Other
158 stars 39 forks source link

BSON.@save has side effects #78

Open jonas-eschmann opened 3 years ago

jonas-eschmann commented 3 years ago

Hi,

I just encountered following side effect (in a more complex scenario, boiled down to the minimum):

using BSON
a = Dict{Symbol, Any}(:a => Float32.([1]))
BSON.@save "/tmp/deleteme.bson" a

After that a is changed to contain all the type information that is probably generated to write the output.

Dict{Symbol,Any} with 1 entry:
  :t => Dict{Symbol,Any}(:tag=>"array",:type=>Dict{Symbol,Any}(:tag=>"datatype",:params=>Any[],:name=>Any["Core", "Float32"]),:size=>Any[3],:data=>UInt8[0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x40, 0x00, 0…

After loading the dict again:

BSON.@load "/tmp/deleteme.bson" a

A is restored in its original form. To me this was unexpected behaviour and I did not find any documentation that there may be side effects when using @save.

System:

Julia Version 1.5.2
Commit 539f3ce943 (2020-09-23 23:17 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: AMD Ryzen 7 4800H with Radeon Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, znver2)

BSON:

  [fbb218c0] BSON v0.2.6

Apart from that minor issue, thanks for this fabulous library!

racinmat commented 3 years ago

This probably boils down to #26 , right?