From 2708e08f40933d57aee0ba5f3406f1f75f3d9f55 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carl=20=C3=85stholm?= <[EMAIL REDACTED]>
Date: Sun, 16 Mar 2025 18:43:19 +0100
Subject: [PATCH] emscripten: Don't use legacy JS library functions for
assertions
(cherry picked from commit 54f5b73333c6fb067af37f976718a5fef8890931)
(cherry picked from commit a8f0eb4c330526d48dc40f611eb4f2881f32fa3a)
---
src/SDL_assert.c | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/src/SDL_assert.c b/src/SDL_assert.c
index 76c7491fa7dce..99a376e948ca8 100644
--- a/src/SDL_assert.c
+++ b/src/SDL_assert.c
@@ -42,15 +42,7 @@
#endif
#if defined(__EMSCRIPTEN__)
- #include <emscripten.h>
- /* older Emscriptens don't have this, but we need to for wasm64 compatibility. */
- #ifndef MAIN_THREAD_EM_ASM_PTR
- #ifdef __wasm64__
- #error You need to upgrade your Emscripten compiler to support wasm64
- #else
- #define MAIN_THREAD_EM_ASM_PTR MAIN_THREAD_EM_ASM_INT
- #endif
- #endif
+#include <emscripten.h>
#endif
/* The size of the stack buffer to use for rendering assert messages. */
@@ -259,7 +251,7 @@ static SDL_assert_state SDLCALL SDL_PromptAssertion(const SDL_assert_data *data,
for (;;) {
SDL_bool okay = SDL_TRUE;
/* *INDENT-OFF* */ /* clang-format off */
- char *buf = (char *) MAIN_THREAD_EM_ASM_PTR({
+ int reply = MAIN_THREAD_EM_ASM_INT({
var str =
UTF8ToString($0) + '\n\n' +
'Abort/Retry/Ignore/AlwaysIgnore? [ariA] :';
@@ -267,26 +259,31 @@ static SDL_assert_state SDLCALL SDL_PromptAssertion(const SDL_assert_data *data,
if (reply === null) {
reply = "i";
}
- return allocate(intArrayFromString(reply), 'i8', ALLOC_NORMAL);
+ return reply.length === 1 ? reply.charCodeAt(0) : -1;
}, message);
/* *INDENT-ON* */ /* clang-format on */
- if (SDL_strcmp(buf, "a") == 0) {
+ switch (reply) {
+ case 'a':
state = SDL_ASSERTION_ABORT;
#if 0 /* (currently) no break functionality on Emscripten */
- } else if (SDL_strcmp(buf, "b") == 0) {
+ case 'b':
state = SDL_ASSERTION_BREAK;
+ break;
#endif
- } else if (SDL_strcmp(buf, "r") == 0) {
+ case 'r':
state = SDL_ASSERTION_RETRY;
- } else if (SDL_strcmp(buf, "i") == 0) {
+ break;
+ case 'i':
state = SDL_ASSERTION_IGNORE;
- } else if (SDL_strcmp(buf, "A") == 0) {
+ break;
+ case 'A':
state = SDL_ASSERTION_ALWAYS_IGNORE;
- } else {
+ break;
+ default:
okay = SDL_FALSE;
+ break;
}
- free(buf);
if (okay) {
break;