Skip to content

Commit 6c18213

Browse files
committed
ompi: use best practice when declaring internal-only function pointer types
It is not recommended to declare function typedefs. The MPI external interface makes this mistake but Open MPI should not makes this mistake for internal typedefs. This commit updates various internal-only attribute typedefs to declare function pointer types. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
1 parent 02b2010 commit 6c18213

11 files changed

+96
-121
lines changed

ompi/attribute/attribute.h

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -64,50 +64,34 @@ typedef enum ompi_attribute_type_t ompi_attribute_type_t;
6464
delete. These will only be used here and not in the front end
6565
functions. */
6666

67-
typedef void (ompi_fint_copy_attr_function)(MPI_Fint *oldobj,
68-
MPI_Fint *keyval,
69-
MPI_Fint *extra_state,
70-
MPI_Fint *attr_in,
71-
MPI_Fint *attr_out,
72-
ompi_fortran_logical_t *flag,
73-
MPI_Fint *ierr);
74-
typedef void (ompi_fint_delete_attr_function)(MPI_Fint *obj,
75-
MPI_Fint *keyval,
76-
MPI_Fint *attr_in,
77-
MPI_Fint *extra_state,
78-
MPI_Fint *ierr);
67+
typedef void (*ompi_fint_copy_attr_function)(MPI_Fint *oldobj, MPI_Fint *keyval,
68+
MPI_Fint *extra_state, MPI_Fint *attr_in,
69+
MPI_Fint *attr_out, ompi_fortran_logical_t *flag,
70+
MPI_Fint *ierr);
71+
typedef void (*ompi_fint_delete_attr_function)(MPI_Fint *obj, MPI_Fint *keyval, MPI_Fint *attr_in,
72+
MPI_Fint *extra_state, MPI_Fint *ierr);
7973

8074
/* New-style MPI-2 Fortran function pointer declarations for copy and
8175
delete. These will only be used here and not in the front end
8276
functions. */
8377

84-
typedef void (ompi_aint_copy_attr_function)(MPI_Fint *oldobj,
85-
MPI_Fint *keyval,
86-
void *extra_state,
87-
void *attr_in,
88-
void *attr_out,
89-
ompi_fortran_logical_t *flag,
90-
MPI_Fint *ierr);
91-
typedef void (ompi_aint_delete_attr_function)(MPI_Fint *obj,
92-
MPI_Fint *keyval,
93-
void *attr_in,
94-
void *extra_state,
95-
MPI_Fint *ierr);
78+
typedef void (*ompi_aint_copy_attr_function)(MPI_Fint *oldobj, MPI_Fint *keyval, void *extra_state,
79+
void *attr_in, void *attr_out,
80+
ompi_fortran_logical_t *flag, MPI_Fint *ierr);
81+
typedef void (*ompi_aint_delete_attr_function)(MPI_Fint *obj, MPI_Fint *keyval, void *attr_in,
82+
void *extra_state, MPI_Fint *ierr);
9683
/*
9784
* Internally the copy function for all kinds of MPI objects has one more
9885
* argument, the pointer to the new object. Therefore, we can do on the
9986
* flight modifications of the new communicator based on attributes stored
10087
* on the main communicator.
10188
*/
102-
typedef int (MPI_Comm_internal_copy_attr_function)(MPI_Comm, int, void *,
103-
void *, void *, int *,
104-
MPI_Comm);
105-
typedef int (MPI_Type_internal_copy_attr_function)(MPI_Datatype, int, void *,
106-
void *, void *, int *,
107-
MPI_Datatype);
108-
typedef int (MPI_Win_internal_copy_attr_function)(MPI_Win, int, void *,
109-
void *, void *, int *,
110-
MPI_Win);
89+
typedef int (*MPI_Comm_internal_copy_attr_function)(MPI_Comm, int, void *, void *, void *, int *,
90+
MPI_Comm);
91+
typedef int (*MPI_Type_internal_copy_attr_function)(MPI_Datatype, int, void *, void *, void *,
92+
int *, MPI_Datatype);
93+
typedef int (*MPI_Win_internal_copy_attr_function)(MPI_Win, int, void *, void *, void *, int *,
94+
MPI_Win);
11195

11296
typedef void (ompi_attribute_keyval_destructor_fn_t)(int);
11397

