[vmkit-commits] [vmkit] r198305 - Correct implementation of utf related JNI functions
Gael Thomas
gael.thomas at lip6.fr
Thu Jan 2 05:55:20 PST 2014
Author: gthomas
Date: Thu Jan 2 07:55:19 2014
New Revision: 198305
URL: http://llvm.org/viewvc/llvm-project?rev=198305&view=rev
Log:
Correct implementation of utf related JNI functions
Modified:
vmkit/branches/mcjit/include/j3/j3utf16.h
vmkit/branches/mcjit/lib/j3/vm/j3jni.cc
Modified: vmkit/branches/mcjit/include/j3/j3utf16.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3utf16.h?rev=198305&r1=198304&r2=198305&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3utf16.h (original)
+++ vmkit/branches/mcjit/include/j3/j3utf16.h Thu Jan 2 07:55:19 2014
@@ -1,36 +1,30 @@
#ifndef _J3_UTF16_H_
#define _J3_UTF16_H_
+#include <sys/types.h>
+#include <stdint.h>
+
+namespace vmkit {
+ class Name;
+}
+
namespace j3 {
+ class J3ObjectHandle;
+
class J3Utf16Converter {
const vmkit::Name* name;
size_t pos;
public:
- J3Utf16Converter(const vmkit::Name* _name) { name = _name; pos = 0; }
+ J3Utf16Converter(const vmkit::Name* _name);
- bool isEof() { return pos == name->length(); }
+ bool isEof();
+ uint16_t nextUtf16();
+ };
- uint16_t nextUtf16() {
- const char* str = name->cStr();
- size_t n = 0;
- size_t i = 0;
- uint16_t x = str[pos++];
-
- if(x & 0x80) {
- uint16_t y = str[pos++];
- if (x & 0x20) {
- char z = str[pos++];
- x = ((x & 0x0F) << 12) +
- ((y & 0x3F) << 6) +
- (z & 0x3F);
- } else {
- x = ((x & 0x1F) << 6) +
- (y & 0x3F);
- }
- }
-
- return x;
- }
+ class J3CharConverter {
+ public:
+ static size_t maxSize(J3ObjectHandle* charArray);
+ static size_t convert(J3ObjectHandle* charArray, char* dest);
};
}
Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3jni.cc?rev=198305&r1=198304&r2=198305&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3jni.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Thu Jan 2 07:55:19 2014
@@ -5,6 +5,7 @@
#include "j3/j3object.h"
#include "j3/j3method.h"
#include "j3/j3thread.h"
+#include "j3/j3utf16.h"
#include <stdlib.h>
#define enterJVM() try {
@@ -381,7 +382,9 @@ jstring JNICALL NewStringUTF(JNIEnv* env
jsize JNICALL GetStringUTFLength(JNIEnv* env, jstring str) {
jsize res;
enterJVM();
- res = str->getObject(J3Thread::get()->vm()->stringClassValue)->arrayLength();
+ jobject content = str->getObject(J3Thread::get()->vm()->stringClassValue);
+ char buf[J3CharConverter::maxSize(content)];
+ res = J3CharConverter::convert(content, buf);
leaveJVM();
return res;
}
@@ -392,13 +395,8 @@ const char* JNICALL GetStringUTFChars(JN
enterJVM();
J3* vm = J3Thread::get()->vm();
jobject content = str->getObject(vm->stringClassValue);
- uint32_t length = content->arrayLength();
- res = new char[length+1];
-
- for(uint32_t i=0; i<length; i++)
- res[i] = content->getCharAt(i);
-
- res[length] = 0;
+ res = new char[J3CharConverter::maxSize(content)];
+ J3CharConverter::convert(content, res);
if(isCopy)
*isCopy = 1;
@@ -473,11 +471,7 @@ void JNICALL GetStringUTFRegion(JNIEnv*
enterJVM();
J3* vm = J3Thread::get()->vm();
jobject content = str->getObject(vm->stringClassValue);
-
- for(uint32_t i=0; i<len; i++)
- buf[i] = content->getCharAt(start+i);
-
- buf[len] = 0;
+ J3CharConverter::convert(content, buf);
leaveJVM();
}
More information about the vmkit-commits
mailing list