Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] More const for pointer and reference local variables and parameters.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 28 Dec 2019 10:28:59 +0000 (11:28 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 28 Dec 2019 13:45:15 +0000 (14:45 +0100)
examples/deprecated/msg/dht-kademlia/dht-kademlia.c
examples/deprecated/msg/dht-kademlia/node.c
examples/deprecated/msg/dht-pastry/dht-pastry.c
examples/deprecated/simdag/scheduling/sd_scheduling.c
examples/s4u/app-bittorrent/s4u-peer.cpp
examples/s4u/app-bittorrent/s4u-peer.hpp
examples/s4u/dht-kademlia/node.cpp
examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp
src/bindings/java/jmsg_process.cpp
src/bindings/java/jmsg_task.cpp
src/kernel/routing/DijkstraZone.cpp

index f008973..ab505c1 100644 (file)
@@ -322,7 +322,7 @@ unsigned int send_find_node_to_best(node_t node, const_answer_t node_list)
 /** @brief Handles an incoming received task */
 void handle_task(node_t node, msg_task_t task)
 {
-  task_data_t data = MSG_task_get_data(task);
+  const_task_data_t data = MSG_task_get_data(task);
   xbt_assert((data != NULL), "Received NULL data");
   //Adding/updating the guy to our routing table
   node_routing_table_update(node, data->sender_id);
index 5450a69..4a8d1a5 100644 (file)
@@ -44,9 +44,9 @@ void node_free(node_t node)
   */
 void node_routing_table_update(const_node_t node, unsigned int id)
 {
-  routing_table_t table = node->table;
+  const_routing_table_t table = node->table;
   //retrieval of the bucket in which the should be
-  bucket_t bucket = routing_table_find_bucket(table, id);
+  const_bucket_t bucket = routing_table_find_bucket(table, id);
 
   //check if the id is already in the bucket.
   unsigned int id_pos = bucket_find_id(bucket, id);
@@ -79,7 +79,7 @@ answer_t node_find_closest(const_node_t node, unsigned int destination_id)
   int i;
   answer_t answer = answer_init(destination_id);
   /* We find the corresponding bucket for the id */
-  bucket_t bucket = routing_table_find_bucket(node->table, destination_id);
+  const_bucket_t bucket = routing_table_find_bucket(node->table, destination_id);
   int bucket_id = bucket->id;
   xbt_assert((bucket_id <= IDENTIFIER_SIZE), "Bucket found has a wrong identifier");
   /* So, we copy the contents of the bucket unsigned into our result dynar */
@@ -91,12 +91,12 @@ answer_t node_find_closest(const_node_t node, unsigned int destination_id)
   for (i = 1; answer->size < BUCKET_SIZE && ((bucket_id - i > 0) || (bucket_id + i < IDENTIFIER_SIZE)); i++) {
     /* We check the previous buckets */
     if (bucket_id - i >= 0) {
-      bucket_t bucket_p = &node->table->buckets[bucket_id - i];
+      const_bucket_t bucket_p = &node->table->buckets[bucket_id - i];
       answer_add_bucket(bucket_p, answer);
     }
     /* We check the next buckets */
     if (bucket_id + i <= IDENTIFIER_SIZE) {
-      bucket_t bucket_n = &node->table->buckets[bucket_id + i];
+      const_bucket_t bucket_n = &node->table->buckets[bucket_id + i];
       answer_add_bucket(bucket_n, answer);
     }
   }
index 274e2ba..c232a8e 100644 (file)
@@ -134,7 +134,8 @@ static int closest_in_namespace_set(const_node_t node, int dest)
 }
 
 /* Find the next node to forward a message to */
-static int routing_next(node_t node, int dest) {
+static int routing_next(const_node_t node, int dest)
+{
   int closest = closest_in_namespace_set(node, dest);
   if (closest!=-1)
     return closest;
index 5da1b6a..f8afd59 100644 (file)
@@ -46,7 +46,7 @@ static void sg_host_set_last_scheduled_task(sg_host_t host, SD_task_t task){
   sg_host_data_set(host, attr);
 }
 
-static xbt_dynar_t get_ready_tasks(xbt_dynar_t dax)
+static xbt_dynar_t get_ready_tasks(const_xbt_dynar_t dax)
 {
   unsigned int i;
   xbt_dynar_t ready_tasks;
index 84d3196..788d96a 100644 (file)
@@ -429,7 +429,7 @@ void Peer::removeCurrentPiece(Connection* remote_peer, unsigned int current_piec
  * @param remote_peer: information about the connection
  * @return the piece to download if possible. -1 otherwise
  */
-int Peer::selectPieceToDownload(Connection* remote_peer)
+int Peer::selectPieceToDownload(const Connection* remote_peer)
 {
   int piece = partiallyDownloadedPiece(remote_peer);
   // strict priority policy
@@ -645,7 +645,7 @@ int Peer::getFirstMissingBlockFrom(int piece)
 }
 
 /** Returns a piece that is partially downloaded and stored by the remote peer if any -1 otherwise. */
-int Peer::partiallyDownloadedPiece(Connection* remote_peer)
+int Peer::partiallyDownloadedPiece(const Connection* remote_peer)
 {
   for (unsigned int i = 0; i < FILE_PIECES; i++)
     if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i) && getFirstMissingBlockFrom(i) > 0)
index 4282830..b71ae28 100644 (file)
@@ -64,12 +64,12 @@ public:
   unsigned int countPieces(unsigned int bitfield);
   /** Check that a piece is not currently being download by the peer. */
   bool isNotDownloadingPiece(unsigned int piece) const { return not(current_pieces & 1U << piece); }
-  int partiallyDownloadedPiece(Connection* remote_peer);
+  int partiallyDownloadedPiece(const Connection* remote_peer);
   void updatePiecesCountFromBitfield(unsigned int bitfield);
   void removeCurrentPiece(Connection* remote_peer, unsigned int current_piece);
   void updateBitfieldBlocks(int piece, int block_index, int block_length);
   int getFirstMissingBlockFrom(int piece);
-  int selectPieceToDownload(Connection* remote_peer);
+  int selectPieceToDownload(const Connection* remote_peer);
   void requestNewPieceTo(Connection* remote_peer);
 
   bool getPeersFromTracker();
index 8ab688c..76ac971 100644 (file)
@@ -41,7 +41,7 @@ bool Node::join(unsigned int known_id)
       XBT_DEBUG("Received an answer from the node I know.");
       got_answer = true;
       // retrieve the node list and ping them.
-      Message* msg = static_cast<Message*>(received_msg);
+      const Message* msg = static_cast<Message*>(received_msg);
       node_list    = msg->answer_;
       if (node_list) {
         for (auto contact : node_list->nodes)
@@ -206,7 +206,7 @@ bool Node::findNode(unsigned int id_to_find, bool count_in_stats)
         receive_comm = mailbox->get_async(&received_msg);
 
       if (receive_comm->test()) {
-        Message* msg = static_cast<Message*>(received_msg);
+        const Message* msg = static_cast<Message*>(received_msg);
         // Check if what we have received is what we are looking for.
         if (msg->answer_ && msg->answer_->getDestinationId() == id_to_find) {
           routingTableUpdate(msg->sender_id_);
index c6c8fc1..7efb03f 100644 (file)
@@ -52,7 +52,7 @@ static int node(int argc, char* argv[])
 
       if (node->receive_comm->test()) {
         // There has been a message, we need to handle it !
-        kademlia::Message* msg = static_cast<kademlia::Message*>(node->received_msg);
+        const kademlia::Message* msg = static_cast<kademlia::Message*>(node->received_msg);
         if (msg) {
           node->handleFindNode(msg);
           delete msg->answer_;
index cfb82d6..8a6509d 100644 (file)
@@ -110,7 +110,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_killAll(JNIEnv* env, jclass
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jclass cls, jint pid)
 {
-  msg_process_t process = MSG_process_from_PID(pid);
+  auto const* process = MSG_process_from_PID(pid);
 
   if (not process) {
     jxbt_throw_process_not_found(env, std::string("PID = ") + std::to_string(static_cast<int>(pid)));
index 657d3a0..09aa323 100644 (file)
@@ -162,8 +162,6 @@ JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Task_getName(JNIEnv * env, jobjec
 }
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSender(JNIEnv * env, jobject jtask) {
-  msg_process_t process;
-
   msg_task_t task = jtask_to_native(jtask, env);
 
   if (not task) {
@@ -171,7 +169,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSender(JNIEnv * env, jobj
     return nullptr;
   }
 
-  process = MSG_task_get_sender(task);
+  auto const* process = MSG_task_get_sender(task);
   if (process == nullptr) {
     return nullptr;
   }
index 2694cdf..25818ae 100644 (file)
@@ -77,7 +77,7 @@ void DijkstraZone::seal()
   }
 
   /* initialize graph indexes in nodes after graph has been built */
-  xbt_dynar_t nodes = xbt_graph_get_nodes(route_graph_);
+  const_xbt_dynar_t nodes = xbt_graph_get_nodes(route_graph_);
 
   xbt_dynar_foreach (nodes, cursor, node) {
     GraphNodeData* data = static_cast<GraphNodeData*>(xbt_graph_node_get_data(node));