diff --git a/src/clib/pio_error.h b/src/clib/pio_error.h index d95a59fa548..488460d2751 100644 --- a/src/clib/pio_error.h +++ b/src/clib/pio_error.h @@ -14,13 +14,28 @@ #include /** - * Handle non-MPI errors by printing error message and goto exit. + * Handle non-MPI errors by printing error message and goto exit. This + * is used in test code. */ #define BAIL(e) do { \ fprintf(stderr, "%d Error %d in %s, line %d\n", my_rank, e, __FILE__, __LINE__); \ goto exit; \ } while (0) +/** + * Handle non-MPI errors by calling pio_err(), setting return code, + * and goto exit. This is used in library code. + */ +#define EXIT(ios, e) do { \ + ret = pio_err(NULL, NULL, e, __FILE__, __LINE__); \ + goto exit; \ + } while (0) + +/** + * Same as the EXIT macro, but uses NULL for iosystem. + */ +#define EXIT1(e) EXIT(NULL, e) + /** * Handle non-MPI errors by finalizing the MPI library and exiting * with an exit code. @@ -35,7 +50,7 @@ * Handle MPI errors. This should only be used with MPI library * function calls. Print error message, finalize MPI and return error * code. -*/ + */ #define MPIERR(e) do { \ MPI_Error_string(e, err_buffer, &resultlen); \ fprintf(stderr, "MPI error, line %d, file %s: %s\n", __LINE__, __FILE__, err_buffer); \ diff --git a/src/clib/pio_rearrange.c b/src/clib/pio_rearrange.c index 2e17e863566..0638dfcbdee 100644 --- a/src/clib/pio_rearrange.c +++ b/src/clib/pio_rearrange.c @@ -355,7 +355,7 @@ create_mpi_datatypes(MPI_Datatype mpitype, int msgcnt, int *displace; if (!(displace = malloc(sizeof(int) * len))) - return pio_err(NULL, NULL, PIO_ENOMEM, __FILE__, __LINE__); + EXIT1(PIO_ENOMEM); LOG((3, "blocksize = %d i = %d mcount[%d] = %d len = %d", blocksize, i, i, mcount[i], len)); @@ -412,12 +412,14 @@ create_mpi_datatypes(MPI_Datatype mpitype, int msgcnt, } } + LOG((3, "done with create_mpi_datatypes()")); + +exit: /* Free resources. */ if (lindex) free(lindex); - LOG((3, "done with create_mpi_datatypes()")); - return PIO_NOERR; + return ret; } /**