Commit 4efc8b2e authored by Junchao Zhang's avatar Junchao Zhang
Browse files

Allocate mem. for a cvar when its type is MPI_CHAR

https://svn.mpi-forum.org/trac/mpi-forum-web/ticket/405

 says :
"The use of the datatype MPI_CHAR in the MPI tool information interface implies a
null-terminated character array, i.e. a string in the C language. If a variable has
type MPI_CHAR, the value of the count parameter returned by MPI_T_CVAR_HANDLE_ALLOC
and MPI_T_PVAR_HANDLE_ALLOC will include the null-terminating character."

Unlike cvars of type MPI_INT etc, MPI_CHAR cvars need explicit memory allocation for their storage.
Note: In MPI standard, MPI_CHAR is not in types of pvar.

Fixes #2021
Signed-off-by: Sangmin Seo's avatarSangmin Seo <sseo@anl.gov>
parent 998a8a0b
......@@ -315,7 +315,19 @@ void MPIR_T_CVAR_REGISTER_impl(
cvar->datatype = dtype;
cvar->name = MPIU_Strdup(name);
MPIU_Assert(cvar->name);
cvar->addr = (void *)addr;
if (dtype != MPI_CHAR) {
cvar->addr = (void *)addr;
} else {
cvar->addr = MPIU_Malloc(count);
MPIU_Assert(cvar->addr);
if (defaultval.str == NULL) {
((char *)(cvar->addr))[0] = '\0';
} else {
/* Use greater (>), since count includes the terminating '\0', but strlen does not */
MPIU_Assert(count > strlen(defaultval.str));
strcpy(cvar->addr, defaultval.str);
}
}
cvar->count = count;
cvar->verbosity = verb;
cvar->bind = binding;
......
......@@ -102,6 +102,7 @@ static void MPIR_T_cvar_env_finalize(void)
cvar = (cvar_table_entry_t *)utarray_eltptr(cvar_table, i);
MPIU_Free((void *)cvar->name);
MPIU_Free((void *)cvar->desc);
if (cvar->datatype == MPI_CHAR) MPIU_Free(cvar->addr);
}
/* Free pvar_table itself */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment