Hi,

here is the last patch in the mauve JDK 1.0
compatibility series. This
one fixes the remaining[1] mauve bugs in
java.lang.Math, java.lang.String,
java.lang.StringBuffer.


* Math
there is a problem with the pow method, on i386-linux
using glibc
2.2.4 at least. Its output differs from what the spec
says for
 +-1.0 ** Inf.

I'm quite sure that this patch makes pow slower, since
the parameter
check is performed in java code. If that's a problem,
I'll try to
rewrite it in C.

* String
indexOf didn't throw NullPointerException if the
pattern String was
null. Now it does.

* StringBuffer
insert didn't allow Strings to be inserted after the
last
character. That's appending, basically. I've factored
out the index
checking code into two small private methods, and used
them to
eliminate duplicate index checking code in the class.

Performance effect: could be negative if the compiler
doesn't inline
private methods.

have fun

dalibor topic

[1] together with my double/float printing patch. You
might experience a failure in the Float test as well
if you use jikes, but that's due to a bug in jikes.


__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
        * libraries/clib/native/Math.c:
        (pow) renamed to (pow0).
        * libraries/javalib/java/lang/Math.java:
        (pow) return NaN if abs(a) is 1.0 and b is infinite. i368-linux
        glibc 2.2.4 doesn't do it.
        (pow0) new native method.
        * libraries/clib/native/String.c:
        (java_lang_String_indexOf) throw NullPointerException if pattern
        is NULL.
        * libraries/javalib/java/lang/StringBuffer.java:
        (checkIndex) new method.
        (checkExistingIndex) new method.
        (deleteCharAt) use checkExistingIndex instead of inlined check.
        (insert) use checkIndex instead of inlined check.
        (setCharAt) same.
diff -ur current/kaffe/libraries/clib/native/Math.c my-kaffe/libraries/clib/native/Math.c
--- current/kaffe/libraries/clib/native/Math.c	Mon Feb  8 06:07:18 1999
+++ my-kaffe/libraries/clib/native/Math.c	Fri Apr  5 01:23:39 2002
@@ -100,7 +100,7 @@
 }
 
 double
-java_lang_Math_pow(double v1, double v2)
+java_lang_Math_pow0(double v1, double v2)
 {
 	return (pow(v1, v2));
 }
diff -ur current/kaffe/libraries/clib/native/String.c my-kaffe/libraries/clib/native/String.c
--- current/kaffe/libraries/clib/native/String.c	Wed Jan 19 11:59:20 2000
+++ my-kaffe/libraries/clib/native/String.c	Fri Apr  5 01:09:14 2002
@@ -41,7 +41,11 @@
   unsigned char  bs[256];
   int *ibs;
 
-  if ( !pat || !str ) return -1;
+  if (pat == 0) {
+    SignalError("java.lang.NullPointerException", "");
+  }
+
+  if ( !str ) return -1;
 
   a = &(unhand_array(unhand(str)->value)->body[unhand(str)->offset]);
   n = unhand(str)->count;
diff -ur current/kaffe/libraries/javalib/java/lang/Math.java my-kaffe/libraries/javalib/java/lang/Math.java
--- current/kaffe/libraries/javalib/java/lang/Math.java	Mon Dec  6 22:08:18 1999
+++ my-kaffe/libraries/javalib/java/lang/Math.java	Fri Apr  5 01:24:18 2002
@@ -91,7 +91,14 @@
 
 public static long min(long a, long b) { return (a < b) ? (a) : (b); }
 
-native public static double pow(double a, double b);
+public static double pow(double a, double b) {
+	if (abs(a) == 1.0 && Double.isInfinite(b)) {
+		return Double.NaN;
+	}
+	return pow0(a, b);
+}
+
+native private static double pow0(double a, double b);
 
 public static synchronized double random() {
 	return MathRandom.random.nextDouble();
diff -ur current/kaffe/libraries/javalib/java/lang/StringBuffer.java my-kaffe/libraries/javalib/java/lang/StringBuffer.java
--- current/kaffe/libraries/javalib/java/lang/StringBuffer.java	Thu Nov 22 07:21:12 2001
+++ my-kaffe/libraries/javalib/java/lang/StringBuffer.java	Fri Apr  5 01:27:07 2002
@@ -97,9 +97,20 @@
 	return buffer[index];
 }
 
-public synchronized StringBuffer deleteCharAt(int index) {
-	if (index < 0 || index >= used)
+private void checkIndex(int index) {
+	if (index < 0 || index > length()) {
+		throw new StringIndexOutOfBoundsException();
+	}
+}
+
+private void checkExistingIndex(int index) {
+	if (index < 0 || index >= length()) {
 		throw new StringIndexOutOfBoundsException();
+	}
+}
+
+public synchronized StringBuffer deleteCharAt(int index) {
+	checkExistingIndex(index);
 	System.arraycopy(buffer, index + 1, buffer, index, --used - index);
 	return this;
 }
@@ -193,14 +204,13 @@
 }
 
 public StringBuffer insert(int offset, char[] str) {
+	checkIndex(offset);
 	return insert(offset, str, 0, str.length);
 }
 
 public synchronized StringBuffer insert(int index, char[] str,
 		int offset, int len) {
-	if (index < 0 || index > used) {
-		throw new StringIndexOutOfBoundsException();
-	}
+	checkIndex(index);
 	if (offset < 0 || len < 0 || offset + len > str.length) {
 		throw new StringIndexOutOfBoundsException();
 	}
@@ -250,8 +260,7 @@
 }
 
 public synchronized void setCharAt(int index, char ch) {
-	if (index < 0 || index >= used)
-		throw new StringIndexOutOfBoundsException();
+	checkIndex(index);
 	if (isStringized)				// optimization
 		ensureCapacity(used, true);
 	buffer[index] = ch;

Reply via email to