From f4e9ed55bfc9d01e829ebc51112a0c55bf042624 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Fri, 21 Feb 2020 18:10:43 +0100 Subject: [PATCH] [sonar] Const again. --- examples/c/app-chainsend/broadcaster.c | 2 +- examples/c/app-chainsend/chainsend.h | 1 + examples/c/app-chainsend/peer.c | 10 +++++----- include/simgrid/exec.h | 2 +- src/s4u/s4u_Exec.cpp | 2 +- teshsuite/s4u/host-on-off/host-on-off.cpp | 12 ++++++------ 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/c/app-chainsend/broadcaster.c b/examples/c/app-chainsend/broadcaster.c index feb690b8d0..ad60acdafa 100644 --- a/examples/c/app-chainsend/broadcaster.c +++ b/examples/c/app-chainsend/broadcaster.c @@ -34,7 +34,7 @@ static void broadcaster_build_chain(broadcaster_t bc) } } -static void broadcaster_send_file(broadcaster_t bc) +static void broadcaster_send_file(const_broadcaster_t bc) { int nb_pending_sends = 0; diff --git a/examples/c/app-chainsend/chainsend.h b/examples/c/app-chainsend/chainsend.h index baef90ac53..84caabb612 100644 --- a/examples/c/app-chainsend/chainsend.h +++ b/examples/c/app-chainsend/chainsend.h @@ -35,6 +35,7 @@ typedef struct s_broadcaster { } s_broadcaster_t; typedef s_broadcaster_t* broadcaster_t; +typedef const s_broadcaster_t* const_broadcaster_t; void broadcaster(int argc, char* argv[]); /* Message struct */ diff --git a/examples/c/app-chainsend/peer.c b/examples/c/app-chainsend/peer.c index a0036b2726..f3dff0cc5c 100644 --- a/examples/c/app-chainsend/peer.c +++ b/examples/c/app-chainsend/peer.c @@ -10,16 +10,16 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(chainsend_peer, "Messages specific for the peer"); static void peer_join_chain(peer_t p) { - const chain_message_t msg = (chain_message_t)sg_mailbox_get(p->me); - p->prev = msg->prev_; - p->next = msg->next_; - p->total_pieces = msg->num_pieces; + chain_message_t msg = (chain_message_t)sg_mailbox_get(p->me); + p->prev = msg->prev_; + p->next = msg->next_; + p->total_pieces = msg->num_pieces; XBT_DEBUG("Peer %s got a 'BUILD_CHAIN' message (prev: %s / next: %s)", sg_mailbox_get_name(p->me), p->prev ? sg_mailbox_get_name(p->prev) : NULL, p->next ? sg_mailbox_get_name(p->next) : NULL); free(msg); } -static void peer_forward_file(const peer_t p) +static void peer_forward_file(peer_t p) { void* received; int done = 0; diff --git a/include/simgrid/exec.h b/include/simgrid/exec.h index 17e7ae9596..74d8ac8ff9 100644 --- a/include/simgrid/exec.h +++ b/include/simgrid/exec.h @@ -13,7 +13,7 @@ SG_BEGIN_DECL XBT_PUBLIC void sg_exec_set_bound(sg_exec_t exec, double bound); -XBT_PUBLIC double sg_exec_get_remaining(sg_exec_t exec); +XBT_PUBLIC double sg_exec_get_remaining(const_sg_exec_t exec); XBT_PUBLIC void sg_exec_start(sg_exec_t exec); XBT_PUBLIC void sg_exec_wait(sg_exec_t exec); diff --git a/src/s4u/s4u_Exec.cpp b/src/s4u/s4u_Exec.cpp index 6d629ed30e..b16393c97f 100644 --- a/src/s4u/s4u_Exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -216,7 +216,7 @@ void sg_exec_set_bound(sg_exec_t exec, double bound) exec->set_bound(bound); } -double sg_exec_get_remaining(sg_exec_t exec) +double sg_exec_get_remaining(const_sg_exec_t exec) { return exec->get_remaining(); } diff --git a/teshsuite/s4u/host-on-off/host-on-off.cpp b/teshsuite/s4u/host-on-off/host-on-off.cpp index 6566ce5b10..906c5361c5 100644 --- a/teshsuite/s4u/host-on-off/host-on-off.cpp +++ b/teshsuite/s4u/host-on-off/host-on-off.cpp @@ -10,13 +10,13 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example") static void worker() { - std::string* payload; + const std::string* payload; simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("jupi"); while (1) { try { payload = static_cast(mailbox->get()); - } catch (simgrid::HostFailureException&) { + } catch (const simgrid::HostFailureException&) { XBT_DEBUG("The host has been turned off, this was expected"); return; } @@ -50,7 +50,7 @@ static void master() payload = new std::string("task off"); try { mailbox->put_async(payload, 1E6)->wait_for(1); - } catch (simgrid::TimeoutException&) { + } catch (const simgrid::TimeoutException&) { delete payload; } @@ -64,7 +64,7 @@ static void master() payload = new std::string("task on without actor"); try { mailbox->put_async(payload, 1E6)->wait_for(1); - } catch (simgrid::TimeoutException&) { + } catch (const simgrid::TimeoutException&) { delete payload; } @@ -74,7 +74,7 @@ static void master() payload = new std::string("task on with actor"); try { mailbox->put_async(payload, 1E6)->wait_for(1); - } catch (simgrid::TimeoutException&) { + } catch (const simgrid::TimeoutException&) { delete payload; } @@ -82,7 +82,7 @@ static void master() payload = new std::string("finalize"); try { mailbox->put_async(payload, 0)->wait_for(1); - } catch (simgrid::TimeoutException&) { + } catch (const simgrid::TimeoutException&) { delete payload; } -- 2.20.1