Skip to content

Commit b54565f

Browse files
Address pedantic compiler warnings (#2581)
* Change how the global pmix_regattr_input_t dictionary is created. This commit changes how the pmix_regattr_input_t dictionary is created. It addresses a 'defined but not used' warning (or error) that is generated when pedantic developer flags are enabled by --enable-devel-check. In particular, construct_dictionary.py now generates two files: pmix_dictionary.h and pmix_dictionary.c. The previous methodology generated a single file named dictionary.h. Please note that we changed the name of the generated files to more closely match OpenPMIx's file naming convention. Since the dictionary's symbol is now exported, we also changed its name to pmix_dictionary. Additionally, the generated array is now declared as const to match its intended usage. construct_dictionary.py was also modified to address some warnings generated by flake8. These changes were trivial. Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov> * Fix issues identified by Ralph. Fixes 'no newline at end of file' warning and multiple definitions of PMIX_INDEX_BOUNDARY. Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov> * Silence the remaining picky compiler warnings. With this commit a build configured with --enable-devel-check now compiles cleanly on my setup. Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov>
1 parent 90c06ff commit b54565f

File tree

11 files changed

+108
-49
lines changed

11 files changed

+108
-49
lines changed

contrib/construct_dictionary.py

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) 2020 Intel, Inc. All rights reserved.
33
# Copyright (c) 2020 Cisco Systems, Inc. All rights reserved
44
# Copyright (c) 2021-2022 Nanook Consulting. All rights reserved.
5+
# Copyright (c) 2022 Triad National Security, LLC. All rights reserved.
56
# $COPYRIGHT$
67
#
78
# Construct a dictionary for translating attributes to/from
@@ -10,11 +11,14 @@
1011
#
1112

1213
from __future__ import print_function
13-
import os, os.path, sys, shutil
14+
import os
15+
import os.path
16+
import sys
1417
from optparse import OptionParser, OptionGroup
1518

1619
index = 0
1720

21+
1822
def harvest_constants(options, path, constants):
1923
global index
2024
# open the file
@@ -234,6 +238,47 @@ def harvest_constants(options, path, constants):
234238
inputfile.close()
235239
return 0
236240

241+
242+
def _write_header(options, base_path, num_elements):
243+
contents = '''/*
244+
* This file is autogenerated by construct_dictionary.py.
245+
* Do not edit this file by hand.
246+
*/
247+
248+
#include "src/include/pmix_config.h"
249+
#include "src/include/pmix_globals.h"
250+
#include "include/pmix_common.h"
251+
252+
#ifndef PMIX_DICTIONARY_H
253+
#define PMIX_DICTIONARY_H
254+
255+
BEGIN_C_DECLS
256+
257+
PMIX_EXPORT extern const pmix_regattr_input_t pmix_dictionary[{}];
258+
259+
#define PMIX_INDEX_BOUNDARY {}
260+
261+
END_C_DECLS
262+
263+
#endif\n
264+
'''.format(num_elements, num_elements - 1)
265+
266+
if options.dryrun:
267+
constants = sys.stdout
268+
outpath = None
269+
else:
270+
outpath = os.path.join(base_path, "pmix_dictionary.h")
271+
try:
272+
constants = open(outpath, "w+")
273+
except Exception as e:
274+
print("{outpath} CANNOT BE OPENED - DICTIONARY COULD NOT BE CONSTRUCTED: {e}"
275+
.format(outpath=outpath, e=e))
276+
return 1
277+
constants.write(contents)
278+
constants.close()
279+
return 0
280+
281+
237282
def main():
238283
parser = OptionParser("usage: %prog [options]")
239284
debugGroup = OptionGroup(parser, "Debug Options")
@@ -272,24 +317,23 @@ def main():
272317
constants = sys.stdout
273318
outpath = None
274319
else:
275-
outpath = os.path.join(build_src_include_dir, "dictionary.h")
320+
outpath = os.path.join(build_src_include_dir, "pmix_dictionary.c")
276321
try:
277322
constants = open(outpath, "w+")
278323
except Exception as e:
279324
print("{outpath} CANNOT BE OPENED - DICTIONARY COULD NOT BE CONSTRUCTED: {e}"
280325
.format(outpath=outpath, e=e))
281326
return 1
282327

