Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix misc sonar issues.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 16 Mar 2022 10:18:23 +0000 (11:18 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 16 Mar 2022 15:47:19 +0000 (16:47 +0100)
examples/cpp/synchro-mutex/s4u-synchro-mutex.cpp
src/bindings/python/simgrid_python.cpp
src/kernel/actor/ActorImpl.cpp
src/kernel/actor/ActorImpl.hpp
src/kernel/resource/profile/Profile.cpp
src/kernel/resource/profile/Profile.hpp
src/kernel/resource/profile/ProfileBuilder.cpp
teshsuite/smpi/MBI/MBIutils.py

index 52e2595..2127d03 100644 (file)
@@ -47,10 +47,9 @@ static void workerLockGuard(sg4::MutexPtr mutex, int& result)
 static void master()
 {
   /* Create the requested amount of actors pairs. Each pair has a specific mutex and cell in `result`. */
-  int result[cfg_actor_count.get()];
+  std::vector<int> result(cfg_actor_count.get());
 
   for (int i = 0; i < cfg_actor_count; i++) {
-    result[i]           = 0;
     sg4::MutexPtr mutex = sg4::Mutex::create();
     sg4::Actor::create("worker", sg4::Host::by_name("Jupiter"), workerLockGuard, mutex, std::ref(result[i]));
     sg4::Actor::create("worker", sg4::Host::by_name("Tremblay"), worker, mutex, std::ref(result[i]));
index 8e054b2..eded4f1 100644 (file)
@@ -791,7 +791,7 @@ PYBIND11_MODULE(simgrid, m)
       .def("unlock", &Mutex::unlock, py::call_guard<py::gil_scoped_release>(), "Release the mutex")
       // Allow mutexes to be automatically acquired/released with a context manager: `with mutex: ...`
       .def("__enter__", [](Mutex* self){ self->lock(); }, py::call_guard<py::gil_scoped_release>())
-      .def("__exit__", [](Mutex* self, py::object&, py::object&, py::object&){ self->unlock(); },
+      .def("__exit__", [](Mutex* self, const py::object&, const py::object&, const py::object&) { self->unlock(); },
           py::call_guard<py::gil_scoped_release>());
 
   /* Class Barrier */
index 2542751..ef37508 100644 (file)
@@ -48,7 +48,7 @@ unsigned long* get_maxpid_addr()
 {
   return &maxpid;
 }
-ActorIDTrait::ActorIDTrait(std::string name, aid_t ppid) : name_(std::move(name)), pid_(maxpid++), ppid_(ppid) {}
+ActorIDTrait::ActorIDTrait(const std::string& name, aid_t ppid) : name_(name), pid_(maxpid++), ppid_(ppid) {}
 
 ActorImpl* ActorImpl::self()
 {
index 5ea6048..9979c40 100644 (file)
@@ -28,7 +28,7 @@ class XBT_PUBLIC ActorIDTrait {
   aid_t ppid_        = -1;
 
 public:
-  explicit ActorIDTrait(std::string name, aid_t ppid);
+  explicit ActorIDTrait(const std::string& name, aid_t ppid);
   const xbt::string& get_name() const { return name_; }
   const char* get_cname() const { return name_.c_str(); }
   aid_t get_pid() const { return pid_; }
index 5a2ab18..3422094 100644 (file)
@@ -65,7 +65,7 @@ DatedValue Profile::next(Event* event)
   if(event->idx>=event_list.size())
     event->free_me = true;
   else {
-    DatedValue& nextDateVal=event_list.at(event->idx);
+    const DatedValue& nextDateVal = event_list.at(event->idx);
     xbt_assert(nextDateVal.date_>=0);
     xbt_assert(nextDateVal.value_>=0);
     fes_->add_event(event_date +nextDateVal.date_, event);
@@ -73,7 +73,9 @@ DatedValue Profile::next(Event* event)
   return dateVal;
 }
 
-Profile::Profile(const std::string& name, const std::function<ProfileBuilder::UpdateCb>& cb, double repeat_delay): name(name),cb(std::move(cb)),repeat_delay(repeat_delay) {
+Profile::Profile(const std::string& name, const std::function<ProfileBuilder::UpdateCb>& cb, double repeat_delay)
+    : name(name), cb(cb), repeat_delay(repeat_delay)
+{
   xbt_assert(trace_list.find(name) == trace_list.end(), "Refusing to define trace %s twice", name.c_str());
   trace_list.insert({name,this});
   cb(event_list);
index 8a25e3b..02fe86f 100644 (file)
@@ -43,7 +43,7 @@ public:
   DatedValue next(Event* event);
 
   const std::vector<DatedValue>& get_event_list() const { return event_list; }
-  const std::string get_name() const { return name; }
+  const std::string& get_name() const { return name; }
   bool is_repeating() const { return repeat_delay>=0;}
   double get_repeat_delay() const { return repeat_delay;}
   
index 23fb0db..b92928e 100644 (file)
@@ -200,18 +200,18 @@ public:
     xbt_assert(loop_delay >= 0, "Profile loop conditions are not realizable!");
   }
 
-  double get_repeat_delay()
+  double get_repeat_delay() const
   {
     if (not stochastic and loop)
       return loop_delay;
     return -1.0;
   }
 
-  void operator()(std::vector<DatedValue>& event_list)
+  void operator()(std::vector<DatedValue>& event_list) const
   {
     size_t initial_size = event_list.size();
     if (loop or not initial_size) {
-      for (auto dv : pattern)
+      for (auto const& dv : pattern)
         event_list.emplace_back(dv.get_datedvalue());
       if (initial_size)
         event_list.at(initial_size).date_ += loop_delay;
index 4c56706..433466f 100644 (file)
@@ -150,16 +150,16 @@ def parse_one_code(filename):
         raise Exception(f"No test found in {filename}. Please fix it.")
     return res
 
-def categorize(tool, toolname, test_ID, expected):
-    outcome = tool.parse(test_ID)
+def categorize(tool, toolname, test_id, expected):
+    outcome = tool.parse(test_id)
 
-    if not os.path.exists(f'{test_ID}.elapsed') and not os.path.exists(f'logs/{toolname}/{test_ID}.elapsed'):
+    if not os.path.exists(f'{test_id}.elapsed') and not os.path.exists(f'logs/{toolname}/{test_id}.elapsed'):
         if outcome == 'failure':
             elapsed = 0
         else:
-            raise Exception(f"Invalid test result: {test_ID}.txt exists but not {test_ID}.elapsed")
+            raise Exception(f"Invalid test result: {test_id}.txt exists but not {test_id}.elapsed")
     else:
-        with open(f'{test_ID}.elapsed' if os.path.exists(f'{test_ID}.elapsed') else f'logs/{toolname}/{test_ID}.elapsed', 'r') as infile:
+        with open(f'{test_id}.elapsed' if os.path.exists(f'{test_id}.elapsed') else f'logs/{toolname}/{test_id}.elapsed', 'r') as infile:
             elapsed = infile.read()
 
     # Properly categorize this run
@@ -314,10 +314,10 @@ def run_cmd(buildcmd, execcmd, cachefile, filename, binary, timeout, batchinfo,
     with open(f'{cachefile}.txt', 'w') as outfile:
         outfile.write(output)
     with open(f'{cachefile}.md5sum', 'w') as outfile:
-        hash = hashlib.md5()
+        hashed = hashlib.md5()
         with open(filename, 'rb') as sourcefile :
             for chunk in iter(lambda: sourcefile.read(4096), b""):
-                hash.update(chunk)
-        outfile.write(hash.hexdigest())
+                hashed.update(chunk)
+        outfile.write(hashed.hexdigest())
     
     return True