This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Hashtable, RuleBasedCollator and natIconv (again)
- From: Vladimir Puškaš <vpuskas at eunet dot yu>
- To: java at gcc dot gnu dot org
- Date: Wed, 5 Mar 2003 22:17:12 +0100
- Subject: Hashtable, RuleBasedCollator and natIconv (again)
Hi,
I am using "gcc version 3.3 20030305 (prerelease)", configured with:
"../gcc/configure --prefix=/home/support/gcc-3.3 \
--enable-threads=posix --enable-languages=c,c++,java \
--enable-java-awt=xlib", on Slackware 8.1 Linux.
I had some problems, here are solutions which work for me.
First - java.util.Hashtable
Xalan 1.2 (yes, it's old, but it's included with project I have to build
native) has a simple class "org.apache.xalan.xpath.xml.StringKey".
StringKey caches hash values of its String for fast lookups when used
in Hashtables. Idea is to fill StringKeys into hashtable, then using a
String (!?!) get values out.
hashtable.put(new StringKey("one"),new Integer(1));
hashtable.put(new StringKey("two"),new Integer(2));
hashtable.put(new StringKey("three"),new Integer(3));
someInteger = hashtable.get("two");
GNU Classpaths's Hashtable doesn't work this way. All methods use
key.equals(element), instead element.equals(key), thus invalidating the
concept, so get method returns null.
One solution is attached bellow :), other approach would be to search
and replace all hashtable gets in Xalan which use this little trick :(
Second - Tom's patch for natIconv.cc
It's discussed earlier (last August) on the list, so I'll repeat only
test class:
---sample-- (by Suresh Raman)
public class encodingtest
{
public static void main(String args[]) throws Exception
{
String encoding = "UTF-16BE";
String str = "hello world";
byte[] strbytes = str.getBytes(encoding);
String newstr = new String(strbytes, encoding);
System.out.println(newstr);
}
}
--end sample---
Third - java.text.RuleBasedCollator
Collator.getInstance throws an exception for "de" locale. Problem is in
RuleBasedCollator constructor which doesn't handle '&' reset properly.
---sample---
import java.text.Collator;
import java.text.RuleBasedCollator;
import java.util.Locale;
class TestCollator {
public static void main (String[]argv) throws Throwable
{
Collator c = Collator.getInstance (new Locale ("de"));
printCompare (c, "stra\u00dfe", "stra\u00dfe");
printCompare (c, "M\u00fcnchen", "Muenchen");
c = new RuleBasedCollator ("<a<b<c&c<d<e");
printCompare (c, "bc", "bc");
printCompare (c, "abcde", "abcd");
}
public static void printCompare (Collator c, String one, String two)
{
System.out.println (one +"-("+ c.compare (one, two) +")-"+ two);
}
}
--end sample---
This diff helps me, if you find it good enough to merge in, please do.
V.Puskas
--- gcc-cvs/libjava/java/util/Hashtable.java 2002-06-18 17:39:52.000000000 +0200
+++ gcc-local/libjava/java/util/Hashtable.java 2003-01-22 14:47:22.000000000 +0100
@@ -383,7 +383,7 @@
HashEntry e = buckets[idx];
while (e != null)
{
- if (key.equals(e.key))
+ if (e.key.equals(key))
return true;
e = e.next;
}
@@ -406,7 +406,7 @@
HashEntry e = buckets[idx];
while (e != null)
{
- if (key.equals(e.key))
+ if (e.key.equals(key))
return e.value;
e = e.next;
}
@@ -436,7 +436,7 @@
while (e != null)
{
- if (key.equals(e.key))
+ if (e.key.equals(key))
{
// Bypass e.setValue, since we already know value is non-null.
Object r = e.value;
@@ -482,7 +482,7 @@
while (e != null)
{
- if (key.equals(e.key))
+ if (e.key.equals(key))
{
modCount++;
if (last == null)
@@ -842,7 +842,7 @@
HashEntry e = buckets[idx];
while (e != null)
{
- if (o.equals(e))
+ if (e.equals(o))
return e;
e = e.next;
}
--- gcc-cvs/libjava/gnu/gcj/convert/natIconv.cc 2002-02-18 03:52:44.000000000 +0100
+++ gcc-local/libjava/gnu/gcj/convert/natIconv.cc 2003-01-24 02:00:06.000000000 +0100
@@ -1,6 +1,6 @@
-// Input_iconv.java -- Java side of iconv() reader.
+// natIconv.cc -- Java side of iconv() reader.
-/* Copyright (C) 2000, 2001 Free Software Foundation
+/* Copyright (C) 2000, 2001, 2002 Free Software Foundation
This file is part of libgcj.
@@ -201,25 +201,39 @@
inbuf = (char *) temp_buffer;
}
- // If the conversion fails on the very first character, then we
- // assume that the character can't be represented in the output
- // encoding. There's nothing useful we can do here, so we simply
- // omit that character. Note that we can't check `errno' because
- // glibc 2.1.3 doesn't set it correctly. We could check it if we
- // really needed to, but we'd have to disable support for 2.1.3.
size_t loop_old_in = old_in;
while (1)
{
size_t r = iconv_adapter (iconv, (iconv_t) handle,
&inbuf, &inavail,
&outbuf, &outavail);
- if (r == (size_t) -1 && inavail == loop_old_in)
+ if (r == (size_t) -1)
{
- inavail -= 2;
- if (inavail == 0)
- break;
- loop_old_in -= 2;
- inbuf += 2;
+ if (errno == EINVAL)
+ {
+ // Incomplete byte sequence at the end of the input
+ // buffer. This shouldn't be able to happen here.
+ break;
+ }
+ else if (errno == E2BIG)
+ {
+ // Output buffer is too small.
+ break;
+ }
+ else if (errno == EILSEQ || inavail == loop_old_in)
+ {
+ // Untranslatable sequence. Since glibc 2.1.3 doesn't
+ // properly set errno, we also assume that this is what
+ // is happening if no conversions took place. (This can
+ // be a bogus assumption if in fact the output buffer is
+ // too small.) We skip the first character and try
+ // again.
+ inavail -= 2;
+ if (inavail == 0)
+ break;
+ loop_old_in -= 2;
+ inbuf += 2;
+ }
}
else
break;
--- gcc-cvs/libjava/java/text/RuleBasedCollator.java 2001-09-07 02:15:47.000000000 +0200
+++ gcc-local/libjava/java/text/RuleBasedCollator.java 2003-03-05 10:41:39.000000000 +0100
@@ -286,12 +286,24 @@
if (argument.length() == 0)
throw new ParseException ("invalid character", save);
String arg = argument.toString();
- int item_index = vec.indexOf(arg);
+ char arg_c = arg.charAt (0);
+ int item_index = -1;
+ boolean remove2 = false;
+ for (int i = vec.size () - 1; i > 0; --i ) {
+ RBCElement rbc = (RBCElement) vec.elementAt (i);
+ if (arg_c == rbc.key.charAt (0)) {
+ item_index = i;
+ if (arg.equals (rbc.key)&&(c == rbc.relation)) {
+ remove2 = true;
+ }
+ break;
+ }
+ }
if (c != '&')
{
// If the argument already appears in the vector, then we
// must remove it in order to re-order.
- if (item_index != -1)
+ if ((item_index != -1)&&remove2)
{
vec.removeElementAt(item_index);
if (insertion_index >= item_index)