include/vcl/lok.hxx      |    1 +
 vcl/headless/svpinst.cxx |    9 +++++----
 vcl/source/app/svapp.cxx |   15 ++++++++++++++-
 3 files changed, 20 insertions(+), 5 deletions(-)

New commits:
commit 6a95ebee89aa941ee1a30476997f07eb99acc00b
Author:     Tor Lillqvist <t...@collabora.com>
AuthorDate: Tue May 14 13:34:46 2019 +0300
Commit:     Michael Meeks <michael.me...@collabora.com>
CommitDate: Tue May 14 13:54:21 2019 +0200

    Introduce vcl::lok::unregisterPollCallbacks() and clarify isUnipoll()
    
    There was a problem in the iOS app where a callback was done passing a
    registered mpPollClosure that pointed to the mainKit variable in
    lokit_main() even though that variable had already gone out of scope
    and been destructed.
    
    Introduce unregisterPollCallbacks(), which just sets the mpPollClosure
    pointer to null. That means no callbacks should be done any more. It
    does not mean that Unipoll would not be active. Change isUnipoll() to
    look at whether the mpPollCallback pointer has been set or not.
    
    Change-Id: I5d5527c0ef097682679371dc642f8896ff05450d
    Reviewed-on: https://gerrit.libreoffice.org/72283
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>
    Tested-by: Michael Meeks <michael.me...@collabora.com>

diff --git a/include/vcl/lok.hxx b/include/vcl/lok.hxx
index 2dbc0443d7b7..7fc5479a25cd 100644
--- a/include/vcl/lok.hxx
+++ b/include/vcl/lok.hxx
@@ -21,6 +21,7 @@ namespace lok
 bool VCL_DLLPUBLIC isUnipoll();
 void VCL_DLLPUBLIC registerPollCallbacks(LibreOfficeKitPollCallback 
pPollCallback,
                                          LibreOfficeKitWakeCallback 
pWakeCallback, void* pData);
+void VCL_DLLPUBLIC unregisterPollCallbacks();
 }
 }
 
diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx
index 7161521624d9..487e6ddf3881 100644
--- a/vcl/headless/svpinst.cxx
+++ b/vcl/headless/svpinst.cxx
@@ -27,6 +27,7 @@
 #include <sal/types.h>
 
 #include <vcl/inputtypes.hxx>
+#include <vcl/lok.hxx>
 #ifndef LIBO_HEADLESS
 # include <vcl/opengl/OpenGLContext.hxx>
 #endif
@@ -165,7 +166,7 @@ void SvpSalInstance::Wakeup(SvpRequest const request)
 
     ImplSVData* pSVData = ImplGetSVData();
 
-    if (pSVData->mpWakeCallback)
+    if (pSVData->mpWakeCallback && pSVData->mpPollClosure)
         pSVData->mpWakeCallback(pSVData->mpPollClosure);
 
     SvpSalYieldMutex *const 
pMutex(static_cast<SvpSalYieldMutex*>(mpSalYieldMutex.get()));
@@ -354,8 +355,7 @@ sal_uInt32 SvpSalYieldMutex::doRelease(bool const 
bUnlockAll)
         nCount = comphelper::GenericSolarMutex::doRelease( bUnlockAll );
         if (isReleased)
         {
-            ImplSVData* pSVData = ImplGetSVData();
-            if (pSVData->mpPollCallback) // is unipoll
+            if (vcl::lok::isUnipoll())
             {
                 if (pInst)
                     pInst->Wakeup(SvpRequest::NONE);
@@ -450,7 +450,8 @@ bool SvpSalInstance::DoYield(bool bWait, bool 
bHandleAllCurrentEvents)
                     nTimeoutMS = 5000;
 
                 // External poll.
-                if (pSVData->mpPollCallback(pSVData->mpPollClosure, nTimeoutMS 
* 1000 /* us */) < 0)
+                if (pSVData->mpPollClosure != nullptr &&
+                    pSVData->mpPollCallback(pSVData->mpPollClosure, nTimeoutMS 
* 1000 /* us */) < 0)
                     pSVData->maAppData.mbAppQuit = true;
             }
             else
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index ea094534833e..ceeaada7da58 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -1727,10 +1727,23 @@ void registerPollCallbacks(
     }
 }
 
+void unregisterPollCallbacks()
+{
+    ImplSVData * pSVData = ImplGetSVData();
+    if (pSVData)
+    {
+        // Just set mpPollClosure to null as that is what calling this means, 
that the callback data
+        // points to an object that no longer exists. In particular, don't set
+        // pSVData->mpPollCallback to nullptr as that is used to detect 
whether Unipoll is in use in
+        // isUnipoll().
+        pSVData->mpPollClosure = nullptr;
+    }
+}
+
 bool isUnipoll()
 {
     ImplSVData * pSVData = ImplGetSVData();
-    return pSVData && pSVData->mpPollClosure != nullptr;
+    return pSVData && pSVData->mpPollCallback != nullptr;
 }
 
 } } // namespace lok, namespace vcl
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to