[Libreoffice-commits] core.git: linguistic/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 9 22:51:15 UTC 2019


 linguistic/source/gciterator.cxx |   90 ++++++++++++++++++++-------------------
 1 file changed, 48 insertions(+), 42 deletions(-)

New commits:
commit 8e9de1ad055d1d8f41a6cf6d8cea245463f61d40
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue Apr 9 22:23:23 2019 +0100
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Apr 10 00:50:53 2019 +0200

    Fix double-clear of clearable mutex guard
    
    Change-Id: I91f04cae91cbb5510f70baaf8c31ecc59f6402c7
    Reviewed-on: https://gerrit.libreoffice.org/70479
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx
index 325af32849bd..62322ae67032 100644
--- a/linguistic/source/gciterator.cxx
+++ b/linguistic/source/gciterator.cxx
@@ -611,57 +611,63 @@ void GrammarCheckingIterator::DequeueAndCheck()
                     const bool bModified = xFlatPara->isModified();
                     if (!bModified)
                     {
-                        // ---- THREAD SAFE START ----
-                        ::osl::ClearableGuard< ::osl::Mutex > aGuard( MyMutex::get() );
-
-                        sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex;
-                        sal_Int32 nSuggestedEnd = GetSuggestedEndOfSentence( aCurTxt, nStartPos, aCurLocale );
-                        DBG_ASSERT( (nSuggestedEnd == 0 && aCurTxt.isEmpty()) || nSuggestedEnd > nStartPos,
-                                    "nSuggestedEndOfSentencePos calculation failed?" );
-
                         linguistic2::ProofreadingResult aRes;
 
-                        uno::Reference< linguistic2::XProofreader > xGC( GetGrammarChecker( aCurLocale ), uno::UNO_QUERY );
-                        if (xGC.is())
+                        // ---- THREAD SAFE START ----
                         {
-                            aGuard.clear();
-                            uno::Sequence<beans::PropertyValue> const aProps(
-                                lcl_makeProperties(xFlatPara));
-                            aRes = xGC->doProofreading( aCurDocId, aCurTxt,
-                                                        aCurLocale, nStartPos, nSuggestedEnd, aProps );
-
-                            //!! work-around to prevent looping if the grammar checker
-                            //!! failed to properly identify the sentence end
-                            if (
-                                aRes.nBehindEndOfSentencePosition <= nStartPos &&
-                                aRes.nBehindEndOfSentencePosition != nSuggestedEnd
-                            )
+                            osl::ClearableMutexGuard aGuard(MyMutex::get());
+
+                            sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex;
+                            sal_Int32 nSuggestedEnd
+                                = GetSuggestedEndOfSentence(aCurTxt, nStartPos, aCurLocale);
+                            DBG_ASSERT((nSuggestedEnd == 0 && aCurTxt.isEmpty())
+                                           || nSuggestedEnd > nStartPos,
+                                       "nSuggestedEndOfSentencePos calculation failed?");
+
+                            uno::Reference<linguistic2::XProofreader> xGC(
+                                GetGrammarChecker(aCurLocale), uno::UNO_QUERY);
+                            if (xGC.is())
+                            {
+                                aGuard.clear();
+                                uno::Sequence<beans::PropertyValue> const aProps(
+                                    lcl_makeProperties(xFlatPara));
+                                aRes = xGC->doProofreading(aCurDocId, aCurTxt, aCurLocale,
+                                                           nStartPos, nSuggestedEnd, aProps);
+
+                                //!! work-around to prevent looping if the grammar checker
+                                //!! failed to properly identify the sentence end
+                                if (aRes.nBehindEndOfSentencePosition <= nStartPos
+                                    && aRes.nBehindEndOfSentencePosition != nSuggestedEnd)
+                                {
+                                    SAL_WARN(
+                                        "linguistic",
+                                        "!! Grammarchecker failed to provide end of sentence !!");
+                                    aRes.nBehindEndOfSentencePosition = nSuggestedEnd;
+                                }
+
+                                aRes.xFlatParagraph = xFlatPara;
+                                aRes.nStartOfSentencePosition = nStartPos;
+                            }
+                            else
                             {
-                                SAL_WARN( "linguistic", "!! Grammarchecker failed to provide end of sentence !!" );
+                                // no grammar checker -> no error
+                                // but we need to provide the data below in order to continue with the next sentence
+                                aRes.aDocumentIdentifier = aCurDocId;
+                                aRes.xFlatParagraph = xFlatPara;
+                                aRes.aText = aCurTxt;
+                                aRes.aLocale = aCurLocale;
+                                aRes.nStartOfSentencePosition = nStartPos;
                                 aRes.nBehindEndOfSentencePosition = nSuggestedEnd;
                             }
+                            aRes.nStartOfNextSentencePosition
+                                = lcl_SkipWhiteSpaces(aCurTxt, aRes.nBehindEndOfSentencePosition);
+                            aRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces(
+                                aCurTxt, aRes.nStartOfNextSentencePosition);
 
-                            aRes.xFlatParagraph      = xFlatPara;
-                            aRes.nStartOfSentencePosition = nStartPos;
+                            //guard has to be cleared as ProcessResult calls out of this class
                         }
-                        else
-                        {
-                            // no grammar checker -> no error
-                            // but we need to provide the data below in order to continue with the next sentence
-                            aRes.aDocumentIdentifier = aCurDocId;
-                            aRes.xFlatParagraph      = xFlatPara;
-                            aRes.aText               = aCurTxt;
-                            aRes.aLocale             = aCurLocale;
-                            aRes.nStartOfSentencePosition       = nStartPos;
-                            aRes.nBehindEndOfSentencePosition   = nSuggestedEnd;
-                        }
-                        aRes.nStartOfNextSentencePosition = lcl_SkipWhiteSpaces( aCurTxt, aRes.nBehindEndOfSentencePosition );
-                        aRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces( aCurTxt, aRes.nStartOfNextSentencePosition );
-
-                        //guard has to be cleared as ProcessResult calls out of this class
-                        aGuard.clear();
-                        ProcessResult( aRes, xFPIterator, aFPEntryItem.m_bAutomatic );
                         // ---- THREAD SAFE END ----
+                        ProcessResult( aRes, xFPIterator, aFPEntryItem.m_bAutomatic );
                     }
                     else
                     {


More information about the Libreoffice-commits mailing list