From dc532577db12f5ea546b12433757d61c346f2fe0 Mon Sep 17 00:00:00 2001 From: Edgar Gabriel Date: Thu, 21 Dec 2006 19:36:31 +0000 Subject: [PATCH] Adding more accurate checking of the input parameters for the add_error_class and add_error_code files. Also fixed the update of the lastusedcode attribute, all of work according to my tests pretty fine. Please note: the testcode attached to the bug 683 still reports some bugs. I am however pretty sure that the testcode is wrong at that points: - the standard says that the attribute MPI_LASTUSEDCODE has to be updated for a new error_class or a new error_code. The test currently assumes, that only the add_error_code call changes the attribute value. - you have to comment out the two lines 73 and 74 in order to make the test finish, since these lines check for the error string of non-existent codes. - line 126 the error-string of MPI_ERR_ARG is not "invalid argument" but a little bit more, so the test thinks the output is wrong. So probably the test has to be update to match the according error string of MPI_ERR_ARG. Fixes trac:682 This commit was SVN r12913. The following Trac tickets were found above: Ticket 682 --> https://svn.open-mpi.org/trac/ompi/ticket/682 --- ompi/errhandler/errcode.c | 10 ++++----- ompi/errhandler/errcode.h | 41 ++++++++++++++++++++++++++++++----- ompi/mpi/c/add_error_class.c | 18 +++++++++++++++ ompi/mpi/c/add_error_code.c | 20 +++++++++++++++++ ompi/mpi/c/add_error_string.c | 8 +++++++ 5 files changed, 87 insertions(+), 10 deletions(-) diff --git a/ompi/errhandler/errcode.c b/ompi/errhandler/errcode.c index b61dc8adea..a9334c584c 100644 --- a/ompi/errhandler/errcode.c +++ b/ompi/errhandler/errcode.c @@ -430,8 +430,8 @@ int ompi_mpi_errcode_init (void) strcpy(ompi_err_win.errstring, "MPI_ERR_WIN:invalid window"); ompi_pointer_array_set_item(&ompi_mpi_errcodes, MPI_ERR_WIN, &ompi_err_win); - ompi_mpi_errcode_lastused=MPI_ERR_WIN+1; - ompi_mpi_errcode_lastpredefined=MPI_ERR_WIN+1; + ompi_mpi_errcode_lastused=MPI_ERR_WIN; + ompi_mpi_errcode_lastpredefined=MPI_ERR_WIN; return OMPI_SUCCESS; } @@ -440,7 +440,7 @@ int ompi_mpi_errcode_finalize(void) int i; ompi_mpi_errcode_t *errc; - for (i=ompi_mpi_errcode_lastpredefined; icode = ompi_mpi_errcode_lastused; + newerrcode->code = (ompi_mpi_errcode_lastused+1); newerrcode->cls = errclass; ompi_pointer_array_set_item(&ompi_mpi_errcodes, newerrcode->code, newerrcode); @@ -526,7 +526,7 @@ int ompi_mpi_errclass_add(void) ompi_mpi_errcode_t *newerrcode; newerrcode = OBJ_NEW(ompi_mpi_errcode_t); - newerrcode->cls = ompi_mpi_errcode_lastused; + newerrcode->cls = ( ompi_mpi_errcode_lastused+1); ompi_pointer_array_set_item(&ompi_mpi_errcodes, newerrcode->cls, newerrcode); ompi_mpi_errcode_lastused++; diff --git a/ompi/errhandler/errcode.h b/ompi/errhandler/errcode.h index d70a3167d3..1a8cf73493 100644 --- a/ompi/errhandler/errcode.h +++ b/ompi/errhandler/errcode.h @@ -36,10 +36,8 @@ extern "C" { * Please note: * if code == MPI_UNDEFINED, than the according structure * represents an error class. - * if cls == MPI_UNDEFINED, than the according structure - * represents an error code. - * For the predefined error codes and classes, code and - * cls are both set to the according value. + * For the predefined error codes and classes, code and + * cls are both set to the according value. */ struct ompi_mpi_errcode_t { opal_object_t super; @@ -51,6 +49,7 @@ typedef struct ompi_mpi_errcode_t ompi_mpi_errcode_t; OMPI_DECLSPEC extern ompi_pointer_array_t ompi_mpi_errcodes; OMPI_DECLSPEC extern int ompi_mpi_errcode_lastused; +OMPI_DECLSPEC extern int ompi_mpi_errcode_lastpredefined; OMPI_DECLSPEC extern ompi_mpi_errcode_t ompi_err_unknown; @@ -59,7 +58,7 @@ OMPI_DECLSPEC extern ompi_mpi_errcode_t ompi_err_unknown; */ static inline bool ompi_mpi_errcode_is_invalid(int errcode) { - if ( errcode >= 0 && errcode < ompi_mpi_errcode_lastused ) + if ( errcode >= 0 && errcode <= ompi_mpi_errcode_lastused ) return 0; else return 1; @@ -81,6 +80,38 @@ static inline int ompi_mpi_errcode_get_class (int errcode) } return ompi_err_unknown.cls; } + +static inline int ompi_mpi_errcode_is_predefined ( int errcode ) +{ + if ( errcode >= 0 && errcode <= ompi_mpi_errcode_lastpredefined ) + return true; + + return false; +} + +static inline int ompi_mpi_errnum_is_class ( int errnum ) +{ + ompi_mpi_errcode_t *err; + + if ( errnum <= ompi_mpi_errcode_lastpredefined ) { + /* Predefined error values represent an error code and + an error class at the same time */ + return true; + } + + err = (ompi_mpi_errcode_t *)ompi_pointer_array_get_item(&ompi_mpi_errcodes, errnum); + if (NULL != err) { + if ( MPI_UNDEFINED == err->code) { + /* Distinction between error class and error code is that for the + first one the code section is set to MPI_UNDEFINED */ + return true; + } + } + + return false; +} + + /** * Return the error string */ diff --git a/ompi/mpi/c/add_error_class.c b/ompi/mpi/c/add_error_class.c index a5a98da1a5..b2366a5846 100644 --- a/ompi/mpi/c/add_error_class.c +++ b/ompi/mpi/c/add_error_class.c @@ -21,6 +21,7 @@ #include "ompi/mpi/c/bindings.h" #include "ompi/errhandler/errcode.h" +#include "ompi/attribute/attribute.h" #if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILING_DEFINES #pragma weak MPI_Add_error_class = PMPI_Add_error_class @@ -36,6 +37,7 @@ static const char FUNC_NAME[] = "MPI_Add_error_class"; int MPI_Add_error_class(int *errorclass) { int err_class; + int rc; if ( MPI_PARAM_CHECK ) { OMPI_ERR_INIT_FINALIZE(FUNC_NAME); @@ -47,6 +49,22 @@ int MPI_Add_error_class(int *errorclass) FUNC_NAME); } + + /* + ** Update the attribute value. See the comments + ** in attribute/attribute.c and attribute/attribute_predefined.c + ** why we have to call the fortran attr_set function + */ + rc = ompi_attr_set_fortran_mpi1 (COMM_ATTR, + MPI_COMM_WORLD, + &MPI_COMM_WORLD->c_keyhash, + MPI_LASTUSEDCODE, + ompi_mpi_errcode_lastused, + true, true); + if ( MPI_SUCCESS != rc ) { + return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, rc, FUNC_NAME); + } + *errorclass = err_class; return MPI_SUCCESS; } diff --git a/ompi/mpi/c/add_error_code.c b/ompi/mpi/c/add_error_code.c index b9bebb1016..1d8a570481 100644 --- a/ompi/mpi/c/add_error_code.c +++ b/ompi/mpi/c/add_error_code.c @@ -21,6 +21,7 @@ #include "ompi/mpi/c/bindings.h" #include "ompi/errhandler/errcode.h" +#include "ompi/attribute/attribute.h" #if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILING_DEFINES #pragma weak MPI_Add_error_code = PMPI_Add_error_code @@ -36,6 +37,7 @@ static const char FUNC_NAME[] = "MPI_Add_error_code"; int MPI_Add_error_code(int errorclass, int *errorcode) { int code; + int rc; if ( MPI_PARAM_CHECK ) { OMPI_ERR_INIT_FINALIZE(FUNC_NAME); @@ -44,6 +46,9 @@ int MPI_Add_error_code(int errorclass, int *errorcode) return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, FUNC_NAME); + if ( !ompi_mpi_errnum_is_class ( errorclass) ) + return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, + FUNC_NAME); } code = ompi_mpi_errcode_add ( errorclass); @@ -51,6 +56,21 @@ int MPI_Add_error_code(int errorclass, int *errorcode) return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_INTERN, FUNC_NAME); } + + /* + ** Update the attribute value. See the comments + ** in attribute/attribute.c and attribute/attribute_predefined.c + ** why we have to call the fortran attr_set function + */ + rc = ompi_attr_set_fortran_mpi1 (COMM_ATTR, + MPI_COMM_WORLD, + &MPI_COMM_WORLD->c_keyhash, + MPI_LASTUSEDCODE, + ompi_mpi_errcode_lastused, + true, true); + if ( MPI_SUCCESS != rc ) { + return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, rc, FUNC_NAME); + } *errorcode = code; return MPI_SUCCESS; diff --git a/ompi/mpi/c/add_error_string.c b/ompi/mpi/c/add_error_string.c index cea6dc51cd..00052c3b7b 100644 --- a/ompi/mpi/c/add_error_string.c +++ b/ompi/mpi/c/add_error_string.c @@ -44,6 +44,14 @@ int MPI_Add_error_string(int errorcode, char *string) if ( ompi_mpi_errcode_is_invalid(errorcode) ) return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, FUNC_NAME); + + if ( ompi_mpi_errcode_is_predefined(errorcode) ) + return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, + FUNC_NAME); + + if ( MPI_MAX_ERROR_STRING < (strlen(string)+1) ) + return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, + FUNC_NAME); } rc = ompi_mpi_errnum_add_string (errorcode, string, (int)(strlen(string)+1));