large Class.forName() patch

Mo DeJong mdejong at cygnus.com
Thu Feb 3 15:22:58 PST 2000


It sounds like there is still some debate as to how the
primitive classes should be searched for by name, so could
we agree on this trimmed down patch that does not include
the part that disables lookups for "int" and such?

After lookups for "int" and friends are fixed the right
way (assuming there is agreement on what that way is),
will the following test still work? If we can not search
by a class name like "void" then will there be macro
tests like CLASS_ISVOID() CLASS_ISINT() added so we can
do such tests?

if (strcmp(CLASS_CNAME(c), "void") == 0) {
  // Do Something
}

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/02/03 23:06:12
@@ -1110,12 +1110,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 +2282,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 +2311,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/02/03 23:06:12
@@ -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