Skip to content

Commit f689ed5

Browse files
committed
fix Info issues on Windows
1 parent dd3e256 commit f689ed5

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/info.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function Base.getindex(info::Info, key::Symbol)
8484
@assert isascii(skey) && length(skey) <= MPI_MAX_INFO_KEY
8585
valuelen = Ref{Cint}()
8686
flag = Ref{Cint}()
87+
# int MPI_Info_get_valuelen(MPI_Info info, const char *key, int *valuelen, int *flag)
8788
@mpichk ccall((:MPI_Info_get_valuelen, libmpi), Cint,
8889
(MPI_Info, Cstring, Ptr{Cint}, Ptr{Cint}),
8990
info, skey, valuelen, flag)
@@ -92,12 +93,18 @@ function Base.getindex(info::Info, key::Symbol)
9293
throw(KeyError(key))
9394
end
9495

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

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

120127
function nthkey(info::Info, n::Integer)
121-
buffer = Vector{UInt8}(undef, MPI_MAX_INFO_KEY)
128+
buffer = Vector{UInt8}(undef, MPI_MAX_INFO_KEY+1)
122129
@mpichk ccall((:MPI_Info_get_nthkey, libmpi), Cint,
123130
(MPI_Info, Cint, Ptr{UInt8}), info, n, buffer)
124131
i = findfirst(isequal(UInt8(0)), buffer)

0 commit comments

Comments
 (0)