From 9c621ad5a46a0787c6d768b0c369be4102658d5c Mon Sep 17 00:00:00 2001 From: Nathan Hjelm Date: Fri, 23 Jun 2017 08:01:31 -0600 Subject: [PATCH] opal/info: fix abstraction break The new info infrastructure introduced an abstration break by including mpi.h and using MPI_ constants in opal. This commit fixes the break by changing the constants to their opal equivalents. Signed-off-by: Nathan Hjelm --- opal/util/info.c | 53 ++++++++++++--------------- opal/util/info.h | 73 ++++++++++++++++++------------------- opal/util/info_subscriber.c | 22 +++++------ 3 files changed, 71 insertions(+), 77 deletions(-) diff --git a/opal/util/info.c b/opal/util/info.c index 9697d3e52a..48cfd90775 100644 --- a/opal/util/info.c +++ b/opal/util/info.c @@ -43,11 +43,6 @@ #include "opal/util/strncpy.h" #include "opal/util/info.h" -#ifdef XXX -#include "ompi/runtime/mpiruntime.h" -#include "ompi/runtime/params.h" -#endif - /* * Local functions @@ -88,13 +83,13 @@ int opal_info_dup (opal_info_t *info, opal_info_t **newinfo) OPAL_THREAD_LOCK(info->i_lock); OPAL_LIST_FOREACH(iterator, &info->super, opal_info_entry_t) { err = opal_info_set(*newinfo, iterator->ie_key, iterator->ie_value); - if (MPI_SUCCESS != err) { + if (OPAL_SUCCESS != err) { OPAL_THREAD_UNLOCK(info->i_lock); return err; } } OPAL_THREAD_UNLOCK(info->i_lock); - return MPI_SUCCESS; + return OPAL_SUCCESS; } /* @@ -115,8 +110,8 @@ int opal_info_dup_mode (opal_info_t *info, opal_info_t **newinfo, { int err, flag; opal_info_entry_t *iterator; - char savedkey[MPI_MAX_INFO_KEY]; - char savedval[MPI_MAX_INFO_VAL]; + char savedkey[OPAL_MAX_INFO_KEY]; + char savedval[OPAL_MAX_INFO_VAL]; char *valptr, *pkey; int is_IN_key; int exists_IN_key, exists_reg_key; @@ -144,9 +139,9 @@ int opal_info_dup_mode (opal_info_t *info, opal_info_t **newinfo, exists_reg_key = 1; // see if there is an __IN_ for the current - if (strlen(iterator->ie_key) + 5 < MPI_MAX_INFO_KEY) { + if (strlen(iterator->ie_key) + 5 < OPAL_MAX_INFO_KEY) { sprintf(savedkey, "__IN_%s", iterator->ie_key); - err = opal_info_get (info, savedkey, MPI_MAX_INFO_VAL, + err = opal_info_get (info, savedkey, OPAL_MAX_INFO_VAL, savedval, &flag); } else { flag = 0; @@ -166,7 +161,7 @@ int opal_info_dup_mode (opal_info_t *info, opal_info_t **newinfo, // so base our behavior on the omit_ignored if (!omit_ignored) { err = opal_info_set(*newinfo, pkey, iterator->ie_value); - if (MPI_SUCCESS != err) { + if (OPAL_SUCCESS != err) { OPAL_THREAD_UNLOCK(info->i_lock); return err; } @@ -191,7 +186,7 @@ int opal_info_dup_mode (opal_info_t *info, opal_info_t **newinfo, } if (valptr) { err = opal_info_set(*newinfo, pkey, valptr); - if (MPI_SUCCESS != err) { + if (OPAL_SUCCESS != err) { OPAL_THREAD_UNLOCK(info->i_lock); return err; } @@ -199,7 +194,7 @@ int opal_info_dup_mode (opal_info_t *info, opal_info_t **newinfo, } } OPAL_THREAD_UNLOCK(info->i_lock); - return MPI_SUCCESS; + return OPAL_SUCCESS; } /* @@ -222,7 +217,7 @@ int opal_info_set (opal_info_t *info, const char *key, const char *value) new_value = strdup(value); if (NULL == new_value) { - return MPI_ERR_NO_MEM; + return OPAL_ERR_OUT_OF_RESOURCE; } OPAL_THREAD_LOCK(info->i_lock); @@ -238,14 +233,14 @@ int opal_info_set (opal_info_t *info, const char *key, const char *value) if (NULL == new_info) { free(new_value); OPAL_THREAD_UNLOCK(info->i_lock); - return MPI_ERR_NO_MEM; + return OPAL_ERR_OUT_OF_RESOURCE; } - strncpy (new_info->ie_key, key, MPI_MAX_INFO_KEY); + strncpy (new_info->ie_key, key, OPAL_MAX_INFO_KEY); new_info->ie_value = new_value; opal_list_append (&(info->super), (opal_list_item_t *) new_info); } OPAL_THREAD_UNLOCK(info->i_lock); - return MPI_SUCCESS; + return OPAL_SUCCESS; } @@ -293,7 +288,7 @@ int opal_info_get (opal_info_t *info, const char *key, int valuelen, strcpy(value, search->ie_value); } else { opal_strncpy(value, search->ie_value, valuelen); - if (MPI_MAX_INFO_VAL == valuelen) { + if (OPAL_MAX_INFO_VAL == valuelen) { value[valuelen-1] = 0; } else { value[valuelen] = 0; @@ -301,7 +296,7 @@ int opal_info_get (opal_info_t *info, const char *key, int valuelen, } } OPAL_THREAD_UNLOCK(info->i_lock); - return MPI_SUCCESS; + return OPAL_SUCCESS; } int opal_info_get_value_enum (opal_info_t *info, const char *key, int *value, @@ -318,7 +313,7 @@ int opal_info_get_value_enum (opal_info_t *info, const char *key, int *value, if (NULL == search){ OPAL_THREAD_UNLOCK(info->i_lock); *flag = 0; - return MPI_SUCCESS; + return OPAL_SUCCESS; } /* we found a mathing key. pass the string value to the enumerator and @@ -346,7 +341,7 @@ int opal_info_get_bool(opal_info_t *info, char *key, bool *value, int *flag) *value = opal_str_to_bool(str); } - return MPI_SUCCESS; + return OPAL_SUCCESS; } @@ -392,7 +387,7 @@ int opal_info_delete(opal_info_t *info, const char *key) search = info_find_key (info, key); if (NULL == search){ OPAL_THREAD_UNLOCK(info->i_lock); - return MPI_ERR_INFO_NOKEY; + return OPAL_ERR_NOT_FOUND; } else { /* * An entry with this key value was found. Remove the item @@ -404,7 +399,7 @@ int opal_info_delete(opal_info_t *info, const char *key) OBJ_RELEASE(search); } OPAL_THREAD_UNLOCK(info->i_lock); - return MPI_SUCCESS; + return OPAL_SUCCESS; } @@ -429,7 +424,7 @@ int opal_info_get_valuelen (opal_info_t *info, const char *key, int *valuelen, *valuelen = strlen(search->ie_value); } OPAL_THREAD_UNLOCK(info->i_lock); - return MPI_SUCCESS; + return OPAL_SUCCESS; } @@ -451,7 +446,7 @@ int opal_info_get_nthkey (opal_info_t *info, int n, char *key) if (opal_list_get_end(&(info->super)) == (opal_list_item_t *) iterator) { OPAL_THREAD_UNLOCK(info->i_lock); - return MPI_ERR_ARG; + return OPAL_ERR_BAD_PARAM; } } /* @@ -459,9 +454,9 @@ int opal_info_get_nthkey (opal_info_t *info, int n, char *key) * cast it to opal_info_entry_t before we can use it to * access the value */ - strncpy(key, iterator->ie_key, MPI_MAX_INFO_KEY); + strncpy(key, iterator->ie_key, OPAL_MAX_INFO_KEY); OPAL_THREAD_UNLOCK(info->i_lock); - return MPI_SUCCESS; + return OPAL_SUCCESS; } @@ -506,7 +501,7 @@ static void info_destructor(opal_info_t *info) static void info_entry_constructor(opal_info_entry_t *entry) { memset(entry->ie_key, 0, sizeof(entry->ie_key)); - entry->ie_key[MPI_MAX_INFO_KEY] = 0; + entry->ie_key[OPAL_MAX_INFO_KEY] = 0; } diff --git a/opal/util/info.h b/opal/util/info.h index b030fd180d..417ff97143 100644 --- a/opal/util/info.h +++ b/opal/util/info.h @@ -12,7 +12,7 @@ * All rights reserved. * Copyright (c) 2007-2012 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved. - * Copyright (c) 2012-2015 Los Alamos National Security, LLC. All rights + * Copyright (c) 2012-2017 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2017 IBM Corporation. All rights reserved. * $COPYRIGHT$ @@ -27,7 +27,6 @@ #include -#include "mpi.h" #include "opal/class/opal_list.h" #include "opal/class/opal_pointer_array.h" #include "opal/threads/mutex.h" @@ -66,7 +65,7 @@ struct opal_info_entry_t { opal_list_item_t super; /**< required for opal_list_t type */ char *ie_value; /**< value part of the (key, value) pair. * Maximum length is MPI_MAX_INFO_VAL */ - char ie_key[MPI_MAX_INFO_KEY + 1]; /**< "key" part of the (key, value) + char ie_key[OPAL_MAX_INFO_KEY + 1]; /**< "key" part of the (key, value) * pair */ }; /** @@ -81,13 +80,13 @@ BEGIN_C_DECLS * \internal * Some declarations needed to use OBJ_NEW and OBJ_DESTRUCT macros */ -OMPI_DECLSPEC OBJ_CLASS_DECLARATION(opal_info_t); +OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_info_t); /** * \internal * Some declarations needed to use OBJ_NEW and OBJ_DESTRUCT macros */ -OMPI_DECLSPEC OBJ_CLASS_DECLARATION(opal_info_entry_t); +OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_info_entry_t); int opal_mpiinfo_init(void*); @@ -98,8 +97,8 @@ int opal_mpiinfo_init(void*); * @param info source info object (handle) * @param newinfo pointer to the new info object (handle) * - * @retval MPI_SUCCESS upon success - * @retval MPI_ERR_NO_MEM if out of memory + * @retval OPAL_SUCCESS upon success + * @retval OPAL_ERR_OUT_OF_RESOURCE if out of memory * * Not only will the (key, value) pairs be duplicated, the order * of keys will be the same in 'newinfo' as it is in 'info'. When @@ -114,8 +113,8 @@ int opal_info_dup (opal_info_t *info, opal_info_t **newinfo); * @param info source info object (handle) * @param newinfo pointer to the new info object (handle) * - * @retval MPI_SUCCESS upon success - * @retval MPI_ERR_NO_MEM if out of memory + * @retval OPAL_SUCCESS upon success + * @retval OPAL_ERR_OUT_OF_RESOURCE if out of memory * * The user sets an info object with key/value pairs and once processed, * we keep key/val pairs that might have been modified vs what the user @@ -143,10 +142,10 @@ int opal_info_dup_mpistandard (opal_info_t *info, opal_info_t **newinfo); * @param key pointer to the new key object * @param value pointer to the new value object * - * @retval MPI_SUCCESS upon success - * @retval MPI_ERR_NO_MEM if out of memory + * @retval OPAL_SUCCESS upon success + * @retval OPAL_ERR_OUT_OF_RESOURCE if out of memory */ -OMPI_DECLSPEC int opal_info_set (opal_info_t *info, const char *key, const char *value); +OPAL_DECLSPEC int opal_info_set (opal_info_t *info, const char *key, const char *value); /** * Set a new key,value pair from a variable enumerator. @@ -156,11 +155,11 @@ OMPI_DECLSPEC int opal_info_set (opal_info_t *info, const char *key, const char * @param value integer value of the info key (must be valid in var_enum) * @param var_enum variable enumerator * - * @retval MPI_SUCCESS upon success - * @retval MPI_ERR_NO_MEM if out of memory + * @retval OPAL_SUCCESS upon success + * @retval OPAL_ERR_OUT_OF_RESOURCE if out of memory * @retval OPAL_ERR_VALUE_OUT_OF_BOUNDS if the value is not valid in the enumerator */ -OMPI_DECLSPEC int opal_info_set_value_enum (opal_info_t *info, const char *key, int value, +OPAL_DECLSPEC int opal_info_set_value_enum (opal_info_t *info, const char *key, int value, mca_base_var_enum_t *var_enum); /** @@ -168,8 +167,8 @@ OMPI_DECLSPEC int opal_info_set_value_enum (opal_info_t *info, const char *key, * * @param info pointer to info (opal_info_t *) object to be freed (handle) * - * @retval MPI_SUCCESS - * @retval MPI_ERR_ARG + * @retval OPAL_SUCCESS + * @retval OPAL_ERR_BAD_PARAM * * Upon successful completion, 'info' will be set to * 'MPI_INFO_NULL'. Free the info handle and all of its keys and @@ -187,7 +186,7 @@ int opal_info_free (opal_info_t **info); * @param flag true (1) if 'key' defined on 'info', false (0) if not * (logical) * - * @retval MPI_SUCCESS + * @retval OPAL_SUCCESS * * If found, the string value will be cast to the boolen output in * the following manner: @@ -200,7 +199,7 @@ int opal_info_free (opal_info_t **info); * result is false * - All other values are false */ -OMPI_DECLSPEC int opal_info_get_bool (opal_info_t *info, char *key, bool *value, +OPAL_DECLSPEC int opal_info_get_bool (opal_info_t *info, char *key, bool *value, int *flag); /** @@ -216,10 +215,10 @@ OMPI_DECLSPEC int opal_info_get_bool (opal_info_t *info, char *key, bool *value, * @param flag true (1) if 'key' defined on 'info', false (0) if not * (logical) * - * @retval MPI_SUCCESS + * @retval OPAL_SUCCESS */ -OMPI_DECLSPEC int opal_info_get_value_enum (opal_info_t *info, const char *key, +OPAL_DECLSPEC int opal_info_get_value_enum (opal_info_t *info, const char *key, int *value, int default_value, mca_base_var_enum_t *var_enum, int *flag); @@ -233,12 +232,12 @@ OMPI_DECLSPEC int opal_info_get_value_enum (opal_info_t *info, const char *key, * @param flag true (1) if 'key' defined on 'info', false (0) if not * (logical) * - * @retval MPI_SUCCESS + * @retval OPAL_SUCCESS * * In C and C++, 'valuelen' should be one less than the allocated * space to allow for for the null terminator. */ -OMPI_DECLSPEC int opal_info_get (opal_info_t *info, const char *key, int valuelen, +OPAL_DECLSPEC int opal_info_get (opal_info_t *info, const char *key, int valuelen, char *value, int *flag); /** @@ -248,8 +247,8 @@ OMPI_DECLSPEC int opal_info_get (opal_info_t *info, const char *key, int valuele * @param key The key portion of the (key,value) pair that * needs to be deleted * - * @retval MPI_SUCCESS - * @retval MPI_ERR_NOKEY + * @retval OPAL_SUCCESS + * @retval OPAL_ERR_NOT_FOUND */ int opal_info_delete(opal_info_t *info, const char *key); @@ -260,15 +259,15 @@ int opal_info_delete(opal_info_t *info, const char *key); * @param flag - true (1) if 'key' defined on 'info', false (0) if not * (logical) * - * @retval MPI_SUCCESS - * @retval MPI_ERR_ARG + * @retval OPAL_SUCCESS + * @retval OPAL_ERR_BAD_PARAM * @retval MPI_ERR_INFO_KEY * * The length returned in C and C++ does not include the end-of-string * character. If the 'key' is not found on 'info', 'valuelen' is left * alone. */ -OMPI_DECLSPEC int opal_info_get_valuelen (opal_info_t *info, const char *key, int *valuelen, +OPAL_DECLSPEC int opal_info_get_valuelen (opal_info_t *info, const char *key, int *valuelen, int *flag); /** @@ -278,8 +277,8 @@ OMPI_DECLSPEC int opal_info_get_valuelen (opal_info_t *info, const char *key, in * @param n index of key to retrieve (integer) * @param key character string of at least 'MPI_MAX_INFO_KEY' characters * - * @retval MPI_SUCCESS - * @retval MPI_ERR_ARG + * @retval OPAL_SUCCESS + * @retval OPAL_ERR_BAD_PARAM */ int opal_info_get_nthkey (opal_info_t *info, int n, char *key); @@ -294,23 +293,23 @@ int opal_info_get_nthkey (opal_info_t *info, int n, char *key); * @param value Value string for info key to interpret * @param interp returned interpretation of the value key * - * @retval OMPI_SUCCESS string was successfully interpreted - * @retval OMPI_ERR_BAD_PARAM string was not able to be interpreted + * @retval OPAL_SUCCESS string was successfully interpreted + * @retval OPAL_ERR_BAD_PARAM string was not able to be interpreted */ -OMPI_DECLSPEC int opal_info_value_to_bool(char *value, bool *interp); +OPAL_DECLSPEC int opal_info_value_to_bool(char *value, bool *interp); /** * Convert value string to integer * * Convert value string \c value into a integer, using the * interpretation rules specified in MPI-2 Section 4.10. - * All others will return \c OMPI_ERR_BAD_PARAM + * All others will return \c OPAL_ERR_BAD_PARAM * * @param value Value string for info key to interpret * @param interp returned interpretation of the value key * - * @retval OMPI_SUCCESS string was successfully interpreted - * @retval OMPI_ERR_BAD_PARAM string was not able to be interpreted + * @retval OPAL_SUCCESS string was successfully interpreted + * @retval OPAL_ERR_BAD_PARAM string was not able to be interpreted */ int opal_info_value_to_int(char *value, int *interp); @@ -327,7 +326,7 @@ static inline int opal_info_get_nkeys(opal_info_t *info, int *nkeys) { *nkeys = (int) opal_list_get_size(&(info->super)); - return MPI_SUCCESS; + return OPAL_SUCCESS; } bool opal_str_to_bool(char*); diff --git a/opal/util/info_subscriber.c b/opal/util/info_subscriber.c index 0b8a8c475e..e03d9ca766 100644 --- a/opal/util/info_subscriber.c +++ b/opal/util/info_subscriber.c @@ -12,7 +12,7 @@ * All rights reserved. * Copyright (c) 2007-2015 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved. - * Copyright (c) 2012-2015 Los Alamos National Security, LLC. All rights + * Copyright (c) 2012-2017 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. @@ -253,19 +253,19 @@ opal_infosubscribe_testregister(opal_infosubscriber_t *object) static int save_original_key_val(opal_info_t *info, char *key, char *val, int overwrite) { - char modkey[MPI_MAX_INFO_KEY]; + char modkey[OPAL_MAX_INFO_KEY]; int flag, err; // Checking strlen, even though it should be unnecessary. // This should only happen on predefined keys with short lengths. - if (strlen(key) + 5 < MPI_MAX_INFO_KEY) { + if (strlen(key) + 5 < OPAL_MAX_INFO_KEY) { sprintf(modkey, "__IN_%s", key); flag = 0; opal_info_get(info, modkey, 0, NULL, &flag); if (!flag || overwrite) { err = opal_info_set(info, modkey, val); - if (MPI_SUCCESS != err) { + if (OPAL_SUCCESS != err) { return err; } } @@ -278,7 +278,7 @@ save_original_key_val(opal_info_t *info, char *key, char *val, int overwrite) printf("WARNING: Unexpected key length [%s]\n", key); #endif } - return MPI_SUCCESS; + return OPAL_SUCCESS; } int @@ -308,9 +308,9 @@ opal_infosubscribe_change_info(opal_infosubscriber_t *object, opal_info_t *new_i // either way it shouldn't be set, which we'll ensure with an unset // in case a previous value exists. err = opal_info_delete(object->s_info, iterator->ie_key); - err = MPI_SUCCESS; // we don't care if the key was found or not + err = OPAL_SUCCESS; // we don't care if the key was found or not } - if (MPI_SUCCESS != err) { + if (OPAL_SUCCESS != err) { return err; } // Save the original at "__IN_":"original" @@ -378,12 +378,12 @@ int opal_infosubscribe_subscribe(opal_infosubscriber_t *object, char *key, char } // - is there a value already associated with key in this obj's info: // to use in the callback() - char *buffer = malloc(MPI_MAX_INFO_VAL+1); // (+1 shouldn't be needed) + char *buffer = malloc(OPAL_MAX_INFO_VAL+1); // (+1 shouldn't be needed) char *val = value; // start as default value int flag = 0; char *updated_value; int err; - opal_info_get(object->s_info, key, MPI_MAX_INFO_VAL, buffer, &flag); + opal_info_get(object->s_info, key, OPAL_MAX_INFO_VAL, buffer, &flag); if (flag) { val = buffer; // become info value if this key was in info } @@ -393,9 +393,9 @@ int opal_infosubscribe_subscribe(opal_infosubscriber_t *object, char *key, char err = opal_info_set(object->s_info, key, updated_value); } else { err = opal_info_delete(object->s_info, key); - err = MPI_SUCCESS; // we don't care if the key was found or not + err = OPAL_SUCCESS; // we don't care if the key was found or not } - if (MPI_SUCCESS != err) { + if (OPAL_SUCCESS != err) { free(buffer); return err; }