[kaffe] CVS kaffe (guilhem): Two new JNI 1.2 calls for JSDL.

Kaffe CVS cvs-commits at kaffe.org
Fri Apr 16 12:04:02 PDT 2004


PatchSet 4655 
Date: 2004/04/16 17:16:22
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Two new JNI 1.2 calls for JSDL.

        * kaffe/kaffevm/jni.c, include/jni.h
        (Kaffe_GetStringRegion, Kaffe_GetStringUTFRegion): New JNI 1.2 calls.

        * kaffe/kaffevm/utf8const.c, kaffe/kaffevm/utf8const.h
        (utf8ConstEncodeTo, utf8ConstEncode): Splitted utf8Encode in two
        parts to remove redundant code.

Members: 
	ChangeLog:1.2231->1.2232 
	include/jni.h:1.28->1.29 
	kaffe/kaffevm/jni.c:1.109->1.110 
	kaffe/kaffevm/utf8const.c:1.34->1.35 
	kaffe/kaffevm/utf8const.h:1.3->1.4 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2231 kaffe/ChangeLog:1.2232
--- kaffe/ChangeLog:1.2231	Fri Apr 16 17:12:05 2004
+++ kaffe/ChangeLog	Fri Apr 16 17:16:22 2004
@@ -1,5 +1,14 @@
 2004-04-16  Guilhem Lavaux <guilhem at kaffe.org>
 
+	* kaffe/kaffevm/jni.c, include/jni.h
+	(Kaffe_GetStringRegion, Kaffe_GetStringUTFRegion): New JNI 1.2 calls.
+
+	* kaffe/kaffevm/utf8const.c, kaffe/kaffevm/utf8const.h
+	(utf8ConstEncodeTo, utf8ConstEncode): Splitted utf8Encode in two
+	parts to remove redundant code.
+
+2004-04-16  Guilhem Lavaux <guilhem at kaffe.org>
+
 	* kaffe/kaffevm/support.c
 	(callMethodV, callMethodA): If the called method is a JNI, then
 	throw the waiting exception in exceptObj.
Index: kaffe/include/jni.h
diff -u kaffe/include/jni.h:1.28 kaffe/include/jni.h:1.29
--- kaffe/include/jni.h:1.28	Mon Mar 29 20:24:29 2004
+++ kaffe/include/jni.h	Fri Apr 16 17:16:24 2004
@@ -321,8 +321,8 @@
 
         /* New JNI 1.2 functions */
 	
-        void* reserved12; /* GetStringRegion */
-        void* reserved13; /* GetStringUTFRegion */
+        void  (*GetStringRegion)                (JNIEnv*, jstring, jsize, jsize, jchar*); 
+        void  (*GetStringUTFRegion)             (JNIEnv*, jstring, jsize, jsize, char*); 
 	void* (*GetPrimitiveArrayCritical)	(JNIEnv*, jarray, jboolean*);
 	void  (*ReleasePrimitiveArrayCritical)	(JNIEnv*, jarray, void*, jint);
         void* reserved16; /* GetStringCritical */
Index: kaffe/kaffe/kaffevm/jni.c
diff -u kaffe/kaffe/kaffevm/jni.c:1.109 kaffe/kaffe/kaffevm/jni.c:1.110
--- kaffe/kaffe/kaffevm/jni.c:1.109	Mon Apr  5 17:43:38 2004
+++ kaffe/kaffe/kaffevm/jni.c	Fri Apr 16 17:16:24 2004
@@ -2806,6 +2806,53 @@
 	BEGIN_EXCEPTION_HANDLING_VOID();
 
 	KFREE(chars);
+	
+	END_EXCEPTION_HANDLING();
+}
+
+static void
+Kaffe_GetStringRegion(JNIEnv *env, jstring data, jsize start, jsize len, jchar *buf)
+{
+	Hjava_lang_String* const str = (Hjava_lang_String*)data;
+        jchar *str_ptr;
+	jsize str_len;
+	
+        BEGIN_EXCEPTION_HANDLING_VOID();
+
+	str_ptr = STRING_DATA(str);
+	str_len = STRING_SIZE(str);
+
+	if (start >= len || start+len >= str_len) {
+	      errorInfo einfo;
+	      
+	      postException(&einfo, "java.lang.StringIndexOutOfBoundsException");
+	      throwError(&einfo);
+	}
+	
+	memcpy(buf, &str_ptr[start], len*sizeof(jchar));
+
+        END_EXCEPTION_HANDLING();
+}
+
+static void
+Kaffe_GetStringUTFRegion(JNIEnv *env, jstring data, jsize start, jsize len, char *buf)
+{
+        Hjava_lang_String* const str = (Hjava_lang_String*)data;
+	jchar *str_ptr;
+	jsize str_len;
+
+	BEGIN_EXCEPTION_HANDLING_VOID();
+	
+	str_ptr = STRING_DATA(str);
+	str_len = STRING_SIZE(str); 
+	if (start >= len || start+len >= str_len) {
+	      errorInfo einfo;
+	      
+	      postException(&einfo, "java.lang.StringIndexOutOfBoundsException");
+	      throwError(&einfo);
+	}
+
+	utf8ConstEncodeTo(&str_ptr[start], len, buf);
 
 	END_EXCEPTION_HANDLING();
 }
