1 /*
2 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * Copyright (c) 2015 Research Organization for Information Science
13 * and Technology (RIST). All rights reserved.
14 * $COPYRIGHT$
15 *
16 * Additional copyrights may follow
17 *
18 * $HEADER$
19 */
20
21 #include "ompi_config.h"
22
23 #include "ompi/mpi/c/bindings.h"
24 #include "ompi/runtime/params.h"
25 #include "ompi/communicator/communicator.h"
26 #include "ompi/errhandler/errhandler.h"
27
28 #if OMPI_BUILD_MPI_PROFILING
29 #if OPAL_HAVE_WEAK_SYMBOLS
30 #pragma weak MPI_Errhandler_free = PMPI_Errhandler_free
31 #endif
32 #define MPI_Errhandler_free PMPI_Errhandler_free
33 #endif
34
35 static const char FUNC_NAME[] = "MPI_Errhandler_free";
36
37
38 int MPI_Errhandler_free(MPI_Errhandler *errhandler)
39 {
40
41 OPAL_CR_NOOP_PROGRESS();
42
43 /* Error checking */
44
45 if (MPI_PARAM_CHECK) {
46 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
47 /* Raise an MPI exception if we got NULL or if we got an intrinsic
48 *and* the reference count is 1 (meaning that this FREE would
49 actually free the underlying intrinsic object). This is ugly
50 but necessary -- see below. */
51 if (NULL == errhandler ||
52 (ompi_errhandler_is_intrinsic(*errhandler) &&
53 1 == (*errhandler)->super.obj_reference_count)) {
54 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
55 "MPI_Errhandler_free");
56 }
57 }
58
59 /* Return the errhandler. According to MPI-2 errata, any errhandler
60 obtained by MPI_*_GET_ERRHANDLER or MPI_ERRHANDLER_GET must also
61 be freed by MPI_ERRHANDLER_FREE (including intrinsic error
62 handlers). For example, this is valid:
63
64 int main() {
65 MPI_Errhandler errhdl;
66 MPI_Init(NULL, NULL);
67 MPI_Comm_get_errhandler(MPI_COMM_WORLD, &errhdl);
68 MPI_Errhandler_free(&errhdl);
69 MPI_Finalize();
70 return 0;
71 }
72
73 So decrease the refcount here. */
74
75 OBJ_RELEASE(*errhandler);
76 *errhandler = MPI_ERRHANDLER_NULL;
77
78 /* All done */
79
80 return MPI_SUCCESS;
81 }