From: Tom Cornebize Date: Tue, 21 Jun 2022 13:26:28 +0000 (+0200) Subject: Renaming: s4u_enforce -> xbt_enforce X-Git-Tag: v3.32~184^2~2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f8446dd01aa71a755c74c9b663ce81490055316b Renaming: s4u_enforce -> xbt_enforce --- diff --git a/ChangeLog b/ChangeLog index f24e2bf4a1..228b4aee0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ SimGrid (3.31.1) NOT RELEASED YET (v3.32 expected June 21. 2022, 09:13 UTC) S4U: - - Added the s4u_enforce macro. This has the same syntax as xbt_assert. The only difference is that an AssertionError + - Added the xbt_enforce macro. This has the same syntax as xbt_assert. The only difference is that an AssertionError exception is thrown if the condition is not satisfied, instead of calling abort(). Python: diff --git a/include/simgrid/Exception.hpp b/include/simgrid/Exception.hpp index d56a371a9c..a8520fc88b 100644 --- a/include/simgrid/Exception.hpp +++ b/include/simgrid/Exception.hpp @@ -153,7 +153,7 @@ DECLARE_SIMGRID_EXCEPTION(TracingError); DECLARE_SIMGRID_EXCEPTION(ParseError, PARSE_ERROR_CONSTRUCTOR); #undef PARSE_ERROR_CONSTRUCTOR -/** Exception raised by s4u_enforce, when an assertion is not satisfied */ +/** Exception raised by xbt_enforce, when an assertion is not satisfied */ #define ASSERTION_ERROR_CONSTRUCTOR \ template AssertionError(const char * f, Args... args) \ : Exception(XBT_THROW_POINT, xbt::string_printf(f, args...)) \ diff --git a/include/xbt/asserts.hpp b/include/xbt/asserts.hpp index bb43097112..5a82ccc4ab 100644 --- a/include/xbt/asserts.hpp +++ b/include/xbt/asserts.hpp @@ -21,16 +21,16 @@ namespace xbt { * If the statement evaluates to false, then a simgrid::AsertionError is thrown. * This is identical to the xbt_assert macro, except that an exception is thrown instead of calling abort(). * - * Unlike the standard assert, s4u_enforce is never disabled, even if the macro NDEBUG is defined at compile time. + * Unlike the standard assert, xbt_enforce is never disabled, even if the macro NDEBUG is defined at compile time. * Note however that this macro should *not* be used with a condition that has side effects, since the exception can be * caught and ignored. */ /** @brief The condition which failed will be displayed. @hideinitializer */ -#define s4u_enforce(...) \ - _XBT_IF_ONE_ARG(_s4u_enforce_ARG1, _s4u_enforce_ARGN, __VA_ARGS__)(__VA_ARGS__) -#define _s4u_enforce_ARG1(cond) _s4u_enforce_ARGN((cond), "Assertion %s failed", #cond) -#define _s4u_enforce_ARGN(cond, ...) \ +#define xbt_enforce(...) \ + _XBT_IF_ONE_ARG(_xbt_enforce_ARG1, _xbt_enforce_ARGN, __VA_ARGS__)(__VA_ARGS__) +#define _xbt_enforce_ARG1(cond) _xbt_enforce_ARGN((cond), "Assertion %s failed", #cond) +#define _xbt_enforce_ARGN(cond, ...) \ do { \ if (!(cond)) { \ throw simgrid::AssertionError(__VA_ARGS__); \ diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 500fdd2a3e..b1e3416245 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -41,8 +41,8 @@ static void surf_config_models_setup() XBT_DEBUG("host model: %s", host_model_name.c_str()); if (host_model_name == "compound") { - s4u_enforce(not cpu_model_name.empty(), "Set a cpu model to use with the 'compound' host model"); - s4u_enforce(not network_model_name.empty(), "Set a network model to use with the 'compound' host model"); + xbt_enforce(not cpu_model_name.empty(), "Set a cpu model to use with the 'compound' host model"); + xbt_enforce(not network_model_name.empty(), "Set a network model to use with the 'compound' host model"); const auto* cpu_model = find_model_description(surf_cpu_model_description, cpu_model_name); cpu_model->model_init_preparse(); @@ -94,7 +94,7 @@ NetZoneImpl::NetZoneImpl(const std::string& name) : piface_(this), name_(name) surf_config_models_setup(); } - s4u_enforce(nullptr == engine->netpoint_by_name_or_null(get_name()), + xbt_enforce(nullptr == engine->netpoint_by_name_or_null(get_name()), "Refusing to create a second NetZone called '%s'.", get_cname()); netpoint_ = new NetPoint(name_, NetPoint::Type::NetZone); XBT_DEBUG("NetZone '%s' created with the id '%lu'", get_cname(), netpoint_->id()); @@ -154,7 +154,7 @@ xbt_edge_t NetZoneImpl::new_xbt_graph_edge(const s_xbt_graph_t* graph, xbt_node_ void NetZoneImpl::add_child(NetZoneImpl* new_zone) { - s4u_enforce(not sealed_, "Cannot add a new child to the sealed zone %s", get_cname()); + xbt_enforce(not sealed_, "Cannot add a new child to the sealed zone %s", get_cname()); /* set the parent behavior */ hierarchy_ = RoutingMode::recursive; children_.push_back(new_zone); @@ -208,10 +208,10 @@ size_t NetZoneImpl::get_link_count() const s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector& speed_per_pstate) { - s4u_enforce(cpu_model_pm_, + xbt_enforce(cpu_model_pm_, "Impossible to create host: %s. Invalid CPU model: nullptr. Have you set the parent of this NetZone: %s?", name.c_str(), get_cname()); - s4u_enforce(not sealed_, "Impossible to create host: %s. NetZone %s already sealed", name.c_str(), get_cname()); + xbt_enforce(not sealed_, "Impossible to create host: %s. NetZone %s already sealed", name.c_str(), get_cname()); auto* host = (new resource::HostImpl(name))->set_englobing_zone(this); hosts_[name] = host; host->get_iface()->set_netpoint((new NetPoint(name, NetPoint::Type::Host))->set_englobing_zone(this)); @@ -228,11 +228,11 @@ resource::StandardLinkImpl* NetZoneImpl::do_create_link(const std::string& name, s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector& bandwidths) { - s4u_enforce( + xbt_enforce( network_model_, "Impossible to create link: %s. Invalid network model: nullptr. Have you set the parent of this NetZone: %s?", name.c_str(), get_cname()); - s4u_enforce(not sealed_, "Impossible to create link: %s. NetZone %s already sealed", name.c_str(), get_cname()); + xbt_enforce(not sealed_, "Impossible to create link: %s. NetZone %s already sealed", name.c_str(), get_cname()); links_[name] = do_create_link(name, bandwidths)->set_englobing_zone(this); return links_[name]->get_iface(); } @@ -240,11 +240,11 @@ s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector& bandwidths) { - s4u_enforce( + xbt_enforce( network_model_, "Impossible to create link: %s. Invalid network model: nullptr. Have you set the parent of this NetZone: %s?", name.c_str(), get_cname()); - s4u_enforce(not sealed_, "Impossible to create link: %s. NetZone %s already sealed", name.c_str(), get_cname()); + xbt_enforce(not sealed_, "Impossible to create link: %s. NetZone %s already sealed", name.c_str(), get_cname()); auto* link_up = create_link(name + "_UP", bandwidths)->get_impl()->set_englobing_zone(this); auto* link_down = create_link(name + "_DOWN", bandwidths)->get_impl()->set_englobing_zone(this); @@ -254,10 +254,10 @@ s4u::SplitDuplexLink* NetZoneImpl::create_split_duplex_link(const std::string& n s4u::Disk* NetZoneImpl::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) { - s4u_enforce(disk_model_, + xbt_enforce(disk_model_, "Impossible to create disk: %s. Invalid disk model: nullptr. Have you set the parent of this NetZone: %s?", name.c_str(), get_cname()); - s4u_enforce(not sealed_, "Impossible to create disk: %s. NetZone %s already sealed", name.c_str(), get_cname()); + xbt_enforce(not sealed_, "Impossible to create disk: %s. NetZone %s already sealed", name.c_str(), get_cname()); auto* l = disk_model_->create_disk(name, read_bandwidth, write_bandwidth); return l->get_iface(); @@ -265,9 +265,9 @@ s4u::Disk* NetZoneImpl::create_disk(const std::string& name, double read_bandwid NetPoint* NetZoneImpl::create_router(const std::string& name) { - s4u_enforce(nullptr == s4u::Engine::get_instance()->netpoint_by_name_or_null(name), + xbt_enforce(nullptr == s4u::Engine::get_instance()->netpoint_by_name_or_null(name), "Refusing to create a router named '%s': this name already describes a node.", name.c_str()); - s4u_enforce(not sealed_, "Impossible to create router: %s. NetZone %s already sealed", name.c_str(), get_cname()); + xbt_enforce(not sealed_, "Impossible to create router: %s. NetZone %s already sealed", name.c_str(), get_cname()); return (new NetPoint(name, NetPoint::Type::Router))->set_englobing_zone(this); } @@ -290,7 +290,7 @@ std::vector NetZoneImpl::get_link_list_impl(const s } // split-duplex links const auto* sd_link = dynamic_cast(link.get_link()); - s4u_enforce(sd_link, + xbt_enforce(sd_link, "Add_route: cast to SpliDuplexLink impossible. This should not happen, please contact SimGrid team"); resource::StandardLinkImpl* link_impl; switch (link.get_direction()) { @@ -397,16 +397,16 @@ void NetZoneImpl::add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_sr if (gw_dst) { XBT_DEBUG("Load bypassNetzoneRoute from %s@%s to %s@%s", src->get_cname(), gw_src->get_cname(), dst->get_cname(), gw_dst->get_cname()); - s4u_enforce(not link_list.empty(), "Bypass route between %s@%s and %s@%s cannot be empty.", src->get_cname(), + xbt_enforce(not link_list.empty(), "Bypass route between %s@%s and %s@%s cannot be empty.", src->get_cname(), gw_src->get_cname(), dst->get_cname(), gw_dst->get_cname()); - s4u_enforce(bypass_routes_.find({src, dst}) == bypass_routes_.end(), + xbt_enforce(bypass_routes_.find({src, dst}) == bypass_routes_.end(), "The bypass route between %s@%s and %s@%s already exists.", src->get_cname(), gw_src->get_cname(), dst->get_cname(), gw_dst->get_cname()); } else { XBT_DEBUG("Load bypassRoute from %s to %s", src->get_cname(), dst->get_cname()); - s4u_enforce(not link_list.empty(), "Bypass route between %s and %s cannot be empty.", src->get_cname(), + xbt_enforce(not link_list.empty(), "Bypass route between %s and %s cannot be empty.", src->get_cname(), dst->get_cname()); - s4u_enforce(bypass_routes_.find({src, dst}) == bypass_routes_.end(), + xbt_enforce(bypass_routes_.find({src, dst}) == bypass_routes_.end(), "The bypass route between %s and %s already exists.", src->get_cname(), dst->get_cname()); } @@ -487,8 +487,8 @@ static void find_common_ancestors(const NetPoint* src, const NetPoint* dst, const NetZoneImpl* src_as = src->get_englobing_zone(); const NetZoneImpl* dst_as = dst->get_englobing_zone(); - s4u_enforce(src_as, "Host %s must be in a netzone", src->get_cname()); - s4u_enforce(dst_as, "Host %s must be in a netzone", dst->get_cname()); + xbt_enforce(src_as, "Host %s must be in a netzone", src->get_cname()); + xbt_enforce(dst_as, "Host %s must be in a netzone", dst->get_cname()); /* (2) find the path to the root routing component */ std::vector path_src; @@ -523,7 +523,7 @@ static void find_common_ancestors(const NetPoint* src, const NetPoint* dst, if (*src_ancestor == *dst_ancestor) { // src is the ancestor of dst, or the contrary *common_ancestor = *src_ancestor; } else { - s4u_enforce(parent != nullptr); + xbt_enforce(parent != nullptr); *common_ancestor = parent; } } @@ -653,7 +653,7 @@ void NetZoneImpl::get_global_route_with_netzones(const NetPoint* src, const NetP /* Not in the same netzone, no bypass. We'll have to find our path between the netzones recursively */ common_ancestor->get_local_route(src_ancestor->netpoint_, dst_ancestor->netpoint_, &route, latency); - s4u_enforce((route.gw_src_ != nullptr) && (route.gw_dst_ != nullptr), "Bad gateways for route from '%s' to '%s'.", + xbt_enforce((route.gw_src_ != nullptr) && (route.gw_dst_ != nullptr), "Bad gateways for route from '%s' to '%s'.", src->get_cname(), dst->get_cname()); /* If source gateway is not our source, we have to recursively find our way up to this point */ @@ -743,7 +743,7 @@ void NetZoneImpl::seal() void NetZoneImpl::set_parent(NetZoneImpl* parent) { - s4u_enforce(not sealed_, "Impossible to set parent to an already sealed NetZone(%s)", this->get_cname()); + xbt_enforce(not sealed_, "Impossible to set parent to an already sealed NetZone(%s)", this->get_cname()); parent_ = parent; netpoint_->set_englobing_zone(parent_); if (parent) { @@ -760,37 +760,37 @@ void NetZoneImpl::set_parent(NetZoneImpl* parent) void NetZoneImpl::set_network_model(std::shared_ptr netmodel) { - s4u_enforce(not sealed_, "Impossible to set network model to an already sealed NetZone(%s)", this->get_cname()); + xbt_enforce(not sealed_, "Impossible to set network model to an already sealed NetZone(%s)", this->get_cname()); network_model_ = std::move(netmodel); } void NetZoneImpl::set_cpu_vm_model(std::shared_ptr cpu_model) { - s4u_enforce(not sealed_, "Impossible to set CPU model to an already sealed NetZone(%s)", this->get_cname()); + xbt_enforce(not sealed_, "Impossible to set CPU model to an already sealed NetZone(%s)", this->get_cname()); cpu_model_vm_ = std::move(cpu_model); } void NetZoneImpl::set_cpu_pm_model(std::shared_ptr cpu_model) { - s4u_enforce(not sealed_, "Impossible to set CPU model to an already sealed NetZone(%s)", this->get_cname()); + xbt_enforce(not sealed_, "Impossible to set CPU model to an already sealed NetZone(%s)", this->get_cname()); cpu_model_pm_ = std::move(cpu_model); } void NetZoneImpl::set_disk_model(std::shared_ptr disk_model) { - s4u_enforce(not sealed_, "Impossible to set disk model to an already sealed NetZone(%s)", this->get_cname()); + xbt_enforce(not sealed_, "Impossible to set disk model to an already sealed NetZone(%s)", this->get_cname()); disk_model_ = std::move(disk_model); } void NetZoneImpl::set_host_model(std::shared_ptr host_model) { - s4u_enforce(not sealed_, "Impossible to set host model to an already sealed NetZone(%s)", this->get_cname()); + xbt_enforce(not sealed_, "Impossible to set host model to an already sealed NetZone(%s)", this->get_cname()); host_model_ = std::move(host_model); } const NetZoneImpl* NetZoneImpl::get_netzone_recursive(const NetPoint* netpoint) const { - s4u_enforce(netpoint && netpoint->is_netzone(), "Netpoint %s must be of the type NetZone", + xbt_enforce(netpoint && netpoint->is_netzone(), "Netpoint %s must be of the type NetZone", netpoint ? netpoint->get_cname() : "nullptr"); if (netpoint == netpoint_) diff --git a/src/kernel/routing/RoutedZone.cpp b/src/kernel/routing/RoutedZone.cpp index 5e11f12319..908f57e131 100644 --- a/src/kernel/routing/RoutedZone.cpp +++ b/src/kernel/routing/RoutedZone.cpp @@ -30,7 +30,7 @@ Route* RoutedZone::new_extended_route(RoutingMode hierarchy, NetPoint* gw_src, N auto* result = new Route(); if (hierarchy == RoutingMode::recursive) { - s4u_enforce(gw_src && gw_dst, "nullptr is obviously a deficient gateway"); + xbt_enforce(gw_src && gw_dst, "nullptr is obviously a deficient gateway"); result->gw_src_ = gw_src; result->gw_dst_ = gw_dst; @@ -47,17 +47,17 @@ Route* RoutedZone::new_extended_route(RoutingMode hierarchy, NetPoint* gw_src, N void RoutedZone::get_route_check_params(const NetPoint* src, const NetPoint* dst) const { - s4u_enforce(src, "Cannot have a route with (nullptr) source"); - s4u_enforce(dst, "Cannot have a route with (nullptr) destination"); + xbt_enforce(src, "Cannot have a route with (nullptr) source"); + xbt_enforce(dst, "Cannot have a route with (nullptr) destination"); const NetZoneImpl* src_as = src->get_englobing_zone(); const NetZoneImpl* dst_as = dst->get_englobing_zone(); - s4u_enforce(src_as == dst_as, + xbt_enforce(src_as == dst_as, "Internal error: %s@%s and %s@%s are not in the same netzone as expected. Please report that bug.", src->get_cname(), src_as->get_cname(), dst->get_cname(), dst_as->get_cname()); - s4u_enforce(this == dst_as, + xbt_enforce(this == dst_as, "Internal error: route destination %s@%s is not in netzone %s as expected (route source: " "%s@%s). Please report that bug.", src->get_cname(), dst->get_cname(), src_as->get_cname(), dst_as->get_cname(), get_cname()); @@ -72,40 +72,40 @@ void RoutedZone::add_route_check_params(NetPoint* src, NetPoint* dst, NetPoint* if (not gw_dst || not gw_src) { XBT_DEBUG("Load Route from \"%s\" to \"%s\"", srcName, dstName); - s4u_enforce(not link_list.empty(), "Empty route (between %s and %s) forbidden.", srcName, dstName); - s4u_enforce(not src->is_netzone(), + xbt_enforce(not link_list.empty(), "Empty route (between %s and %s) forbidden.", srcName, dstName); + xbt_enforce(not src->is_netzone(), "When defining a route, src cannot be a netzone such as '%s'. Did you meant to have a NetzoneRoute?", srcName); - s4u_enforce(not dst->is_netzone(), + xbt_enforce(not dst->is_netzone(), "When defining a route, dst cannot be a netzone such as '%s'. Did you meant to have a NetzoneRoute?", dstName); NetZoneImpl::on_route_creation(symmetrical, src, dst, gw_src, gw_dst, get_link_list_impl(link_list, false)); } else { XBT_DEBUG("Load NetzoneRoute from %s@%s to %s@%s", srcName, gw_src->get_cname(), dstName, gw_dst->get_cname()); - s4u_enforce(src->is_netzone(), "When defining a NetzoneRoute, src must be a netzone but '%s' is not", srcName); - s4u_enforce(dst->is_netzone(), "When defining a NetzoneRoute, dst must be a netzone but '%s' is not", dstName); + xbt_enforce(src->is_netzone(), "When defining a NetzoneRoute, src must be a netzone but '%s' is not", srcName); + xbt_enforce(dst->is_netzone(), "When defining a NetzoneRoute, dst must be a netzone but '%s' is not", dstName); - s4u_enforce(gw_src->is_host() || gw_src->is_router(), + xbt_enforce(gw_src->is_host() || gw_src->is_router(), "When defining a NetzoneRoute, gw_src must be a host or a router but '%s' is not.", srcName); - s4u_enforce(gw_dst->is_host() || gw_dst->is_router(), + xbt_enforce(gw_dst->is_host() || gw_dst->is_router(), "When defining a NetzoneRoute, gw_dst must be a host or a router but '%s' is not.", dstName); - s4u_enforce(gw_src != gw_dst, "Cannot define a NetzoneRoute from '%s' to itself", gw_src->get_cname()); + xbt_enforce(gw_src != gw_dst, "Cannot define a NetzoneRoute from '%s' to itself", gw_src->get_cname()); - s4u_enforce(src, "Cannot add a route from %s@%s to %s@%s: %s does not exist.", srcName, gw_src->get_cname(), dstName, + xbt_enforce(src, "Cannot add a route from %s@%s to %s@%s: %s does not exist.", srcName, gw_src->get_cname(), dstName, gw_dst->get_cname(), srcName); - s4u_enforce(dst, "Cannot add a route from %s@%s to %s@%s: %s does not exist.", srcName, gw_src->get_cname(), dstName, + xbt_enforce(dst, "Cannot add a route from %s@%s to %s@%s: %s does not exist.", srcName, gw_src->get_cname(), dstName, gw_dst->get_cname(), dstName); - s4u_enforce(not link_list.empty(), "Empty route (between %s@%s and %s@%s) forbidden.", srcName, gw_src->get_cname(), + xbt_enforce(not link_list.empty(), "Empty route (between %s@%s and %s@%s) forbidden.", srcName, gw_src->get_cname(), dstName, gw_dst->get_cname()); const auto* netzone_src = get_netzone_recursive(src); - s4u_enforce(netzone_src->is_component_recursive(gw_src), + xbt_enforce(netzone_src->is_component_recursive(gw_src), "Invalid NetzoneRoute from %s@%s to %s@%s: gw_src %s belongs to %s, not to %s.", srcName, gw_src->get_cname(), dstName, gw_dst->get_cname(), gw_src->get_cname(), gw_src->get_englobing_zone()->get_cname(), srcName); const auto* netzone_dst = get_netzone_recursive(dst); - s4u_enforce(netzone_dst->is_component_recursive(gw_dst), + xbt_enforce(netzone_dst->is_component_recursive(gw_dst), "Invalid NetzoneRoute from %s@%s to %s@%s: gw_dst %s belongs to %s, not to %s.", srcName, gw_src->get_cname(), dstName, gw_dst->get_cname(), gw_dst->get_cname(), gw_dst->get_englobing_zone()->get_cname(), dst->get_cname()); diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 272b1d87ee..82b2f92995 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -29,7 +29,7 @@ namespace simgrid::kernel::resource { ************/ HostImpl::HostImpl(const std::string& name) : piface_(this), name_(name) { - s4u_enforce(s4u::Host::by_name_or_null(name_) == nullptr, "Refusing to create a second host named '%s'.", get_cname()); + xbt_enforce(s4u::Host::by_name_or_null(name_) == nullptr, "Refusing to create a second host named '%s'.", get_cname()); } HostImpl::~HostImpl()