From d0e24e71be9100371207e703e25cab7d612f521c Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Fri, 18 Dec 2015 12:18:20 +0100 Subject: [PATCH] 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. --- include/xbt/Facetable.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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: -- 2.20.1