[Kaffe] whatever became of my Class.forName() patches?

Mo DeJong mdejong at cygnus.com
Mon Feb 28 15:41:41 PST 2000


I was just looking over the ChangeLog and I noticed that my
Class.forName() patches never got added. I seem to remember
that there was a problem with one of the changes in the patch.
I am going to repost my patch minus the change that was
causing problems and see if that is acceptable. Does anyone
see any problems with the patch in its current form?

Mo Dejong
Red Hat Inc.
-------------- next part --------------
Index: kaffe/kaffevm/classMethod.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/classMethod.c,v
retrieving revision 1.75
diff -u -r1.75 classMethod.c
--- kaffe/kaffevm/classMethod.c	2000/01/19 11:04:31	1.75
+++ kaffe/kaffevm/classMethod.c	2000/01/29 01:19:59
@@ -1110,12 +1122,13 @@
 	}
 	class = loadClass(utf8, NULL, einfo);
 	utf8ConstRelease(utf8);
+
 	if (class != 0) {
 		if (processClass(class, CSTATE_COMPLETE, einfo) == true) {
 			return (class);
 		}
 	}
-	return (0);
+	return (NULL);
 }
 
 /*
@@ -2281,12 +2294,18 @@
 	/* If we couldn't resolve the element type, there's no way we can
 	 * construct the array type.
 	 */
-	if (c == 0) {
-		return (0);
+	if (c == NULL) {
+		return (NULL);
 	}
 
 	/* Build signature for array type */
 	if (CLASS_IS_PRIMITIVE (c)) {
+		/* An array of type void is not allowed */
+		if (strcmp(CLASS_CNAME(c), "void") == 0) {
+			postException(einfo, JAVA_LANG(VerifyError));
+			return (NULL);
+		}
+
 		arr_class = CLASS_ARRAY_CACHE(c);
 		if (arr_class) {
 			return (arr_class);
@@ -2304,12 +2323,12 @@
 	arr_name = utf8ConstNew(sig, -1);	/* release before returning */
 	if (!arr_name) {
 		postOutOfMemory(einfo);
-		return 0;
+		return (NULL);
 	}
 	centry = lookupClassEntry(arr_name, c->loader, einfo);
 	if (centry == 0) {
 		utf8ConstRelease(arr_name);
-		return (0);
+		return (NULL);
 	}
 
 	if (centry->class != 0) {
Index: kaffe/kaffevm/itypes.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/itypes.c,v
retrieving revision 1.17
diff -u -r1.17 itypes.c
--- kaffe/kaffevm/itypes.c	1999/11/29 23:44:10	1.17
+++ kaffe/kaffevm/itypes.c	2000/01/29 01:19:59
@@ -131,21 +131,49 @@
 Hjava_lang_Class*
 classFromSig(const char** strp, Hjava_lang_ClassLoader* loader, errorInfo *einfo)
 {
-	Hjava_lang_Class* cl;
+	Hjava_lang_Class* cl = NULL;
 	Utf8Const* utf8;
 	const char* start;
 	const char* end;
 
 	switch (*(*strp)++) {
-	case 'V': return (voidClass);
-	case 'I': return (intClass);
-	case 'Z': return (booleanClass);
-	case 'S': return (shortClass);
-	case 'B': return (byteClass);
-	case 'C': return (charClass);
-	case 'F': return (floatClass);
-	case 'D': return (doubleClass);
-	case 'J': return (longClass);
+	case 'V':
+	    if (cl == NULL)
+		cl = voidClass;
+	case 'I':
+	    if (cl == NULL)
+		cl = intClass;
+	case 'Z':
+	    if (cl == NULL)
+		cl = booleanClass;
+	case 'S':
+	    if (cl == NULL)
+		cl = shortClass;
+	case 'B':
+	    if (cl == NULL)
+		cl = byteClass;
+	case 'C':
+	    if (cl == NULL)
+		cl = charClass;
+	case 'F':
+	    if (cl == NULL)
+		cl = floatClass;
+	case 'D':
+	    if (cl == NULL)
+		cl = doubleClass;
+	case 'J':
+	    if (cl == NULL)
+		cl = longClass;
+
+	    if (cl != NULL) {
+		/* If build in type char is not at the end of the string, malformed signature */
+		if (*(*strp) != 0) {
+		    postException(einfo, JAVA_LANG(VerifyError));
+		    return (NULL);
+		}
+	    }
+
+	    return (cl);
 	case '[': return (lookupArray(classFromSig(strp, loader, einfo),
 				      einfo));
 	case 'L':
@@ -159,11 +187,17 @@
 		utf8 = utf8ConstNew(start, end - start);
 		if (!utf8) {
 			postOutOfMemory(einfo);
-			return 0;
+			return (NULL);
 		}
 		cl = loadClass(utf8, loader, einfo);
 		utf8ConstRelease(utf8);
-		return(cl);
+
+		/* Only class names can appear after a [L in the class name */
+		if (cl && CLASS_IS_PRIMITIVE(cl)) {
+			postException(einfo, JAVA_LANG(VerifyError));
+			cl = NULL;
+		}
+		return (cl);
 	default:
 		/* malformed signature */
 		postException(einfo, JAVA_LANG(VerifyError));


More information about the kaffe mailing list