Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2008-05-09 18:51:13 +0000
committerAndrew Niefer2008-05-09 18:51:13 +0000
commita9049f67902ad98d4fafbb721a73c29c806af6c8 (patch)
treed99cd7254ccb8d4e83c4fd15db89844a7655bac2 /bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
parent55a3f945a9c7e0d833077809decd80f847d18b34 (diff)
downloadrt.equinox.framework-a9049f67902ad98d4fafbb721a73c29c806af6c8.tar.gz
rt.equinox.framework-a9049f67902ad98d4fafbb721a73c29c806af6c8.tar.xz
rt.equinox.framework-a9049f67902ad98d4fafbb721a73c29c806af6c8.zip
bug 222576 - Bidi characters in switch workspace
Diffstat (limited to 'bundles/org.eclipse.equinox.executable/library/eclipseJNI.c')
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipseJNI.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c b/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
index f0e32f1bd..6ac45ce23 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
@@ -173,8 +173,19 @@ void setExitData(JNIEnv *env, jstring id, jstring s){
static const _TCHAR * JNI_GetStringChars(JNIEnv *env, jstring str) {
const _TCHAR * result = NULL;
#ifdef UNICODE
- result = (*env)->GetStringChars(env, str, 0);
+ /* GetStringChars is not null terminated, make a copy */
+ const _TCHAR * stringChars = (*env)->GetStringChars(env, str, 0);
+ int length = (*env)->GetStringLength(env, str);
+ _TCHAR * copy = malloc( (length + 1) * sizeof(_TCHAR));
+ _tcsncpy(copy, stringChars, length);
+ copy[length] = _T_ECLIPSE('\0');
+ (*env)->ReleaseStringChars(env, str, stringChars);
+ result = copy;
+#elif MACOSX
+ /* Use UTF on the Mac */
+ result = (*env)->GetStringUTFChars(env, str, 0);
#else
+ /* Other platforms, use java's default encoding */
_TCHAR* buffer = NULL;
jclass stringClass = (*env)->FindClass(env, "java/lang/String");
if (stringClass != NULL) {
@@ -202,7 +213,9 @@ static const _TCHAR * JNI_GetStringChars(JNIEnv *env, jstring str) {
/* 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);
+ free((_TCHAR*)data);
+#elif MACOSX
+ (*env)->ReleaseStringUTFChars(env, s, data);
#else
free((_TCHAR*)data);
#endif
@@ -211,11 +224,13 @@ static void JNI_ReleaseStringChars(JNIEnv *env, jstring s, const _TCHAR* data) {
static jstring newJavaString(JNIEnv *env, _TCHAR * str)
{
jstring newString = NULL;
- size_t length = _tcslen(str);
-
#ifdef UNICODE
+ size_t length = _tcslen(str);
newString = (*env)->NewString(env, str, length);
+#elif MACOSX
+ newString = (*env)->NewStringUTF(env, str);
#else
+ size_t length = _tcslen(str);
jbyteArray bytes = (*env)->NewByteArray(env, length);
if(bytes != NULL) {
(*env)->SetByteArrayRegion(env, bytes, 0, length, str);

Back to the top