SDL: Use stdbool for SDL_bool

From f08ac438ed95dcdac2086f9bf84211d8ed6203a2 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 26 Aug 2024 16:49:57 -0700
Subject: [PATCH] Use stdbool for SDL_bool

This helps the compiler warn people when they're doing something like "if (SDL_Init(0) < 0)"
---
 cmake/test/main.swift     |  2 +-
 docs/README-migration.md  |  2 ++
 include/SDL3/SDL_stdinc.h | 10 +++++++---
 src/SDL_internal.h        | 10 ----------
 4 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/cmake/test/main.swift b/cmake/test/main.swift
index 7932a39cbbde4..1943f7c42b087 100644
--- a/cmake/test/main.swift
+++ b/cmake/test/main.swift
@@ -2,7 +2,7 @@
 
 import SDL3
 
-guard SDL_Init(SDL_INIT_VIDEO) != 0 else {
+guard SDL_Init(SDL_INIT_VIDEO) else {
   fatalError("SDL_Init error: \(String(cString: SDL_GetError()))")
 }
 
diff --git a/docs/README-migration.md b/docs/README-migration.md
index 63f0782581260..86bd110df1ba9 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -1696,6 +1696,8 @@ This header has been removed and a simplified version of this API has been added
 The standard C headers like stdio.h and stdlib.h are no longer included, you should include them directly in your project if you use non-SDL C runtime functions.
 M_PI is no longer defined in SDL_stdinc.h, you can use the new symbols SDL_PI_D (double) and SDL_PI_F (float) instead.
 
+SDL_bool is now defined as bool, and is 1 byte instead of the size of an int.
+
 SDL3 attempts to apply consistency to case-insensitive string functions. In SDL2, things like SDL_strcasecmp() would usually only work on English letters, and depending on the user's locale, possibly not even those. In SDL3, consistency is applied:
 
 - Many things that don't care about case-insensitivity, like SDL_strcmp(), continue to work with any null-terminated string of bytes, even if it happens to be malformed UTF-8.
diff --git a/include/SDL3/SDL_stdinc.h b/include/SDL3/SDL_stdinc.h
index 3436c4ab6c97c..ec09766081a0e 100644
--- a/include/SDL3/SDL_stdinc.h
+++ b/include/SDL3/SDL_stdinc.h
@@ -36,6 +36,9 @@
 #include <inttypes.h>
 #endif
 #include <stdarg.h>
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
 #include <stdint.h>
 #include <string.h>
 #include <wchar.h>
@@ -191,7 +194,7 @@ void *alloca(size_t);
  *
  * \sa SDL_bool
  */
-#define SDL_FALSE 0
+#define SDL_FALSE false
 
 /**
  * A boolean true.
@@ -200,7 +203,7 @@ void *alloca(size_t);
  *
  * \sa SDL_bool
  */
-#define SDL_TRUE 1
+#define SDL_TRUE true
 
 /**
  * A boolean type: true or false.
@@ -210,7 +213,7 @@ void *alloca(size_t);
  * \sa SDL_TRUE
  * \sa SDL_FALSE
  */
-typedef int SDL_bool;
+typedef bool SDL_bool;
 
 /**
  * A signed 8-bit integer type.
@@ -482,6 +485,7 @@ typedef Sint64 SDL_Time;
 
 /** \cond */
 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
+SDL_COMPILE_TIME_ASSERT(bool, sizeof(SDL_bool) == 1);
 SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
 SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
 SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
diff --git a/src/SDL_internal.h b/src/SDL_internal.h
index 469b050210dfe..c44f631fc6c1e 100644
--- a/src/SDL_internal.h
+++ b/src/SDL_internal.h
@@ -121,16 +121,6 @@
 #include <float.h>
 #endif
 
-#ifndef __cplusplus
-#ifdef HAVE_STDBOOL_H
-#include <stdbool.h>
-#else
-typedef int bool;
-#define true    1
-#define false   0
-#endif
-#endif // !__cplusplus
-
 // If you run into a warning that O_CLOEXEC is redefined, update the SDL configuration header for your platform to add HAVE_O_CLOEXEC
 #ifndef HAVE_O_CLOEXEC
 #define O_CLOEXEC 0