Skip to content

Commit

Permalink
Removed dependency to stdbool.h in implementation file for Android.
Browse files Browse the repository at this point in the history
This reduced mixing of different types in the file (bool, jboolean, SDL_bool).
  • Loading branch information
philippwiesemann committed Dec 10, 2014
1 parent d999115 commit 0f87761
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions src/core/android/SDL_android.c
Expand Up @@ -44,8 +44,8 @@
#define LOG_TAG "SDL_android"
/* #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) */
/* #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) */
#define LOGI(...) do {} while (false)
#define LOGE(...) do {} while (false)
#define LOGI(...) do {} while (0)
#define LOGE(...) do {} while (0)

/* Uncomment this to log messages entering and exiting methods in this file */
/* #define DEBUG_JNI */
Expand All @@ -57,7 +57,6 @@ static void Android_JNI_ThreadDestroyed(void*);
*******************************************************************************/
#include <jni.h>
#include <android/log.h>
#include <stdbool.h>


/*******************************************************************************
Expand All @@ -80,7 +79,7 @@ static jmethodID midPollInputDevices;

/* Accelerometer data storage */
static float fLastAccelerometer[3];
static bool bHasNewData;
static SDL_bool bHasNewData;

/*******************************************************************************
Functions called by JNI
Expand Down Expand Up @@ -132,7 +131,7 @@ JNIEXPORT void JNICALL SDL_Android_Init(JNIEnv* mEnv, jclass cls)
midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
"pollInputDevices", "()V");

bHasNewData = false;
bHasNewData = SDL_FALSE;

if(!midGetNativeSurface || !midFlipBuffers || !midAudioInit ||
!midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit || !midPollInputDevices) {
Expand Down Expand Up @@ -302,7 +301,7 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeAccel(
fLastAccelerometer[0] = x;
fLastAccelerometer[1] = y;
fLastAccelerometer[2] = z;
bHasNewData = true;
bHasNewData = SDL_TRUE;
}

/* Low memory */
Expand Down Expand Up @@ -487,7 +486,7 @@ SDL_bool Android_JNI_GetAccelerometerValues(float values[3])
for (i = 0; i < 3; ++i) {
values[i] = fLastAccelerometer[i];
}
bHasNewData = false;
bHasNewData = SDL_FALSE;
retval = SDL_TRUE;
}

Expand Down Expand Up @@ -647,7 +646,7 @@ void Android_JNI_CloseAudioDevice()

/* Test for an exception and call SDL_SetError with its detail if one occurs */
/* If the parameter silent is truthy then SDL_SetError() will not be called. */
static bool Android_JNI_ExceptionOccurred(bool silent)
static SDL_bool Android_JNI_ExceptionOccurred(SDL_bool silent)
{
SDL_assert(LocalReferenceHolder_IsActive());
JNIEnv *mEnv = Android_JNI_GetEnv();
Expand Down Expand Up @@ -681,10 +680,10 @@ static bool Android_JNI_ExceptionOccurred(bool silent)
(*mEnv)->ReleaseStringUTFChars(mEnv, exceptionName, exceptionNameUTF8);
}

return true;
return SDL_TRUE;
}

return false;
return SDL_FALSE;
}

static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
Expand Down Expand Up @@ -728,19 +727,19 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
*/
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager), "openFd", "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;");
inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString);
if (Android_JNI_ExceptionOccurred(true)) {
if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
goto fallback;
}

mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getStartOffset", "()J");
ctx->hidden.androidio.offset = (*mEnv)->CallLongMethod(mEnv, inputStream, mid);
if (Android_JNI_ExceptionOccurred(true)) {
if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
goto fallback;
}

mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getDeclaredLength", "()J");
ctx->hidden.androidio.size = (*mEnv)->CallLongMethod(mEnv, inputStream, mid);
if (Android_JNI_ExceptionOccurred(true)) {
if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
goto fallback;
}

Expand All @@ -754,7 +753,7 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
/* Seek to the correct offset in the file. */
lseek(ctx->hidden.androidio.fd, (off_t)ctx->hidden.androidio.offset, SEEK_SET);

if (false) {
if (0) {
fallback:
/* Disabled log message because of spam on the Nexus 7 */
/* __android_log_print(ANDROID_LOG_DEBUG, "SDL", "Falling back to legacy InputStream method for opening file"); */
Expand All @@ -766,13 +765,13 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager),
"open", "(Ljava/lang/String;I)Ljava/io/InputStream;");
inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString, 1 /* ACCESS_RANDOM */);
if (Android_JNI_ExceptionOccurred(false)) {
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
// Try fallback to APK Extension files
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context),
"openAPKExtensionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
inputStream = (*mEnv)->CallObjectMethod(mEnv, context, mid, fileNameJString);

if (Android_JNI_ExceptionOccurred(false)) {
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
goto failure;
}
}
Expand All @@ -790,7 +789,7 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream),
"available", "()I");
ctx->hidden.androidio.size = (long)(*mEnv)->CallIntMethod(mEnv, inputStream, mid);
if (Android_JNI_ExceptionOccurred(false)) {
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
goto failure;
}

Expand All @@ -801,7 +800,7 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
"(Ljava/io/InputStream;)Ljava/nio/channels/ReadableByteChannel;");
readableByteChannel = (*mEnv)->CallStaticObjectMethod(
mEnv, channels, mid, inputStream);
if (Android_JNI_ExceptionOccurred(false)) {
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
goto failure;
}

Expand All @@ -814,7 +813,7 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
ctx->hidden.androidio.readMethod = mid;
}

if (false) {
if (0) {
failure:
result = -1;

Expand Down Expand Up @@ -907,7 +906,7 @@ size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
/* result = readableByteChannel.read(...); */
int result = (*mEnv)->CallIntMethod(mEnv, readableByteChannel, readMethod, byteBuffer);

if (Android_JNI_ExceptionOccurred(false)) {
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
LocalReferenceHolder_Cleanup(&refs);
return 0;
}
Expand All @@ -932,7 +931,7 @@ size_t Android_JNI_FileWrite(SDL_RWops* ctx, const void* buffer,
return 0;
}

static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, bool release)
static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, SDL_bool release)
{
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);

Expand All @@ -955,7 +954,7 @@ static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, bool release)
"close", "()V");
(*mEnv)->CallVoidMethod(mEnv, inputStream, mid);
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.assetFileDescriptorRef);
if (Android_JNI_ExceptionOccurred(false)) {
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
result = -1;
}
}
Expand All @@ -968,7 +967,7 @@ static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, bool release)
(*mEnv)->CallVoidMethod(mEnv, inputStream, mid);
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.inputStreamRef);
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.readableByteChannelRef);
if (Android_JNI_ExceptionOccurred(false)) {
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
result = -1;
}
}
Expand Down Expand Up @@ -1059,7 +1058,7 @@ Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)
} else if (movement < 0) {
/* We can't seek backwards so we have to reopen the file and seek */
/* forwards which obviously isn't very efficient */
Internal_Android_JNI_FileClose(ctx, false);
Internal_Android_JNI_FileClose(ctx, SDL_FALSE);
Internal_Android_JNI_FileOpen(ctx);
Android_JNI_FileSeek(ctx, newPosition, RW_SEEK_SET);
}
Expand All @@ -1071,7 +1070,7 @@ Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)

int Android_JNI_FileClose(SDL_RWops* ctx)
{
return Internal_Android_JNI_FileClose(ctx, true);
return Internal_Android_JNI_FileClose(ctx, SDL_TRUE);
}

/* returns a new global reference which needs to be released later */
Expand Down

0 comments on commit 0f87761

Please sign in to comment.