Skip to content

Commit

Permalink
fix Info issues on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Jun 26, 2019
1 parent dd3e256 commit f689ed5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/info.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function Base.getindex(info::Info, key::Symbol)
@assert isascii(skey) && length(skey) <= MPI_MAX_INFO_KEY
valuelen = Ref{Cint}()
flag = Ref{Cint}()
# int MPI_Info_get_valuelen(MPI_Info info, const char *key, int *valuelen, int *flag)
@mpichk ccall((:MPI_Info_get_valuelen, libmpi), Cint,
(MPI_Info, Cstring, Ptr{Cint}, Ptr{Cint}),
info, skey, valuelen, flag)
Expand All @@ -92,12 +93,18 @@ function Base.getindex(info::Info, key::Symbol)
throw(KeyError(key))
end

# According to the MPI standard:
# "`valuelen` should be one less than the amount of allocated
# space to allow for the null terminator."
# But MS-MPI will insists on setting the `n`th character as NUL,
# so we simply pad both to avoid problems.
n = valuelen[]
buffer = Vector{UInt8}(undef, n)
buffer = Vector{UInt8}(undef, n+2)
# int MPI_Info_get(MPI_Info info, const char *key, int valuelen, char *value, int *flag)
@mpichk ccall((:MPI_Info_get, libmpi), Cint,
(MPI_Info, Cstring, Cint, Ptr{UInt8}, Ptr{Cint}),
info, skey, n, buffer, flag)
return String(buffer)
info, skey, n+1, buffer, flag)
return String(resize!(buffer,n))
end

function Base.delete!(info::Info,key::Symbol)
Expand All @@ -118,7 +125,7 @@ function Base.length(info::Info)
end

function nthkey(info::Info, n::Integer)
buffer = Vector{UInt8}(undef, MPI_MAX_INFO_KEY)
buffer = Vector{UInt8}(undef, MPI_MAX_INFO_KEY+1)
@mpichk ccall((:MPI_Info_get_nthkey, libmpi), Cint,
(MPI_Info, Cint, Ptr{UInt8}), info, n, buffer)
i = findfirst(isequal(UInt8(0)), buffer)
Expand Down

0 comments on commit f689ed5

Please sign in to comment.