From 25ebe436f1984c3992a9d24b138ede33f5683d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Sep 2023 14:51:47 +0200 Subject: [PATCH] Platform: use UTF8ToString instead of AsciiToString on Emscripten. AsciiToString is not included by default on 3.1.21+ and including it is basically impossible on the library side because I don't think they fixed the case of supplying multiple DEFAULT_LIBRARY_FUNCS_TO_INCLUDE options on the command line in order to concatenate those lists yet. Also, given that UTF8ToString is probably already used in other places since it's included by default, using AsciiToString would only mean inflating the JS code. --- doc/changelog.dox | 3 +++ src/Magnum/Platform/EmscriptenApplication.cpp | 8 ++------ src/Magnum/Platform/Sdl2Application.cpp | 8 ++------ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 2b2b2b921..e1fd41708 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -945,6 +945,9 @@ See also: [mosra/toolchains#13](https://github.com/mosra/toolchains/issues/13), [mosra/toolchains#14](https://github.com/mosra/toolchains/pull/14) and [mosra/magnum#490](https://github.com/mosra/magnum/issues/490). +- @ref Platform::Sdl2Application and @ref Platform::EmscriptenApplication now + use `UTF8ToString` instead of `AsciiToString` as the latter is no longer + included by default on Emscripten 3.1.21+ (see [mosra/magnum#619](https://github.com/mosra/magnum/issues/619)). @subsection changelog-latest-bugfixes Bug fixes diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp index 2f6c822f6..4af13d7a9 100644 --- a/src/Magnum/Platform/EmscriptenApplication.cpp +++ b/src/Magnum/Platform/EmscriptenApplication.cpp @@ -486,11 +486,7 @@ void EmscriptenApplication::setContainerCssClass(const Containers::StringView cs EM_ASM_({ /* Handle also the classic #container for backwards compatibility. We also need to preserve the mn-container otherwise next time we'd have - no way to look for it anymore. - - Using UTF8ToString() instead of AsciiToString() as it has an - explicit size parameter and thus doesn't need a null-terminated - input, which would potentially require yet another allocation. */ + no way to look for it anymore. */ (Module['canvas'].closest('.mn-container') || document.getElementById('container')).className = (['mn-container', UTF8ToString($0, $1)]).join(' '); }, cssClass.data(), cssClass.size()); @@ -745,7 +741,7 @@ void EmscriptenApplication::setCursor(Cursor cursor) { CORRADE_INTERNAL_ASSERT(UnsignedInt(cursor) < Containers::arraySize(CursorMap)); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension" - EM_ASM_({Module['canvas'].style.cursor = AsciiToString($0);}, CursorMap[UnsignedInt(cursor)]); + EM_ASM_({Module['canvas'].style.cursor = UTF8ToString($0);}, CursorMap[UnsignedInt(cursor)]); #pragma GCC diagnostic pop } diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index 7407a8b2d..cab1cc188 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -771,11 +771,7 @@ void Sdl2Application::setContainerCssClass(const Containers::StringView cssClass EM_ASM_({ /* Handle also the classic #container for backwards compatibility. We also need to preserve the mn-container otherwise next time we'd have - no way to look for it anymore. - - Using UTF8ToString() instead of AsciiToString() as it has an - explicit size parameter and thus doesn't need a null-terminated - input, which would potentially require yet another allocation. */ + no way to look for it anymore. */ (Module['canvas'].closest('.mn-container') || document.getElementById('container')).className = (['mn-container', UTF8ToString($0, $1)]).join(' '); }, cssClass.data(), cssClass.size()); @@ -1122,7 +1118,7 @@ void Sdl2Application::setCursor(Cursor cursor) { CORRADE_INTERNAL_ASSERT(UnsignedInt(cursor) < Containers::arraySize(CursorMap)); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension" - EM_ASM_({Module['canvas'].style.cursor = AsciiToString($0);}, CursorMap[UnsignedInt(cursor)]); + EM_ASM_({Module['canvas'].style.cursor = UTF8ToString($0);}, CursorMap[UnsignedInt(cursor)]); #pragma GCC diagnostic pop #endif }