SDL: include: Documented important SDL_begin_code symbols.

From 624a4d5f269802cc958721af9fda7e61d4b27927 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 19 Dec 2024 12:19:46 -0500
Subject: [PATCH] include: Documented important SDL_begin_code symbols.

---
 include/SDL3/SDL_begin_code.h | 232 ++++++++++++++++++++++++++++++++++
 1 file changed, 232 insertions(+)

diff --git a/include/SDL3/SDL_begin_code.h b/include/SDL3/SDL_begin_code.h
index 6c9116278e78a..5a089e5194131 100644
--- a/include/SDL3/SDL_begin_code.h
+++ b/include/SDL3/SDL_begin_code.h
@@ -36,6 +36,238 @@
 #endif
 #define SDL_begin_code_h
 
+#ifdef SDL_WIKI_DOCUMENTATION_SECTION
+
+/**
+ * A macro to tag a symbol as deprecated.
+ *
+ * A function is marked deprecated by adding this macro to its declaration:
+ *
+ * ```c
+ * extern SDL_DEPRECATED int ThisFunctionWasABadIdea(void);
+ * ```
+ *
+ * Compilers with deprecation support can give a warning when a deprecated
+ * function is used. This symbol may be used in SDL's headers, but apps are
+ * welcome to use it for their own interfaces as well.
+ *
+ * SDL, on occasion, might deprecate a function for various reasons. However,
+ * SDL never removes symbols before major versions, so deprecated interfaces
+ * in SDL3 will remain available under SDL4, where it would be expected an
+ * app would have to take steps to migrate anyhow.
+ *
+ * On compilers without a deprecation mechanism, this is defined to nothing,
+ * and using a deprecated function will not generate a warning.
+ *
+ * \since This macro is available since SDL 3.1.3.
+ */
+#define SDL_DEPRECATED __attribute__((deprecated))
+
+/**
+ * A macro to tag a symbol as a public API.
+ *
+ * SDL uses this macro for all its public functions. On some targets, it
+ * is used to signal to the compiler that this function needs to be exported
+ * from a shared library, but it might have other side effects.
+ *
+ * This symbol is used in SDL's headers, but apps and other libraries are
+ * welcome to use it for their own interfaces as well.
+ *
+ * \since This macro is available since SDL 3.1.3.
+ */
+#define SDL_DECLSPEC __attribute__ ((visibility("default")))
+
+/**
+ * A macro to set a function's calling conventions.
+ *
+ * SDL uses this macro for all its public functions, and any callbacks it
+ * defines. This macro guarantees that calling conventions match between
+ * SDL and the app, even if the two were built with different compilers
+ * or optimization settings.
+ *
+ * When writing a callback function, it is very important for it to be
+ * correctly tagged with SDLCALL, as mismatched calling conventions can
+ * cause strange behaviors and can be difficult to diagnose. Plus, on many
+ * platforms, SDLCALL is defined to nothing, so compilers won't be able to
+ * warn that the tag is missing.
+ *
+ * This symbol is used in SDL's headers, but apps and other libraries are
+ * welcome to use it for their own interfaces as well.
+ *
+ * \since This macro is available since SDL 3.1.3.
+ */
+#define SDLCALL __cdecl
+
+/**
+ * A macro to request a function be inlined.
+ *
+ * This is a hint to the compiler to inline a function. The compiler is free
+ * to ignore this request. On compilers without inline support, this is
+ * defined to nothing.
+ *
+ * \since This macro is available since SDL 3.1.3.
+ */
+#define SDL_INLINE __inline
+
+/**
+ * A macro to demand a function be inlined.
+ *
+ * This is a command to the compiler to inline a function. SDL uses this
+ * macro in its public headers for a handful of simple functions. On compilers
+ * without forceinline support, this is defined to `static SDL_INLINE`, which
+ * is often good enough.
+ *
+ * This symbol is used in SDL's headers, but apps and other libraries are
+ * welcome to use it for their own interfaces as well.
+ *
+ * \since This macro is available since SDL 3.1.3.
+ */
+#define SDL_FORCE_INLINE __forceinline
+
+/**
+ * A macro to tag a function as never-returning.
+ *
+ * This is a hint to the compiler that a function does not return. An example
+ * of a function like this is the C runtime's exit() function.
+ *
+ * This hint can lead to code optimizations, and help analyzers understand
+ * code flow better. On compilers without noreturn support, this is
+ * defined to nothing.
+ *
+ * This symbol is used in SDL's headers, but apps and other libraries are
+ * welcome to use it for their own interfaces as well.
+ *
+ * \since This macro is available since SDL 3.1.3.
+ */
+#define SDL_NORETURN __attribute__((noreturn))
+
+/**
+ * A macro to tag a function as never-returning (for analysis purposes).
+ *
+ * This is almost identical to SDL_NORETURN, except functions marked with this
+ * _can_ actually return. The difference is that this isn't used for code
+ * generation, but rather static analyzers use this information to assume
+ * truths about program state and available code paths. Specifically, this
+ * tag is useful for writing an assertion mechanism. Indeed, SDL_assert uses
+ * this tag behind the scenes. Generally, apps that don't understand the
+ * specific use-case for this tag should avoid using it directly.
+ *
+ * On compilers without analyzer_noreturn support, this is defined to nothing.
+ *
+ * This symbol is used in SDL's headers, but apps and other libraries are
+ * welcome to use it for their own interfaces as well.
+ *
+ * \since This macro is available since SDL 3.1.3.
+ */
+#define SDL_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
+
+
+/**
+ * A macro to signal that a case statement without a `break` is intentional.
+ *
+ * C compilers have gotten more aggressive about warning when a switch's
+ * `case` block does not end with a `break` or other flow control statement,
+ * flowing into the next case's code, as this is a common accident that leads
+ * to strange bugs. But sometimes falling through to the next case is the
+ * correct and desired behavior. This symbol lets an app communicate this
+ * intention to the compiler, so it doesn't generate a warning.
+ *
+ * It is used like this:
+ *
+ * ```c
+ * switch (x) {
+ *     case 1:
+ *         DoSomethingOnlyForOne();
+ *         SDL_FALLTHROUGH;  // tell the compiler this was intentional.
+ *     case 2:
+ *         DoSomethingForOneAndTwo();
+ *         break;
+ * }
+ * ```
+ *
+ * \since This macro is available since SDL 3.1.3.
+ */
+#define SDL_FALLTHROUGH [[fallthrough]]
+
+/**
+ * A macro to tag a function's return value as critical.
+ *
+ * This is a hint to the compiler that a function's return value should not
+ * be ignored.
+ *
+ * If an NODISCARD function's return value is thrown away (the function is
+ * called as if it returns `void`), the compiler will issue a warning.
+ *
+ * While it's generally good practice to check return values for errors,
+ * often times legitimate programs do not for good reasons. Be careful
+ * about what functions are tagged as NODISCARD. It operates best when
+ * used on a function that's failure is surprising and catastrophic; a good
+ * example would be a program that checks the return values of all its
+ * file write function calls but not the call to close the file, which it
+ * assumes incorrectly never fails.
+ *
+ * Function callers that want to throw away a NODISCARD return value can
+ * call the function with a `(void)` cast, which informs the compiler the
+ * act is intentional.
+ *
+ * On compilers without nodiscard support, this is defined to nothing.
+ *
+ * \since This macro is available since SDL 3.1.3.
+ */
+#define SDL_NODISCARD [[nodiscard]]
+
+/**
+ * A macro to tag a function as an allocator.
+ *
+ * This is a hint to the compiler that a function is an allocator, like
+ * malloc(), with certain rules. A description of how GCC treats this
+ * hint is here:
+ *
+ * https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-malloc-function-attribute
+ *
+ * On compilers without allocator tag support, this is defined to nothing.
+ *
+ * Most apps don't need to, and should not, use this directly.
+ *
+ * \since This macro is available since SDL 3.1.3.
+ */
+#define SDL_MALLOC __declspec(allocator) __desclspec(restrict)
+
+/**
+ * A macro to tag a function as returning a certain allocation.
+ *
+ * This is a hint to the compiler that a function allocates and returns a
+ * specific amount of memory based on one of its arguments.
+ * For example, the C runtime's malloc() function could use this macro
+ * with an argument of 1 (first argument to malloc is the size of the
+ * allocation).
+ *
+ * On compilers without alloc_size support, this is defined to nothing.
+ *
+ * Most apps don't need to, and should not, use this directly.
+ *
+ * \since This macro is available since SDL 3.1.3.
+ */
+#define SDL_ALLOC_SIZE(p) __attribute__((alloc_size(p)))
+
+/**
+ * A macro to tag a pointer variable, to help with pointer aliasing.
+ *
+ * A good explanation of the restrict keyword is here:
+ *
+ * https://en.wikipedia.org/wiki/Restrict
+ *
+ * On compilers without restrict support, this is defined to nothing.
+ *
+ * \since This macro is available since SDL 3.1.3.
+ */
+#define SDL_RESTRICT __restrict__
+
+/* end of wiki documentation section. */
+#endif
+
+
+
 #ifndef SDL_DEPRECATED
 #  if defined(__GNUC__) && (__GNUC__ >= 4)  /* technically, this arrived in gcc 3.1, but oh well. */
 #    define SDL_DEPRECATED __attribute__((deprecated))