1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5 
6 #include "mpiimpl.h"
7 
8 /* -- Begin Profiling Symbol Block for routine MPI_T_enum_get_item */
9 #if defined(HAVE_PRAGMA_WEAK)
10 #pragma weak MPI_T_enum_get_item = PMPI_T_enum_get_item
11 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
12 #pragma _HP_SECONDARY_DEF PMPI_T_enum_get_item  MPI_T_enum_get_item
13 #elif defined(HAVE_PRAGMA_CRI_DUP)
14 #pragma _CRI duplicate MPI_T_enum_get_item as PMPI_T_enum_get_item
15 #elif defined(HAVE_WEAK_ATTRIBUTE)
16 int MPI_T_enum_get_item(MPI_T_enum enumtype, int indx, int *value, char *name, int *name_len)
17     __attribute__ ((weak, alias("PMPI_T_enum_get_item")));
18 #endif
19 /* -- End Profiling Symbol Block */
20 
21 /* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
22    the MPI routines */
23 #ifndef MPICH_MPI_FROM_PMPI
24 #undef MPI_T_enum_get_item
25 #define MPI_T_enum_get_item PMPI_T_enum_get_item
26 #endif /* MPICH_MPI_FROM_PMPI */
27 
28 /*@
29 MPI_T_enum_get_item - Get the information about an item in an enumeration
30 
31 Input/Output Parameters:
32 . name_len - length of the string and/or buffer for name (integer)
33 
34 Input Parameters:
35 . enumtype - enumeration to be queried (handle)
36 
37 Output Parameters:
38 + indx - number of the value to be queried in this enumeration (integer)
39 . value - variable value (integer)
40 - name - buffer to return the string containing the name of the enumeration item (string)
41 
42 .N ThreadSafe
43 
44 .N Errors
45 .N MPI_SUCCESS
46 .N MPI_T_ERR_NOT_INITIALIZED
47 .N MPI_T_ERR_INVALID_HANDLE
48 .N MPI_T_ERR_INVALID_ITEM
49 @*/
MPI_T_enum_get_item(MPI_T_enum enumtype,int indx,int * value,char * name,int * name_len)50 int MPI_T_enum_get_item(MPI_T_enum enumtype, int indx, int *value, char *name, int *name_len)
51 {
52     int mpi_errno = MPI_SUCCESS;
53     enum_item_t *item;
54 
55     MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_T_ENUM_GET_ITEM);
56     MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
57     MPIR_T_THREAD_CS_ENTER();
58     MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPI_T_ENUM_GET_ITEM);
59 
60     /* Validate parameters */
61 #ifdef HAVE_ERROR_CHECKING
62     {
63         MPID_BEGIN_ERROR_CHECKS;
64         {
65             MPIR_ERRTEST_ENUM_HANDLE(enumtype, mpi_errno);
66             MPIR_ERRTEST_ENUM_ITEM(enumtype, indx, mpi_errno);
67             MPIR_ERRTEST_ARGNULL(value, "value", mpi_errno);
68             /* Do not do TEST_ARGNULL for name or name_len, since this is
69              * permitted per MPI_T standard.
70              */
71         }
72         MPID_END_ERROR_CHECKS;
73     }
74 #endif /* HAVE_ERROR_CHECKING */
75 
76     /* ... body of routine ...  */
77 
78     item = (enum_item_t *) utarray_eltptr(enumtype->items, indx);
79     *value = item->value;
80     MPIR_T_strncpy(name, item->name, name_len);
81 
82     /* ... end of body of routine ... */
83 
84 #ifdef HAVE_ERROR_CHECKING
85   fn_exit:
86 #endif
87     MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPI_T_ENUM_GET_ITEM);
88     MPIR_T_THREAD_CS_EXIT();
89     return mpi_errno;
90 
91 #ifdef HAVE_ERROR_CHECKING
92   fn_fail:
93     /* --BEGIN ERROR HANDLING-- */
94     {
95         mpi_errno =
96             MPIR_Err_create_code(mpi_errno, MPIR_ERR_RECOVERABLE, __func__, __LINE__, MPI_ERR_OTHER,
97                                  "**mpi_t_enum_get_item", "**mpi_t_enum_get_item %p %d %p %p %p",
98                                  enumtype, indx, value, name, name_len);
99     }
100     mpi_errno = MPIR_Err_return_comm(NULL, __func__, mpi_errno);
101     goto fn_exit;
102     /* --END ERROR HANDLING-- */
103 #endif
104 }
105