@@ -84,6 +84,7 @@ function Base.getindex(info::Info, key::Symbol)
84
84
@assert isascii (skey) && length (skey) <= MPI_MAX_INFO_KEY
85
85
valuelen = Ref {Cint} ()
86
86
flag = Ref {Cint} ()
87
+ # int MPI_Info_get_valuelen(MPI_Info info, const char *key, int *valuelen, int *flag)
87
88
@mpichk ccall ((:MPI_Info_get_valuelen , libmpi), Cint,
88
89
(MPI_Info, Cstring, Ptr{Cint}, Ptr{Cint}),
89
90
info, skey, valuelen, flag)
@@ -92,12 +93,18 @@ function Base.getindex(info::Info, key::Symbol)
92
93
throw (KeyError (key))
93
94
end
94
95
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.
95
101
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)
97
104
@mpichk ccall ((:MPI_Info_get , libmpi), Cint,
98
105
(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) )
101
108
end
102
109
103
110
function Base. delete! (info:: Info ,key:: Symbol )
@@ -118,7 +125,7 @@ function Base.length(info::Info)
118
125
end
119
126
120
127
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 )
122
129
@mpichk ccall ((:MPI_Info_get_nthkey , libmpi), Cint,
123
130
(MPI_Info, Cint, Ptr{UInt8}), info, n, buffer)
124
131
i = findfirst (isequal (UInt8 (0 )), buffer)
0 commit comments