summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2025-02-18 14:31:48 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2025-02-18 14:31:48 +0100
commitf331e31505ab78620de2670b19bdefaee395b4e8 (patch)
tree3428314c405f177e4bc3042b661d39d984ee3907 /apt-pkg
parent4175a005f98dba139208035d820bcc14de711a5a (diff)
solver3: Fix error stack handling
Pushing the stack in push and popping it in pop did not really work correctly and is more complex than needed. Instead, push the error stack at the start of the Solve() method and revert at the end, such that we leave exactly at the same error stack level we entered. To handle error clearing on backtracking, just discard any pending errors.
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/solver3.cc14
1 files changed, 7 insertions, 7 deletions
diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc
index 233d7c712..7117296ab 100644
--- a/apt-pkg/solver3.cc
+++ b/apt-pkg/solver3.cc
@@ -673,8 +673,6 @@ void APT::Solver::Push(Work work)
choices.push_back(solved.size());
solved.push_back(Solved{Var(), std::move(work)});
- // Pop() will call MergeWithStack() when reverting to level 0, or RevertToStack after dumping to the debug log.
- _error->PushToStack();
}
void APT::Solver::UndoOne()
@@ -713,15 +711,15 @@ bool APT::Solver::Pop()
if (depth() == 0)
return false;
- if (unlikely(debug >= 2))
- for (std::string msg; _error->PopMessage(msg);)
- std::cerr << "Branch failed: " << msg << std::endl;
-
time_t now = time(nullptr);
if (now - startTime >= Timeout)
return _error->Error("Solver timed out.");
- _error->RevertToStack();
+ if (unlikely(debug >= 2))
+ for (std::string msg; _error->PopMessage(msg);)
+ std::cerr << "Branch failed: " << msg << std::endl;
+
+ _error->Discard();
assert(choices.back() < solved.size());
int itemsToUndo = solved.size() - choices.back();
@@ -781,6 +779,8 @@ bool APT::Solver::AddWork(Work &&w)
bool APT::Solver::Solve()
{
+ _error->PushToStack();
+ DEFER([&]() { _error->MergeWithStack(); });
startTime = time(nullptr);
while (true)
{