Skip to content

Commit fcd7184

Browse files
authored
Eliminate using namespace commands (#130)
* Remove unused `using namespace` * Substitute `using namespace` commands with more specific `using` ones * Avoid `using namespace` by namespace-qualified calls * Make anonymous namespace an internal one inside the signal namespace * Enable the build/namespaces cpplint check in actions
1 parent 3c8b6c2 commit fcd7184

10 files changed

Lines changed: 66 additions & 79 deletions

File tree

.github/workflows/cpplint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ jobs:
77
- uses: actions/checkout@v3
88
- uses: actions/setup-python@v4
99
- run: pip install cpplint
10-
- run: cpplint --quiet --root=../ --filter=-build/c++11,-build/include,-build/namespaces,-runtime/array,-runtime/string,-whitespace/braces,-whitespace/indent,-whitespace/line_length,-whitespace/tab --recursive src tests
10+
- run: cpplint --quiet --root=../ --filter=-build/c++11,-build/include,-runtime/array,-runtime/string,-whitespace/braces,-whitespace/indent,-whitespace/line_length,-whitespace/tab --recursive src tests

src/allocators/allocators.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "allocators.hpp"
88

9-
namespace mem = argo::mempools;
109
namespace alloc = argo::allocators;
1110

1211
/* default allocators */
@@ -16,32 +15,28 @@ alloc::collective_allocator alloc::default_collective_allocator;
1615

1716
extern "C"
1817
void* collective_alloc(size_t size) {
19-
using namespace argo::allocators;
2018
/** @bug this is wrong: either it should not be done at all, or also when using the C++ interface */
2119
argo::backend::barrier();
22-
return static_cast<void*>(default_collective_allocator.allocate(size));
20+
return static_cast<void*>(alloc::default_collective_allocator.allocate(size));
2321
}
2422

2523
extern "C"
2624
void collective_free(void* ptr) {
27-
using namespace argo::allocators;
28-
using atype = decltype(default_collective_allocator)::value_type;
25+
using atype = decltype(alloc::default_collective_allocator)::value_type;
2926
if (ptr == NULL)
3027
return;
31-
default_collective_allocator.free(static_cast<atype*>(ptr));
28+
alloc::default_collective_allocator.free(static_cast<atype*>(ptr));
3229
}
3330

3431
extern "C"
3532
void* dynamic_alloc(size_t size) {
36-
using namespace argo::allocators;
37-
return static_cast<void*>(default_dynamic_allocator.allocate(size));
33+
return static_cast<void*>(alloc::default_dynamic_allocator.allocate(size));
3834
}
3935

4036
extern "C"
4137
void dynamic_free(void* ptr) {
42-
using namespace argo::allocators;
43-
using atype = decltype(default_dynamic_allocator)::value_type;
38+
using atype = decltype(alloc::default_dynamic_allocator)::value_type;
4439
if (ptr == NULL)
4540
return;
46-
default_dynamic_allocator.free(static_cast<atype*>(ptr));
41+
alloc::default_dynamic_allocator.free(static_cast<atype*>(ptr));
4742
}

src/allocators/collective_allocator.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ T* conew_(Ps&&... ps) {
107107
}
108108

109109
void* ptr = collective_alloc(sizeof(T));
110-
using namespace data_distribution;
110+
using data_distribution::global_ptr;
111111
global_ptr<void> gptr(ptr, false, false);
112112
// The home node of ptr handles initialization
113113
if (initialize && argo::backend::node_id() == gptr.node()) {
@@ -165,7 +165,7 @@ void codelete_(T* ptr) {
165165
synchronize = false;
166166
}
167167

168-
using namespace data_distribution;
168+
using data_distribution::global_ptr;
169169
global_ptr<T> gptr(ptr, false, false);
170170
// The home node of ptr handles deinitialization
171171
if (deinitialize && argo::backend::node_id() == gptr.node()) {
@@ -218,7 +218,7 @@ T* conew_array(size_t size) {
218218
}
219219

220220
void* ptr = collective_alloc(sizeof(T) * size);
221-
using namespace data_distribution;
221+
using data_distribution::global_ptr;
222222
global_ptr<void> gptr(ptr, false, false);
223223
// The home node of ptr handles initialization
224224
if (initialize && argo::backend::node_id() == gptr.node()) {
@@ -269,7 +269,7 @@ void codelete_array(T* ptr) {
269269
synchronize = false;
270270
}
271271

272-
using namespace data_distribution;
272+
using data_distribution::global_ptr;
273273
global_ptr<T> gptr(ptr, false, false);
274274
// The home node of ptr handles deinitialization
275275
if (deinitialize && argo::backend::node_id() == gptr.node()) {

src/argo.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,14 @@ namespace argo {
8888
*/
8989
static void reset_allocators() {
9090
default_global_mempool->reset();
91-
using namespace alloc;
92-
using namespace mem;
93-
collective_prepool = dynamic_memory_pool<global_allocator, NODE_ZERO_ONLY>(&default_global_allocator);
94-
dynamic_prepool = dynamic_memory_pool<global_allocator, ALWAYS>(&default_global_allocator);
95-
default_global_allocator = global_allocator<char>();
96-
default_dynamic_allocator = default_dynamic_allocator_t();
97-
default_collective_allocator = collective_allocator();
91+
using alloc::default_dynamic_allocator;
92+
using alloc::default_collective_allocator;
93+
using alloc::default_global_allocator;
94+
collective_prepool = mem::dynamic_memory_pool<alloc::global_allocator, mem::NODE_ZERO_ONLY>(&default_global_allocator);
95+
dynamic_prepool = mem::dynamic_memory_pool<alloc::global_allocator, mem::ALWAYS>(&default_global_allocator);
96+
default_global_allocator = alloc::global_allocator<char>();
97+
default_dynamic_allocator = alloc::default_dynamic_allocator_t();
98+
default_collective_allocator = alloc::collective_allocator();
9899
default_global_allocator.set_mempool(default_global_mempool);
99100
default_dynamic_allocator.set_mempool(&dynamic_prepool);
100101
default_collective_allocator.set_mempool(&collective_prepool);

src/backend/mpi/mpi.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
*/
2626
static MPI_Datatype fitting_mpi_int(std::size_t size) {
2727
MPI_Datatype t_type;
28-
using namespace argo;
2928

3029
switch (size) {
3130
// Until UCX supports 1/2 byte atomics, they must be disabled
@@ -60,7 +59,6 @@ static MPI_Datatype fitting_mpi_int(std::size_t size) {
6059
*/
6160
static MPI_Datatype fitting_mpi_uint(std::size_t size) {
6261
MPI_Datatype t_type;
63-
using namespace argo;
6462

6563
switch (size) {
6664
// Until UCX supports 1/2 byte atomics, they must be disabled
@@ -93,7 +91,6 @@ static MPI_Datatype fitting_mpi_uint(std::size_t size) {
9391
*/
9492
static MPI_Datatype fitting_mpi_float(std::size_t size) {
9593
MPI_Datatype t_type;
96-
using namespace argo;
9794

9895
switch (size) {
9996
case 4:

src/backend/singlenode/singlenode.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
namespace vm = argo::virtual_memory;
2323
namespace sig = argo::signal;
24-
using namespace argo::backend;
2524

2625
/** @brief a lock for atomically executed operations */
2726
std::mutex atomic_op_mutex;
@@ -85,12 +84,12 @@ void init(std::size_t argo_size, std::size_t cache_size) {
8584
(void)(cache_size);
8685
memory = static_cast<char*>(vm::allocate_mappable(PAGE_SIZE, argo_size));
8786
memory_size = argo_size;
88-
using namespace data_distribution;
87+
using argo::data_distribution::base_distribution;
8988
base_distribution<0>::set_memory_space(nodes, memory, argo_size);
9089
sig::signal_handler<SIGSEGV>::install_argo_handler(&singlenode_handler);
9190
/** @note first-touch needs a directory for fetching
9291
* the homenode and offset for an address */
93-
if (is_first_touch_policy()) {
92+
if (argo::data_distribution::is_first_touch_policy()) {
9493
/* calculate the directory size and allocate memory */
9594
std::size_t owners_dir_size = 3*(argo_size/PAGE_SIZE);
9695
std::size_t owners_dir_size_bytes = owners_dir_size*sizeof(std::size_t);
@@ -132,10 +131,9 @@ void reset_stats() {}
132131
void finalize() {}
133132

134133
void reset_coherence() {
135-
using namespace data_distribution;
136134
/** @note first-touch needs a directory for fetching
137135
* the homenode and offset for an address */
138-
if (is_first_touch_policy()) {
136+
if (argo::data_distribution::is_first_touch_policy()) {
139137
/* calculate the directory size and allocate memory */
140138
std::size_t owners_dir_size = 3*(memory_size/PAGE_SIZE);
141139
std::size_t owners_dir_size_bytes = owners_dir_size*sizeof(std::size_t);

src/mempools/global_mempool.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class global_memory_pool {
5454
memory = backend::global_base();
5555
max_size = backend::global_size();
5656
/**@todo this initialization should move to tools::init() land */
57-
using namespace data_distribution;
57+
using argo::data_distribution::base_distribution;
5858
base_distribution<0>::set_memory_space(nodes, memory, max_size);
5959

6060
// Reset maximum size to the full memory size minus the space reserved for internal use
@@ -68,6 +68,7 @@ class global_memory_pool {
6868
global_tas_lock = new tas_lock(field);
6969

7070
// Home node makes sure that offset points to Argo's starting address
71+
using argo::data_distribution::global_ptr;
7172
global_ptr<char> gptr(&memory[max_size]);
7273
if(backend::node_id() == gptr.node()) {
7374
*offset = static_cast<std::ptrdiff_t>(0);
@@ -93,7 +94,7 @@ class global_memory_pool {
9394
max_size = backend::global_size() - reserved;
9495

9596
// Home node makes sure that offset points to Argo's starting address
96-
using namespace data_distribution;
97+
using argo::data_distribution::global_ptr;
9798
global_ptr<char> gptr(&memory[max_size]);
9899
if(backend::node_id() == gptr.node()) {
99100
*offset = static_cast<std::ptrdiff_t>(0);

src/signal/signal.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ enum x86_pf_error_code {
4040
};
4141
#endif /* REG_ERR */
4242

43-
namespace {
43+
namespace argo {
44+
namespace signal {
45+
namespace sig_internal {
4446
/** @brief typedef for signal handlers */
4547
using sig_handler = struct sigaction;
4648
/** @brief typedef for function type used by ArgoDSM */
4749
using handler_ftype = void(*)(int, siginfo_t*, void*);
4850

4951
/** @brief error message string */
5052
const std::string msg_argo_unitialized = "ArgoDSM must be configured to capture a signal before application handlers can be installed";
51-
} // namespace
53+
} // namespace sig_internal
5254

53-
namespace argo {
54-
namespace signal {
5555
/**
5656
* @brief Originating access type of segfault
5757
*/
@@ -69,9 +69,9 @@ template<int SIGNAL>
6969
class signal_handler {
7070
private:
7171
/** @brief signal handling function for ArgoDSM */
72-
static handler_ftype argo_handler;
72+
static sig_internal::handler_ftype argo_handler;
7373
/** @brief signal handler for application use */
74-
static sig_handler application_handler;
74+
static sig_internal::sig_handler application_handler;
7575

7676
public:
7777
/**
@@ -80,9 +80,9 @@ class signal_handler {
8080
* @details The function will only be called for signals
8181
* that relate to ArgoDSM's internal workings
8282
*/
83-
static void install_argo_handler(const handler_ftype h) {
83+
static void install_argo_handler(const sig_internal::handler_ftype h) {
8484
argo_handler = h;
85-
sig_handler s;
85+
sig_internal::sig_handler s;
8686
s.sa_flags = SA_SIGINFO;
8787
s.sa_sigaction = argo_signal_handler;
8888
sigaction(SIGNAL, &s, &application_handler);
@@ -95,11 +95,11 @@ class signal_handler {
9595
* @details The signal handler will only be called for signals
9696
* that are not consumed by ArgoDSM internally
9797
*/
98-
static sig_handler install_application_handler(sig_handler* h) {
98+
static sig_internal::sig_handler install_application_handler(sig_internal::sig_handler* h) {
9999
if(argo_handler == nullptr) {
100-
throw std::runtime_error(msg_argo_unitialized);
100+
throw std::runtime_error(sig_internal::msg_argo_unitialized);
101101
}
102-
sig_handler r = *h;
102+
sig_internal::sig_handler r = *h;
103103
std::swap(r, application_handler);
104104
return r;
105105
}
@@ -133,8 +133,8 @@ class signal_handler {
133133
}
134134
};
135135

136-
template<int S> handler_ftype signal_handler<S>::argo_handler = nullptr;
137-
template<int S> sig_handler signal_handler<S>::application_handler;
136+
template<int S> sig_internal::handler_ftype signal_handler<S>::argo_handler = nullptr;
137+
template<int S> sig_internal::sig_handler signal_handler<S>::application_handler;
138138

139139
} // namespace signal
140140
} // namespace argo

tests/allocators.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -369,41 +369,42 @@ TEST_F(AllocatorTest, PerfectForwardingCollectiveNew) {
369369
* @brief Test the "parser" for the allocation parameters
370370
*/
371371
TEST_F(AllocatorTest, AllocationParametersParsing) {
372-
using namespace argo;
373-
using namespace argo::_internal;
374-
375-
ASSERT_TRUE((alloc_param_in<allocation::initialize,
376-
allocation::initialize>::value));
377-
ASSERT_TRUE((alloc_param_in<allocation::no_initialize,
378-
allocation::no_initialize>::value));
379-
ASSERT_TRUE((alloc_param_in<allocation::deinitialize,
380-
allocation::deinitialize>::value));
381-
ASSERT_TRUE((alloc_param_in<allocation::no_deinitialize,
382-
allocation::no_deinitialize>::value));
383-
ASSERT_TRUE((alloc_param_in<allocation::synchronize,
384-
allocation::synchronize>::value));
385-
ASSERT_TRUE((alloc_param_in<allocation::no_synchronize,
386-
allocation::no_synchronize>::value));
387-
388-
using all_yes = alloc_params<allocation::initialize,
389-
allocation::deinitialize, allocation::synchronize>;
372+
using alloc = argo::allocation;
373+
374+
using argo::_internal::alloc_param_in;
375+
ASSERT_TRUE((alloc_param_in<alloc::initialize,
376+
alloc::initialize>::value));
377+
ASSERT_TRUE((alloc_param_in<alloc::no_initialize,
378+
alloc::no_initialize>::value));
379+
ASSERT_TRUE((alloc_param_in<alloc::deinitialize,
380+
alloc::deinitialize>::value));
381+
ASSERT_TRUE((alloc_param_in<alloc::no_deinitialize,
382+
alloc::no_deinitialize>::value));
383+
ASSERT_TRUE((alloc_param_in<alloc::synchronize,
384+
alloc::synchronize>::value));
385+
ASSERT_TRUE((alloc_param_in<alloc::no_synchronize,
386+
alloc::no_synchronize>::value));
387+
388+
using argo::_internal::alloc_params;
389+
using all_yes = alloc_params<alloc::initialize,
390+
alloc::deinitialize, alloc::synchronize>;
390391
ASSERT_TRUE(all_yes::initialize);
391392
ASSERT_TRUE(all_yes::deinitialize);
392393
ASSERT_TRUE(all_yes::synchronize);
393394
ASSERT_FALSE(all_yes::no_initialize);
394395
ASSERT_FALSE(all_yes::no_deinitialize);
395396
ASSERT_FALSE(all_yes::no_synchronize);
396397

397-
using all_no = alloc_params<allocation::no_initialize,
398-
allocation::no_deinitialize, allocation::no_synchronize>;
398+
using all_no = alloc_params<alloc::no_initialize,
399+
alloc::no_deinitialize, alloc::no_synchronize>;
399400
ASSERT_FALSE(all_no::initialize);
400401
ASSERT_FALSE(all_no::deinitialize);
401402
ASSERT_FALSE(all_no::synchronize);
402403
ASSERT_TRUE(all_no::no_initialize);
403404
ASSERT_TRUE(all_no::no_deinitialize);
404405
ASSERT_TRUE(all_no::no_synchronize);
405406

406-
using just_one = alloc_params<allocation::synchronize>;
407+
using just_one = alloc_params<alloc::synchronize>;
407408
ASSERT_FALSE(just_one::initialize);
408409
ASSERT_FALSE(just_one::deinitialize);
409410
ASSERT_TRUE(just_one::synchronize);

tests/stlallocation.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,15 @@ class cppTest : public testing::Test {
3636
* @brief Unittest that checks that an STL list can be allocated globally and populated
3737
*/
3838
TEST_F(cppTest, simpleList) {
39-
using namespace std;
40-
using namespace argo;
41-
using namespace argo::allocators;
42-
using my_list = std::list<int, dynamic_allocator<int>>;
39+
using my_list = std::list<int, argo::allocators::dynamic_allocator<int>>;
4340

44-
my_list* l = conew_<my_list>();
41+
my_list* l = argo::conew_<my_list>();
4542

4643
for(unsigned int i = 0; i < argo_number_of_nodes(); i++) {
4744
if(argo_node_id() == i) {
4845
ASSERT_NO_THROW(l->push_back(i));
4946
}
50-
barrier();
47+
argo::barrier();
5148
}
5249

5350
int id = 0;
@@ -61,18 +58,15 @@ TEST_F(cppTest, simpleList) {
6158
* @brief Unittest that checks that an STL vector can be allocated globally and populated
6259
*/
6360
TEST_F(cppTest, simpleVector) {
64-
using namespace std;
65-
using namespace argo;
66-
using namespace argo::allocators;
67-
using my_vector = std::vector<int, dynamic_allocator<int>>;
61+
using my_vector = std::vector<int, argo::allocators::dynamic_allocator<int>>;
6862

69-
my_vector* v = conew_<my_vector>();
63+
my_vector* v = argo::conew_<my_vector>();
7064

7165
for(unsigned int i = 0; i < argo_number_of_nodes(); i++) {
7266
if(argo_node_id() == i) {
7367
ASSERT_NO_THROW(v->push_back(i));
7468
}
75-
barrier();
69+
argo::barrier();
7670
}
7771

7872
int id = 0;

0 commit comments

Comments
 (0)