Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Fix more implicit casts that should not lower precision (S5276).
[simgrid.git] / src / bindings / python / simgrid_python.cpp
index deaa3af..f900c97 100644 (file)
@@ -134,6 +134,7 @@ PYBIND11_MODULE(simgrid, m)
       .def(
           "on_exit",
           [](py::object fun) {
+            fun.inc_ref(); // FIXME: why is this needed for tests like actor-kill and actor-lifetime?
             simgrid::s4u::this_actor::on_exit([fun](bool /*failed*/) {
               GilScopedAcquire py_context; // need a new context for callback
               try {
@@ -151,7 +152,7 @@ PYBIND11_MODULE(simgrid, m)
   py::class_<Engine>(m, "Engine", "Simulation Engine")
       .def(py::init([](std::vector<std::string> args) {
         static char noarg[] = {'\0'};
-        int argc            = args.size();
+        int argc            = static_cast<int>(args.size());
         std::unique_ptr<char* []> argv(new char*[argc + 1]);
         for (int i = 0; i != argc; ++i)
           argv[i] = args[i].empty() ? noarg : &args[i].front();
@@ -198,7 +199,7 @@ PYBIND11_MODULE(simgrid, m)
   /* Class Host */
   py::class_<simgrid::s4u::Host, std::unique_ptr<Host, py::nodelete>>(m, "Host", "Simulated host")
       .def("by_name", &Host::by_name, "Retrieves a host from its name, or die")
-      .def("get_pstate_count", &Host::get_pstate_count, "Retrieve the cound of defined pstate levels")
+      .def("get_pstate_count", &Host::get_pstate_count, "Retrieve the count of defined pstate levels")
       .def("get_pstate_speed", &Host::get_pstate_speed, "Retrieve the maximal speed at the given pstate")
       .def_property(
           "pstate", &Host::get_pstate,
@@ -256,7 +257,13 @@ PYBIND11_MODULE(simgrid, m)
             // data.dec_ref(); // FIXME: why does it break python-actor-create?
             return data;
           },
-          py::call_guard<GilScopedRelease>(), "Blocking data reception");
+          py::call_guard<GilScopedRelease>(), "Blocking data reception")
+      .def("set_receiver",
+        [](Mailbox* self, ActorPtr actor) {
+          self->set_receiver(actor);
+        },
+        py::call_guard<GilScopedRelease>(),
+        "Sets the actor as permanent receiver");
 
   /* Class Comm */
   py::class_<simgrid::s4u::Comm, simgrid::s4u::CommPtr>(m, "Comm", "Communication")
@@ -286,16 +293,8 @@ PYBIND11_MODULE(simgrid, m)
           },
           "Amount of work remaining until completion from 0 (completely done) to 1 (nothing done "
           "yet).")
-      .def_property(
-          "host",
-          [](simgrid::s4u::ExecPtr self) {
-            simgrid::s4u::ExecSeqPtr seq = boost::dynamic_pointer_cast<simgrid::s4u::ExecSeq>(self);
-            if (seq != nullptr)
-              return seq->get_host();
-            xbt_throw_unimplemented(__FILE__, __LINE__,
-                                    "host of parallel executions is not implemented in python yet.");
-          },
-          &simgrid::s4u::Exec::set_host, "Host on which this execution runs.")
+      .def_property("host", &simgrid::s4u::Exec::get_host, &simgrid::s4u::Exec::set_host,
+                    "Host on which this execution runs. Only the first host is returned for parallel executions.")
       .def("test", &simgrid::s4u::Exec::test, py::call_guard<GilScopedRelease>(),
            "Test whether the execution is terminated.")
       .def("cancel", &simgrid::s4u::Exec::cancel, py::call_guard<GilScopedRelease>(), "Cancel that execution.")