connectivity/source/parse/sqlbison.y  |    2 +-
 connectivity/source/parse/sqlnode.cxx |   15 +++++++--------
 include/connectivity/sqlparse.hxx     |    3 ++-
 3 files changed, 10 insertions(+), 10 deletions(-)

New commits:
commit e469a171833c2d88c4e129f339415c15a3a14b1e
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Jun 15 15:34:40 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jun 15 18:39:31 2023 +0200

    wrap OSQLParser::s_xLocaleData in vcl::DeleteOnDeinit
    
    since my adaption of i18npool to use OUStringLiteral, this
    data structure might get torn down after the i18npool data is
    has pointers to.
    
    Change-Id: If83d232d5bfb003ed4dbfb70d47f707a73d2bcc1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153121
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/connectivity/source/parse/sqlbison.y 
b/connectivity/source/parse/sqlbison.y
index cbad86149fc2..0c5d359d083e 100644
--- a/connectivity/source/parse/sqlbison.y
+++ b/connectivity/source/parse/sqlbison.y
@@ -4493,7 +4493,7 @@ sal_Int32                 OSQLParser::s_nRefCount = 0;
 //     ::osl::Mutex            OSQLParser::s_aMutex;
 OSQLScanner*           OSQLParser::s_pScanner = nullptr;
 OSQLParseNodesGarbageCollector*                OSQLParser::s_pGarbageCollector 
= nullptr;
-css::uno::Reference< css::i18n::XLocaleData4>  OSQLParser::s_xLocaleData = 
nullptr;
+vcl::DeleteOnDeinit<css::uno::Reference< css::i18n::XLocaleData4>> 
OSQLParser::s_xLocaleData(vcl::DeleteOnDeinitFlag::Empty);
 
 void setParser(OSQLParser* _pParser)
 {
diff --git a/connectivity/source/parse/sqlnode.cxx 
b/connectivity/source/parse/sqlnode.cxx
index 4f213bf4f902..1153a216cffd 100644
--- a/connectivity/source/parse/sqlnode.cxx
+++ b/connectivity/source/parse/sqlnode.cxx
@@ -803,7 +803,7 @@ void OSQLParser::killThousandSeparator(OSQLParseNode* 
pLiteral)
 {
     if ( pLiteral )
     {
-        if ( s_xLocaleData->getLocaleItem( m_pData->aLocale 
).decimalSeparator.toChar() == ',' )
+        if ( s_xLocaleData.get()->get()->getLocaleItem( m_pData->aLocale 
).decimalSeparator.toChar() == ',' )
         {
             pLiteral->m_aNodeValue = pLiteral->m_aNodeValue.replace('.', 
sal_Unicode());
             // and replace decimal
@@ -1118,7 +1118,7 @@ OUString OSQLParser::stringToDouble(const OUString& 
_rValue,sal_Int16 _nScale)
     OUString aValue;
     if(!m_xCharClass.is())
         m_xCharClass  = CharacterClassification::create( m_xContext );
-    if( s_xLocaleData.is() )
+    if( s_xLocaleData.get() )
     {
         try
         {
@@ -1129,7 +1129,8 @@ OUString OSQLParser::stringToDouble(const OUString& 
_rValue,sal_Int16 _nScale)
                 sal_Int32 nPos = aValue.lastIndexOf('.');
                 if((nPos+_nScale) < aValue.getLength())
                     aValue = 
aValue.replaceAt(nPos+_nScale,aValue.getLength()-nPos-_nScale, u"");
-                aValue = 
aValue.replaceAt(aValue.lastIndexOf('.'),1,s_xLocaleData->getLocaleItem(m_pData->aLocale).decimalSeparator);
+                OUString sDecimalSeparator = 
s_xLocaleData.get()->get()->getLocaleItem(m_pData->aLocale).decimalSeparator;
+                aValue = aValue.replaceAt(aValue.lastIndexOf('.'), 1, 
sDecimalSeparator);
                 return aValue;
             }
         }
@@ -1247,7 +1248,7 @@ std::unique_ptr<OSQLParseNode> 
OSQLParser::predicateTree(OUString& rErrorMessage
                 s_pScanner->SetRule(OSQLScanner::GetSTRINGRule());
                 break;
             default:
-                if ( s_xLocaleData->getLocaleItem( m_pData->aLocale 
).decimalSeparator.toChar() == ',' )
+                if ( s_xLocaleData.get()->get()->getLocaleItem( 
m_pData->aLocale ).decimalSeparator.toChar() == ',' )
                     s_pScanner->SetRule(OSQLScanner::GetGERRule());
                 else
                     s_pScanner->SetRule(OSQLScanner::GetENGRule());
@@ -1330,8 +1331,8 @@ OSQLParser::OSQLParser(css::uno::Reference< 
css::uno::XComponentContext > xConte
         s_pScanner->setScanner();
         s_pGarbageCollector = new OSQLParseNodesGarbageCollector();
 
-        if(!s_xLocaleData.is())
-            s_xLocaleData = LocaleData::create(m_xContext);
+        if(!s_xLocaleData.get())
+            s_xLocaleData.set(LocaleData::create(m_xContext));
 
         // reset to UNKNOWN_RULE
         static_assert(OSQLParseNode::UNKNOWN_RULE==0, "UNKNOWN_RULE must be 0 
for memset to 0 to work");
@@ -1482,8 +1483,6 @@ OSQLParser::~OSQLParser()
 
         delete s_pGarbageCollector;
         s_pGarbageCollector = nullptr;
-        // Is only set the first time, so we should delete it only when there 
are no more instances
-        s_xLocaleData = nullptr;
 
         RuleIDMap().swap(s_aReverseRuleIDLookup);
     }
diff --git a/include/connectivity/sqlparse.hxx 
b/include/connectivity/sqlparse.hxx
index c3314c470c6b..15400c112240 100644
--- a/include/connectivity/sqlparse.hxx
+++ b/include/connectivity/sqlparse.hxx
@@ -25,6 +25,7 @@
 #include <connectivity/dbtoolsdllapi.hxx>
 #include <connectivity/sqlerror.hxx>
 #include <comphelper/singletonref.hxx>
+#include <vcl/lazydelete.hxx>
 
 #include <map>
 #include <memory>
@@ -138,7 +139,7 @@ namespace connectivity
         sal_Int32                   m_nDateFormatKey;
         css::uno::Reference< css::uno::XComponentContext >    m_xContext;
         css::uno::Reference< css::i18n::XCharacterClassification> m_xCharClass;
-        static css::uno::Reference< css::i18n::XLocaleData4>       
s_xLocaleData;
+        static vcl::DeleteOnDeinit<css::uno::Reference< 
css::i18n::XLocaleData4>> s_xLocaleData;
 
         // convert a string into double trim it to scale of _nscale and then 
transform it back to string
         OUString stringToDouble(const OUString& _rValue,sal_Int16 _nScale);

Reply via email to