Skip to content

unsafe use of unsafe_load, needs GC.@preserve #29

@rfourquet

Description

@rfourquet

When using unsafe_load, we must ensure the resource being read from is kept alive, which can be accomplished via GC.@preserve.
For example, in "src/common.jl" there is

_value(r::AbstractR123{T}, i = 1, ::Type{T2} = T) where {T, T2} = unsafe_load(Ptr{T2}(pointer_from_objref(r)), i)

While highly unlikely to be practically a problem in current julia versions, a safe fix would be:

_value(r::AbstractR123{T}, i = 1, ::Type{T2} = T) where {T, T2} = GC.@preserve r unsafe_load(Ptr{T2}(pointer_from_objref(r)), i)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions