Kaydet (Commit) 8e9de1ad authored tarafından Mike Kaganski's avatar Mike Kaganski

Fix double-clear of clearable mutex guard

Change-Id: I91f04cae91cbb5510f70baaf8c31ecc59f6402c7
Reviewed-on: https://gerrit.libreoffice.org/70479
Tested-by: Jenkins
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 36883a9f
...@@ -611,57 +611,63 @@ void GrammarCheckingIterator::DequeueAndCheck() ...@@ -611,57 +611,63 @@ void GrammarCheckingIterator::DequeueAndCheck()
const bool bModified = xFlatPara->isModified(); const bool bModified = xFlatPara->isModified();
if (!bModified) 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; linguistic2::ProofreadingResult aRes;
uno::Reference< linguistic2::XProofreader > xGC( GetGrammarChecker( aCurLocale ), uno::UNO_QUERY ); // ---- THREAD SAFE START ----
if (xGC.is())
{ {
aGuard.clear(); osl::ClearableMutexGuard aGuard(MyMutex::get());
uno::Sequence<beans::PropertyValue> const aProps(
lcl_makeProperties(xFlatPara)); sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex;
aRes = xGC->doProofreading( aCurDocId, aCurTxt, sal_Int32 nSuggestedEnd
aCurLocale, nStartPos, nSuggestedEnd, aProps ); = GetSuggestedEndOfSentence(aCurTxt, nStartPos, aCurLocale);
DBG_ASSERT((nSuggestedEnd == 0 && aCurTxt.isEmpty())
//!! work-around to prevent looping if the grammar checker || nSuggestedEnd > nStartPos,
//!! failed to properly identify the sentence end "nSuggestedEndOfSentencePos calculation failed?");
if (
aRes.nBehindEndOfSentencePosition <= nStartPos && uno::Reference<linguistic2::XProofreader> xGC(
aRes.nBehindEndOfSentencePosition != nSuggestedEnd 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.nBehindEndOfSentencePosition = nSuggestedEnd;
} }
aRes.nStartOfNextSentencePosition
= lcl_SkipWhiteSpaces(aCurTxt, aRes.nBehindEndOfSentencePosition);
aRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces(
aCurTxt, aRes.nStartOfNextSentencePosition);
aRes.xFlatParagraph = xFlatPara; //guard has to be cleared as ProcessResult calls out of this class
aRes.nStartOfSentencePosition = nStartPos;
} }
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 ---- // ---- THREAD SAFE END ----
ProcessResult( aRes, xFPIterator, aFPEntryItem.m_bAutomatic );
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment