Kaydet (Commit) 233c9a12 authored tarafından Luboš Luňák's avatar Luboš Luňák Kaydeden (comit) Michael Meeks

do not call GetFormatTable() from GetNonThreadedContext() (tdf#121949)

ScDocument dtor calls ClearLookupCaches(), which calls GetNonThreadedContext().
But ScDocument instances used for copy&paste GetFormatTable() fails
on null mxPoolHelper, because ScDocument ctor doesn't set it in such a case.
So set up the pointer in ScInterpreterContext on demand only if actually
needed.

Change-Id: If3811da5bb00a2d7d404c089ee1bf46037a2cddb
Reviewed-on: https://gerrit.libreoffice.org/68350
Tested-by: Jenkins
Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
(cherry picked from commit b5c3f38c)
Reviewed-on: https://gerrit.libreoffice.org/68539
üst 7b9e1337
...@@ -201,6 +201,8 @@ public: ...@@ -201,6 +201,8 @@ public:
.Class("ScDocument").GlobalNamespace()) // not owning .Class("ScDocument").GlobalNamespace()) // not owning
|| name == "s_pLOKWindowsMap" // LOK only, guarded by assert, and LOK never tries to perform a VCL cleanup || name == "s_pLOKWindowsMap" // LOK only, guarded by assert, and LOK never tries to perform a VCL cleanup
|| name == "gStaticManager" // vcl/source/graphic/Manager.cxx - stores non-owning pointers || name == "gStaticManager" // vcl/source/graphic/Manager.cxx - stores non-owning pointers
|| name == "aThreadedInterpreterPool" // ScInterpreterContext(Pool), not owning
|| name == "aNonThreadedInterpreterPool" // ScInterpreterContext(Pool), not owning
) // these variables appear unproblematic ) // these variables appear unproblematic
{ {
return true; return true;
......
...@@ -582,8 +582,7 @@ public: ...@@ -582,8 +582,7 @@ public:
ScInterpreterContext& GetNonThreadedContext() const ScInterpreterContext& GetNonThreadedContext() const
{ {
// GetFormatTable() asserts that we are not in a threaded calculation assert(!IsThreadedGroupCalcInProgress());
maInterpreterContext.mpFormatter = GetFormatTable();
return maInterpreterContext; return maInterpreterContext;
} }
// Uses thread_local. // Uses thread_local.
......
...@@ -809,7 +809,7 @@ public: ...@@ -809,7 +809,7 @@ public:
SvNumberFormatter* pFormatter, SvNumFormatType & rCurFmtType ); SvNumberFormatter* pFormatter, SvNumFormatType & rCurFmtType );
/// Calc's threaded group calculation is in progress. /// Calc's threaded group calculation is in progress.
static bool bThreadedGroupCalcInProgress; SC_DLLPUBLIC static bool bThreadedGroupCalcInProgress;
}; };
// maybe move to dbdata.hxx (?): // maybe move to dbdata.hxx (?):
......
...@@ -37,7 +37,6 @@ class ScInterpreterContextPool; ...@@ -37,7 +37,6 @@ class ScInterpreterContextPool;
struct ScInterpreterContext struct ScInterpreterContext
{ {
const ScDocument* mpDoc; const ScDocument* mpDoc;
SvNumberFormatter* mpFormatter;
size_t mnTokenCachePos; size_t mnTokenCachePos;
std::vector<formula::FormulaToken*> maTokens; std::vector<formula::FormulaToken*> maTokens;
std::vector<DelayedSetNumberFormat> maDelayedSetNumberFormat; std::vector<DelayedSetNumberFormat> maDelayedSetNumberFormat;
...@@ -48,10 +47,10 @@ struct ScInterpreterContext ...@@ -48,10 +47,10 @@ struct ScInterpreterContext
ScInterpreterContext(const ScDocument& rDoc, SvNumberFormatter* pFormatter) ScInterpreterContext(const ScDocument& rDoc, SvNumberFormatter* pFormatter)
: mpDoc(&rDoc) : mpDoc(&rDoc)
, mpFormatter(pFormatter)
, mnTokenCachePos(0) , mnTokenCachePos(0)
, maTokens(TOKEN_CACHE_SIZE, nullptr) , maTokens(TOKEN_CACHE_SIZE, nullptr)
, mScLookupCache(nullptr) , mScLookupCache(nullptr)
, mpFormatter(pFormatter)
{ {
} }
...@@ -59,7 +58,12 @@ struct ScInterpreterContext ...@@ -59,7 +58,12 @@ struct ScInterpreterContext
~ScInterpreterContext(); ~ScInterpreterContext();
SvNumberFormatter* GetFormatTable() const { return mpFormatter; } SvNumberFormatter* GetFormatTable() const
{
if (mpFormatter == nullptr)
const_cast<ScInterpreterContext*>(this)->initFormatTable();
return mpFormatter;
}
private: private:
friend class ScInterpreterContextPool; friend class ScInterpreterContextPool;
...@@ -67,6 +71,8 @@ private: ...@@ -67,6 +71,8 @@ private:
void SetDocAndFormatter(const ScDocument& rDoc, SvNumberFormatter* pFormatter); void SetDocAndFormatter(const ScDocument& rDoc, SvNumberFormatter* pFormatter);
void Cleanup(); void Cleanup();
void ClearLookupCache(); void ClearLookupCache();
void initFormatTable();
SvNumberFormatter* mpFormatter;
}; };
class ScThreadedInterpreterContextGetterGuard; class ScThreadedInterpreterContextGetterGuard;
......
...@@ -2409,7 +2409,7 @@ public: ...@@ -2409,7 +2409,7 @@ public:
{ {
sal_uInt32 nNumFmt = pContext ? mrTab.GetNumberFormat(*pContext, ScAddress(nCol, nRow, mrTab.GetTab())) : sal_uInt32 nNumFmt = pContext ? mrTab.GetNumberFormat(*pContext, ScAddress(nCol, nRow, mrTab.GetTab())) :
mrTab.GetNumberFormat(nCol, nRow); mrTab.GetNumberFormat(nCol, nRow);
SvNumberFormatter* pFormatter = pContext ? pContext->mpFormatter : mrDoc.GetFormatTable(); SvNumberFormatter* pFormatter = pContext ? pContext->GetFormatTable() : mrDoc.GetFormatTable();
const SvNumberformat* pEntry = pFormatter->GetEntry(nNumFmt); const SvNumberformat* pEntry = pFormatter->GetEntry(nNumFmt);
if (pEntry) if (pEntry)
{ {
...@@ -2483,7 +2483,7 @@ public: ...@@ -2483,7 +2483,7 @@ public:
sal_uInt32 nFormat = pContext ? mrTab.GetNumberFormat( *pContext, ScAddress(static_cast<SCCOL>(rEntry.nField), nRow, mrTab.GetTab()) ) : sal_uInt32 nFormat = pContext ? mrTab.GetNumberFormat( *pContext, ScAddress(static_cast<SCCOL>(rEntry.nField), nRow, mrTab.GetTab()) ) :
mrTab.GetNumberFormat( static_cast<SCCOL>(rEntry.nField), nRow ); mrTab.GetNumberFormat( static_cast<SCCOL>(rEntry.nField), nRow );
OUString aStr; OUString aStr;
SvNumberFormatter* pFormatter = pContext ? pContext->mpFormatter : mrDoc.GetFormatTable(); SvNumberFormatter* pFormatter = pContext ? pContext->GetFormatTable() : mrDoc.GetFormatTable();
ScCellFormat::GetInputString(rCell, nFormat, aStr, *pFormatter, &mrDoc); ScCellFormat::GetInputString(rCell, nFormat, aStr, *pFormatter, &mrDoc);
return compareByStringComparator(rEntry, rItem, nullptr, &aStr); return compareByStringComparator(rEntry, rItem, nullptr, &aStr);
} }
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
*/ */
#include <interpretercontext.hxx> #include <interpretercontext.hxx>
#include <document.hxx>
#include <formula/token.hxx> #include <formula/token.hxx>
#include <lookupcache.hxx> #include <lookupcache.hxx>
#include <algorithm> #include <algorithm>
...@@ -47,6 +49,11 @@ void ScInterpreterContext::SetDocAndFormatter(const ScDocument& rDoc, SvNumberFo ...@@ -47,6 +49,11 @@ void ScInterpreterContext::SetDocAndFormatter(const ScDocument& rDoc, SvNumberFo
mpFormatter = pFormatter; mpFormatter = pFormatter;
} }
void ScInterpreterContext::initFormatTable()
{
mpFormatter = mpDoc->GetFormatTable(); // will assert if not main thread
}
void ScInterpreterContext::Cleanup() void ScInterpreterContext::Cleanup()
{ {
// Do not disturb mScLookupCache // Do not disturb mScLookupCache
......
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