Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer and reference parameters in src/bindings/.
[simgrid.git] / src / bindings / python / simgrid_python.cpp
index b8301ad..1f3acfd 100644 (file)
@@ -63,7 +63,6 @@ static std::string simgrid_version = get_simgrid_version();
 
 PYBIND11_MODULE(simgrid, m)
 {
-
   m.doc() = "SimGrid userspace API";
 
   m.attr("simgrid_version") = simgrid_version;
@@ -101,7 +100,7 @@ PYBIND11_MODULE(simgrid, m)
            simgrid::s4u::this_actor::on_exit([act, fun](bool /*failed*/) {
              try {
                fun();
-             } catch (py::error_already_set& e) {
+             } catch (const py::error_already_set& e) {
                xbt_die("Error while executing the on_exit lambda: %s", e.what());
              }
            });
@@ -142,7 +141,7 @@ PYBIND11_MODULE(simgrid, m)
                  /* If I was passed a class, I just built an instance, so I need to call it now */
                  if (py::isinstance<py::function>(res))
                    res();
-               } catch (py::error_already_set& ex) {
+               } catch (const py::error_already_set& ex) {
                  if (ex.matches(pyForcefulKillEx)) {
                    XBT_VERB("Actor killed");
                    /* Stop here that ForcefulKill exception which was meant to free the RAII stuff on the stack */
@@ -162,7 +161,7 @@ PYBIND11_MODULE(simgrid, m)
       .def_property("pstate", &Host::get_pstate, &Host::set_pstate, "The current pstate")
 
       .def("current", &Host::current, "Retrieves the host on which the running actor is located, see :cpp:func:`simgrid::s4u::Host::current()`")
-      .def_property_readonly("name", [](Host* self) -> const std::string {
+      .def_property_readonly("name", [](const Host* self) -> const std::string {
           return std::string(self->get_name().c_str()); // Convert from xbt::string because of MC
         }, "The name of this host")
       .def_property_readonly("load", &Host::get_load,
@@ -172,11 +171,11 @@ PYBIND11_MODULE(simgrid, m)
 
   /* Class Mailbox */
   py::class_<simgrid::s4u::Mailbox, std::unique_ptr<Mailbox, py::nodelete>>(m, "Mailbox", "Mailbox, see :ref:`class s4u::Mailbox <API_s4u_Mailbox>`")
-      .def("__str__", [](Mailbox* self) -> const std::string {
+      .def("__str__", [](const Mailbox* self) -> const std::string {
          return std::string("Mailbox(") + self->get_cname() + ")";
       }, "Textual representation of the Mailbox`")
       .def("by_name", &Mailbox::by_name, "Retrieve a Mailbox from its name, see :cpp:func:`simgrid::s4u::Mailbox::by_name()`")
-      .def_property_readonly("name", [](Mailbox* self) -> const std::string {
+      .def_property_readonly("name", [](const Mailbox* self) -> const std::string {
          return std::string(self->get_name().c_str()); // Convert from xbt::string because of MC
       }, "The name of that mailbox, see :cpp:func:`simgrid::s4u::Mailbox::get_name()`")
       .def("put", [](Mailbox* self, py::object data, int size) {
@@ -234,15 +233,12 @@ PYBIND11_MODULE(simgrid, m)
   py::class_<simgrid::s4u::Actor, ActorPtr>(m, "Actor",
                                             "An actor is an independent stream of execution in your distributed "
                                             "application, see :ref:`class s4u::Actor <API_s4u_Actor>`")
-
       .def("create",
            [](py::str name, py::object host, py::object fun, py::args args) {
-
              return simgrid::s4u::Actor::create(name, host.cast<Host*>(), [fun, args]() {
-
                try {
                  fun(*args);
-               } catch (py::error_already_set& ex) {
+               } catch (const py::error_already_set& ex) {
                  if (ex.matches(pyForcefulKillEx)) {
                    XBT_VERB("Actor killed");
                    /* Stop here that ForcefulKill exception which was meant to free the RAII stuff on the stack */