Skip to content

Commit 8acb59d

Browse files
committed
opal,ompi: move container_of definition to its own header
Centralize container_of macro definition so that we don't have to define it everywhere. Signed-off-by: Wenduo Wang <[email protected]>
1 parent b4390af commit 8acb59d

File tree

6 files changed

+43
-19
lines changed

6 files changed

+43
-19
lines changed

contrib/check_unnecessary_headers.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,18 @@ SEARCH_HEADER[30]="opal/util/convert.h opal_size2int"
116116
SEARCH_HEADER[31]="opal/util/daemon_init.h opal_daemon_init"
117117
SEARCH_HEADER[32]="opal/util/error.h opal_perror opal_strerror opal_strerror_r opal_err2str_fn_t opal_error_register"
118118
SEARCH_HEADER[33]="opal/util/if.h IF_NAMESIZE opal_ifnametoaddr opal_ifaddrtoname opal_ifnametoindex opal_ifnametokindex opal_ifindextokindex opal_ifcount opal_ifbegin opal_ifnext opal_ifindextoname opal_ifkindextoname opal_ifindextoaddr opal_ifindextomask opal_ifindextoflags opal_ifislocal opal_iffinalize"
119-
SEARCH_HEADER[34]="opal/util/net.h opal_net_init opal_net_finalize opal_net_prefix2netmask opal_net_islocalhost opal_net_samenetwork opal_net_addr_isipv4public opal_net_get_hostname opal_net_get_port"
120-
SEARCH_HEADER[35]="opal/util/opal_environ.h opal_environ_merge opal_setenv opal_unsetenv opal_home_directory opal_tmp_directory environ"
121-
SEARCH_HEADER[36]="opal/util/opal_getcwd.h opal_getcwd"
122-
SEARCH_HEADER[37]="opal/util/os_dirpath.h opal_os_dirpath_create opal_os_dirpath_is_empty opal_os_dirpath_access opal_os_dirpath_destroy"
123-
SEARCH_HEADER[38]="opal/util/os_path.h opal_os_path opal_make_filename_os_friendly"
124-
SEARCH_HEADER[39]="opal/util/output.h opal_output_stream_t opal_output_init opal_output_finalize opal_output_open opal_output_reopen opal_output_switch opal_output_reopen_all opal_output_close opal_output opal_output_verbose opal_output_vverbose opal_output_string opal_output_vstring opal_output_set_verbosity opal_output_get_verbosity opal_output_set_output_file_info OPAL_OUTPUT OPAL_OUTPUT_VERBOSE"
125-
SEARCH_HEADER[40]="opal/util/path.h opal_path_find opal_path_findv opal_path_is_absolute opal_find_absolute_path opal_path_access"
126-
SEARCH_HEADER[41]="opal/util/printf.h snprintf vsnprintf"
127-
SEARCH_HEADER[42]="opal/util/show_help.h opal_show_help_init opal_show_help_finalize opal_show_help opal_show_vhelp opal_show_help_string opal_show_help_finish_parsing"
128-
SEARCH_HEADER[43]="opal/util/strncpy.h opal_strncpy"
129-
SEARCH_HEADER[44]=""
119+
SEARCH_HEADER[34]="opal/util/misc.h container_of"
120+
SEARCH_HEADER[35]="opal/util/net.h opal_net_init opal_net_finalize opal_net_prefix2netmask opal_net_islocalhost opal_net_samenetwork opal_net_addr_isipv4public opal_net_get_hostname opal_net_get_port"
121+
SEARCH_HEADER[36]="opal/util/opal_environ.h opal_environ_merge opal_setenv opal_unsetenv opal_home_directory opal_tmp_directory environ"
122+
SEARCH_HEADER[37]="opal/util/opal_getcwd.h opal_getcwd"
123+
SEARCH_HEADER[38]="opal/util/os_dirpath.h opal_os_dirpath_create opal_os_dirpath_is_empty opal_os_dirpath_access opal_os_dirpath_destroy"
124+
SEARCH_HEADER[39]="opal/util/os_path.h opal_os_path opal_make_filename_os_friendly"
125+
SEARCH_HEADER[40]="opal/util/output.h opal_output_stream_t opal_output_init opal_output_finalize opal_output_open opal_output_reopen opal_output_switch opal_output_reopen_all opal_output_close opal_output opal_output_verbose opal_output_vverbose opal_output_string opal_output_vstring opal_output_set_verbosity opal_output_get_verbosity opal_output_set_output_file_info OPAL_OUTPUT OPAL_OUTPUT_VERBOSE"
126+
SEARCH_HEADER[41]="opal/util/path.h opal_path_find opal_path_findv opal_path_is_absolute opal_find_absolute_path opal_path_access"
127+
SEARCH_HEADER[42]="opal/util/printf.h snprintf vsnprintf"
128+
SEARCH_HEADER[43]="opal/util/show_help.h opal_show_help_init opal_show_help_finalize opal_show_help opal_show_vhelp opal_show_help_string opal_show_help_finish_parsing"
129+
SEARCH_HEADER[44]="opal/util/strncpy.h opal_strncpy"
130+
SEARCH_HEADER[45]=""
130131