@@ -120,19 +104,19 @@ union ompi_attribute_fn_ptr_union_t {
120104
MPI_Type_delete_attr_function *attr_datatype_delete_fn;
121105
MPI_Win_delete_attr_function *attr_win_delete_fn;
122106

123-
MPI_Comm_internal_copy_attr_function *attr_communicator_copy_fn;
124-
MPI_Type_internal_copy_attr_function *attr_datatype_copy_fn;
125-
MPI_Win_internal_copy_attr_function *attr_win_copy_fn;
107+
MPI_Comm_internal_copy_attr_function attr_communicator_copy_fn;
108+
MPI_Type_internal_copy_attr_function attr_datatype_copy_fn;
109+
MPI_Win_internal_copy_attr_function attr_win_copy_fn;
126110

127111
/* For Fortran old MPI-1 callback functions */
128112

129-
ompi_fint_delete_attr_function *attr_fint_delete_fn;
130-
ompi_fint_copy_attr_function *attr_fint_copy_fn;
113+
ompi_fint_delete_attr_function attr_fint_delete_fn;
114+
ompi_fint_copy_attr_function attr_fint_copy_fn;
131115

132116
/* For Fortran new MPI-2 callback functions */
133117

134-
ompi_aint_delete_attr_function *attr_aint_delete_fn;
135-
ompi_aint_copy_attr_function *attr_aint_copy_fn;
118+
ompi_aint_delete_attr_function attr_aint_delete_fn;
119+
ompi_aint_copy_attr_function attr_aint_copy_fn;
136120
};
137121

138122
typedef union ompi_attribute_fn_ptr_union_t ompi_attribute_fn_ptr_union_t;

ompi/attribute/attribute_predefined.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ static int create_comm(int target_keyval, bool want_inherit)
194194
ompi_attribute_fn_ptr_union_t del;
195195

196196
keyval = -1;
197-
copy.attr_communicator_copy_fn = (MPI_Comm_internal_copy_attr_function*)
198-
(want_inherit ? MPI_COMM_DUP_FN : MPI_COMM_NULL_COPY_FN);
197+
copy.attr_communicator_copy_fn = (MPI_Comm_internal_copy_attr_function)(
198+
want_inherit ? MPI_COMM_DUP_FN : MPI_COMM_NULL_COPY_FN);
199199
del.attr_communicator_delete_fn = MPI_COMM_NULL_DELETE_FN;
200200
err = ompi_attr_create_keyval(COMM_ATTR, copy, del,
201201
&keyval, NULL, OMPI_KEYVAL_PREDEFINED, NULL);
@@ -224,7 +224,7 @@ static int create_win(int target_keyval)
224224
ompi_attribute_fn_ptr_union_t del;
225225

226226
keyval = -1;
227-
copy.attr_win_copy_fn = (MPI_Win_internal_copy_attr_function*)MPI_WIN_NULL_COPY_FN;
227+
copy.attr_win_copy_fn = (MPI_Win_internal_copy_attr_function) MPI_WIN_NULL_COPY_FN;
228228
del.attr_win_delete_fn = MPI_WIN_NULL_DELETE_FN;
229229
err = ompi_attr_create_keyval(WIN_ATTR, copy, del,
230230
&keyval, NULL, OMPI_KEYVAL_PREDEFINED, NULL);

ompi/mpi/c/comm_create_keyval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int MPI_Comm_create_keyval(MPI_Comm_copy_attr_function *comm_copy_attr_fn,
5454
}
5555
}
5656

57-
copy_fn.attr_communicator_copy_fn = (MPI_Comm_internal_copy_attr_function*)comm_copy_attr_fn;
57+
copy_fn.attr_communicator_copy_fn = (MPI_Comm_internal_copy_attr_function) comm_copy_attr_fn;
5858
del_fn.attr_communicator_delete_fn = comm_delete_attr_fn;
5959

6060
ret = ompi_attr_create_keyval(COMM_ATTR, copy_fn,

ompi/mpi/c/keyval_create.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int MPI_Keyval_create(MPI_Copy_function *copy_attr_fn,
5656
}
5757
}
5858

59-
copy_fn.attr_communicator_copy_fn = (MPI_Comm_internal_copy_attr_function*)copy_attr_fn;
59+
copy_fn.attr_communicator_copy_fn = (MPI_Comm_internal_copy_attr_function) copy_attr_fn;
6060
del_fn.attr_communicator_delete_fn = delete_attr_fn;
6161

6262
ret = ompi_attr_create_keyval(COMM_ATTR, copy_fn,

ompi/mpi/c/type_create_keyval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int MPI_Type_create_keyval(MPI_Type_copy_attr_function *type_copy_attr_fn,
5656
}
5757
}
5858

