From: Gabriel Corona Date: Fri, 18 Dec 2015 11:18:20 +0000 (+0100) Subject: Call destructors of facets in reverse order of their registrations X-Git-Tag: v3_13~1427 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d0e24e71be9100371207e703e25cab7d612f521c?ds=sidebyside Call destructors of facets in reverse order of their registrations The rationale for this, is that if a level B as been added after a facet A, the subsystem of B might depend on the subsystem on A and a facet of B might need to have the facet of A around when executing its cleanup function/destructor. --- diff --git a/include/xbt/Facetable.hpp b/include/xbt/Facetable.hpp index 84fe635033..34bd0725e7 100644 --- a/include/xbt/Facetable.hpp +++ b/include/xbt/Facetable.hpp @@ -70,9 +70,15 @@ public: Facetable() : facets_(deleters_.size(), nullptr) {} ~Facetable() { - for (std::size_t i = 0; i < facets_.size(); ++i) - if (facets_[i] != nullptr) - deleters_[i](facets_[i]); + /* Call destructors in reverse order of their registrations + * + * The rationale for this, is that if a level B as been added after a + * facet A, the subsystem of B might depend on the subsystem on A and a + * facet of B might need to have the facet of A around when executing + * its cleanup function/destructor. */ + for (std::size_t i = facets_.size(); i > 0; --i) + if (facets_[i - 1] != nullptr) + deleters_[i - 1](facets_[i - 1]); } // Type-unsafe versions of the facet access methods: