summaryrefslogtreecommitdiffstats
path: root/libnativehelper
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2011-04-08 17:15:16 -0700
committerElliott Hughes <enh@google.com>2011-04-08 17:15:16 -0700
commit2c155af928ea2285b8925002d216476ec06275aa (patch)
tree425323069ef585cec530b15ccfcf2e0ad98cd626 /libnativehelper
parent2f5e3cb20ed3fa00e474fb4813f2c1f46d04afd4 (diff)
downloadandroid_dalvik-2c155af928ea2285b8925002d216476ec06275aa.tar.gz
android_dalvik-2c155af928ea2285b8925002d216476ec06275aa.tar.bz2
android_dalvik-2c155af928ea2285b8925002d216476ec06275aa.zip
Add jniThrowExceptionFmt.
I still think you should be doing checks and throwing exceptions in Java, and your native code should just crash if you lie to it, but this will ease the translation of frameworks/base code over to using JNI more correctly. Change-Id: I9f2512e2349452b82360b375911c814ab00db23b
Diffstat (limited to 'libnativehelper')
-rw-r--r--libnativehelper/JNIHelp.c8
-rw-r--r--libnativehelper/include/nativehelper/JNIHelp.h17
2 files changed, 25 insertions, 0 deletions
diff --git a/libnativehelper/JNIHelp.c b/libnativehelper/JNIHelp.c
index e5abc0f5d..fb23a9e83 100644
--- a/libnativehelper/JNIHelp.c
+++ b/libnativehelper/JNIHelp.c
@@ -211,6 +211,14 @@ int jniThrowException(JNIEnv* env, const char* className, const char* msg)
return result;
}
+int jniThrowExceptionFmt(JNIEnv* env, const char* className, const char* fmt,
+ va_list args)
+{
+ char msgBuf[512];
+ vsnprintf(msgBuf, sizeof(msgBuf), fmt, args);
+ return jniThrowException(env, className, msgBuf);
+}
+
/*
* Throw a java.lang.NullPointerException, with an optional message.
*/
diff --git a/libnativehelper/include/nativehelper/JNIHelp.h b/libnativehelper/include/nativehelper/JNIHelp.h
index 71ecf3844..1b5ff0c2e 100644
--- a/libnativehelper/include/nativehelper/JNIHelp.h
+++ b/libnativehelper/include/nativehelper/JNIHelp.h
@@ -118,6 +118,23 @@ inline int jniThrowException(JNIEnv* env, const char* className,
{
return jniThrowException(&env->functions, className, msg);
}
+
+extern "C" int jniThrowExceptionFmt(C_JNIEnv* env, const char* className,
+ const char* fmt, va_list args);
+
+/*
+ * Equivalent to jniThrowException but with a printf-like format string and
+ * variable-length argument list. This is only available in C++.
+ */
+inline int jniThrowExceptionFmt(JNIEnv* env, const char* className,
+ const char* fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ return jniThrowExceptionFmt(&env->functions, className, fmt, args);
+ va_end(args);
+}
+
inline int jniThrowNullPointerException(JNIEnv* env, const char* msg)
{
return jniThrowNullPointerException(&env->functions, msg);