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()
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
{
......
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