diff --git a/src/buffers.jl b/src/buffers.jl index 57d848d6c..156c76805 100644 --- a/src/buffers.jl +++ b/src/buffers.jl @@ -1,13 +1,23 @@ MPIBuffertype{T} = Union{Ptr{T}, Array{T}, SubArray{T}, Ref{T}} MPIBuffertypeOrConst{T} = Union{MPIBuffertype{T}, SentinelPtr} +# Implementation note +# Base.cconvert and Base.unsafe_convert are a matched pair. +# We must implement Base.unsafe_convert(MPIPtr, ::typeof(Base.cconvert(MPIPtr, x))), +# which is not possible to do generically. So we must define them as we find them. + Base.cconvert(::Type{MPIPtr}, x::Union{Ptr{T}, Array{T}, Ref{T}}) where T = Base.cconvert(Ptr{T}, x) Base.cconvert(::Type{MPIPtr}, x::SubArray{T}) where T = Base.cconvert(Ptr{T}, x) function Base.unsafe_convert(::Type{MPIPtr}, x::MPIBuffertype{T}) where T ptr = Base.unsafe_convert(Ptr{T}, x) reinterpret(MPIPtr, ptr) end - +@static if VERSION >= v"1.14.0-DEV" + function Base.unsafe_convert(::Type{MPIPtr}, x::Base.OffsetCConvert{T}) where {T} + ptr = Base.unsafe_convert(Ptr{T}, x) # Base handles offset arithmetic + reinterpret(MPIPtr, ptr) + end +end Base.cconvert(::Type{MPIPtr}, x::String) = x Base.unsafe_convert(::Type{MPIPtr}, x::String) = reinterpret(MPIPtr, pointer(x)) diff --git a/test/runtests.jl b/test/runtests.jl index 30d27b674..351c87564 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -84,7 +84,7 @@ testfiles = sort(filter(istest, readdir(testdir))) # test number of processes. "JULIA_MPI_TEST_NUM_PROCESSES"=>string(n)) if f == "test_spawn.jl" - # Some command as the others, but always use a single process + # Same command as the others, but always use a single process run(cmd(1)) elseif f == "test_threads.jl" # Legacy Intel MPI (before 2020) crashes threads tests: