1
1

Fix the cases where the default values of MCA params were not always

handled properly when MCA parameters are re-registered and their types
change.  Specifically, this case was broken:

 1. Register an int MCA param with a non-zero default value
 1. Re-register the same MCA param as a string with a NULL default value

The 2nd step would cause a segv because the first int default value
wasn't being reset properly.  Here's sample code that shows the issue:

{{{
{
    int ibogus;
    char *sbogus;
    opal_init(&argc, &argv);
    mca_base_param_reg_int_name("type", "name", "help", false, false, 3, &ibogus);
    printf("Ibogus: %d\n", ibogus);
    mca_base_param_reg_string_name("type", "name", "help", false, false, NULL, &sbogus);
    printf("Sbogus: %s\n", (NULL == sbogus) ? "NULL" : sbogus);
    exit(0);
}
}}}

This commit fixes the problem from the sample code above as well as
the a similar issue for file-set MCA params and override values.  It
also resets default values for MCA params initially registered as a
string but then re-registered as an int.

This commit was SVN r25392.
Этот коммит содержится в:
Jeff Squyres 2011-10-29 12:29:31 +00:00
родитель b0bd0b3924
Коммит 6092b50ebb

Просмотреть файл

@ -1432,6 +1432,12 @@ static int param_register(const char *type_name,
NULL != param.mbp_default_value.stringval) {
array[i].mbp_default_value.stringval =
strdup(param.mbp_default_value.stringval);
} else {
/* If the new STRING doesn't have a default value, we
must set the default value to "NULL" because it still
contains the old INT default value (which may not
compare equally to NULL) */
array[i].mbp_default_value.stringval = NULL;
}
if (NULL != file_value &&
@ -1439,6 +1445,12 @@ static int param_register(const char *type_name,
array[i].mbp_file_value.stringval =
strdup(param.mbp_file_value.stringval);
array[i].mbp_file_value_set = true;
} else {
/* Similar to above, be sure to set the file default
value to NULL to ensure that it's not still set to a
non-NULL value from the prior INT default value */
array[i].mbp_file_value.stringval = NULL;
array[i].mbp_file_value_set = false;
}
if (NULL != override_value &&
@ -1446,6 +1458,12 @@ static int param_register(const char *type_name,
array[i].mbp_override_value.stringval =
strdup(param.mbp_override_value.stringval);
array[i].mbp_override_value_set = true;
} else {
/* Similar to above, be sure to set the file default
value to NULL to ensure that it's not still set to a
non-NULL value from the prior INT default value */
array[i].mbp_file_value.stringval = NULL;
array[i].mbp_file_value_set = false;
}
array[i].mbp_type = param.mbp_type;
@ -1455,13 +1473,19 @@ static int param_register(const char *type_name,
else if (MCA_BASE_PARAM_TYPE_STRING == array[i].mbp_type &&
MCA_BASE_PARAM_TYPE_INT == param.mbp_type) {
/* Free the old STRING default value, if it exists */
if (NULL != array[i].mbp_default_value.stringval) {
free(array[i].mbp_default_value.stringval);
}
/* Set the new default value, or 0 if one wasn't provided */
if (NULL != default_value) {
if (NULL != array[i].mbp_default_value.stringval) {
free(array[i].mbp_default_value.stringval);
}
array[i].mbp_default_value.intval =
param.mbp_default_value.intval;
} else {
array[i].mbp_default_value.intval = 0;
}
if (NULL != file_value) {
if (NULL != array[i].mbp_file_value.stringval) {
free(array[i].mbp_file_value.stringval);
@ -1469,7 +1493,11 @@ static int param_register(const char *type_name,
array[i].mbp_file_value.intval =
param.mbp_file_value.intval;
array[i].mbp_file_value_set = true;
} else {
array[i].mbp_file_value.intval = 0;
array[i].mbp_file_value_set = false;
}
if (NULL != override_value) {
if (NULL != array[i].mbp_override_value.stringval) {
free(array[i].mbp_override_value.stringval);
@ -1477,6 +1505,9 @@ static int param_register(const char *type_name,
array[i].mbp_override_value.intval =
param.mbp_override_value.intval;
array[i].mbp_override_value_set = true;
} else {
array[i].mbp_file_value.intval = 0;
array[i].mbp_file_value_set = false;
}
array[i].mbp_type = param.mbp_type;