59-
copy_fn.attr_datatype_copy_fn = (MPI_Type_internal_copy_attr_function*)type_copy_attr_fn;
59+
copy_fn.attr_datatype_copy_fn = (MPI_Type_internal_copy_attr_function) type_copy_attr_fn;
6060
del_fn.attr_datatype_delete_fn = type_delete_attr_fn;
6161

6262
ret = ompi_attr_create_keyval(TYPE_ATTR, copy_fn, del_fn,

ompi/mpi/c/win_create_keyval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int MPI_Win_create_keyval(MPI_Win_copy_attr_function *win_copy_attr_fn,
5454
}
5555
}
5656

57-
copy_fn.attr_win_copy_fn = (MPI_Win_internal_copy_attr_function*)win_copy_attr_fn;
57+
copy_fn.attr_win_copy_fn = (MPI_Win_internal_copy_attr_function) win_copy_attr_fn;
5858
del_fn.attr_win_delete_fn = win_delete_attr_fn;
5959

6060
ret = ompi_attr_create_keyval(WIN_ATTR, copy_fn, del_fn,

ompi/mpi/fortran/mpif-h/comm_create_keyval_f.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
#pragma weak PMPI_Comm_create_keyval_f = ompi_comm_create_keyval_f
3535
#pragma weak PMPI_Comm_create_keyval_f08 = ompi_comm_create_keyval_f
3636
#else
37-
OMPI_GENERATE_F77_BINDINGS (PMPI_COMM_CREATE_KEYVAL,
38-
pmpi_comm_create_keyval,
39-
pmpi_comm_create_keyval_,
40-
pmpi_comm_create_keyval__,
37+
OMPI_GENERATE_F77_BINDINGS(PMPI_COMM_CREATE_KEYVAL, pmpi_comm_create_keyval,
38+
pmpi_comm_create_keyval_, pmpi_comm_create_keyval__,
4139
pompi_comm_create_keyval_f,
42-
(ompi_aint_copy_attr_function* comm_copy_attr_fn, ompi_aint_delete_attr_function* comm_delete_attr_fn, MPI_Fint *comm_keyval, MPI_Aint *extra_state, MPI_Fint *ierr),
43-
(comm_copy_attr_fn, comm_delete_attr_fn, comm_keyval, extra_state, ierr) )
40+
(ompi_aint_copy_attr_function comm_copy_attr_fn,
41+
ompi_aint_delete_attr_function comm_delete_attr_fn,
42+
MPI_Fint *comm_keyval, MPI_Aint *extra_state, MPI_Fint *ierr),
43+
(comm_copy_attr_fn, comm_delete_attr_fn, comm_keyval, extra_state, ierr))
4444
#endif
4545
#endif
4646

@@ -54,25 +54,22 @@ OMPI_GENERATE_F77_BINDINGS (PMPI_COMM_CREATE_KEYVAL,
5454
#pragma weak MPI_Comm_create_keyval_f08 = ompi_comm_create_keyval_f
5555
#else
5656
#if ! OMPI_BUILD_MPI_PROFILING
57-
OMPI_GENERATE_F77_BINDINGS (MPI_COMM_CREATE_KEYVAL,
58-
mpi_comm_create_keyval,
59-
mpi_comm_create_keyval_,
60-
mpi_comm_create_keyval__,
61-
ompi_comm_create_keyval_f,
62-
(ompi_aint_copy_attr_function* comm_copy_attr_fn, ompi_aint_delete_attr_function* comm_delete_attr_fn, MPI_Fint *comm_keyval, MPI_Aint *extra_state, MPI_Fint *ierr),
63-
(comm_copy_attr_fn, comm_delete_attr_fn, comm_keyval, extra_state, ierr) )
57+
OMPI_GENERATE_F77_BINDINGS(MPI_COMM_CREATE_KEYVAL, mpi_comm_create_keyval, mpi_comm_create_keyval_,
58+
mpi_comm_create_keyval__, ompi_comm_create_keyval_f,
59+
(ompi_aint_copy_attr_function comm_copy_attr_fn,
60+
ompi_aint_delete_attr_function comm_delete_attr_fn,
61+
MPI_Fint *comm_keyval, MPI_Aint *extra_state, MPI_Fint *ierr),
62+
(comm_copy_attr_fn, comm_delete_attr_fn, comm_keyval, extra_state, ierr))
6463
#else
6564
#define ompi_comm_create_keyval_f pompi_comm_create_keyval_f
6665
#endif
6766
#endif
6867

6968
static const char FUNC_NAME[] = "MPI_Comm_create_keyval_f";
7069

71-
72-
void ompi_comm_create_keyval_f(ompi_aint_copy_attr_function* comm_copy_attr_fn,
73-
ompi_aint_delete_attr_function* comm_delete_attr_fn,
74-
MPI_Fint *comm_keyval,
75-
MPI_Aint *extra_state, MPI_Fint *ierr)
70+
void ompi_comm_create_keyval_f(ompi_aint_copy_attr_function comm_copy_attr_fn,
71+
ompi_aint_delete_attr_function comm_delete_attr_fn,
72+
MPI_Fint *comm_keyval, MPI_Aint *extra_state, MPI_Fint *ierr)
7673
{
7774
int ret, c_ierr;
7875
OMPI_SINGLE_NAME_DECL(comm_keyval);

ompi/mpi/fortran/mpif-h/keyval_create_f.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@
3434
#pragma weak PMPI_Keyval_create_f = ompi_keyval_create_f
3535
#pragma weak PMPI_Keyval_create_f08 = ompi_keyval_create_f
3636
#else
37-
OMPI_GENERATE_F77_BINDINGS (PMPI_KEYVAL_CREATE,
38-
pmpi_keyval_create,
39-
pmpi_keyval_create_,
40-
pmpi_keyval_create__,
41-
pompi_keyval_create_f,
42-
(ompi_fint_copy_attr_function* copy_fn, ompi_fint_delete_attr_function* delete_fn, MPI_Fint *keyval, MPI_Fint *extra_state, MPI_Fint *ierr),
43-
(copy_fn, delete_fn, keyval, extra_state, ierr) )
37+
OMPI_GENERATE_F77_BINDINGS(PMPI_KEYVAL_CREATE, pmpi_keyval_create, pmpi_keyval_create_,
38+
pmpi_keyval_create__, pompi_keyval_create_f,
39+
(ompi_fint_copy_attr_function copy_fn,
40+
ompi_fint_delete_attr_function delete_fn, MPI_Fint *keyval,
41+
MPI_Fint *extra_state, MPI_Fint *ierr),
42+
(copy_fn, delete_fn, keyval, extra_state, ierr))
4443
#endif
4544
#endif
4645

@@ -54,24 +53,22 @@ OMPI_GENERATE_F77_BINDINGS (PMPI_KEYVAL_CREATE,
5453
#pragma weak MPI_Keyval_create_f08 = ompi_keyval_create_f
5554
#else
5655
#if ! OMPI_BUILD_MPI_PROFILING
57-
OMPI_GENERATE_F77_BINDINGS (MPI_KEYVAL_CREATE,
58-
mpi_keyval_create,
59-
mpi_keyval_create_,
60-
mpi_keyval_create__,
61-
ompi_keyval_create_f,
62-
(ompi_fint_copy_attr_function* copy_fn, ompi_fint_delete_attr_function* delete_fn, MPI_Fint *keyval, MPI_Fint *extra_state, MPI_Fint *ierr),
63-
(copy_fn, delete_fn, keyval, extra_state, ierr) )
56+
OMPI_GENERATE_F77_BINDINGS(MPI_KEYVAL_CREATE, mpi_keyval_create, mpi_keyval_create_,
57+
mpi_keyval_create__, ompi_keyval_create_f,
58+
(ompi_fint_copy_attr_function copy_fn,
59+
ompi_fint_delete_attr_function delete_fn, MPI_Fint *keyval,
60+
MPI_Fint *extra_state, MPI_Fint *ierr),
61+
(copy_fn, delete_fn, keyval, extra_state, ierr))
6462
#else
6563
#define ompi_keyval_create_f pompi_keyval_create_f
6664
#endif
6765
#endif
6866

6967
static const char FUNC_NAME[] = "MPI_keyval_create_f";
7068

71-
void ompi_keyval_create_f(ompi_fint_copy_attr_function* copy_attr_fn,
72-
ompi_fint_delete_attr_function* delete_attr_fn,
73-
MPI_Fint *keyval, MPI_Fint *extra_state,
74-
MPI_Fint *ierr)
69+
void ompi_keyval_create_f(ompi_fint_copy_attr_function copy_attr_fn,
70+
ompi_fint_delete_attr_function delete_attr_fn, MPI_Fint *keyval,
71+
MPI_Fint *extra_state, MPI_Fint *ierr)
7572
{
7673
int ret, c_ierr;
7774
OMPI_SINGLE_NAME_DECL(keyval);

0 commit comments

Comments
 (0)