Merge pull request #5642 from bosilca/topic/less_mca_mem
Use less memory for the MCA variable names.
Этот коммит содержится в:
Коммит
d944e9f3ab
@ -1381,7 +1381,7 @@ static int register_variable (const char *project_name, const char *framework_na
|
||||
var->mbv_type = type;
|
||||
var->mbv_flags = flags;
|
||||
var->mbv_group_index = group_index;
|
||||
var->mbv_info_lvl = info_lvl;
|
||||
var->mbv_info_lvl = info_lvl;
|
||||
var->mbv_scope = scope;
|
||||
var->mbv_synonym_for = synonym_for;
|
||||
var->mbv_bind = bind;
|
||||
@ -1390,27 +1390,23 @@ static int register_variable (const char *project_name, const char *framework_na
|
||||
var->mbv_description = strdup(description);
|
||||
}
|
||||
|
||||
if (NULL != variable_name) {
|
||||
var->mbv_variable_name = strdup(variable_name);
|
||||
if (NULL == var->mbv_variable_name) {
|
||||
OBJ_RELEASE(var);
|
||||
return OPAL_ERR_OUT_OF_RESOURCE;
|
||||
}
|
||||
}
|
||||
|
||||
ret = mca_base_var_generate_full_name4 (NULL, framework_name, component_name,
|
||||
variable_name, &var->mbv_full_name);
|
||||
if (OPAL_SUCCESS != ret) {
|
||||
OBJ_RELEASE(var);
|
||||
return OPAL_ERROR;
|
||||
}
|
||||
|
||||
ret = mca_base_var_generate_full_name4 (project_name, framework_name, component_name,
|
||||
variable_name, &var->mbv_long_name);
|
||||
if (OPAL_SUCCESS != ret) {
|
||||
OBJ_RELEASE(var);
|
||||
return OPAL_ERROR;
|
||||
}
|
||||
/* The mbv_full_name and the variable name are subset of the mbv_long_name
|
||||
* so instead of allocating them we can just point into the var mbv_long_name
|
||||
* at the right location.
|
||||
*/
|
||||
var->mbv_full_name = var->mbv_long_name +
|
||||
(NULL == project_name ? 0 : (strlen(project_name)+1)); /* 1 for _ */
|
||||
if( NULL != variable_name ) {
|
||||
var->mbv_variable_name = var->mbv_full_name +
|
||||
(NULL == framework_name ? 0 : (strlen(framework_name)+1)) +
|
||||
(NULL == component_name ? 0 : (strlen(component_name)+1));
|
||||
}
|
||||
|
||||
/* Add it to the array. Note that we copy the mca_var_t by value,
|
||||
so the entire contents of the struct is copied. The synonym list
|
||||
@ -1588,31 +1584,27 @@ int mca_base_var_register_synonym (int synonym_for, const char *project_name,
|
||||
|
||||
static int var_get_env (mca_base_var_t *var, const char *name, char **source, char **value)
|
||||
{
|
||||
char *source_env, *value_env;
|
||||
char envvar[128];
|
||||
int ret;
|
||||
|
||||
ret = asprintf (&source_env, "%sSOURCE_%s", mca_prefix, name);
|
||||
ret = snprintf(envvar, 128, "%s%s", mca_prefix, name);
|
||||
if (0 > ret) {
|
||||
opal_output(0, "Variable string too short to hold %s%s\n", mca_prefix, name);
|
||||
return OPAL_ERROR;
|
||||
}
|
||||
|
||||
ret = asprintf (&value_env, "%s%s", mca_prefix, name);
|
||||
if (0 > ret) {
|
||||
free (source_env);
|
||||
return OPAL_ERROR;
|
||||
}
|
||||
|
||||
*source = getenv (source_env);
|
||||
*value = getenv (value_env);
|
||||
|
||||
free (source_env);
|
||||
free (value_env);
|
||||
|
||||
if (NULL == *value) {
|
||||
*value = getenv(envvar);
|
||||
if( NULL == *value ) {
|
||||
*source = NULL;
|
||||
return OPAL_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
ret = snprintf(envvar, 128, "%sSOURCE_%s", mca_prefix, name);
|
||||
if( ret >= 128 ) {
|
||||
opal_output(0, "Variable string too short to hold %sSOURCE_%s\n", mca_prefix, name);
|
||||
return OPAL_ERROR;
|
||||
}
|
||||
*source = getenv(envvar);
|
||||
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
|
||||
@ -1851,15 +1843,11 @@ static void var_destructor(mca_base_var_t *var)
|
||||
OBJ_RELEASE(var->mbv_enumerator);
|
||||
}
|
||||
|
||||
if (NULL != var->mbv_variable_name) {
|
||||
free(var->mbv_variable_name);
|
||||
}
|
||||
if (NULL != var->mbv_full_name) {
|
||||
free(var->mbv_full_name);
|
||||
}
|
||||
if (NULL != var->mbv_long_name) {
|
||||
free(var->mbv_long_name);
|
||||
}
|
||||
var->mbv_full_name = NULL;
|
||||
var->mbv_variable_name = NULL;
|
||||
|
||||
if (NULL != var->mbv_description) {
|
||||
free(var->mbv_description);
|
||||
@ -1998,10 +1986,6 @@ static int var_value_string (mca_base_var_t *var, char **value_string)
|
||||
} else {
|
||||
ret = var->mbv_enumerator->string_from_value(var->mbv_enumerator, value->intval, value_string);
|
||||
}
|
||||
|
||||
if (OPAL_SUCCESS != ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user