Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2007-04-13 18:32:06 +0000
committerAndrew Niefer2007-04-13 18:32:06 +0000
commitb19c64517dc209979ee5a05a803f1863eeaa016f (patch)
tree2935719eecbe587ec02ee88ac14d261567add12f /bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
parent898e492e4978ff1e95ecf146cb68a83cff07c685 (diff)
downloadrt.equinox.framework-b19c64517dc209979ee5a05a803f1863eeaa016f.tar.gz
rt.equinox.framework-b19c64517dc209979ee5a05a803f1863eeaa016f.tar.xz
rt.equinox.framework-b19c64517dc209979ee5a05a803f1863eeaa016f.zip
bug 180185
Diffstat (limited to 'bundles/org.eclipse.equinox.executable/library/eclipseJNI.c')
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipseJNI.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c b/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
index 9b2a4a055..d3292df62 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
@@ -35,6 +35,8 @@ static jstring newJavaString(JNIEnv *env, _TCHAR * str);
static void splash(JNIEnv *env, jstring s);
static void registerNatives(JNIEnv *env);
static int shouldShutdown(JNIEnv *env);
+static void JNI_ReleaseStringChars(JNIEnv *env, jstring s, const _TCHAR* data);
+static const _TCHAR* JNI_GetStringChars(JNIEnv *env, jstring str);
void setExitData(JNIEnv *env, jstring id, jstring s);
@@ -166,6 +168,45 @@ void setExitData(JNIEnv *env, jstring id, jstring s){
}
}
+/* Get a _TCHAR* from a jstring, string should be released later with JNI_ReleaseStringChars */
+static const _TCHAR * JNI_GetStringChars(JNIEnv *env, jstring str) {
+ const _TCHAR * result = NULL;
+#ifdef UNICODE
+ result = (*env)->GetStringChars(env, str, 0);
+#else
+ _TCHAR* buffer = NULL;
+ jclass stringClass = (*env)->FindClass(env, "java/lang/String");
+ if (stringClass != NULL) {
+ jmethodID getBytesMethod = (*env)->GetMethodID(env, stringClass, "getBytes", "()[B");
+ if (getBytesMethod != NULL) {
+ jbyteArray bytes = (*env)->CallObjectMethod(env, str, getBytesMethod);
+ if (!(*env)->ExceptionOccurred(env)) {
+ jint length = (*env)->GetArrayLength(env, bytes);
+ buffer = malloc( (length + 1) * sizeof(_TCHAR*));
+ (*env)->GetByteArrayRegion(env, bytes, 0, length, (jbyte*)buffer);
+ buffer[length] = 0;
+ }
+ (*env)->DeleteLocalRef(env, bytes);
+ }
+ }
+ if(buffer == NULL) {
+ (*env)->ExceptionDescribe(env);
+ (*env)->ExceptionClear(env);
+ }
+ result = buffer;
+#endif
+ return result;
+}
+
+/* Release the string that was obtained using JNI_GetStringChars */
+static void JNI_ReleaseStringChars(JNIEnv *env, jstring s, const _TCHAR* data) {
+#ifdef UNICODE
+ (*env)->ReleaseStringChars(env, s, data);
+#else
+ free((_TCHAR*)data);
+#endif
+}
+
static jstring newJavaString(JNIEnv *env, _TCHAR * str)
{
jstring newString = NULL;

Back to the top