From c101e719fd32f2062320d526b783cd390263896b Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Wed, 12 Apr 2023 11:07:28 +0200
Subject: [PATCH] testprogram: let main() return normally, don't exit for
platform (eg Android) where there is some cleanup afterward.
---
test/checkkeys.c | 5 ++++-
test/checkkeysthreads.c | 5 ++++-
test/loopwave.c | 5 ++++-
test/loopwavequeue.c | 5 ++++-
test/testaudiohotplug.c | 5 ++++-
test/testautomation.c | 5 ++++-
test/testcustomcursor.c | 5 ++++-
test/testdropfile.c | 5 ++++-
test/testerror.c | 5 ++++-
test/testgeometry.c | 5 ++++-
test/testgl.c | 5 ++++-
test/testgles.c | 5 ++++-
test/testgles2.c | 5 ++++-
test/testgles2_sdf.c | 5 ++++-
test/testlock.c | 7 +++++--
test/testmessage.c | 5 ++++-
test/testnative.c | 5 ++++-
test/testoverlay.c | 4 ++--
test/testpopup.c | 13 ++++++++-----
test/testrendercopyex.c | 5 ++++-
test/testrendertarget.c | 5 ++++-
test/testscale.c | 5 ++++-
test/testsem.c | 2 +-
test/testsprite.c | 4 +---
test/testspriteminimal.c | 5 ++++-
test/teststreaming.c | 7 +++++--
test/testthread.c | 7 +++++--
test/testviewport.c | 5 ++++-
test/testvulkan.c | 5 ++++-
test/testwm.c | 5 ++++-
test/torturethread.c | 5 ++++-
31 files changed, 123 insertions(+), 41 deletions(-)
diff --git a/test/checkkeys.c b/test/checkkeys.c
index bc4d7f12629f..89bae8eeee32 100644
--- a/test/checkkeys.c
+++ b/test/checkkeys.c
@@ -35,7 +35,10 @@ static void
quit(int rc)
{
SDL_Quit();
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void
diff --git a/test/checkkeysthreads.c b/test/checkkeysthreads.c
index 23b93ebeae6b..f245bc96550a 100644
--- a/test/checkkeysthreads.c
+++ b/test/checkkeysthreads.c
@@ -33,7 +33,10 @@ static void
quit(int rc)
{
SDL_Quit();
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void
diff --git a/test/loopwave.c b/test/loopwave.c
index 7ebb01477d67..ac5f84d3522a 100644
--- a/test/loopwave.c
+++ b/test/loopwave.c
@@ -41,7 +41,10 @@ static void
quit(int rc)
{
SDL_Quit();
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void
diff --git a/test/loopwavequeue.c b/test/loopwavequeue.c
index b28c6a8fcb94..e8c4daaabdc0 100644
--- a/test/loopwavequeue.c
+++ b/test/loopwavequeue.c
@@ -40,7 +40,10 @@ static void
quit(int rc)
{
SDL_Quit();
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static int done = 0;
diff --git a/test/testaudiohotplug.c b/test/testaudiohotplug.c
index 333823cb0425..61047a562046 100644
--- a/test/testaudiohotplug.c
+++ b/test/testaudiohotplug.c
@@ -42,7 +42,10 @@ quit(int rc)
{
SDL_Quit();
SDLTest_CommonDestroyState(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void SDLCALL
diff --git a/test/testautomation.c b/test/testautomation.c
index a017f481935f..dab400902ae3 100644
--- a/test/testautomation.c
+++ b/test/testautomation.c
@@ -52,7 +52,10 @@ static void
quit(int rc)
{
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
int main(int argc, char *argv[])
diff --git a/test/testcustomcursor.c b/test/testcustomcursor.c
index 9438613a6967..12d54208caad 100644
--- a/test/testcustomcursor.c
+++ b/test/testcustomcursor.c
@@ -144,7 +144,10 @@ static void
quit(int rc)
{
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void loop(void)
diff --git a/test/testdropfile.c b/test/testdropfile.c
index bb85afb50ec0..acb016122f6e 100644
--- a/test/testdropfile.c
+++ b/test/testdropfile.c
@@ -22,7 +22,10 @@ static void
quit(int rc)
{
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
int main(int argc, char *argv[])
diff --git a/test/testerror.c b/test/testerror.c
index 0b3c6541c75c..b52c206c8afd 100644
--- a/test/testerror.c
+++ b/test/testerror.c
@@ -25,7 +25,10 @@ static void
quit(int rc)
{
SDL_Quit();
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static int SDLCALL
diff --git a/test/testgeometry.c b/test/testgeometry.c
index e262ace8a22b..d494d95607ba 100644
--- a/test/testgeometry.c
+++ b/test/testgeometry.c
@@ -38,7 +38,10 @@ quit(int rc)
{
SDL_free(sprites);
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static int LoadSprite(const char *file)
diff --git a/test/testgl.c b/test/testgl.c
index 21617c1bdbce..5cd03f9c1484 100644
--- a/test/testgl.c
+++ b/test/testgl.c
@@ -65,7 +65,10 @@ static void quit(int rc)
SDL_GL_DeleteContext(context);
}
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void Render(void)
diff --git a/test/testgles.c b/test/testgles.c
index ecaa9d251ca9..0afae5428e52 100644
--- a/test/testgles.c
+++ b/test/testgles.c
@@ -43,7 +43,10 @@ quit(int rc)
}
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void
diff --git a/test/testgles2.c b/test/testgles2.c
index 7ea006992f42..b4ed5fe3c269 100644
--- a/test/testgles2.c
+++ b/test/testgles2.c
@@ -100,7 +100,10 @@ quit(int rc)
}
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
#define GL_CHECK(x) \
diff --git a/test/testgles2_sdf.c b/test/testgles2_sdf.c
index 771091b4ca60..f0396bdb01e2 100644
--- a/test/testgles2_sdf.c
+++ b/test/testgles2_sdf.c
@@ -102,7 +102,10 @@ quit(int rc)
}
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
#define GL_CHECK(x) \
diff --git a/test/testlock.c b/test/testlock.c
index dd9c942e77c2..e9fd8bf22c3f 100644
--- a/test/testlock.c
+++ b/test/testlock.c
@@ -65,7 +65,10 @@ static void closemutex(int sig)
threads = NULL;
}
SDL_DestroyMutex(mutex);
- exit(sig);
+ /* Let 'main()' return normally */
+ if (sig != 0) {
+ exit(sig);
+ }
}
static int SDLCALL
@@ -100,7 +103,7 @@ Run(void *data)
}
#ifndef _WIN32
-Uint32 hit_timeout(Uint32 interval, void *param) {
+static Uint32 hit_timeout(Uint32 interval, void *param) {
SDL_Log("Hit timeout! Sending SIGINT!");
kill(0, SIGINT);
return 0;
diff --git a/test/testmessage.c b/test/testmessage.c
index 587a110adcf1..c490787d318c 100644
--- a/test/testmessage.c
+++ b/test/testmessage.c
@@ -23,7 +23,10 @@ static void
quit(int rc)
{
SDL_Quit();
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static int SDLCALL
diff --git a/test/testnative.c b/test/testnative.c
index a58ce3ad50a3..ef587ede7729 100644
--- a/test/testnative.c
+++ b/test/testnative.c
@@ -52,7 +52,10 @@ quit(int rc)
factory->DestroyNativeWindow(native_window);
}
SDLTest_CommonDestroyState(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void MoveSprites(SDL_Renderer *renderer, SDL_Texture *sprite)
diff --git a/test/testoverlay.c b/test/testoverlay.c
index 6b9adefa5e69..abd97c40ab17 100644
--- a/test/testoverlay.c
+++ b/test/testoverlay.c
@@ -176,9 +176,9 @@ quit(int rc)
SDLTest_CommonQuit(state);
-
+ /* Let 'main()' return normally */
if (rc != 0) {
- exit(rc);
+ exit(rc);
}
}
diff --git a/test/testpopup.c b/test/testpopup.c
index 47502364206b..6ce0b0bd58dd 100644
--- a/test/testpopup.c
+++ b/test/testpopup.c
@@ -47,8 +47,8 @@ struct PopupWindow
int idx;
};
-struct PopupWindow *menus;
-struct PopupWindow tooltip;
+static struct PopupWindow *menus;
+static struct PopupWindow tooltip;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void quit(int rc)
@@ -57,7 +57,10 @@ static void quit(int rc)
menus = NULL;
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static int get_menu_index_by_window(SDL_Window *window)
@@ -115,7 +118,7 @@ static SDL_bool create_popup(struct PopupWindow *new_popup, SDL_bool is_menu)
return SDL_FALSE;
}
-static void close_popups()
+static void close_popups(void)
{
int i;
@@ -135,7 +138,7 @@ static void close_popups()
}
}
-static void loop()
+static void loop(void)
{
int i;
char fmt_str[128];
diff --git a/test/testrendercopyex.c b/test/testrendercopyex.c
index 4c166a4189ec..ffb522957e32 100644
--- a/test/testrendercopyex.c
+++ b/test/testrendercopyex.c
@@ -41,7 +41,10 @@ static void
quit(int rc)
{
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void Draw(DrawState *s)
diff --git a/test/testrendertarget.c b/test/testrendertarget.c
index 19b07fba25b5..abaf09c66b1c 100644
--- a/test/testrendertarget.c
+++ b/test/testrendertarget.c
@@ -42,7 +42,10 @@ static void
quit(int rc)
{
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static SDL_bool
diff --git a/test/testscale.c b/test/testscale.c
index 1fa2975b21b5..16acb3f83790 100644
--- a/test/testscale.c
+++ b/test/testscale.c
@@ -41,7 +41,10 @@ static void
quit(int rc)
{
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void Draw(DrawState *s)
diff --git a/test/testsem.c b/test/testsem.c
index 0010fcd13445..a1706ca8431d 100644
--- a/test/testsem.c
+++ b/test/testsem.c
@@ -256,7 +256,7 @@ int main(int argc, char **argv)
{
int arg_count = 0;
int i;
- int init_sem;
+ int init_sem = 0;
SDLTest_CommonState *state;
/* Initialize test framework */
diff --git a/test/testsprite.c b/test/testsprite.c
index d1cbac14ac4c..68b3b7b2db6f 100644
--- a/test/testsprite.c
+++ b/test/testsprite.c
@@ -57,9 +57,7 @@ quit(int rc)
SDL_free(positions);
SDL_free(velocities);
SDLTest_CommonQuit(state);
- /* If rc is 0, just let main return normally rather than calling exit.
- * This allows testing of platforms where SDL_main is required and does meaningful cleanup.
- */
+ /* Let 'main()' return normally */
if (rc != 0) {
exit(rc);
}
diff --git a/test/testspriteminimal.c b/test/testspriteminimal.c
index 7a837de1b44d..b58d21d6eff6 100644
--- a/test/testspriteminimal.c
+++ b/test/testspriteminimal.c
@@ -40,7 +40,10 @@ static void
quit(int rc)
{
SDL_Quit();
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void MoveSprites(void)
diff --git a/test/teststreaming.c b/test/teststreaming.c
index 4c649964948e..dcd5b4423ee9 100644
--- a/test/teststreaming.c
+++ b/test/teststreaming.c
@@ -64,13 +64,16 @@ static SDL_Renderer *renderer;
static int frame;
static SDL_Texture *MooseTexture;
static SDL_bool done = SDL_FALSE;
-SDLTest_CommonState *state;
+static SDLTest_CommonState *state;
static void quit(int rc)
{
SDL_Quit();
SDLTest_CommonDestroyState(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void UpdateTexture(SDL_Texture *texture)
diff --git a/test/testthread.c b/test/testthread.c
index 15297e320aed..78560f92860c 100644
--- a/test/testthread.c
+++ b/test/testthread.c
@@ -22,7 +22,7 @@
static SDL_TLSID tls;
static int alive = 0;
static int testprio = 0;
-SDLTest_CommonState *state;
+static SDLTest_CommonState *state;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
@@ -30,7 +30,10 @@ quit(int rc)
{
SDLTest_CommonDestroyState(state);
SDL_Quit();
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static const char *
diff --git a/test/testviewport.c b/test/testviewport.c
index 004f3f047518..006d3c2442ab 100644
--- a/test/testviewport.c
+++ b/test/testviewport.c
@@ -38,7 +38,10 @@ static void
quit(int rc)
{
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void DrawOnViewport(SDL_Renderer *renderer)
diff --git a/test/testvulkan.c b/test/testvulkan.c
index 8eb98c986bea..dede60e94cbe 100644
--- a/test/testvulkan.c
+++ b/test/testvulkan.c
@@ -187,7 +187,10 @@ static void quit(int rc)
{
shutdownVulkan(SDL_TRUE);
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static void loadGlobalFunctions(void)
diff --git a/test/testwm.c b/test/testwm.c
index 66a0df4fb3f8..8066aa3af3d0 100644
--- a/test/testwm.c
+++ b/test/testwm.c
@@ -47,7 +47,10 @@ static void
quit(int rc)
{
SDLTest_CommonQuit(state);
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
/* Draws the modes menu, and stores the mode index under the mouse in highlighted_mode */
diff --git a/test/torturethread.c b/test/torturethread.c
index 4b8eeba5a760..c2a0dd1a8186 100644
--- a/test/torturethread.c
+++ b/test/torturethread.c
@@ -28,7 +28,10 @@ static void
quit(int rc)
{
SDL_Quit();
- exit(rc);
+ /* Let 'main()' return normally */
+ if (rc != 0) {
+ exit(rc);
+ }
}
static int SDLCALL