sdl2-compat: vulkan: Updated SDL_Vulkan_GetInstanceExtensions to match latest SDL3.

From 15cdc96b81ff6baaa9a514def1f4bb8f948dad18 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 2 Nov 2023 15:36:32 -0400
Subject: [PATCH] vulkan: Updated SDL_Vulkan_GetInstanceExtensions to match
 latest SDL3.

---
 src/sdl2_compat.c | 45 +++++++++++++++++++++++++++++++++++++++++----
 src/sdl3_syms.h   |  2 +-
 2 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index bd71258..767e2ba 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -5056,12 +5056,49 @@ SDL_RenderCopyExF(SDL_Renderer *renderer, SDL_Texture *texture,
     return SDL3_RenderTextureRotated(renderer, texture, psrcfrect, dstrect, angle, center, flip);
 }
 
-/* SDL3 removed window parameter from SDL_Vulkan_GetInstanceExtensions() */
+/* this came out of SDL2 directly. */
+static SDL_bool SDL_Vulkan_GetInstanceExtensions_Helper(unsigned int *userCount,
+                                                 const char **userNames,
+                                                 unsigned int nameCount,
+                                                 const char *const *names)
+{
+    if (userNames) {
+        unsigned i;
+
+        if (*userCount < nameCount) {
+            SDL_SetError("Output array for SDL_Vulkan_GetInstanceExtensions needs to be at least %d big", nameCount);
+            return SDL_FALSE;
+        }
+
+        for (i = 0; i < nameCount; i++) {
+            userNames[i] = names[i];
+        }
+    }
+    *userCount = nameCount;
+    return SDL_TRUE;
+}
+
+
+/* SDL3 simplified SDL_Vulkan_GetInstanceExtensions() extensively. */
 DECLSPEC SDL_bool SDLCALL
-SDL_Vulkan_GetInstanceExtensions(SDL_Window *window, unsigned int *pCount, const char **pNames)
+SDL_Vulkan_GetInstanceExtensions(SDL_Window *window, unsigned int *puiCount, const char **pNames)
 {
-    (void) window;
-    return SDL3_Vulkan_GetInstanceExtensions(pCount, pNames);
+    Uint32 ui32count = 0;
+    char const* const* extensions = NULL;
+
+    (void) window;  /* Strictly speaking, SDL2 would report failure if this window was invalid, but we'll just go on until someone complains. */
+
+    if (puiCount == NULL) {
+        SDL3_InvalidParamError("count");
+        return SDL_FALSE;
+    }
+
+    extensions = SDL3_Vulkan_GetInstanceExtensions(&ui32count);
+    if (!extensions) {
+        return SDL_FALSE;
+    }
+
+    return SDL_Vulkan_GetInstanceExtensions_Helper(puiCount, pNames, (unsigned int) ui32count, extensions);
 }
 
 
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 36215ed..605617f 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -560,7 +560,7 @@ SDL3_SYM_PASSTHROUGH(SDL_Surface*,DuplicateSurface,(SDL_Surface *a),(a),return)
 SDL3_SYM_PASSTHROUGH(int,Vulkan_LoadLibrary,(const char *a),(a),return)
 SDL3_SYM_PASSTHROUGH(void*,Vulkan_GetVkGetInstanceProcAddr,(void),(),return)
 SDL3_SYM_PASSTHROUGH(void,Vulkan_UnloadLibrary,(void),(),)
-SDL3_SYM(SDL_bool,Vulkan_GetInstanceExtensions,(unsigned int *a, const char **b),(a,b),return)
+SDL3_SYM(char const* const* ,Vulkan_GetInstanceExtensions,(Uint32 *a),(a),return)
 SDL3_SYM_PASSTHROUGH(SDL_bool,Vulkan_CreateSurface,(SDL_Window *a, VkInstance b, VkSurfaceKHR *c),(a,b,c),return)
 SDL3_SYM_PASSTHROUGH(void,GetMemoryFunctions,(SDL_malloc_func *a, SDL_calloc_func *b, SDL_realloc_func *c, SDL_free_func *d),(a,b,c,d),)
 SDL3_SYM_PASSTHROUGH(int,SetMemoryFunctions,(SDL_malloc_func a, SDL_calloc_func b, SDL_realloc_func c, SDL_free_func d),(a,b,c,d),return)