From 2d3fa03d53b419bed2647cab2574ae27e9889586 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 17 Oct 2024 09:23:52 -0700
Subject: [PATCH] Use the correct return type for SDL_GetAndroidJNIEnv()
This prevents application code from having to cast to JNIEnv everywhere.
---
include/SDL3/SDL_system.h | 9 ++++++++-
src/core/SDL_core_unsupported.c | 4 ++--
src/core/android/SDL_android.c | 2 +-
src/dynapi/SDL_dynapi_procs.h | 2 +-
4 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/include/SDL3/SDL_system.h b/include/SDL3/SDL_system.h
index e283233dc502f..eee8ee2c540a2 100644
--- a/include/SDL3/SDL_system.h
+++ b/include/SDL3/SDL_system.h
@@ -261,6 +261,13 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetiOSEventPump(bool enabled);
/*
* Platform specific functions for Android
*/
+
+#if defined(__cplusplus)
+typedef struct _JNIEnv JNIEnv;
+#else
+typedef const struct JNINativeInterface* JNIEnv;
+#endif
+
#ifdef SDL_PLATFORM_ANDROID
/**
@@ -283,7 +290,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetiOSEventPump(bool enabled);
*
* \sa SDL_GetAndroidActivity
*/
-extern SDL_DECLSPEC void * SDLCALL SDL_GetAndroidJNIEnv(void);
+extern SDL_DECLSPEC JNIEnv * SDLCALL SDL_GetAndroidJNIEnv(void);
/**
* Retrieve the Java instance of the Android activity class.
diff --git a/src/core/SDL_core_unsupported.c b/src/core/SDL_core_unsupported.c
index b36c7f7441ec7..54fa095a85bdc 100644
--- a/src/core/SDL_core_unsupported.c
+++ b/src/core/SDL_core_unsupported.c
@@ -146,8 +146,8 @@ const char *SDL_GetAndroidInternalStoragePath(void)
return NULL;
}
-SDL_DECLSPEC void *SDLCALL SDL_GetAndroidJNIEnv(void);
-void *SDL_GetAndroidJNIEnv(void)
+SDL_DECLSPEC JNIEnv *SDLCALL SDL_GetAndroidJNIEnv(void);
+JNIEnv *SDL_GetAndroidJNIEnv(void)
{
SDL_Unsupported();
return NULL;
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 78d8b71941e1c..7f8b56ee88349 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -2177,7 +2177,7 @@ bool Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *b
//////////////////////////////////////////////////////////////////////////////
*/
-void *SDL_GetAndroidJNIEnv(void)
+JNIEnv *SDL_GetAndroidJNIEnv(void)
{
return Android_JNI_GetEnv();
}
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index f308ce52efc38..165de3c0640fb 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -255,7 +255,7 @@ SDL_DYNAPI_PROC(const char*,SDL_GetAndroidCachePath,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetAndroidExternalStoragePath,(void),(),return)
SDL_DYNAPI_PROC(Uint32,SDL_GetAndroidExternalStorageState,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetAndroidInternalStoragePath,(void),(),return)
-SDL_DYNAPI_PROC(void*,SDL_GetAndroidJNIEnv,(void),(),return)
+SDL_DYNAPI_PROC(JNIEnv*,SDL_GetAndroidJNIEnv,(void),(),return)
SDL_DYNAPI_PROC(int,SDL_GetAndroidSDKVersion,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetAppMetadataProperty,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetAssertionHandler,(void **a),(a),return)