[Libreoffice-commits] core.git: sal/cppunittester sal/Executable_cppunittester.mk

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Sun May 24 08:29:34 UTC 2020


 sal/Executable_cppunittester.mk     |    4 ++++
 sal/cppunittester/cppunittester.cxx |   10 ++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

New commits:
commit 1126515226b60630b3a0fd72c45258b230dfe8fd
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sun May 24 09:18:10 2020 +0200
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun May 24 10:28:59 2020 +0200

    Try to blind-solve cppunittester hangs on Windows
    
    ... calling OleInitialize early in sal_main to initialize COM and concurrency.
    
    Seeing intermittent hangs in main thread in CAPNDataObject::GetData calling
    m_rIDataObjectOrg->GetData, and the inner stack waiting objects in the code
    doing apartment switching (I forgot to save a stack to paste unfortunately),
    I suspect that being related to incorrect concurrency model. OleInitialize
    docs [1] mention:
    
      Applications that use the following functionality must call OleInitialize
      before calling any other function in the COM library:
    
      * Clipboard
      * Drag and Drop
      * Object linking and embedding (OLE)
      * In-place activation
    
      ...
    
      Because OLE operations are not thread-safe, OleInitialize specifies the
      concurrency model as single-thread apartment.
    
    CoInitializeEx sets COINIT_MULTITHREADED by default, so possibly that might
    get called somewhere before clipboard/OLE code is called. I hope that this
    change would fix those hangs.
    
    [1] https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-oleinitialize
    
    Change-Id: I7213c9d6cb4bd0691a3ce355995157797d7db93f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94675
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sal/Executable_cppunittester.mk b/sal/Executable_cppunittester.mk
index 3b9016783b80..65426e722240 100644
--- a/sal/Executable_cppunittester.mk
+++ b/sal/Executable_cppunittester.mk
@@ -28,6 +28,10 @@ $(eval $(call gb_Executable_add_exception_objects,cppunittester,\
 	sal/cppunittester/cppunittester \
 ))
 
+$(eval $(call gb_Executable_use_system_win32_libs,cppunittester,\
+	ole32 \
+))
+
 ifeq ($(COM),MSC)
 
 $(eval $(call gb_Executable_add_ldflags,cppunittester,\
diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx
index a760ecf8ff41..1b3c518c4b21 100644
--- a/sal/cppunittester/cppunittester.cxx
+++ b/sal/cppunittester/cppunittester.cxx
@@ -18,10 +18,9 @@
  */
 
 #ifdef _WIN32
-#if !defined WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
-#endif
-#include <windows.h>
+#include <prewin.h>
+#include <ole2.h>
+#include <postwin.h>
 #endif
 
 #ifdef UNX
@@ -389,6 +388,9 @@ SAL_IMPLEMENT_MAIN()
         _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG|_CRTDBG_MODE_FILE);
         _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
 #endif
+
+        // Tests may use e.g. OLE or clipboard; initialize COM and appropriate concurrency early
+        OleInitialize(nullptr);
 #endif
 
         std::vector<CppUnit::Protector *> protectors;


More information about the Libreoffice-commits mailing list