SDL: Added SDL_GetGlobalProperties()

From 979214363fca0a7a07887ae2ae705c16085c8f6c Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 8 Nov 2023 11:55:04 -0800
Subject: [PATCH] Added SDL_GetGlobalProperties()

We'll undoubtedly want to have global properties available
---
 include/SDL3/SDL_properties.h     | 13 +++++++++++++
 src/SDL_properties.c              | 21 +++++++++++++++++++++
 src/dynapi/SDL_dynapi.sym         |  1 +
 src/dynapi/SDL_dynapi_overrides.h |  1 +
 src/dynapi/SDL_dynapi_procs.h     |  1 +
 5 files changed, 37 insertions(+)

diff --git a/include/SDL3/SDL_properties.h b/include/SDL3/SDL_properties.h
index 9a6ebf3152c1..588bdfc4ca49 100644
--- a/include/SDL3/SDL_properties.h
+++ b/include/SDL3/SDL_properties.h
@@ -39,6 +39,19 @@ extern "C" {
  */
 typedef Uint32 SDL_PropertiesID;
 
+/**
+ * Get the global SDL properties
+ *
+ * \returns a valid property ID on success or 0 on failure; call
+ *          SDL_GetError() for more information.
+ *
+ * \since This function is available since SDL 3.0.0.
+ *
+ * \sa SDL_GetProperty
+ * \sa SDL_SetProperty
+ */
+extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGlobalProperties(void);
+
 /**
  * Create a set of properties
  *
diff --git a/src/SDL_properties.c b/src/SDL_properties.c
index d0b9c60f17d7..49ae6866cdcc 100644
--- a/src/SDL_properties.c
+++ b/src/SDL_properties.c
@@ -39,6 +39,7 @@ typedef struct
 static SDL_HashTable *SDL_properties;
 static SDL_RWLock *SDL_properties_lock;
 static SDL_PropertiesID SDL_last_properties_id;
+static SDL_PropertiesID SDL_global_properties;
 
 
 static void SDL_FreeProperty(const void *key, const void *value, void *data)
@@ -81,11 +82,23 @@ int SDL_InitProperties(void)
             return -1;
         }
     }
+
+    /* Create the global properties here to avoid race conditions later */
+    if (!SDL_global_properties) {
+        SDL_global_properties = SDL_CreateProperties();
+        if (!SDL_global_properties) {
+            return -1;
+        }
+    }
     return 0;
 }
 
 void SDL_QuitProperties(void)
 {
+    if (SDL_global_properties) {
+        SDL_DestroyProperties(SDL_global_properties);
+        SDL_global_properties = 0;
+    }
     if (SDL_properties) {
         SDL_DestroyHashTable(SDL_properties);
         SDL_properties = NULL;
@@ -96,6 +109,14 @@ void SDL_QuitProperties(void)
     }
 }
 
+SDL_PropertiesID SDL_GetGlobalProperties(void)
+{
+    if (!SDL_properties && SDL_InitProperties() < 0) {
+        return 0;
+    }
+    return SDL_global_properties;
+}
+
 SDL_PropertiesID SDL_CreateProperties(void)
 {
     SDL_PropertiesID props = 0;
diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym
index 720591affbeb..e6fd996c6429 100644
--- a/src/dynapi/SDL_dynapi.sym
+++ b/src/dynapi/SDL_dynapi.sym
@@ -922,6 +922,7 @@ SDL3_0.0.0 {
     SDL_GetDisplayProperties;
     SDL_SetPropertyWithCleanup;
     SDL_SetX11EventHook;
+    SDL_GetGlobalProperties;
     # extra symbols go here (don't modify this line)
   local: *;
 };
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index a6c5440ca33d..97d05e88ba0b 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -947,3 +947,4 @@
 #define SDL_GetDisplayProperties SDL_GetDisplayProperties_REAL
 #define SDL_SetPropertyWithCleanup SDL_SetPropertyWithCleanup_REAL
 #define SDL_SetX11EventHook SDL_SetX11EventHook_REAL
+#define SDL_GetGlobalProperties SDL_GetGlobalProperties_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 3348c67a8f44..64022522244f 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -980,3 +980,4 @@ SDL_DYNAPI_PROC(void*,SDL_AllocateEventMemory,(size_t a),(a),return)
 SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetDisplayProperties,(SDL_DisplayID a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_SetPropertyWithCleanup,(SDL_PropertiesID a, const char *b, void *c, void (SDLCALL *d)(void *userdata, void *value), void *e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(void,SDL_SetX11EventHook,(SDL_X11EventHook a, void *b),(a,b),)
+SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetGlobalProperties,(void),(),return)