Browse Source

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.
pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
25ebe436f1
  1. 3
      doc/changelog.dox
  2. 8
      src/Magnum/Platform/EmscriptenApplication.cpp
  3. 8
      src/Magnum/Platform/Sdl2Application.cpp

3
doc/changelog.dox

@ -945,6 +945,9 @@ See also:
[mosra/toolchains#13](https://github.com/mosra/toolchains/issues/13), [mosra/toolchains#13](https://github.com/mosra/toolchains/issues/13),
[mosra/toolchains#14](https://github.com/mosra/toolchains/pull/14) and [mosra/toolchains#14](https://github.com/mosra/toolchains/pull/14) and
[mosra/magnum#490](https://github.com/mosra/magnum/issues/490). [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 @subsection changelog-latest-bugfixes Bug fixes

8
src/Magnum/Platform/EmscriptenApplication.cpp

@ -486,11 +486,7 @@ void EmscriptenApplication::setContainerCssClass(const Containers::StringView cs
EM_ASM_({ EM_ASM_({
/* Handle also the classic #container for backwards compatibility. We /* Handle also the classic #container for backwards compatibility. We
also need to preserve the mn-container otherwise next time we'd have also need to preserve the mn-container otherwise next time we'd have
no way to look for it anymore. 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. */
(Module['canvas'].closest('.mn-container') || (Module['canvas'].closest('.mn-container') ||
document.getElementById('container')).className = (['mn-container', UTF8ToString($0, $1)]).join(' '); document.getElementById('container')).className = (['mn-container', UTF8ToString($0, $1)]).join(' ');
}, cssClass.data(), cssClass.size()); }, cssClass.data(), cssClass.size());
@ -745,7 +741,7 @@ void EmscriptenApplication::setCursor(Cursor cursor) {
CORRADE_INTERNAL_ASSERT(UnsignedInt(cursor) < Containers::arraySize(CursorMap)); CORRADE_INTERNAL_ASSERT(UnsignedInt(cursor) < Containers::arraySize(CursorMap));
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension" #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 #pragma GCC diagnostic pop
} }

8
src/Magnum/Platform/Sdl2Application.cpp

@ -771,11 +771,7 @@ void Sdl2Application::setContainerCssClass(const Containers::StringView cssClass
EM_ASM_({ EM_ASM_({
/* Handle also the classic #container for backwards compatibility. We /* Handle also the classic #container for backwards compatibility. We
also need to preserve the mn-container otherwise next time we'd have also need to preserve the mn-container otherwise next time we'd have
no way to look for it anymore. 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. */
(Module['canvas'].closest('.mn-container') || (Module['canvas'].closest('.mn-container') ||
document.getElementById('container')).className = (['mn-container', UTF8ToString($0, $1)]).join(' '); document.getElementById('container')).className = (['mn-container', UTF8ToString($0, $1)]).join(' ');
}, cssClass.data(), cssClass.size()); }, cssClass.data(), cssClass.size());
@ -1122,7 +1118,7 @@ void Sdl2Application::setCursor(Cursor cursor) {
CORRADE_INTERNAL_ASSERT(UnsignedInt(cursor) < Containers::arraySize(CursorMap)); CORRADE_INTERNAL_ASSERT(UnsignedInt(cursor) < Containers::arraySize(CursorMap));
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension" #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 #pragma GCC diagnostic pop
#endif #endif
} }

Loading…
Cancel
Save