Move emulator-base native code into its own non-Gradle directory.
[SquirrelJME.git] / emulators / emulator-base-native / c / utils.c
blob176f671d4dab0d2a0ae8acae5cc29bd405266944
1 /* -*- Mode: C++; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 #include "squirreljme.h"
12 #include <stdarg.h>
14 forwardMethod JNICALL findForwardMethod(JNIEnv* env,
15 const char* const classy, const char* const name, const char* const type)
17 forwardMethod result;
19 result.xclass = (*env)->FindClass(env, classy);
20 result.xmeth = (*env)->GetStaticMethodID(env, result.xclass, name, type);
22 return result;
25 // Preface
26 #define SQUEAK_PREF \
27 forwardMethod call; \
28 va_list vaArgs; \
30 call = findForwardMethod(env, classy, name, type);\
32 va_start(vaArgs, type);
34 // Post handling
35 #define SQUEAK_POST \
36 va_end(vaArgs);
38 // Debugging?
39 #if 0 /*defined(_DEBUG) || defined(DEBUG)*/
40 #define DEBUG_CALL fprintf(stderr, "JNI Forward: %s:%s\n", classy, name);
41 #else
42 #define DEBUG_CALL
43 #endif
45 void JNICALL forwardCallStaticVoid(JNIEnv* env,
46 const char* const classy, const char* const name, const char* const type,
47 ...)
49 SQUEAK_PREF;
50 DEBUG_CALL;
51 (*env)->CallStaticVoidMethodV(env, call.xclass, call.xmeth, vaArgs);
52 SQUEAK_POST;
55 jint JNICALL forwardCallStaticInteger(JNIEnv* env,
56 const char* const classy, const char* const name, const char* const type,
57 ...)
59 jint rv;
61 SQUEAK_PREF;
62 DEBUG_CALL;
63 rv = (*env)->CallStaticIntMethodV(env, call.xclass, call.xmeth, vaArgs);
64 SQUEAK_POST;
66 return rv;
69 jlong JNICALL forwardCallStaticLong(JNIEnv* env,
70 const char* const classy, const char* const name, const char* const type,
71 ...)
73 jlong rv;
75 SQUEAK_PREF;
76 DEBUG_CALL;
77 rv = (*env)->CallStaticLongMethodV(env, call.xclass, call.xmeth, vaArgs);
78 SQUEAK_POST;
80 return rv;
83 jobject JNICALL forwardCallStaticObject(JNIEnv* env,
84 const char* const classy, const char* const name, const char* const type,
85 ...)
87 jobject rv;
89 SQUEAK_PREF;
90 DEBUG_CALL;
91 rv = (*env)->CallStaticObjectMethodV(env, call.xclass, call.xmeth, vaArgs);
92 SQUEAK_POST;
94 return rv;
97 jboolean JNICALL forwardCallStaticBoolean(JNIEnv* env,
98 const char* const classy, const char* const name, const char* const type,
99 ...)
101 jboolean rv;
103 SQUEAK_PREF;
104 DEBUG_CALL;
105 rv = (*env)->CallStaticBooleanMethodV(env, call.xclass, call.xmeth, vaArgs);
106 SQUEAK_POST;
108 return rv;