Skip to content

Commit a5485ef

Browse files
committed
hook: Clean up component hook casts
Add a bit of indirection on the hook initialization code to add a minimal amount of type checking around the component type. This still assumes that a const mca_base_component_t * can be cast to a const ompi_hook_base_component_ti *, but at least if the thing that we're reading from is giving us something other than a const mca_base_component_t *, the compiler will get angry with us. Signed-off-by: Brian Barrett <bbarrett@amazon.com>
1 parent bb1f6dc commit a5485ef

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

ompi/mca/hook/base/hook_base.c

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static int ompi_hook_base_open( mca_base_open_flag_t flags )
5151
int ret;
5252
const mca_base_component_t **static_components = ompi_hook_base_framework.framework_static_components;
5353
mca_base_component_list_item_t *cli = NULL;
54-
mca_base_component_t *component = NULL;
54+
const mca_base_component_t *component = NULL;
5555
bool found = false;
5656

5757
additional_callback_components = OBJ_NEW(opal_list_t);
@@ -68,21 +68,22 @@ static int ompi_hook_base_open( mca_base_open_flag_t flags )
6868
*/
6969
if( NULL != static_components ) {
7070
for (int i = 0 ; NULL != static_components[i]; ++i) {
71-
if( static_components[i]->mca_component_flags & MCA_BASE_COMPONENT_FLAG_REQUIRED ) {
71+
const mca_base_component_t *static_component = static_components[i];
72+
if( static_component->mca_component_flags & MCA_BASE_COMPONENT_FLAG_REQUIRED ) {
7273
// Make sure that this component is in the list of components that
7374
// were included in the earlier framework_components_open() call.
7475
found = false;
7576
OPAL_LIST_FOREACH(cli, &ompi_hook_base_framework.framework_components, mca_base_component_list_item_t) {
76-
component = (mca_base_component_t*)cli->cli_component;
77-
if( component == static_components[i] ) {
77+
component = cli->cli_component;
78+
if( component == static_component ) {
7879
found = true;
7980
break;
8081
}
8182
}
8283
if( !found ) {
8384
opal_show_help("help-mca-hook-base.txt", "hook:missing-required-component", true,
8485
ompi_hook_base_framework.framework_name,
85-
static_components[i]->mca_component_name);
86+
static_component->mca_component_name);
8687
return OPAL_ERR_NOT_SUPPORTED;
8788
}
8889
}
@@ -180,18 +181,20 @@ MCA_BASE_FRAMEWORK_DECLARE(ompi, hook, "hook hooks",
180181
* Otherwise we would need to initialize opal outside of ompi_mpi_init and possibly
181182
* after ompi_mpi_finalize which gets messy (especially when trying to cleanup).
182183
*/
183-
#define HOOK_CALL_COMMON_HOOK_NOT_INITIALIZED(fn_name, ...) \
184-
do { \
185-
ompi_hook_base_component_t *component; \
186-
int idx; \
187-
\
188-
for(idx = 0; NULL != mca_hook_base_static_components[idx]; ++idx ) { \
189-
component = (ompi_hook_base_component_t*)mca_hook_base_static_components[idx]; \
190-
if( NULL != component->hookm_ ## fn_name && \
191-
ompi_hook_base_ ## fn_name != component->hookm_ ## fn_name ) { \
192-
component->hookm_ ## fn_name ( __VA_ARGS__ ); \
193-
} \
194-
} \
184+
#define HOOK_CALL_COMMON_HOOK_NOT_INITIALIZED(fn_name, ...) \
185+
do { \
186+
const mca_base_component_t **static_components = ompi_hook_base_framework.framework_static_components; \
187+
\
188+
if( NULL != static_components ) { \
189+
for (int i = 0 ; NULL != static_components[i]; ++i) { \
190+
const mca_base_component_t *base_component = static_components[i]; \
191+
const ompi_hook_base_component_t *component = (const ompi_hook_base_component_t*)base_component; \
192+
if( NULL != component->hookm_ ## fn_name && \
193+
ompi_hook_base_ ## fn_name != component->hookm_ ## fn_name ) { \
194+
component->hookm_ ## fn_name ( __VA_ARGS__ ); \
195+
} \
196+
} \
197+
} \
195198
} while(0)
196199

197200
/*
@@ -204,18 +207,19 @@ MCA_BASE_FRAMEWORK_DECLARE(ompi, hook, "hook hooks",
204207
#define HOOK_CALL_COMMON_HOOK_INITIALIZED(fn_name, ...) \
205208
do { \
206209
mca_base_component_list_item_t *cli; \
207-
ompi_hook_base_component_t *component; \
208210
\
209211
OPAL_LIST_FOREACH(cli, &ompi_hook_base_framework.framework_components, mca_base_component_list_item_t) { \
210-
component = (ompi_hook_base_component_t*)cli->cli_component; \
212+
const mca_base_component_t *base_component = cli->cli_component; \
213+
const ompi_hook_base_component_t *component = (const ompi_hook_base_component_t*)base_component; \
211214
if( NULL != component->hookm_ ## fn_name && \
212215
ompi_hook_base_ ## fn_name != component->hookm_ ## fn_name ) { \
213216
component->hookm_ ## fn_name ( __VA_ARGS__ ); \
214217
} \
215218
} \
216219
\
217220
OPAL_LIST_FOREACH(cli, additional_callback_components, mca_base_component_list_item_t) { \
218-
component = (ompi_hook_base_component_t*)cli->cli_component; \
221+
const mca_base_component_t *base_component = cli->cli_component; \
222+
const ompi_hook_base_component_t *component = (const ompi_hook_base_component_t*)base_component; \
219223
if( NULL != component->hookm_ ## fn_name && \
220224
ompi_hook_base_ ## fn_name != component->hookm_ ## fn_name ) { \
221225
component->hookm_ ## fn_name ( __VA_ARGS__ ); \

0 commit comments

Comments
 (0)