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

UndefRefError: access to undefined reference #601

Closed
SamuelBadr opened this issue Sep 20, 2024 · 3 comments · Fixed by #602
Closed

UndefRefError: access to undefined reference #601

SamuelBadr opened this issue Sep 20, 2024 · 3 comments · Fixed by #602

Comments

@SamuelBadr
Copy link
Contributor

Starting in 0.5.2, this errors:

julia> using JLD2

julia> struct Foo <: Function
           x::Int
       end

julia> foo = Foo(2)
(::Foo) (generic function with 0 methods)

julia> jldsave(tempname(); foo)
ERROR: UndefRefError: access to undefined reference
Stacktrace:
  [1] getproperty
    @ ./Base.jl:43 [inlined]
  [2] h5convert!(out::JLD2.IndirectPointer, ::JLD2.OnDiskRepresentation{…}, f::JLD2.JLDFile{…}, T::DataType, wsession::JLD2.JLDWriteSession{…})
    @ JLD2 ~/.julia/packages/JLD2/JyzIz/src/data/writing_datatypes.jl:448
  [3] write_data(io::JLD2.MmapIO, f::JLD2.JLDFile{…}, data::Type, odr::JLD2.OnDiskRepresentation{…}, ::JLD2.HasReferences, wsession::JLD2.JLDWriteSession{…})
    @ JLD2 ~/.julia/packages/JLD2/JyzIz/src/dataio.jl:96
  [4] write_attribute(io::JLD2.MmapIO, f::JLD2.JLDFile{…}, attr::JLD2.WrittenAttribute{…}, wsession::JLD2.JLDWriteSession{…})
    @ JLD2 ~/.julia/packages/JLD2/JyzIz/src/attributes.jl:47
  [5] write_header_message(io::JLD2.MmapIO, f::JLD2.JLDFile{…}, msg::JLD2.WrittenAttribute{…}, wsession::JLD2.JLDWriteSession{…})
    @ JLD2 ~/.julia/packages/JLD2/JyzIz/src/explicit_datasets.jl:233
  [6] write_header_message
    @ ~/.julia/packages/JLD2/JyzIz/src/explicit_datasets.jl:232 [inlined]
  [7] commit(f::JLD2.JLDFile{JLD2.MmapIO}, dt::JLD2.H5Datatype, attrs::Tuple{JLD2.WrittenAttribute{…}})
    @ JLD2 ~/.julia/packages/JLD2/JyzIz/src/datatypes.jl:302
  [8] commit(::JLD2.JLDFile{JLD2.MmapIO}, ::Any, ::DataType, ::DataType)
    @ JLD2 ~/.julia/packages/JLD2/JyzIz/src/data/writing_datatypes.jl:248
  [9] commit_compound(f::JLD2.JLDFile{JLD2.MmapIO}, names::Vector{Symbol}, writtenas::DataType, readas::Type)
    @ JLD2 ~/.julia/packages/JLD2/JyzIz/src/data/writing_datatypes.jl:209
 [10] h5type(f::JLD2.JLDFile{JLD2.MmapIO}, writtenas::Any, x::Any)
    @ JLD2 ~/.julia/packages/JLD2/JyzIz/src/data/writing_datatypes.jl:136
 [11] h5type(f::JLD2.JLDFile{JLD2.MmapIO}, x::Any)
    @ JLD2 ~/.julia/packages/JLD2/JyzIz/src/data/writing_datatypes.jl:141
 [12] write_dataset(f::JLD2.JLDFile{JLD2.MmapIO}, x::Any, wsession::JLD2.JLDWriteSession{Dict{UInt64, JLD2.RelOffset}})
    @ JLD2 ~/.julia/packages/JLD2/JyzIz/src/datasets.jl:389
 [13] write(g::JLD2.Group{…}, name::String, obj::Function, wsession::JLD2.JLDWriteSession{…}; compress::Nothing)
    @ JLD2 ~/.julia/packages/JLD2/JyzIz/src/compression.jl:87
 [14] write(f::JLD2.JLDFile{JLD2.MmapIO}, name::String, obj::Any, wsession::JLD2.JLDWriteSession{Dict{…}}; compress::Nothing)
    @ JLD2 ~/.julia/packages/JLD2/JyzIz/src/compression.jl:71
 [15] write
    @ ~/.julia/packages/JLD2/JyzIz/src/compression.jl:71 [inlined]
 [16] jldsave(filename::String, compress::Bool, iotype::Type{JLD2.MmapIO}; kwargs...)
    @ JLD2 ~/.julia/packages/JLD2/JyzIz/src/loadsave.jl:290
 [17] jldsave
    @ ~/.julia/packages/JLD2/JyzIz/src/loadsave.jl:283 [inlined]
 [18] top-level scope
    @ REPL[4]:1
Some type information was truncated. Use `show(err)` to see complete types.

This is because the instance property can't be accessed for all function types, c.f. https://discourse.julialang.org/t/how-to-get-a-function-instance-from-a-function-type/79585.

In 0.5.1, this used to throw warnings

julia> jldsave(tempname(); foo)
┌ Warning: Attempting to store Foo.
│  Function types cannot be propertly stored in JLD2 files.
│  Loading may yield unexpected results.
└ @ JLD2 ~/.julia/packages/JLD2/JHhTf/src/data/writing_datatypes.jl:631
┌ Warning: Attempting to store Foo.
│  Function types cannot be propertly stored in JLD2 files.
│  Loading may yield unexpected results.
└ @ JLD2 ~/.julia/packages/JLD2/JHhTf/src/data/writing_datatypes.jl:631
@JonasIsensee
Copy link
Collaborator

Ah, thanks for the report.
Sorry about that....

Do you happen to know of a more reliable way to retrieve the name of a function?

@SamuelBadr
Copy link
Contributor Author

I think Base.isgensym(Symbol(T)) does the trick. I can make a PR :)

@JonasIsensee
Copy link
Collaborator

I think Base.isgensym(Symbol(T)) does the trick. I can make a PR :)

Awesome!
Please do :)

Since you also found such a nice example, you could add that as a test?

I'd add it at the bottom of test/loadsave.jl in the same style as the ones above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants