From 5ac96c6127bf92e384bbe0d9730f745cf4ff93fe Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 3 Apr 2019 17:03:50 +0100 Subject: [PATCH] More mutex locking for SCH_FIELDs. Fixes: lp:1822678 * https://bugs.launchpad.net/kicad/+bug/1822678 --- eeschema/sch_field.cpp | 34 ++++++++++++++++++++++++++++++++++ eeschema/sch_field.h | 4 ++++ include/eda_text.h | 6 +++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 852925c5e2..e27666883f 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -79,6 +79,10 @@ EDA_ITEM* SCH_FIELD::Clone() const const wxString SCH_FIELD::GetFullyQualifiedText() const { + // When in UTF-8 mode, wxString puts string iterators in a linked list, and + // that linked list is not thread-safe. + std::lock_guard guard( m_mutex ); + wxString text = m_Text; /* For more than one part per package, we must add the part selection @@ -98,6 +102,36 @@ const wxString SCH_FIELD::GetFullyQualifiedText() const } +const wxString SCH_FIELD::GetText() const +{ + // When in UTF-8 mode, wxString puts string iterators in a linked list, and + // that linked list is not thread-safe. + std::lock_guard guard( m_mutex ); + + return m_Text; +} + + +wxString SCH_FIELD::GetShownText() const +{ + // When in UTF-8 mode, wxString puts string iterators in a linked list, and + // that linked list is not thread-safe. + std::lock_guard guard( m_mutex ); + + return m_Text; +} + + +void SCH_FIELD::SetText( const wxString& aText ) +{ + // When in UTF-8 mode, wxString puts string iterators in a linked list, and + // that linked list is not thread-safe. + std::lock_guard guard( m_mutex ); + + m_Text = aText; +} + + int SCH_FIELD::GetPenSize() const { int pensize = GetThickness(); diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 8adf7526ff..e91f3ea3dd 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -90,6 +90,10 @@ public: void SetId( int aId ) { m_id = aId; } + const wxString GetText() const override; + wxString GetShownText() const override; + void SetText( const wxString& aText ) override; + /** * Function GetFullyQualifiedText * returns the fully qualified field text by allowing for the part suffix to be added diff --git a/include/eda_text.h b/include/eda_text.h index bbb15f2a10..d0936c5c53 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -139,8 +139,12 @@ public: * returns the string associated with the text object. * * @return a const wxString reference containing the string of the item. + * + * WARNING: this routine MUST NOT return a reference! + * While it would be faster, it would also defeat the use of RAII mutex locks + * in subclasses to get around wxString's multi-threading bugs in UTF-8 mode. */ - const wxString& GetText() const { return m_Text; } + virtual const wxString/* & forbidden */ GetText() const { return m_Text; } /** * Returns the string actually shown after processing of the base