Commit c1a3c229 authored by Junchao Zhang's avatar Junchao Zhang
Browse files

Improve MPI_T error handling



Move error checking from critical paths. Fixes #1978
Signed-off-by: default avatarAntonio J. Pena <apenya@mcs.anl.gov>
parent 84ef4e85
......@@ -15,6 +15,16 @@
#include "mpiu_uthash.h"
#include "mpiimplthread.h" /* For MPICH_IS_THREADED */
#ifdef HAVE_ERROR_CHECKING
typedef enum {
MPIR_T_OBJECT_INVALID = 0,
MPIR_T_ENUM_HANDLE,
MPIR_T_CVAR_HANDLE,
MPIR_T_PVAR_HANDLE,
MPIR_T_PVAR_SESSION
} MPIR_T_object_kind;
#endif
/* MPI_T enum
*/
typedef struct enum_item_s {
......@@ -23,6 +33,9 @@ typedef struct enum_item_s {
} enum_item_t;
typedef struct MPIR_T_enum_s {
#ifdef HAVE_ERROR_CHECKING
MPIR_T_object_kind kind;
#endif
const char *name;
UT_array *items;
} MPIR_T_enum_t;
......@@ -102,6 +115,10 @@ typedef struct cvar_table_entry_s {
} cvar_table_entry_t;
typedef struct MPIR_T_cvar_handle_s {
#ifdef HAVE_ERROR_CHECKING
MPIR_T_object_kind kind;
#endif
/* Address and count of the cvar. Set at handle allocation time */
void *addr;
int count;
......@@ -257,6 +274,10 @@ typedef struct {
} MPIR_T_pvar_watermark_t;
typedef struct MPIR_T_pvar_handle_s {
#ifdef HAVE_ERROR_CHECKING
MPIR_T_object_kind kind;
#endif
/* These are cached fields from pvar table. Do so to avoid extra
* indirection when accessing them through pvar handles.
*/
......@@ -315,6 +336,10 @@ typedef struct MPIR_T_pvar_handle_s {
} MPIR_T_pvar_handle_t;
typedef struct MPIR_T_pvar_session_s {
#ifdef HAVE_ERROR_CHECKING
MPIR_T_object_kind kind;
#endif
/* A linked list of pvar handles */
MPIR_T_pvar_handle_t *hlist;
} MPIR_T_pvar_session_t;
......@@ -1393,12 +1418,4 @@ extern MPIU_Thread_mutex_t mpi_t_mutex;
extern void MPIR_T_env_init(void);
extern void MPIR_T_env_finalize(void);
#define MPIR_T_FAIL_IF_UNINITIALIZED() \
do { \
if (!MPIR_T_is_initialized()) { \
mpi_errno = MPI_T_ERR_NOT_INITIALIZED; \
goto fn_fail; \
} \
} while (0)
#endif
......@@ -49,14 +49,24 @@ int MPI_T_category_changed(int *stamp)
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CATEGORY_CHANGED);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CATEGORY_CHANGED);
/* Validate parameters */
# ifdef HAVE_ERROR_CHECKING
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_ARGNULL(stamp, "stamp", mpi_errno);
}
MPID_END_ERROR_CHECKS
}
# endif /* HAVE_ERROR_CHECKING */
/* ... body of routine ... */
if (stamp != NULL)
*stamp = cat_stamp;
*stamp = cat_stamp;
/* ... end of body of routine ... */
......
......@@ -76,7 +76,7 @@ int MPI_T_category_get_categories(int cat_index, int len, int indices[])
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CATEGORY_GET_CATEGORIES);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CATEGORY_GET_CATEGORIES);
......@@ -85,6 +85,7 @@ int MPI_T_category_get_categories(int cat_index, int len, int indices[])
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_CAT_INDEX(cat_index, mpi_errno);
if (len != 0)
MPIR_ERRTEST_ARGNULL(indices, "indices", mpi_errno);
}
......@@ -93,10 +94,6 @@ int MPI_T_category_get_categories(int cat_index, int len, int indices[])
# endif /* HAVE_ERROR_CHECKING */
/* ... body of routine ... */
if (cat_index < 0 || cat_index >= utarray_len(cat_table)) {
mpi_errno = MPI_T_ERR_INVALID_INDEX;
goto fn_fail;
}
if (len == 0) goto fn_exit;
......
......@@ -76,7 +76,7 @@ int MPI_T_category_get_cvars(int cat_index, int len, int indices[])
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CATEGORY_GET_CVARS);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CATEGORY_GET_CVARS);
......@@ -85,6 +85,7 @@ int MPI_T_category_get_cvars(int cat_index, int len, int indices[])
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_CAT_INDEX(cat_index, mpi_errno);
if (len != 0)
MPIR_ERRTEST_ARGNULL(indices, "indices", mpi_errno);
}
......@@ -93,10 +94,6 @@ int MPI_T_category_get_cvars(int cat_index, int len, int indices[])
# endif /* HAVE_ERROR_CHECKING */
/* ... body of routine ... */
if (cat_index < 0 || cat_index >= utarray_len(cat_table)) {
mpi_errno = MPI_T_ERR_INVALID_INDEX;
goto fn_fail;
}
if (len == 0) goto fn_exit;
......
......@@ -57,7 +57,7 @@ int MPI_T_category_get_info(int cat_index, char *name, int *name_len, char *desc
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CATEGORY_GET_INFO);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CATEGORY_GET_INFO);
......@@ -66,7 +66,8 @@ int MPI_T_category_get_info(int cat_index, char *name, int *name_len, char *desc
{
MPID_BEGIN_ERROR_CHECKS
{
/* Do not do _TEST_ARGNULL for any argument, since this is
MPIR_ERRTEST_CAT_INDEX(cat_index, mpi_errno);
/* Do not do _TEST_ARGNULL for other arguments, since this is
* allowed or will be allowed by MPI_T standard.
*/
}
......@@ -75,10 +76,6 @@ int MPI_T_category_get_info(int cat_index, char *name, int *name_len, char *desc
# endif /* HAVE_ERROR_CHECKING */
/* ... body of routine ... */
if (cat_index < 0 || cat_index >= utarray_len(cat_table)) {
mpi_errno = MPI_T_ERR_INVALID_INDEX;
goto fn_fail;
}
cat_table_entry_t *cat;
cat = (cat_table_entry_t *)utarray_eltptr(cat_table, cat_index);
......
......@@ -44,14 +44,24 @@ int MPI_T_category_get_num(int *num_cat)
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CATEGORY_GET_NUM);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CATEGORY_GET_NUM);
/* Validate parameters */
# ifdef HAVE_ERROR_CHECKING
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_ARGNULL(num_cat, "num_cat", mpi_errno);
}
MPID_END_ERROR_CHECKS
}
# endif /* HAVE_ERROR_CHECKING */
/* ... body of routine ... */
if (*num_cat)
*num_cat = utarray_len(cat_table);
*num_cat = utarray_len(cat_table);
/* ... end of body of routine ... */
......
......@@ -76,7 +76,7 @@ int MPI_T_category_get_pvars(int cat_index, int len, int indices[])
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CATEGORY_GET_PVARS);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CATEGORY_GET_PVARS);
......@@ -85,6 +85,7 @@ int MPI_T_category_get_pvars(int cat_index, int len, int indices[])
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_CAT_INDEX(cat_index, mpi_errno);
if (len != 0)
MPIR_ERRTEST_ARGNULL(indices, "indices", mpi_errno);
}
......@@ -93,10 +94,6 @@ int MPI_T_category_get_pvars(int cat_index, int len, int indices[])
# endif /* HAVE_ERROR_CHECKING */
/* ... body of routine ... */
if (cat_index < 0 || cat_index >= utarray_len(cat_table)) {
mpi_errno = MPI_T_ERR_INVALID_INDEX;
goto fn_fail;
}
if (len == 0) goto fn_exit;
......
......@@ -60,7 +60,7 @@ int MPI_T_cvar_get_info(int cvar_index, char *name, int *name_len,
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CVAR_GET_INFO);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CVAR_GET_INFO);
......@@ -69,6 +69,7 @@ int MPI_T_cvar_get_info(int cvar_index, char *name, int *name_len,
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_CVAR_INDEX(cvar_index, mpi_errno);
/* Do not do *_TEST_ARGNULL for pointer arguments, since this is
* allowed or will be allowed by MPI_T standard.
*/
......@@ -78,10 +79,6 @@ int MPI_T_cvar_get_info(int cvar_index, char *name, int *name_len,
# endif /* HAVE_ERROR_CHECKING */
/* ... body of routine ... */
if (cvar_index < 0 || cvar_index >= utarray_len(cvar_table)) {
mpi_errno = MPI_T_ERR_INVALID_INDEX;
goto fn_fail;
}
const cvar_table_entry_t *cvar;
cvar = (cvar_table_entry_t *)utarray_eltptr(cvar_table, cvar_index);
......
......@@ -44,14 +44,25 @@ int MPI_T_cvar_get_num(int *num_cvar)
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CVAR_GET_NUM);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CVAR_GET_NUM);
/* Validate parameters */
# ifdef HAVE_ERROR_CHECKING
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_ARGNULL(num_cvar, "num_cvar", mpi_errno);
}
MPID_END_ERROR_CHECKS
}
# endif /* HAVE_ERROR_CHECKING */
/* ... body of routine ... */
if (num_cvar != NULL)
*num_cvar = utarray_len(cvar_table);
*num_cvar = utarray_len(cvar_table);
/* ... end of body of routine ... */
......
......@@ -39,6 +39,9 @@ int MPIR_T_cvar_handle_alloc_impl(int cvar_index, void *obj_handle, MPI_T_cvar_h
/* Allocate handle memory */
MPIU_CHKPMEM_MALLOC(hnd, MPIR_T_cvar_handle_t*, sizeof(*hnd), mpi_errno, "control variable handle");
#ifdef HAVE_ERROR_CHECKING
hnd->kind = MPIR_T_CVAR_HANDLE;
#endif
/* It is time to fix addr and count if they are unknown */
if (cvar->get_count != NULL)
......@@ -98,7 +101,7 @@ int MPI_T_cvar_handle_alloc(int cvar_index, void *obj_handle, MPI_T_cvar_handle
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CVAR_HANDLE_ALLOC);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CVAR_HANDLE_ALLOC);
......@@ -107,6 +110,9 @@ int MPI_T_cvar_handle_alloc(int cvar_index, void *obj_handle, MPI_T_cvar_handle
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_CVAR_INDEX(cvar_index, mpi_errno);
/* obj_handle is ignored if cvar has no binding, so no
TEST_ARGNULL for it */
MPIR_ERRTEST_ARGNULL(handle, "handle", mpi_errno);
MPIR_ERRTEST_ARGNULL(count, "count", mpi_errno);
}
......@@ -115,10 +121,6 @@ int MPI_T_cvar_handle_alloc(int cvar_index, void *obj_handle, MPI_T_cvar_handle
# endif /* HAVE_ERROR_CHECKING */
/* ... body of routine ... */
if (cvar_index < 0 || cvar_index >= utarray_len(cvar_table)) {
mpi_errno = MPI_T_ERR_INVALID_INDEX;
goto fn_fail;
}
mpi_errno = MPIR_T_cvar_handle_alloc_impl(cvar_index, obj_handle, handle, count);
if (mpi_errno) MPIU_ERR_POP(mpi_errno);
......
......@@ -45,17 +45,26 @@ int MPI_T_cvar_handle_free(MPI_T_cvar_handle *handle)
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CVAR_HANDLE_FREE);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CVAR_HANDLE_FREE);
/* Validate parameters */
# ifdef HAVE_ERROR_CHECKING
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_ARGNULL(handle, "handle", mpi_errno);
}
MPID_END_ERROR_CHECKS
}
# endif /* HAVE_ERROR_CHECKING */
/* ... body of routine ... */
if (handle != NULL) {
MPIR_T_cvar_handle_t *hnd = *handle;
MPIU_Free(hnd);
*handle = MPI_T_CVAR_HANDLE_NULL;
}
MPIR_T_cvar_handle_t *hnd = *handle;
MPIU_Free(hnd);
*handle = MPI_T_CVAR_HANDLE_NULL;
/* ... end of body of routine ... */
......
......@@ -102,7 +102,7 @@ int MPI_T_cvar_read(MPI_T_cvar_handle handle, void *buf)
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CVAR_READ);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CVAR_READ);
......@@ -111,7 +111,7 @@ int MPI_T_cvar_read(MPI_T_cvar_handle handle, void *buf)
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_ARGNULL(handle, "handle", mpi_errno);
MPIR_ERRTEST_CVAR_HANDLE(handle, mpi_errno);
MPIR_ERRTEST_ARGNULL(buf, "buf", mpi_errno);
}
MPID_END_ERROR_CHECKS
......
......@@ -110,7 +110,7 @@ int MPI_T_cvar_write(MPI_T_cvar_handle handle, void *buf)
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CVAR_WRITE);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CVAR_WRITE);
......@@ -119,7 +119,7 @@ int MPI_T_cvar_write(MPI_T_cvar_handle handle, void *buf)
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_ARGNULL(handle, "handle", mpi_errno);
MPIR_ERRTEST_CVAR_HANDLE(handle, mpi_errno);
MPIR_ERRTEST_ARGNULL(buf, "buf", mpi_errno);
}
MPID_END_ERROR_CHECKS
......
......@@ -52,7 +52,7 @@ int MPI_T_enum_get_info(MPI_T_enum enumtype, int *num, char *name, int *name_len
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_ENUM_GET_INFO);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_ENUM_GET_INFO);
......@@ -61,7 +61,7 @@ int MPI_T_enum_get_info(MPI_T_enum enumtype, int *num, char *name, int *name_len
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_ARGNULL(enumtype, "enumtype", mpi_errno);
MPIR_ERRTEST_ENUM_HANDLE(enumtype, mpi_errno);
MPIR_ERRTEST_ARGNULL(num, "num", mpi_errno);
/* Do not do _TEST_ARGNULL for name or name_len, since this is
* permitted per MPI_T standard.
......
......@@ -54,7 +54,7 @@ int MPI_T_enum_get_item(MPI_T_enum enumtype, int index, int *value, char *name,
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_ENUM_GET_ITEM);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_ENUM_GET_ITEM);
......@@ -63,7 +63,8 @@ int MPI_T_enum_get_item(MPI_T_enum enumtype, int index, int *value, char *name,
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_ARGNULL(enumtype, "enumtype", mpi_errno);
MPIR_ERRTEST_ENUM_HANDLE(enumtype, mpi_errno);
MPIR_ERRTEST_ENUM_ITEM(enumtype, index, mpi_errno);
MPIR_ERRTEST_ARGNULL(value, "value", mpi_errno);
/* Do not do TEST_ARGNULL for name or name_len, since this is
* permitted per MPI_T standard.
......@@ -75,11 +76,6 @@ int MPI_T_enum_get_item(MPI_T_enum enumtype, int index, int *value, char *name,
/* ... body of routine ... */
if (index < 0 || index > utarray_len(enumtype->items) - 1) {
mpi_errno = MPI_T_ERR_INVALID_ITEM;
goto fn_fail;
}
enum_item_t *item = (enum_item_t *)utarray_eltptr(enumtype->items, index);
*value = item->value;
MPIR_T_strncpy(name, item->name, name_len);
......
......@@ -44,6 +44,9 @@ void MPIR_T_enum_create(const char *enum_name, MPI_T_enum *handle)
e = (MPIR_T_enum_t *)utarray_back(enum_table);
e->name = MPIU_Strdup(enum_name);
MPIU_Assert(e->name);
#ifdef HAVE_ERROR_CHECKING
e->kind = MPIR_T_ENUM_HANDLE;
#endif
utarray_new(e->items, &enum_item_icd);
(*handle) = e;
}
......
......@@ -63,7 +63,7 @@ int MPI_T_pvar_get_info(int pvar_index, char *name, int *name_len, int *verbosit
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_PVAR_GET_INFO);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_PVAR_GET_INFO);
......@@ -72,7 +72,8 @@ int MPI_T_pvar_get_info(int pvar_index, char *name, int *name_len, int *verbosit
{
MPID_BEGIN_ERROR_CHECKS
{
/* Do not do _TEST_ARGNULL for any argument, since this is
MPIR_ERRTEST_PVAR_INDEX(pvar_index, mpi_errno);
/* Do not do _TEST_ARGNULL for other arguments, since this is
* allowed or will be allowed by MPI_T standard.
*/
}
......@@ -83,11 +84,6 @@ int MPI_T_pvar_get_info(int pvar_index, char *name, int *name_len, int *verbosit
/* ... body of routine ... */
const pvar_table_entry_t *entry;
if (pvar_index < 0 || pvar_index >= utarray_len(pvar_table)) {
mpi_errno = MPI_T_ERR_INVALID_INDEX;
goto fn_fail;
}
entry = (pvar_table_entry_t *) utarray_eltptr(pvar_table, pvar_index);
if (!entry->active) {
mpi_errno = MPI_T_ERR_INVALID_INDEX;
......
......@@ -44,14 +44,24 @@ int MPI_T_pvar_get_num(int *num_pvar)
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_PVAR_GET_NUM);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_PVAR_GET_NUM);
/* Validate parameters */
# ifdef HAVE_ERROR_CHECKING
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_ARGNULL(num_pvar, "num_pvar", mpi_errno);
}
MPID_END_ERROR_CHECKS
}
# endif /* HAVE_ERROR_CHECKING */
/* ... body of routine ... */
if (num_pvar != NULL)
*num_pvar = utarray_len(pvar_table);
*num_pvar = utarray_len(pvar_table);
/* ... end of body of routine ... */
......
......@@ -24,7 +24,13 @@
#define MPI_T_pvar_handle_alloc PMPI_T_pvar_handle_alloc
/* Define storage for the ALL_HANDLES constant */
MPIR_T_pvar_handle_t MPIR_T_pvar_all_handles_obj = {0};
MPIR_T_pvar_handle_t MPIR_T_pvar_all_handles_obj =
{
#ifdef HAVE_ERROR_CHECKING
MPIR_T_PVAR_HANDLE, /* pvar handle tag for error checking */
#endif
0
};
MPIR_T_pvar_handle_t * const MPI_T_PVAR_ALL_HANDLES = &MPIR_T_pvar_all_handles_obj;
/* any non-MPI functions go here, especially non-static ones */
......@@ -74,6 +80,9 @@ int MPIR_T_pvar_handle_alloc_impl(MPI_T_pvar_session session, int pvar_index,
/* Allocate memory and bzero it */
MPIU_CHKPMEM_CALLOC(hnd, MPIR_T_pvar_handle_t*, sizeof(*hnd) + extra,
mpi_errno, "performance variable handle");
#ifdef HAVE_ERROR_CHECKING
hnd->kind = MPIR_T_PVAR_HANDLE;
#endif
/* Setup the common fields */
if (is_sum)
......@@ -193,7 +202,7 @@ int MPI_T_pvar_handle_alloc(MPI_T_pvar_session session, int pvar_index,
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_PVAR_HANDLE_ALLOC);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_PVAR_HANDLE_ALLOC);
......@@ -202,6 +211,8 @@ int MPI_T_pvar_handle_alloc(MPI_T_pvar_session session, int pvar_index,
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_PVAR_SESSION(session, mpi_errno);
MPIR_ERRTEST_PVAR_INDEX(pvar_index, mpi_errno);
MPIR_ERRTEST_ARGNULL(count, "count", mpi_errno);
MPIR_ERRTEST_ARGNULL(handle, "handle", mpi_errno);
/* Do not test obj_handle since it may be NULL when no binding */
......@@ -212,13 +223,7 @@ int MPI_T_pvar_handle_alloc(MPI_T_pvar_session session, int pvar_index,
/* ... body of routine ... */
pvar_table_entry_t *entry;
if (pvar_index < 0 || pvar_index >= utarray_len(pvar_table)) {
mpi_errno = MPI_T_ERR_INVALID_INDEX;
goto fn_fail;
}
entry = (pvar_table_entry_t *) utarray_eltptr(pvar_table, pvar_index);
pvar_table_entry_t *entry = (pvar_table_entry_t *) utarray_eltptr(pvar_table, pvar_index);
if (!entry->active) {
mpi_errno = MPI_T_ERR_INVALID_INDEX;
goto fn_fail;
......
......@@ -92,7 +92,7 @@ int MPI_T_pvar_handle_free(MPI_T_pvar_session session, MPI_T_pvar_handle *handle
int mpi_errno = MPI_SUCCESS;
MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_PVAR_HANDLE_FREE);
MPIR_T_FAIL_IF_UNINITIALIZED();
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
MPIR_T_THREAD_CS_ENTER();
MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_PVAR_HANDLE_FREE);
......@@ -101,19 +101,22 @@ int MPI_T_pvar_handle_free(MPI_T_pvar_session session, MPI_T_pvar_handle *handle
{
MPID_BEGIN_ERROR_CHECKS
{
MPIR_ERRTEST_ARGNULL(session, "session", mpi_errno);
MPIR_ERRTEST_ARGNULL(handle, "handle", mpi_errno);
if (mpi_errno != MPI_SUCCESS) goto fn_fail;
if (*handle == MPI_T_PVAR_HANDLE_NULL) /* free NULL is OK */
goto fn_exit;
MPIR_ERRTEST_PVAR_SESSION(session, mpi_errno);
MPIR_ERRTEST_PVAR_HANDLE(*handle, mpi_errno);
if ((*handle) == MPI_T_PVAR_ALL_HANDLES || (*handle)->session != session) {
mpi_errno = MPI_T_ERR_INVALID_HANDLE;
goto fn_fail;
}
}
MPID_END_ERROR_CHECKS
}
# endif /* HAVE_ERROR_CHECKING */
/* ... body of routine ... */
if ((*handle) == MPI_T_PVAR_ALL_HANDLES || (*handle)->session != session) {
mpi_errno = MPI_T_ERR_INVALID_HANDLE;
goto fn_fail;
}
mpi_errno = MPIR_T_pvar_handle_free_impl(session, handle);
if (mpi_errno) MPIU_ERR_POP(mpi_errno);
......
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