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

Fix incorrect wrapping of a Datatype #151

Merged
merged 1 commit into from
Nov 24, 2020

Conversation

jmert
Copy link
Contributor

@jmert jmert commented Nov 24, 2020

This was noticed in the CI of #145.

create_datatype already returns an HDF5.Datatype object, so by
wrapping again, the finalizer on the original object was allowed to
run too early.

`create_datatype` already returns an HDF5.Datatype object, so by
wrapping again, the finalizer on the original object was allowed to
run too early.
@musm
Copy link
Member

musm commented Nov 24, 2020

Good catch!

@musm musm merged commit b9de52a into JuliaIO:master Nov 24, 2020
@jmert jmert deleted the fix_complex_datatype branch November 24, 2020 19:21
jmert added a commit to jmert/HDF5.jl that referenced this pull request Nov 24, 2020
By defining `Base.convert(::Type{hid_t}, x)` for all of the high-level
object types, implicit conversion to an integer is permitted.
This has the unfortunate consquence --- as found in JuliaIO/MAT.jl#145
and JuliaIO/MAT.jl#151 --- that incorrectly "wrapping" a wrapped object
was allowed, but doing so allows the garbage collector to reap the
object too early.

The main reason for allowing conversion from an object to integer
(namely `HDF5.hid_t`) is to support passing the objects to `ccall`s
without requiring reaching into the `obj.id` raw integer ID.

We can easily still allow this while disabling implicit conversion by
just replacing all definitions of `Base.convert` with `Base.cconvert`.
Doing this would have caught the mistake in MAT.jl at the Julia type
level rather than having to debug a runtime error.
musm pushed a commit to JuliaIO/HDF5.jl that referenced this pull request Nov 25, 2020
…#750)

By defining `Base.convert(::Type{hid_t}, x)` for all of the high-level
object types, implicit conversion to an integer is permitted.
This has the unfortunate consquence --- as found in JuliaIO/MAT.jl#145
and JuliaIO/MAT.jl#151 --- that incorrectly "wrapping" a wrapped object
was allowed, but doing so allows the garbage collector to reap the
object too early.

The main reason for allowing conversion from an object to integer
(namely `HDF5.hid_t`) is to support passing the objects to `ccall`s
without requiring reaching into the `obj.id` raw integer ID.

We can easily still allow this while disabling implicit conversion by
just replacing all definitions of `Base.convert` with `Base.cconvert`.
Doing this would have caught the mistake in MAT.jl at the Julia type
level rather than having to debug a runtime error.
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 this pull request may close these issues.

2 participants