desktop/source/app/sofficemain.cxx |   15 +++++++++++++--
 static/README.wasm.md              |    7 +++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

New commits:
commit 146fafa691e63de00d6030d88626833ab43d7a65
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Wed Aug 7 15:01:25 2024 +0200
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Wed Aug 7 17:18:34 2024 +0200

    I finally understand why we need that hack
    
    ...that 77129fbb74bcefde4551d494f029169e7c6026e3 "Emscripten: Add hack to
    prepare for --enable-wasm-exceptions" was puzzled about
    
    Change-Id: Iba54a77e3c2a71fe45b97795ca2da0606c3adf41
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171594
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>

diff --git a/desktop/source/app/sofficemain.cxx 
b/desktop/source/app/sofficemain.cxx
index 9470add3b488..bfa1a66d886a 100644
--- a/desktop/source/app/sofficemain.cxx
+++ b/desktop/source/app/sofficemain.cxx
@@ -75,8 +75,19 @@ extern "C" int DESKTOP_DLLPUBLIC soffice_main()
     tools::extendApplicationEnvironment();
 
 #if defined EMSCRIPTEN
-    //TODO, see "Experimental (AKA currently broken) WASM exception + SjLj 
build" in
-    // static/README.wasm.md:
+    //HACK: Qt5 QWasmEventDispatcher::processEvents
+    // (qtbase/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp) calls
+    // emscripten_set_main_loop_arg with simulateInfiniteLoop == true, and as 
we use
+    // -fwasm-exceptions (cf. solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk), 
aDesktop allocated on
+    // the stack would run into the issue warned about at
+    // 
<https://emscripten.org/docs/api_reference/emscripten.h.html#c.emscripten_set_main_loop>
+    // "Note: Currently, using the new Wasm exception handling and 
simulate_infinite_loop == true at
+    // the same time does not work yet in C++ projects that have objects with 
destructors on the
+    // stack at the time of the call."  (Also see the mailing list thread at
+    // <https://groups.google.com/g/emscripten-discuss/c/xpWDVwyJu-M> 
"Implementation of
+    // -fexceptions and -fwasm-exceptions" for why such automatic variables 
are destroyed with
+    // -fwasm-exceptions but not with -fexceptions.)  So deliberately leak the 
Desktop instance
+    // here:
     new desktop::Desktop();
 #else
     desktop::Desktop aDesktop;
diff --git a/static/README.wasm.md b/static/README.wasm.md
index cb5d0aa7fc3e..de595b19b459 100644
--- a/static/README.wasm.md
+++ b/static/README.wasm.md
@@ -69,6 +69,13 @@ With "-opensource -confirm-license" you agree to the open 
source license.
     ./configure -opensource -confirm-license -xplatform wasm-emscripten 
-feature-thread -prefix <whatever> QMAKE_CFLAGS+=-sSUPPORT_LONGJMP=wasm 
QMAKE_CXXFLAGS+=-sSUPPORT_LONGJMP=wasm
     make -j<CORES> module-qtbase
 
+Do not include `-fwasm-exceptions` in the above `QMAKE_CXXFLAGS`, see
+<https://emscripten.org/docs/api_reference/emscripten.h.html#c.emscripten_set_main_loop>
 "Note:
+Currently, using the new Wasm exception handling and simulate_infinite_loop == 
true at the same time
+does not work yet in C++ projects that have objects with destructors on the 
stack at the time of the
+call."  (Also see the EMSCRIPTEN-specific HACK in soffice_main, 
desktop/source/app/sofficemain.cxx,
+for what we need to do to work around that.)
+
 Optionally you can add the configure flag "-compile-examples". But then you 
also have to
 patch at least mkspecs/wasm-emscripten/qmake.conf with EXIT_RUNTIME=0, 
otherwise they will
 fail to run. In addition, building with examples will break with some of them, 
but at that

Reply via email to