283-
# write the header
328+
# write the source file
284329
constants.write("""/*
285330
* This file is autogenerated by construct_dictionary.py.
286331
* Do not edit this file by hand.
287332
*/
288333
289-
#include "src/include/pmix_config.h"
290-
#include "src/include/pmix_globals.h"
334+
#include "src/include/pmix_dictionary.h"
291335
292-
static pmix_regattr_input_t dictionary[] = {
336+
const pmix_regattr_input_t pmix_dictionary[] = {
293337
""")
294338

295339
# scan across the header files in the src directory
@@ -323,9 +367,12 @@ def main():
323367
{.index = UINT32_MAX, .name = "", .string = "", .type = PMIX_POINTER, .description = (char *[]){"NONE", NULL}}
324368
};
325369
""")
326-
constants.write("\n#define PMIX_INDEX_BOUNDARY " + str(index) + "\n")
370+
constants.write("\n")
327371
constants.close()
328-
return 0
372+
373+
# write the header
374+
return _write_header(options, build_src_include_dir, index + 1)
375+
329376

330377
if __name__ == '__main__':
331378
exit(main())

examples/dmodex.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Copyright (c) 2015 Mellanox Technologies, Inc. All rights reserved.
1818
* Copyright (c) 2019-2022 IBM Corporation. All rights reserved.
1919
* Copyright (c) 2021-2022 Nanook Consulting All rights reserved.
20+
* Copyright (c) 2022 Triad National Security, LLC. All rights reserved.
2021
* $COPYRIGHT$
2122
*
2223
* Additional copyrights may follow
@@ -142,7 +143,7 @@ int main(int argc, char **argv)
142143
}
143144
PMIX_ARGV_FREE(peers);
144145

145-
snprintf(proc.nspace, PMIX_MAX_NSLEN, "%s", myproc.nspace);
146+
PMIX_LOAD_NSPACE(proc.nspace, myproc.nspace);
146147
/* get the committed data - ask for someone who doesn't exist as well */
147148
for (n = 0; n < nprocs; n++) {
148149
if (all_local) {

src/common/pmix_attributes.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* All rights reserved.
66
* Copyright (c) 2016 IBM Corporation. All rights reserved.
77
* Copyright (c) 2021-2022 Nanook Consulting All rights reserved.
8+
* Copyright (c) 2022 Triad National Security, LLC. All rights reserved.
89
* $COPYRIGHT$
910
*
1011
* Additional copyrights may follow
@@ -26,7 +27,7 @@
2627
#include "src/util/pmix_hash.h"
2728

2829
#include "src/common/pmix_attributes.h"
29-
#include "src/include/dictionary.h"
30+
#include "src/include/pmix_dictionary.h"
3031

3132
static bool initialized = false;
3233
static pmix_list_t client_attrs;
@@ -72,13 +73,13 @@ PMIX_EXPORT void pmix_init_registered_attrs(void)
7273

7374
/* cycle across the dictionary and load a hash
7475
* table with translations of key -> index */
75-
for (n=0; UINT32_MAX != dictionary[n].index; n++) {
76+
for (n=0; UINT32_MAX != pmix_dictionary[n].index; n++) {
7677
p = (pmix_regattr_input_t*)pmix_malloc(sizeof(pmix_regattr_input_t));
77-
p->index = dictionary[n].index;
78-
p->name = strdup(dictionary[n].name);
79-
p->string = strdup(dictionary[n].string);
80-
p->type = dictionary[n].type;
81-
p->description = pmix_argv_copy(dictionary[n].description);
78+
p->index = pmix_dictionary[n].index;
79+
p->name = strdup(pmix_dictionary[n].name);
80+
p->string = strdup(pmix_dictionary[n].string);
81+
p->type = pmix_dictionary[n].type;
82+
p->description = pmix_argv_copy(pmix_dictionary[n].description);
8283
pmix_hash_register_key(p->index, p);
8384
}
8485
initialized = true;
@@ -850,9 +851,9 @@ PMIX_EXPORT const char *pmix_attributes_lookup(char *attr)
850851
{
851852
size_t n;
852853

853-
for (n = 0; 0 != strlen(dictionary[n].name); n++) {
854-
if (0 == strcasecmp(dictionary[n].name, attr)) {
855-
return dictionary[n].string;
854+
for (n = 0; 0 != strlen(pmix_dictionary[n].name); n++) {
855+
if (0 == strcasecmp(pmix_dictionary[n].name, attr)) {
856+
return pmix_dictionary[n].string;
856857
}
857858
}
858859
return NULL;
@@ -862,9 +863,9 @@ PMIX_EXPORT const char *pmix_attributes_reverse_lookup(char *attrstring)
862863
{
863864
size_t n;
864865

865-
for (n = 0; 0 != strlen(dictionary[n].name); n++) {
866-
if (0 == strcasecmp(dictionary[n].string, attrstring)) {
867-
return dictionary[n].name;
866+
for (n = 0; 0 != strlen(pmix_dictionary[n].name); n++) {
867+
if (0 == strcasecmp(pmix_dictionary[n].string, attrstring)) {
868+
return pmix_dictionary[n].name;
868869
}
869870
}
870871
return NULL;
@@ -874,9 +875,9 @@ PMIX_EXPORT const pmix_regattr_input_t *pmix_attributes_lookup_term(char *attr)
874875
{
875876
size_t n;
876877

877-
for (n = 0; 0 != strlen(dictionary[n].name); n++) {
878-
if (0 == strcmp(dictionary[n].name, attr)) {
879-
return &dictionary[n];
878+
for (n = 0; 0 != strlen(pmix_dictionary[n].name); n++) {
879+
if (0 == strcmp(pmix_dictionary[n].name, attr)) {
880+
return &pmix_dictionary[n];
880881
}
881882
}
882883
return NULL;

src/include/Makefile.am

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Copyright (c) 2017 Research Organization for Information Science
1616
# and Technology (RIST). All rights reserved.
1717
# Copyright (c) 2021-2022 Nanook Consulting All rights reserved.
18+
# Copyright (c) 2022 Triad National Security, LLC. All rights reserved.
1819
# $COPYRIGHT$
1920
#
2021
# Additional copyrights may follow
@@ -32,7 +33,8 @@ noinst_LTLIBRARIES = libpmixglobal.la
3233

3334
libpmixglobal_la_SOURCES = \
3435
pmix_globals.h \
35-
pmix_globals.c
36+
pmix_globals.c \
37+
pmix_dictionary.c
3638

3739
headers = pmix_globals.h
3840

@@ -49,17 +51,22 @@ headers += \
4951
pmix_portable_platform.h \
5052
pmix_portable_platform_real.h \
5153
pmix_frameworks.h \
52-
dictionary.h
54+
pmix_dictionary.h
5355

5456
nobase_pmix_HEADERS = $(headers)
5557

56-
# Need to ensure that dictionary.h is built first -- before any other
57-
# targets.
58-
BUILT_SOURCES = dictionary.h
58+
# Files that are generated here.
59+
libpmixglobal_gen = \
60+
pmix_dictionary.h \
61+
pmix_dictionary.c
5962

60-
dictionary.h: $(top_srcdir)/include/pmix_common.h.in \
61-
$(top_srcdir)/include/pmix_deprecated.h \
62-
$(top_srcdir)/src/common/pmix_attributes.c
63-
$(PYTHON) $(top_srcdir)/contrib/construct_dictionary.py
63+
# Need to ensure that pmix_dictionary.h and pmix_dictionary.c are built first --
64+
# before any other targets.
65+
BUILT_SOURCES = $(libpmixglobal_gen)
6466

65-
MAINTAINERCLEANFILES = dictionary.h
67+
$(libpmixglobal_gen): $(top_srcdir)/include/pmix_common.h.in \
68+
$(top_srcdir)/include/pmix_deprecated.h \
69+
$(top_srcdir)/src/common/pmix_attributes.c
70+
$(PYTHON) $(top_srcdir)/contrib/construct_dictionary.py
71+
72+
MAINTAINERCLEANFILES = $(libpmixglobal_gen)

src/runtime/pmix_init.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* Copyright (c) 2015 Research Organization for Information Science
2020
* and Technology (RIST). All rights reserved.
2121
* Copyright (c) 2021-2022 Nanook Consulting All rights reserved.
22+
* Copyright (c) 2022 Triad National Security, LLC. All rights reserved.
2223
* $COPYRIGHT$
2324
*
2425
* Additional copyrights may follow
@@ -57,7 +58,7 @@
5758
#include "src/client/pmix_client_ops.h"
5859
#include "src/common/pmix_attributes.h"
5960
#include "src/event/pmix_event.h"
60-
#include "src/include/dictionary.h"
61+
#include "src/include/pmix_dictionary.h"
6162
#include "src/include/pmix_types.h"
6263
#include "src/util/pmix_error.h"
6364
#include "src/util/pmix_keyval_parse.h"

src/util/pmix_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#include "src/class/pmix_hash_table.h"
3333
#include "src/class/pmix_pointer_array.h"
34-
#include "src/include/dictionary.h"
34+
#include "src/include/pmix_dictionary.h"
3535
#include "src/include/pmix_globals.h"
3636
#include "src/include/pmix_hash_string.h"
3737
#include "src/mca/bfrops/bfrops.h"

test/test_v2/server_callbacks.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* All rights reserved.
77
* Copyright (c) 2016 IBM Corporation. All rights reserved.
88
* Copyright (c) 2021-2022 Nanook Consulting All rights reserved.
9-
* Copyright (c) 2021 Triad National Security, LLC
9+
* Copyright (c) 2021-2022 Triad National Security, LLC
1010
* All rights reserved.
1111
* $COPYRIGHT$
1212
*
@@ -320,7 +320,9 @@ pmix_status_t spawn_fn(const pmix_proc_t *proc, const pmix_info_t job_info[], si
320320
cb->cbdata = cbdata;
321321

322322
spawn_wait = true;
323-
PMIx_server_register_nspace("foobar", napps, NULL, 0, release_cb, (void *) cb);
323+
pmix_nspace_t foobar;
324+
PMIX_LOAD_NSPACE(foobar, "foobar");
325+
PMIx_server_register_nspace(foobar, napps, NULL, 0, release_cb, (void *) cb);
324326
return PMIX_SUCCESS;
325327
}
326328
static int numconnect = 0;

test/test_v2/test_fence_basic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021 Triad National Security, LLC.
2+
* Copyright (c) 2021-2022 Triad National Security, LLC.
33
* All rights reserved.
44
*
55
* $COPYRIGHT$
@@ -32,7 +32,7 @@ int main(int argc, char *argv[]) {
3232
pmixt_post_init(&this_proc, &l_params, &v_params);
3333

3434
PMIX_PROC_CONSTRUCT(&job_proc);
35-
strncpy(job_proc.nspace, this_proc.nspace, PMIX_MAX_NSLEN);
35+
PMIX_LOAD_NSPACE(job_proc.nspace, this_proc.nspace);
3636
job_proc.rank = PMIX_RANK_WILDCARD;
3737

3838

test/test_v2/test_fence_partial.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021 Triad National Security, LLC.
2+
* Copyright (c) 2021-2022 Triad National Security, LLC.
33
* All rights reserved.
44
*
55
* Copyright (c) 2021 Nanook Consulting All rights reserved.
@@ -67,7 +67,7 @@ int main(int argc, char *argv[]) {
6767
int rc;
6868
long int my_node_num;
6969
size_t i, j, k, node_num_participants;
70-
uint32_t num_procs, num_nodes;
70+
uint32_t num_procs = 0, num_nodes = 0;
7171
size_t ninfo = 0;
7272
test_params params;
7373
validation_params v_params;
@@ -87,7 +87,7 @@ int main(int argc, char *argv[]) {
8787
pmixt_post_init(&this_proc, &params, &v_params);
8888

8989
PMIX_PROC_CONSTRUCT(&job_proc);
90-
strncpy(job_proc.nspace, this_proc.nspace, PMIX_MAX_NSLEN);
90+
PMIX_LOAD_NSPACE(job_proc.nspace, this_proc.nspace);
9191
job_proc.rank = PMIX_RANK_WILDCARD;
9292

9393
PMIXT_CHECK(PMIx_Get(&job_proc, PMIX_JOB_SIZE, NULL, 0, &val), params, v_params);
@@ -141,7 +141,7 @@ int main(int argc, char *argv[]) {
141141
for (i = 1, j = 0; i < num_nodes; i = i + 2){
142142
for (k = 0; k < nodes[i].pmix_local_size; k++) {
143143
PMIX_PROC_CONSTRUCT(&node_procs[j]);
144-
strncpy(node_procs[j].nspace, this_proc.nspace, PMIX_MAX_NSLEN);
144+
PMIX_LOAD_NSPACE(node_procs[j].nspace, this_proc.nspace);
145145
node_procs[j].rank = nodes[i].pmix_rank[k];
146146
TEST_VERBOSE(("participating node_procs[%d].rank = %u", j, node_procs[j].rank));
147147
j++;

test/test_v2/test_fence_wildcard.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021 Triad National Security, LLC.
2+
* Copyright (c) 2021-2022 Triad National Security, LLC.
33
* All rights reserved.
44
*
55
* Copyright (c) 2021 Nanook Consulting All rights reserved.
@@ -83,7 +83,7 @@ int main(int argc, char *argv[]) {
8383
pmixt_post_init(&this_proc, &l_params, &v_params);
8484

8585
PMIX_PROC_CONSTRUCT(&job_proc);
86-
strncpy(job_proc.nspace, this_proc.nspace, PMIX_MAX_NSLEN);
86+
PMIX_LOAD_NSPACE(job_proc.nspace, this_proc.nspace);
8787
job_proc.rank = PMIX_RANK_WILDCARD;
8888

8989
if (l_params.time_fence) {

test/test_v2/test_server.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* All rights reserved.
55
* Copyright (c) 2016-2019 Research Organization for Information Science
66
* and Technology (RIST). All rights reserved.
7-
* Copyright (c) 2020-2021 Triad National Security, LLC
7+
* Copyright (c) 2020-2022 Triad National Security, LLC
88
* All rights reserved.
99
* Copyright (c) 2021-2022 Nanook Consulting. All rights reserved.
1010
* $COPYRIGHT$
@@ -761,7 +761,7 @@ static void server_read_cb(int fd, short event, void *arg)
761761
msg_hdr_t msg_hdr;
762762
char *msg_buf = NULL;
763763
static char *fence_buf = NULL;
764-
int i, n, p, temp_nodeid, fence_idx=0, rc;
764+
int i, n, p, temp_nodeid = -1, fence_idx=0, rc;
765765
static int fences_in_flight = 0;
766766
bool fence_found = false, node_found = false;
767767
// hard limits to fences in flight, procs, and nodes below

0 commit comments

Comments
 (0)