From 7e43f814d5d5bd30bb0676f43adf147ebd411950 Mon Sep 17 00:00:00 2001 From: Jean-Edouard BOULANGER Date: Sat, 12 Mar 2022 08:58:12 +0100 Subject: [PATCH] Make Python bindings static where needed --- ChangeLog | 6 ++++-- src/bindings/python/simgrid_python.cpp | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index db32bd9546..ebb114187f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -62,8 +62,10 @@ XBT: - Drop xbt_dynar_shrink(). Python: - - Fixed the following bindings: - - Actor.kill_all() [previously declared a member of the Actor class although it is a static member] + - Made the following bindings static (previously member functions): + - Actor: Actor.kill_all(), Actor.by_pid() + - Host: Host.by_name(), Host.current(), Host.on_creation_cb() + - Mailbox: Mailbox.by_name() - Added the following bindings: - this_actor.warning() - Mailbox.put_init() [example: examples/python/comm-waitallfor] diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index 60ce5f652f..b6f5e05477 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -318,7 +318,7 @@ PYBIND11_MODULE(simgrid, m) /* Class Host */ py::class_> host( m, "Host", "Simulated host. See the C++ documentation for details."); - host.def("by_name", &Host::by_name, "Retrieves a host from its name, or die") + host.def_static("by_name", &Host::by_name, py::arg("name"), "Retrieves a host from its name, or die") .def( "route_to", [](const simgrid::s4u::Host* h, const simgrid::s4u::Host* to) { @@ -424,7 +424,7 @@ PYBIND11_MODULE(simgrid, m) h->set_pstate(i); }, "The current pstate (read/write property).") - .def("current", &Host::current, py::call_guard(), + .def_static("current", &Host::current, py::call_guard(), "Retrieves the host on which the running actor is located.") .def_property_readonly( "name", @@ -443,7 +443,7 @@ PYBIND11_MODULE(simgrid, m) "Get the available speed ratio, between 0 and 1.\n" "This accounts for external load (see :py:func:`set_speed_profile() " "`) (read-only property).") - .def( + .def_static( "on_creation_cb", [](py::object cb) { Host::on_creation_cb([cb](Host& h) { @@ -627,7 +627,10 @@ PYBIND11_MODULE(simgrid, m) .def( "__str__", [](const Mailbox* self) { return std::string("Mailbox(") + self->get_cname() + ")"; }, "Textual representation of the Mailbox`") - .def("by_name", &Mailbox::by_name, py::call_guard(), "Retrieve a Mailbox from its name") + .def_static("by_name", &Mailbox::by_name, + py::call_guard(), + py::arg("name"), + "Retrieve a Mailbox from its name") .def_property_readonly( "name", [](const Mailbox* self) { @@ -812,7 +815,7 @@ PYBIND11_MODULE(simgrid, m) .def_property_readonly("pid", &Actor::get_pid, "The PID (unique identifier) of this actor (read-only property).") .def_property_readonly("ppid", &Actor::get_ppid, "The PID (unique identifier) of the actor that created this one (read-only property).") - .def("by_pid", &Actor::by_pid, "Retrieve an actor by its PID") + .def_static("by_pid", &Actor::by_pid, py::arg("pid"), "Retrieve an actor by its PID") .def("set_auto_restart", &Actor::set_auto_restart, py::call_guard(), "Specify whether the actor shall restart when its host reboots.") .def("daemonize", &Actor::daemonize, py::call_guard(), -- 2.20.1