From 11193d2cdad1bde150586c458bacf65fa3f39fc0 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 1 Jun 2024 11:37:01 +0100 Subject: [PATCH] Make sure ERC pin-to-pin checks are always in same order. Comparing U1.pin1 : U2.pin1 will return the same results as U2.pin1 : U1.pin1, but will result in a different serialization of any exclusions. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17004 --- eeschema/erc/erc.cpp | 15 +++++++++++++++ eeschema/erc/erc_sch_pin_context.cpp | 4 ++-- eeschema/erc/erc_sch_pin_context.h | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/eeschema/erc/erc.cpp b/eeschema/erc/erc.cpp index d9d01fb2db..8500b65623 100644 --- a/eeschema/erc/erc.cpp +++ b/eeschema/erc/erc.cpp @@ -761,6 +761,21 @@ int ERC_TESTER::TestPinToPin() } } + std::sort( pins.begin(), pins.end(), + []( const ERC_SCH_PIN_CONTEXT& lhs, const ERC_SCH_PIN_CONTEXT& rhs ) + { + int ret = StrNumCmp( lhs.Pin()->GetParentSymbol()->GetRef( &lhs.Sheet() ), + rhs.Pin()->GetParentSymbol()->GetRef( &rhs.Sheet() ) ); + + if( ret == 0 ) + ret = StrNumCmp( lhs.Pin()->GetNumber(), rhs.Pin()->GetNumber() ); + + if( ret == 0 ) + ret = lhs < rhs; // Fallback to hash to guarantee deterministic sort + + return ret < 0; + } ); + ERC_SCH_PIN_CONTEXT needsDriver; bool hasDriver = false; diff --git a/eeschema/erc/erc_sch_pin_context.cpp b/eeschema/erc/erc_sch_pin_context.cpp index 233a6473a4..6373421388 100644 --- a/eeschema/erc/erc_sch_pin_context.cpp +++ b/eeschema/erc/erc_sch_pin_context.cpp @@ -30,13 +30,13 @@ #include -SCH_PIN* ERC_SCH_PIN_CONTEXT::Pin() +SCH_PIN* ERC_SCH_PIN_CONTEXT::Pin() const { return m_pin; } -SCH_SHEET_PATH& ERC_SCH_PIN_CONTEXT::Sheet() +const SCH_SHEET_PATH& ERC_SCH_PIN_CONTEXT::Sheet() const { return m_sheet; } diff --git a/eeschema/erc/erc_sch_pin_context.h b/eeschema/erc/erc_sch_pin_context.h index 0e2da37f28..244c976c5e 100644 --- a/eeschema/erc/erc_sch_pin_context.h +++ b/eeschema/erc/erc_sch_pin_context.h @@ -62,12 +62,12 @@ public: /** * Get the SCH_PIN for this context. */ - SCH_PIN* Pin(); + SCH_PIN* Pin() const; /** * Get the #SCH_SHEET_PATH context for the paired #SCH_PIN. */ - SCH_SHEET_PATH& Sheet(); + const SCH_SHEET_PATH& Sheet() const; /** * Test two pin contexts for equality based on the deterministic hash.