131132
delete_unnessary_header .
132133

ompi/mca/mtl/ofi/mtl_ofi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "ompi/mca/mtl/mtl.h"
2525
#include "ompi/mca/mtl/base/base.h"
2626
#include "opal/datatype/opal_convertor.h"
27+
#include "opal/util/misc.h"
2728
#include "opal/util/show_help.h"
2829
#include "opal/util/printf.h"
2930

opal/mca/btl/usnic/btl_usnic.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "opal/class/opal_hash_table.h"
3636
#include "opal/util/alfg.h"
3737
#include "opal/util/event.h"
38+
#include "opal/util/misc.h"
3839
#include "opal_stdint.h"
3940

4041
#include "opal/mca/btl/base/base.h"
@@ -65,10 +66,6 @@ static inline uint64_t get_ticks(void)
6566
/* RNG buffer declaration */
6667
extern opal_rng_buff_t opal_btl_usnic_rand_buff;
6768

68-
#ifndef container_of
69-
# define container_of(ptr, type, member) ((type *) (((char *) (ptr)) - offsetof(type, member)))
70-
#endif
71-
7269
#ifndef max
7370
# define max(a, b) (((a) > (b)) ? (a) : (b))
7471
#endif

opal/util/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ headers = \
6363
if.h \
6464
keyval_parse.h \
6565
malloc.h \
66+
misc.h \
6667
net.h \
6768
numtostr.h \
6869
opal_environ.h \

opal/util/bipartite_graph.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818
#include "opal/class/opal_pointer_array.h"
1919
#include "opal/constants.h"
2020
#include "opal/util/error.h"
21+
#include "opal/util/misc.h"
2122
#include "opal/util/output.h"
2223
#include "opal_stdint.h"
2324

2425
#include "opal/util/bipartite_graph.h"
2526
#include "opal/util/bipartite_graph_internal.h"
2627

27-
#ifndef container_of
28-
# define container_of(ptr, type, member) ((type *) (((char *) (ptr)) - offsetof(type, member)))
29-
#endif
30-
3128
#define GRAPH_DEBUG 0
3229
#if GRAPH_DEBUG
3330
# define GRAPH_DEBUG_OUT(args) printf(args)

opal/util/misc.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates.
3+
* All Rights reserved.
4+
* $COPYRIGHT$
5+
*
6+
* Additional copyrights may follow
7+
*
8+
* $HEADER$
9+
*/
10+
11+
/** @file:
12+
* Miscellaneous utilities
13+
*/
14+
15+
#ifndef OPAL_UTIL_MISC_H
16+
#define OPAL_UTIL_MISC_H
17+
18+
#include "opal/include/opal_config.h"
19+
20+
BEGIN_C_DECLS
21+
22+
#ifndef container_of
23+
# define container_of(ptr, type, member) ((type *) (((char *) (ptr)) - offsetof(type, member)))
24+
#endif
25+
26+
END_C_DECLS
27+
#endif

0 commit comments

Comments
 (0)