summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2019-02-25 15:45:43 +0100
committerLuboš Luňák <l.lunak@collabora.com>2019-03-01 10:03:05 +0100
commitb5c3f38cb8d4121e3303be362e0757d3d3431059 (patch)
tree92131dad7dcaf1c5b526b4ee4007f2c5699d8028
parentbbd3145f72c4abfbf17dd09d9cb2724f04416450 (diff)
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: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r--compilerplugins/clang/badstatics.cxx2
-rw-r--r--sc/inc/document.hxx3
-rw-r--r--sc/inc/global.hxx2
-rw-r--r--sc/inc/interpretercontext.hxx12
-rw-r--r--sc/source/core/data/table3.cxx4
-rw-r--r--sc/source/core/tool/interpretercontext.cxx7
6 files changed, 22 insertions, 8 deletions
diff --git a/compilerplugins/clang/badstatics.cxx b/compilerplugins/clang/badstatics.cxx
index 3c0a7ba99051..4eebb46d96f3 100644
--- a/compilerplugins/clang/badstatics.cxx
+++ b/compilerplugins/clang/badstatics.cxx
@@ -201,6 +201,8 @@ public:
.Class("ScDocument").GlobalNamespace()) // not owning
|| 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 == "aThreadedInterpreterPool" // ScInterpreterContext(Pool), not owning
+ || name == "aNonThreadedInterpreterPool" // ScInterpreterContext(Pool), not owning
) // these variables appear unproblematic
{
return true;
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index f2b8f1ccec72..c587229c6ce6 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -587,8 +587,7 @@ public:
ScInterpreterContext& GetNonThreadedContext() const
{
- // GetFormatTable() asserts that we are not in a threaded calculation
- maInterpreterContext.mpFormatter = GetFormatTable();
+ assert(!IsThreadedGroupCalcInProgress());
return maInterpreterContext;
}
// Uses thread_local.
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx
index 7acf8ec84a91..75d4ef24ca91 100644
--- a/sc/inc/global.hxx
+++ b/sc/inc/global.hxx
@@ -810,7 +810,7 @@ public:
SvNumberFormatter* pFormatter, SvNumFormatType & rCurFmtType );
/// Calc's threaded group calculation is in progress.
- static bool bThreadedGroupCalcInProgress;
+ SC_DLLPUBLIC static bool bThreadedGroupCalcInProgress;
};
// maybe move to dbdata.hxx (?):
diff --git a/sc/inc/interpretercontext.hxx b/sc/inc/interpretercontext.hxx
index 2f3e33040702..9fb2bc3993c5 100644
--- a/sc/inc/interpretercontext.hxx
+++ b/sc/inc/interpretercontext.hxx
@@ -37,7 +37,6 @@ class ScInterpreterContextPool;
struct ScInterpreterContext
{
const ScDocument* mpDoc;
- SvNumberFormatter* mpFormatter;
size_t mnTokenCachePos;
std::vector<formula::FormulaToken*> maTokens;
std::vector<DelayedSetNumberFormat> maDelayedSetNumberFormat;
@@ -48,10 +47,10 @@ struct ScInterpreterContext
ScInterpreterContext(const ScDocument& rDoc, SvNumberFormatter* pFormatter)
: mpDoc(&rDoc)
- , mpFormatter(pFormatter)
, mnTokenCachePos(0)
, maTokens(TOKEN_CACHE_SIZE, nullptr)
, mScLookupCache(nullptr)
+ , mpFormatter(pFormatter)
{
}
@@ -59,7 +58,12 @@ struct ScInterpreterContext
~ScInterpreterContext();
- SvNumberFormatter* GetFormatTable() const { return mpFormatter; }
+ SvNumberFormatter* GetFormatTable() const
+ {
+ if (mpFormatter == nullptr)
+ const_cast<ScInterpreterContext*>(this)->initFormatTable();
+ return mpFormatter;
+ }
private:
friend class ScInterpreterContextPool;
@@ -67,6 +71,8 @@ private:
void SetDocAndFormatter(const ScDocument& rDoc, SvNumberFormatter* pFormatter);
void Cleanup();
void ClearLookupCache();
+ void initFormatTable();
+ SvNumberFormatter* mpFormatter;
};
class ScThreadedInterpreterContextGetterGuard;
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 055c55fc14ba..4e9f074470ae 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -2360,7 +2360,7 @@ public:
{
sal_uInt32 nNumFmt = pContext ? mrTab.GetNumberFormat(*pContext, ScAddress(nCol, nRow, mrTab.GetTab())) :
mrTab.GetNumberFormat(nCol, nRow);
- SvNumberFormatter* pFormatter = pContext ? pContext->mpFormatter : mrDoc.GetFormatTable();
+ SvNumberFormatter* pFormatter = pContext ? pContext->GetFormatTable() : mrDoc.GetFormatTable();
const SvNumberformat* pEntry = pFormatter->GetEntry(nNumFmt);
if (pEntry)
{
@@ -2434,7 +2434,7 @@ public:
sal_uInt32 nFormat = pContext ? mrTab.GetNumberFormat( *pContext, ScAddress(static_cast<SCCOL>(rEntry.nField), nRow, mrTab.GetTab()) ) :
mrTab.GetNumberFormat( static_cast<SCCOL>(rEntry.nField), nRow );
OUString aStr;
- SvNumberFormatter* pFormatter = pContext ? pContext->mpFormatter : mrDoc.GetFormatTable();
+ SvNumberFormatter* pFormatter = pContext ? pContext->GetFormatTable() : mrDoc.GetFormatTable();
ScCellFormat::GetInputString(rCell, nFormat, aStr, *pFormatter, &mrDoc);
return compareByStringComparator(rEntry, rItem, nullptr, &aStr);
}
diff --git a/sc/source/core/tool/interpretercontext.cxx b/sc/source/core/tool/interpretercontext.cxx
index bc67afca039c..b997effe13c4 100644
--- a/sc/source/core/tool/interpretercontext.cxx
+++ b/sc/source/core/tool/interpretercontext.cxx
@@ -18,6 +18,8 @@
*/
#include <interpretercontext.hxx>
+
+#include <document.hxx>
#include <formula/token.hxx>
#include <lookupcache.hxx>
#include <algorithm>
@@ -47,6 +49,11 @@ void ScInterpreterContext::SetDocAndFormatter(const ScDocument& rDoc, SvNumberFo
mpFormatter = pFormatter;
}
+void ScInterpreterContext::initFormatTable()
+{
+ mpFormatter = mpDoc->GetFormatTable(); // will assert if not main thread
+}
+
void ScInterpreterContext::Cleanup()
{
// Do not disturb mScLookupCache