[kaffe] ByteToCharIconv/CharToByteIconv
Atsushi Nemoto
anemo at mba.ocn.ne.jp
Thu Dec 11 05:47:01 PST 2003
Does ByteToCharIconv/CharToByteIconv work on little endian system?
On my little endian system, iconv with "UCS-2" acts as "UCS-2LE", so
additional swab in those classes is not needed.
Here is a patch. Without this patch, I could not use SHIFT_JIS
encoding.
diff -ur kaffe-1.1.3.org/libraries/clib/native/ByteToCharIconv.c kaffe-1.1.3/libraries/clib/native/ByteToCharIconv.c
--- kaffe-1.1.3.org/libraries/clib/native/ByteToCharIconv.c Wed May 7 00:24:08 2003
+++ kaffe-1.1.3/libraries/clib/native/ByteToCharIconv.c Thu Dec 11 13:44:13 2003
@@ -41,7 +41,11 @@
iconv_t cd;
str = (*env)->GetStringUTFChars(env, enc, 0);
- cd = iconv_open ("UCS-2", (char *)str);
+#ifdef WORDS_BIGENDIAN
+ cd = iconv_open ("UCS-2BE", (char *)str);
+#else
+ cd = iconv_open ("UCS-2LE", (char *)str);
+#endif
(*env)->ReleaseStringUTFChars(env, enc, str);
if (cd != (iconv_t)-1) {
(*env)->SetObjectField(env, _this, cd_id, (jobject)cd);
@@ -74,25 +78,7 @@
size_t icv_outlen = toLen * 2;
iconv_t cd = (iconv_t) (*env)->GetObjectField(env, _this, cd_id);
int ret;
-#ifndef WORDS_BIGENDIAN
- char *buffer;
-#endif
-
-#ifndef WORDS_BIGENDIAN
- if (icv_outlen == 0) {
- return 0;
- }
- buffer = KMALLOC (icv_outlen);
- if (!buffer) {
- jclass oom;
- (*env)->ReleaseByteArrayElements(env, fromBytes, jb, JNI_ABORT);
- (*env)->ReleaseCharArrayElements(env, toChars, jc, 0);
- oom = (*env)->FindClass(env, "java.lang.OutOfMemory");
- (*env)->ThrowNew(env, oom, "iconv()");
- }
- icv_out = buffer;
-#endif
ret = iconv (cd, &icv_in, &icv_inlen, &icv_out, &icv_outlen);
if (ret < 0) {
/* convert the begining of an invalid multibyte sequence to '?' */
@@ -104,10 +90,6 @@
icv_outlen -= 2;
}
}
-#ifndef WORDS_BIGENDIAN
- swab (buffer, jc + toPos, toLen * 2 - icv_outlen);
- KFREE (buffer);
-#endif
if (icv_inlen > 0) {
/* In case we have some bytes left, save them */
(*env)->CallVoidMethod(env, _this, carry_id,
diff -ur kaffe-1.1.3.org/libraries/clib/native/CharToByteIconv.c kaffe-1.1.3/libraries/clib/native/CharToByteIconv.c
--- kaffe-1.1.3.org/libraries/clib/native/CharToByteIconv.c Wed May 7 00:24:08 2003
+++ kaffe-1.1.3/libraries/clib/native/CharToByteIconv.c Thu Dec 11 13:43:54 2003
@@ -39,7 +39,11 @@
iconv_t cd;
str = (*env)->GetStringUTFChars(env, enc, 0);
- cd = iconv_open ((char *)str, "UCS-2");
+#ifdef WORDS_BIGENDIAN
+ cd = iconv_open ((char *)str, "UCS-2BE");
+#else
+ cd = iconv_open ((char *)str, "UCS-2LE");
+#endif
(*env)->ReleaseStringUTFChars(env, enc, str);
if (cd != (iconv_t)-1) {
(*env)->SetObjectField(env, _this, cd_id, (jobject)cd);
@@ -72,32 +76,8 @@
size_t icv_outlen = toLen;
iconv_t cd = (iconv_t) (*env)->GetObjectField(env, _this, cd_id);
int ret;
-#ifndef WORDS_BIGENDIAN
- char *buffer;
-#endif
-#ifndef WORDS_BIGENDIAN
- if (icv_inlen > 0) {
- buffer = KMALLOC (icv_inlen);
- if (!buffer) {
- jclass oom;
-
- (*env)->ReleaseCharArrayElements(env, fromChars, jc, JNI_ABORT);
- (*env)->ReleaseByteArrayElements(env, toBytes, jb, 0);
- oom = (*env)->FindClass(env, "java.lang.OutOfMemory");
- (*env)->ThrowNew(env, oom, "iconv()");
- }
- swab (icv_in, buffer, icv_inlen);
- icv_in = buffer;
- }
- else {
- buffer = NULL;
- }
-#endif
ret = iconv (cd, &icv_in, &icv_inlen, &icv_out, &icv_outlen);
-#ifndef WORDS_BIGENDIAN
- KFREE (buffer);
-#endif
if (icv_inlen > 0) {
/* In case we have some bytes left, save them */
(*env)->CallVoidMethod(env, _this, carry_id,
---
Atsushi Nemoto
More information about the kaffe
mailing list