From 7ca78ea1958f5a8a89400ba06a060ca1b468388e Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Fri, 9 Dec 2022 15:17:43 +0100 Subject: [PATCH] Func: Use std::stable_sort() for sorting bodies by priority Avoids platform/stdlib dependent sorting of bodies with the same priority and the same handler. They should be guaranteed to be executed in load order now. --- src/Func.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Func.cc b/src/Func.cc index 6bfbf8c458..c64928fbc9 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -303,7 +303,7 @@ ScriptFunc::ScriptFunc(std::string _name, FuncTypePtr ft, std::vector b bodies.push_back(b); } - sort(bodies.begin(), bodies.end()); + std::stable_sort(bodies.begin(), bodies.end()); if ( ! bodies.empty() ) { @@ -566,7 +566,7 @@ void ScriptFunc::AddBody(StmtPtr new_body, const std::vector& new_inits, current_priority = b.priority = priority; bodies.push_back(b); - sort(bodies.begin(), bodies.end()); + std::stable_sort(bodies.begin(), bodies.end()); } void ScriptFunc::ReplaceBody(const StmtPtr& old_body, StmtPtr new_body)