Skip to content

Commit

Permalink
replace many unsafe_convert methods with safer cconvert ones (#51764)
Browse files Browse the repository at this point in the history
This seems the correct way to define most conversions, since the unsafe
logic should typically be isolated to a few areas, and everywhere else
just defines conversions to it. This ensures the root is preserved even
if the user later makes unexpected changes to the parent object
(although the length might have later become inconsistent at that point,
so it is not a guaranteed fix for memory issues).
  • Loading branch information
vtjnash authored Oct 24, 2023
1 parent 9360b4f commit 258b8bf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/SharedArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module SharedArrays
using Mmap, Distributed, Random

import Base: length, size, elsize, ndims, IndexStyle, reshape, convert, deepcopy_internal,
show, getindex, setindex!, fill!, similar, reduce, map!, copyto!, unsafe_convert
show, getindex, setindex!, fill!, similar, reduce, map!, copyto!, cconvert
import Random
using Serialization
using Serialization: serialize_cycle_header, serialize_type, writetag, UNDEFREF_TAG, serialize, deserialize
Expand Down Expand Up @@ -358,8 +358,8 @@ for each worker process.
"""
localindices(S::SharedArray) = S.pidx > 0 ? range_1dim(S, S.pidx) : 1:0

unsafe_convert(::Type{Ptr{T}}, S::SharedArray{T}) where {T} = unsafe_convert(Ptr{T}, sdata(S))
unsafe_convert(::Type{Ptr{T}}, S::SharedArray ) where {T} = unsafe_convert(Ptr{T}, sdata(S))
cconvert(::Type{Ptr{T}}, S::SharedArray{T}) where {T} = cconvert(Ptr{T}, sdata(S))
cconvert(::Type{Ptr{T}}, S::SharedArray ) where {T} = cconvert(Ptr{T}, sdata(S))

function SharedArray(A::Array)
S = SharedArray{eltype(A),ndims(A)}(size(A))
Expand Down

0 comments on commit 258b8bf

Please sign in to comment.