@@ -4430,8 +4477,8 @@
 	Kaffe_MonitorEnter,
 	Kaffe_MonitorExit,
 	Kaffe_GetJavaVM,
-	NULL,
-	NULL,
+	Kaffe_GetStringRegion,
+	Kaffe_GetStringUTFRegion,
 	Kaffe_GetPrimitiveArrayCritical,
 	Kaffe_ReleasePrimitiveArrayCritical,
 	NULL,
Index: kaffe/kaffe/kaffevm/utf8const.c
diff -u kaffe/kaffe/kaffevm/utf8const.c:1.34 kaffe/kaffe/kaffevm/utf8const.c:1.35
--- kaffe/kaffe/kaffevm/utf8const.c:1.34	Fri Apr  2 20:14:42 2004
+++ kaffe/kaffe/kaffevm/utf8const.c	Fri Apr 16 17:16:24 2004
@@ -337,15 +337,41 @@
  * Encode a jchar[] Array into a zero-terminated C string
  * that contains the array's utf8 encoding.
  *
+ * NB.: This function assumes the output array has a sufficient size.
+Caller must free via KFREE.
+ */
+void utf8ConstEncodeTo(const jchar *chars, int clength, char *buf)
+{
+	int i, pos = 0;
+
+	for (i = 0; i < clength; i++) {
+		jchar ch = chars[i];
+		if (ch >= 0x0001 && ch <= 0x007f) {
+			buf[pos++] = (char) ch;
+		} else if (ch <= 0x07ff) {
+			buf[pos++] = (char) (0xc0 | (0x3f & (ch >> 6)));
+			buf[pos++] = (char) (0x80 | (0x3f &  ch));
+		} else {
+			buf[pos++] = (char) (0xe0 | (0x0f & (ch >> 12)));
+			buf[pos++] = (char) (0x80 | (0x3f & (ch >>  6)));
+			buf[pos++] = (char) (0x80 | (0x3f &  ch));
+		}
+	}
+}
+
+/*
+ * Encode a jchar[] Array into a zero-terminated C string
+ * that contains the array's utf8 encoding.
+ *
  * NB.: Caller must free via KFREE.
  */
-char *
+char*
 utf8ConstEncode(const jchar *chars, int clength)
 {
-	int i, pos = 0;
+        char *buf;
+	int i;
 	unsigned int size = 0;
-	char * buf;
-
+	
 	/* Size output array */
 	for (i = 0; i < clength; i++) {
 		jchar ch = chars[i];
@@ -361,23 +387,12 @@
 	/* Now fill it in */
 	buf = KMALLOC(size + 1);
 	if (buf == 0) {
-		return (0);
+		return 0;
 	}
 
-	for (i = 0; i < clength; i++) {
-		jchar ch = chars[i];
-		if (ch >= 0x0001 && ch <= 0x007f) {
-			buf[pos++] = (char) ch;
-		} else if (ch <= 0x07ff) {
-			buf[pos++] = (char) (0xc0 | (0x3f & (ch >> 6)));
-			buf[pos++] = (char) (0x80 | (0x3f &  ch));
-		} else {
-			buf[pos++] = (char) (0xe0 | (0x0f & (ch >> 12)));
-			buf[pos++] = (char) (0x80 | (0x3f & (ch >>  6)));
-			buf[pos++] = (char) (0x80 | (0x3f &  ch));
-		}
-	}
-	return (buf);
+	utf8ConstEncodeTo(chars, clength, buf);
+	
+	return buf;
 }
 
 /*
Index: kaffe/kaffe/kaffevm/utf8const.h
diff -u kaffe/kaffe/kaffevm/utf8const.h:1.3 kaffe/kaffe/kaffevm/utf8const.h:1.4
--- kaffe/kaffe/kaffevm/utf8const.h:1.3	Thu Jan 22 19:54:23 2004
+++ kaffe/kaffe/kaffevm/utf8const.h	Fri Apr 16 17:16:24 2004
@@ -52,6 +52,13 @@
  * that contains the array's utf8 encoding.
  */
 extern char * utf8ConstEncode(const jchar *chars, int clength);
+/* 
+ * Encode a jchar[] Array into a zero-terminated C string
+ * that contains the array's utf8 encoding.
+ *
+ * WARNING: buf is assumed to have the sufficient size (clength*2 is sufficient).
+ */
+extern void utf8ConstEncodeTo(const jchar *chars, int clength, char *buf);
 
 static inline bool utf8ConstEqual(Utf8Const* a, Utf8Const* b) __UNUSED__;
 static inline bool utf8ConstEqual(Utf8Const* a, Utf8Const* b)




More information about the kaffe mailing list