From 3bf15ad45770ae3b776962f3f3fb268de4534769 Mon Sep 17 00:00:00 2001 From: Tom Cornebize Date: Tue, 21 Jun 2022 10:57:36 +0200 Subject: [PATCH] Implement s4u_enforce This adds a new macro, s4u_enforce, with the same syntax as xbt_assert. The difference with xbt_assert is that this macro will throw an exception if the statement is false, instead of calling abort(). --- MANIFEST.in | 1 + include/simgrid/Exception.hpp | 10 +++++ include/xbt/asserts.hpp | 44 +++++++++++++++++++ src/bindings/python/simgrid_python.cpp | 1 + src/kernel/routing/NetZoneImpl.cpp | 61 +++++++++++++------------- src/kernel/routing/RoutedZone.cpp | 37 ++++++++-------- src/simgrid/Exception.cpp | 1 + src/surf/HostImpl.cpp | 3 +- 8 files changed, 109 insertions(+), 49 deletions(-) create mode 100644 include/xbt/asserts.hpp diff --git a/MANIFEST.in b/MANIFEST.in index c3f49ce0b6..476919967d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2054,6 +2054,7 @@ include include/xbt.h include include/xbt/Extendable.hpp include include/xbt/PropertyHolder.hpp include include/xbt/asserts.h +include include/xbt/asserts.hpp include include/xbt/automaton.h include include/xbt/automaton.hpp include include/xbt/backtrace.hpp diff --git a/include/simgrid/Exception.hpp b/include/simgrid/Exception.hpp index 304295ae96..d56a371a9c 100644 --- a/include/simgrid/Exception.hpp +++ b/include/simgrid/Exception.hpp @@ -153,6 +153,16 @@ 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 */ +#define ASSERTION_ERROR_CONSTRUCTOR \ + template AssertionError(const char * f, Args... args) \ + : Exception(XBT_THROW_POINT, xbt::string_printf(f, args...)) \ + { \ + } + +DECLARE_SIMGRID_EXCEPTION(AssertionError, ASSERTION_ERROR_CONSTRUCTOR); +#undef ASSERTION_ERROR_CONSTRUCTOR + #undef DECLARE_SIMGRID_EXCEPTION class XBT_PUBLIC ForcefulKillException { diff --git a/include/xbt/asserts.hpp b/include/xbt/asserts.hpp new file mode 100644 index 0000000000..bb43097112 --- /dev/null +++ b/include/xbt/asserts.hpp @@ -0,0 +1,44 @@ +/* Copyright (c) 2016-2022. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef SIMGRID_XBT_ASSERTS_HPP +#define SIMGRID_XBT_ASSERTS_HPP + +#include +#include +#include + +namespace simgrid { +namespace xbt { + +/** + * @brief Those are the SimGrid version of the good ol' assert macro. + * + * You can pass them a format message and arguments, just as if it where a printf. + * + * 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. + * 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, ...) \ + do { \ + if (!(cond)) { \ + throw simgrid::AssertionError(__VA_ARGS__); \ + } \ + } while (0) + + +} // namespace xbt +} // namespace simgrid + +#endif diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index 9d86a99c46..256129e04a 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -103,6 +103,7 @@ PYBIND11_MODULE(simgrid, m) py::register_exception(m, "StorageFailureException"); py::register_exception(m, "VmFailureException"); py::register_exception(m, "CancelException"); + py::register_exception(m, "AssertionError"); /* this_actor namespace */ m.def_submodule("this_actor", "Bindings of the s4u::this_actor namespace. See the C++ documentation for details.") diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 17afb8b3c0..500fdd2a3e 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -9,6 +9,7 @@ #include #include +#include "xbt/asserts.hpp" #include "src/include/simgrid/sg_config.hpp" #include "src/kernel/EngineImpl.hpp" #include "src/kernel/resource/CpuImpl.hpp" @@ -40,8 +41,8 @@ static void surf_config_models_setup() XBT_DEBUG("host model: %s", host_model_name.c_str()); if (host_model_name == "compound") { - xbt_assert(not cpu_model_name.empty(), "Set a cpu model to use with the 'compound' host model"); - xbt_assert(not network_model_name.empty(), "Set a network model to use with the 'compound' host model"); + 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"); const auto* cpu_model = find_model_description(surf_cpu_model_description, cpu_model_name); cpu_model->model_init_preparse(); @@ -93,7 +94,7 @@ NetZoneImpl::NetZoneImpl(const std::string& name) : piface_(this), name_(name) surf_config_models_setup(); } - xbt_assert(nullptr == engine->netpoint_by_name_or_null(get_name()), + s4u_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()); @@ -153,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) { - xbt_assert(not sealed_, "Cannot add a new child to the sealed zone %s", get_cname()); + s4u_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); @@ -207,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) { - xbt_assert(cpu_model_pm_, + s4u_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()); - xbt_assert(not sealed_, "Impossible to create host: %s. NetZone %s already sealed", name.c_str(), get_cname()); + s4u_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)); @@ -227,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) { - xbt_assert( + s4u_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()); - xbt_assert(not sealed_, "Impossible to create link: %s. NetZone %s already sealed", name.c_str(), get_cname()); + s4u_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(); } @@ -239,11 +240,11 @@ s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector& bandwidths) { - xbt_assert( + s4u_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()); - xbt_assert(not sealed_, "Impossible to create link: %s. NetZone %s already sealed", name.c_str(), get_cname()); + s4u_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); @@ -253,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) { - xbt_assert(disk_model_, + s4u_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()); - xbt_assert(not sealed_, "Impossible to create disk: %s. NetZone %s already sealed", name.c_str(), get_cname()); + s4u_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(); @@ -264,9 +265,9 @@ s4u::Disk* NetZoneImpl::create_disk(const std::string& name, double read_bandwid NetPoint* NetZoneImpl::create_router(const std::string& name) { - xbt_assert(nullptr == s4u::Engine::get_instance()->netpoint_by_name_or_null(name), + s4u_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()); - xbt_assert(not sealed_, "Impossible to create router: %s. NetZone %s already sealed", name.c_str(), get_cname()); + s4u_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); } @@ -289,7 +290,7 @@ std::vector NetZoneImpl::get_link_list_impl(const s } // split-duplex links const auto* sd_link = dynamic_cast(link.get_link()); - xbt_assert(sd_link, + s4u_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()) { @@ -396,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()); - xbt_assert(not link_list.empty(), "Bypass route between %s@%s and %s@%s cannot be empty.", src->get_cname(), + s4u_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()); - xbt_assert(bypass_routes_.find({src, dst}) == bypass_routes_.end(), + s4u_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()); - xbt_assert(not link_list.empty(), "Bypass route between %s and %s cannot be empty.", src->get_cname(), + s4u_enforce(not link_list.empty(), "Bypass route between %s and %s cannot be empty.", src->get_cname(), dst->get_cname()); - xbt_assert(bypass_routes_.find({src, dst}) == bypass_routes_.end(), + s4u_enforce(bypass_routes_.find({src, dst}) == bypass_routes_.end(), "The bypass route between %s and %s already exists.", src->get_cname(), dst->get_cname()); } @@ -486,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(); - xbt_assert(src_as, "Host %s must be in a netzone", src->get_cname()); - xbt_assert(dst_as, "Host %s must be in a netzone", dst->get_cname()); + 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()); /* (2) find the path to the root routing component */ std::vector path_src; @@ -522,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 { - xbt_assert(parent != nullptr); + s4u_enforce(parent != nullptr); *common_ancestor = parent; } } @@ -652,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); - xbt_assert((route.gw_src_ != nullptr) && (route.gw_dst_ != nullptr), "Bad gateways for route from '%s' to '%s'.", + s4u_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 */ @@ -742,7 +743,7 @@ void NetZoneImpl::seal() void NetZoneImpl::set_parent(NetZoneImpl* parent) { - xbt_assert(not sealed_, "Impossible to set parent to an already sealed NetZone(%s)", this->get_cname()); + s4u_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) { @@ -759,37 +760,37 @@ void NetZoneImpl::set_parent(NetZoneImpl* parent) void NetZoneImpl::set_network_model(std::shared_ptr netmodel) { - xbt_assert(not sealed_, "Impossible to set network model to an already sealed NetZone(%s)", this->get_cname()); + s4u_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) { - xbt_assert(not sealed_, "Impossible to set CPU model to an already sealed NetZone(%s)", this->get_cname()); + s4u_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) { - xbt_assert(not sealed_, "Impossible to set CPU model to an already sealed NetZone(%s)", this->get_cname()); + s4u_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) { - xbt_assert(not sealed_, "Impossible to set disk model to an already sealed NetZone(%s)", this->get_cname()); + s4u_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) { - xbt_assert(not sealed_, "Impossible to set host model to an already sealed NetZone(%s)", this->get_cname()); + s4u_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 { - xbt_assert(netpoint && netpoint->is_netzone(), "Netpoint %s must be of the type NetZone", + s4u_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 453436887a..5e11f12319 100644 --- a/src/kernel/routing/RoutedZone.cpp +++ b/src/kernel/routing/RoutedZone.cpp @@ -10,6 +10,7 @@ #include "xbt/graph.h" #include "xbt/log.h" #include "xbt/sysdep.h" +#include "xbt/asserts.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_generic, ker_routing, "Kernel Generic Routing"); @@ -29,7 +30,7 @@ Route* RoutedZone::new_extended_route(RoutingMode hierarchy, NetPoint* gw_src, N auto* result = new Route(); if (hierarchy == RoutingMode::recursive) { - xbt_assert(gw_src && gw_dst, "nullptr is obviously a deficient gateway"); + s4u_enforce(gw_src && gw_dst, "nullptr is obviously a deficient gateway"); result->gw_src_ = gw_src; result->gw_dst_ = gw_dst; @@ -46,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 { - xbt_assert(src, "Cannot have a route with (nullptr) source"); - xbt_assert(dst, "Cannot have a route with (nullptr) destination"); + s4u_enforce(src, "Cannot have a route with (nullptr) source"); + s4u_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(); - xbt_assert(src_as == dst_as, + s4u_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()); - xbt_assert(this == dst_as, + s4u_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()); @@ -71,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); - xbt_assert(not link_list.empty(), "Empty route (between %s and %s) forbidden.", srcName, dstName); - xbt_assert(not src->is_netzone(), + s4u_enforce(not link_list.empty(), "Empty route (between %s and %s) forbidden.", srcName, dstName); + s4u_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); - xbt_assert(not dst->is_netzone(), + s4u_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()); - xbt_assert(src->is_netzone(), "When defining a NetzoneRoute, src must be a netzone but '%s' is not", srcName); - xbt_assert(dst->is_netzone(), "When defining a NetzoneRoute, dst must be a netzone but '%s' is not", dstName); + 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_assert(gw_src->is_host() || gw_src->is_router(), + s4u_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); - xbt_assert(gw_dst->is_host() || gw_dst->is_router(), + s4u_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); - xbt_assert(gw_src != gw_dst, "Cannot define a NetzoneRoute from '%s' to itself", gw_src->get_cname()); + s4u_enforce(gw_src != gw_dst, "Cannot define a NetzoneRoute from '%s' to itself", gw_src->get_cname()); - xbt_assert(src, "Cannot add a route from %s@%s to %s@%s: %s does not exist.", srcName, gw_src->get_cname(), dstName, + s4u_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); - xbt_assert(dst, "Cannot add a route from %s@%s to %s@%s: %s does not exist.", srcName, gw_src->get_cname(), dstName, + s4u_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); - xbt_assert(not link_list.empty(), "Empty route (between %s@%s and %s@%s) forbidden.", srcName, gw_src->get_cname(), + s4u_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); - xbt_assert(netzone_src->is_component_recursive(gw_src), + s4u_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); - xbt_assert(netzone_dst->is_component_recursive(gw_dst), + s4u_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/simgrid/Exception.cpp b/src/simgrid/Exception.cpp index 146c978263..89781bd198 100644 --- a/src/simgrid/Exception.cpp +++ b/src/simgrid/Exception.cpp @@ -22,6 +22,7 @@ VmFailureException::~VmFailureException() = default; CancelException::~CancelException() = default; TracingError::~TracingError() = default; ParseError::~ParseError() = default; +AssertionError::~AssertionError() = default; ForcefulKillException::~ForcefulKillException() = default; void ForcefulKillException::do_throw() diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index ef5b9f6546..272b1d87ee 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -7,6 +7,7 @@ #include #include +#include "xbt/asserts.hpp" #include "src/kernel/EngineImpl.hpp" #include "src/kernel/resource/VirtualMachineImpl.hpp" @@ -28,7 +29,7 @@ namespace simgrid::kernel::resource { ************/ HostImpl::HostImpl(const std::string& name) : piface_(this), name_(name) { - xbt_assert(s4u::Host::by_name_or_null(name_) == nullptr, "Refusing to create a second host named '%s'.", get_cname()); + s4u_enforce(s4u::Host::by_name_or_null(name_) == nullptr, "Refusing to create a second host named '%s'.", get_cname()); } HostImpl::~HostImpl() -- 2.20.1