[kaffe] CVS kaffe (robilad): added helper function for creation of new utf8 constants from strings

Kaffe CVS cvs-commits at kaffe.org
Fri Apr 21 19:01:09 PDT 2006


PatchSet 7257 
Date: 2006/04/22 01:53:39
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
added helper function for creation of new utf8 constants from strings

2006-04-22  Dalibor Topic  <robilad at kaffe.org>

        Replaced utf8ConstNew(*,-1) calls with the helper function
        utf8ConstFromString.

        * kaffe/kaffevm/utf8const.h,
        kaffe/kaffevm/utf8const.c (utf8ConstFromString): New function.
        (utf8ConstNew) Factored out creation of utf8 constants from
        null-terminated strings into utf8ConstFromString. Changed len
        parameter type to size_t.

        * kaffe/kaffeh/main.c,
        kaffe/kaffevm/baseClasses.c,
        kaffe/kaffevm/classMethod.c,
        kaffe/kaffevm/itypes.c,
        kaffe/kaffevm/reference.c,
        kaffe/kaffevm/string.c,
        kaffe/kaffevm/support.c,
        kaffe/kaffevm/gcj/gcj-glue.c,
        kaffe/kaffevm/jni/jni-string.c,
        kaffe/kaffevm/jni/jni.c,
        libraries/clib/management/JIT.c,
        libraries/clib/native/ClassLoader.c,
        libraries/clib/net/InetAddressImpl.c,
        libraries/extensions/microsoft/clib/Delegate.c,
        test/internal/jitBasic.c,
        test/internal/jit_stub.c: Replaced use of utf8ConstNew with
        utf8ConstFromString where a utf8 constant was created from a
        null-terminated string.

Members: 
	ChangeLog:1.4762->1.4763 
	kaffe/kaffeh/main.c:1.23->1.24 
	kaffe/kaffevm/baseClasses.c:1.74->1.75 
	kaffe/kaffevm/classMethod.c:1.154->1.155 
	kaffe/kaffevm/itypes.c:1.39->1.40 
	kaffe/kaffevm/reference.c:1.8->1.9 
	kaffe/kaffevm/string.c:1.48->1.49 
	kaffe/kaffevm/support.c:1.92->1.93 
	kaffe/kaffevm/utf8const.c:1.51->1.52 
	kaffe/kaffevm/utf8const.h:1.5->1.6 
	kaffe/kaffevm/gcj/gcj-glue.c:1.10->1.11 
	kaffe/kaffevm/jni/jni-string.c:1.15->1.16 
	kaffe/kaffevm/jni/jni.c:1.43->1.44 
	libraries/clib/management/JIT.c:1.10->1.11 
	libraries/clib/native/ClassLoader.c:1.52->1.53 
	libraries/clib/net/InetAddressImpl.c:1.33->1.34 
	libraries/extensions/microsoft/clib/Delegate.c:INITIAL->1.7 
	test/internal/jitBasic.c:INITIAL->1.10 
	test/internal/jit_stub.c:1.13->1.14 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4762 kaffe/ChangeLog:1.4763
--- kaffe/ChangeLog:1.4762	Sat Apr 22 00:32:11 2006
+++ kaffe/ChangeLog	Sat Apr 22 01:53:39 2006
@@ -1,5 +1,35 @@
 2006-04-22  Dalibor Topic  <robilad at kaffe.org>
 
+	Replaced utf8ConstNew(*,-1) calls with the helper function
+	utf8ConstFromString.
+
+	* kaffe/kaffevm/utf8const.h,
+	kaffe/kaffevm/utf8const.c (utf8ConstFromString): New function.
+	(utf8ConstNew) Factored out creation of utf8 constants from
+	null-terminated strings into utf8ConstFromString. Changed len
+	parameter type to size_t.
+
+	* kaffe/kaffeh/main.c,
+	kaffe/kaffevm/baseClasses.c,
+	kaffe/kaffevm/classMethod.c,
+	kaffe/kaffevm/itypes.c,
+	kaffe/kaffevm/reference.c,
+	kaffe/kaffevm/string.c,
+	kaffe/kaffevm/support.c,
+	kaffe/kaffevm/gcj/gcj-glue.c,
+	kaffe/kaffevm/jni/jni-string.c,
+	kaffe/kaffevm/jni/jni.c,
+	libraries/clib/management/JIT.c,
+	libraries/clib/native/ClassLoader.c,
+	libraries/clib/net/InetAddressImpl.c,
+	libraries/extensions/microsoft/clib/Delegate.c,
+	test/internal/jitBasic.c,
+	test/internal/jit_stub.c: Replaced use of utf8ConstNew with
+	utf8ConstFromString where a utf8 constant was created from a 
+	null-terminated string. 
+
+2006-04-22  Dalibor Topic  <robilad at kaffe.org>
+
 	* kaffe/kaffevm/jit/native-wrapper.c (Kaffe_wrapper):
 	Call the right initInsnSequence depending on the jit engine.
 	Call INIT_JIT_MD if necessary.
Index: kaffe/kaffe/kaffeh/main.c
diff -u kaffe/kaffe/kaffeh/main.c:1.23 kaffe/kaffe/kaffeh/main.c:1.24
--- kaffe/kaffe/kaffeh/main.c:1.23	Thu Mar 30 17:39:15 2006
+++ kaffe/kaffe/kaffeh/main.c	Sat Apr 22 01:53:40 2006
@@ -101,19 +101,19 @@
 	}
 
 	utf8ConstInit();
-	init_name = utf8ConstNew("<clinit>", -1);
-	final_name = utf8ConstNew("finalize", -1);
-	void_signature = utf8ConstNew("()V", -1);
-	constructor_name = utf8ConstNew("<init>", -1);
-	Code_name = utf8ConstNew("Code", -1);
-	LineNumberTable_name = utf8ConstNew("LineNumberTable", -1);
-	LocalVariableTable_name = utf8ConstNew("LocalVariableTable", -1);
-	ConstantValue_name = utf8ConstNew("ConstantValue", -1);
-	Exceptions_name = utf8ConstNew("Exceptions", -1);
-	SourceFile_name = utf8ConstNew("SourceFile", -1);
-	InnerClasses_name = utf8ConstNew("InnerClasses", -1);
-	Synthetic_name = utf8ConstNew("Synthetic", -1);
-	Signature_name = utf8ConstNew("Signature", -1);
+	init_name = utf8ConstFromString("<clinit>");
+	final_name = utf8ConstFromString("finalize");
+	void_signature = utf8ConstFromString("()V");
+	constructor_name = utf8ConstFromString("<init>");
+	Code_name = utf8ConstFromString("Code");
+	LineNumberTable_name = utf8ConstFromString("LineNumberTable");
+	LocalVariableTable_name = utf8ConstFromString("LocalVariableTable");
+	ConstantValue_name = utf8ConstFromString("ConstantValue");
+	Exceptions_name = utf8ConstFromString("Exceptions");
+	SourceFile_name = utf8ConstFromString("SourceFile");
+	InnerClasses_name = utf8ConstFromString("InnerClasses");
+	Synthetic_name = utf8ConstFromString("Synthetic");
+	Signature_name = utf8ConstFromString("Signature");
 
 	/* Process each class */
 	for (nm = argv[farg]; nm != 0; nm = argv[++farg]) {
Index: kaffe/kaffe/kaffevm/baseClasses.c
diff -u kaffe/kaffe/kaffevm/baseClasses.c:1.74 kaffe/kaffe/kaffevm/baseClasses.c:1.75
--- kaffe/kaffe/kaffevm/baseClasses.c:1.74	Mon Apr 17 17:57:05 2006
+++ kaffe/kaffe/kaffevm/baseClasses.c	Sat Apr 22 01:53:40 2006
@@ -247,20 +247,20 @@
 	/* Create the initialise and finalize names and signatures. */
 	DBG(INIT, dprintf("create names and signatures\n"); );
 
-	init_name = utf8ConstNew("<clinit>", -1);
-	final_name = utf8ConstNew("finalize", -1);
-	void_signature = utf8ConstNew("()V", -1);
-	constructor_name = utf8ConstNew("<init>", -1);
-	Code_name = utf8ConstNew("Code", -1);
-	LineNumberTable_name = utf8ConstNew("LineNumberTable", -1);
-	LocalVariableTable_name = utf8ConstNew("LocalVariableTable", -1);
-	ConstantValue_name = utf8ConstNew("ConstantValue", -1);
-	Exceptions_name = utf8ConstNew("Exceptions", -1);
-	SourceFile_name = utf8ConstNew("SourceFile", -1);
-	InnerClasses_name = utf8ConstNew("InnerClasses", -1);
-	Signature_name = utf8ConstNew("Signature", -1);
-	Synthetic_name = utf8ConstNew("Synthetic", -1);
-	EnclosingMethod_name = utf8ConstNew("EnclosingMethod", -1);
+	init_name = utf8ConstFromString("<clinit>");
+	final_name = utf8ConstFromString("finalize");
+	void_signature = utf8ConstFromString("()V");
+	constructor_name = utf8ConstFromString("<init>");
+	Code_name = utf8ConstFromString("Code");
+	LineNumberTable_name = utf8ConstFromString("LineNumberTable");
+	LocalVariableTable_name = utf8ConstFromString("LocalVariableTable");
+	ConstantValue_name = utf8ConstFromString("ConstantValue");
+	Exceptions_name = utf8ConstFromString("Exceptions");
+	SourceFile_name = utf8ConstFromString("SourceFile");
+	InnerClasses_name = utf8ConstFromString("InnerClasses");
+	Signature_name = utf8ConstFromString("Signature");
+	Synthetic_name = utf8ConstFromString("Synthetic");
+	EnclosingMethod_name = utf8ConstFromString("EnclosingMethod");
 
 	if (!(init_name && final_name && void_signature &&
 	      constructor_name && Code_name && LineNumberTable_name &&
Index: kaffe/kaffe/kaffevm/classMethod.c
diff -u kaffe/kaffe/kaffevm/classMethod.c:1.154 kaffe/kaffe/kaffevm/classMethod.c:1.155
--- kaffe/kaffe/kaffevm/classMethod.c:1.154	Mon Apr 17 17:57:05 2006
+++ kaffe/kaffe/kaffevm/classMethod.c	Sat Apr 22 01:53:40 2006
@@ -1613,7 +1613,7 @@
 	classEntry* centry;
 	bool refAdded;
 
-	utf8 = utf8ConstNew(name, -1);
+	utf8 = utf8ConstFromString(name);
 	if (!utf8) goto bad;
 	centry = lookupClassEntry(utf8, NULL, &info);
 	if (!centry) goto bad;
@@ -1665,7 +1665,7 @@
 	Hjava_lang_Class* class;
 	Utf8Const *utf8;
 
-	utf8 = utf8ConstNew(name, -1);
+	utf8 = utf8ConstFromString(name);
 	if (!utf8) {
 		postOutOfMemory(einfo);
 		return NULL;
@@ -2911,7 +2911,7 @@
 			sprintf (sig, "[L%s;", cname);
 		}
 	}
-	arr_name = utf8ConstNew(sig, -1);	/* release before returning */
+	arr_name = utf8ConstFromString(sig);	/* release before returning */
 	KFREE(sig);
 
 	if (!arr_name) {
Index: kaffe/kaffe/kaffevm/itypes.c
diff -u kaffe/kaffe/kaffevm/itypes.c:1.39 kaffe/kaffe/kaffevm/itypes.c:1.40
--- kaffe/kaffe/kaffevm/itypes.c:1.39	Mon May 30 21:16:03 2005
+++ kaffe/kaffe/kaffevm/itypes.c	Sat Apr 22 01:53:41 2006
@@ -55,7 +55,7 @@
 	}
 
 	clazz->vtable = _PRIMITIVE_DTABLE;
-	clazz->name = utf8ConstNew(name, -1);
+	clazz->name = utf8ConstFromString(name);
 	clazz->accflags = ACC_PUBLIC | ACC_FINAL;
 	CLASS_PRIM_SIG(clazz) = sig;
         CLASS_PRIM_NAME(clazz) = utf8ConstNew(&sig, 1);
@@ -75,7 +75,7 @@
 	 */
 	assert(strlen(name) <= 8);
 	sprintf(entryName, ";%s", name);
-	uname = utf8ConstNew(entryName, -1);
+	uname = utf8ConstFromString(entryName);
 	centry = lookupClassEntry(uname, NULL, &info);
 	utf8ConstRelease(uname);
 
Index: kaffe/kaffe/kaffevm/reference.c
diff -u kaffe/kaffe/kaffevm/reference.c:1.8 kaffe/kaffe/kaffevm/reference.c:1.9
--- kaffe/kaffe/kaffevm/reference.c:1.8	Sun Mar 19 16:16:21 2006
+++ kaffe/kaffe/kaffevm/reference.c	Sat Apr 22 01:53:41 2006
@@ -97,7 +97,7 @@
  
   if (referentOffset == ~((uint32)0))
     {
-      Utf8Const *referent_name = utf8ConstNew("referent", -1);
+      Utf8Const *referent_name = utf8ConstFromString("referent");
       Field *referent_field;
       errorInfo einfo;
 
Index: kaffe/kaffe/kaffevm/string.c
diff -u kaffe/kaffe/kaffevm/string.c:1.48 kaffe/kaffe/kaffevm/string.c:1.49
--- kaffe/kaffe/kaffevm/string.c:1.48	Mon Mar 20 21:46:21 2006
+++ kaffe/kaffe/kaffevm/string.c	Sat Apr 22 01:53:41 2006
@@ -245,7 +245,7 @@
 		throwError(&info);
 	}
 
-	utf8 = utf8ConstNew(utf8buf, -1);
+	utf8 = utf8ConstFromString(utf8buf);
 	KFREE(utf8buf);
 	return (utf8);
 }
Index: kaffe/kaffe/kaffevm/support.c
diff -u kaffe/kaffe/kaffevm/support.c:1.92 kaffe/kaffe/kaffevm/support.c:1.93
--- kaffe/kaffe/kaffevm/support.c:1.92	Sun Mar 19 16:16:21 2006
+++ kaffe/kaffe/kaffevm/support.c	Sat Apr 22 01:53:41 2006
@@ -67,7 +67,7 @@
   Utf8Const *fieldUTF;
   Field *field;
 
-  checkPtr(fieldUTF = utf8ConstNew(fieldName, -1));
+  checkPtr(fieldUTF = utf8ConstFromString(fieldName));
   field = lookupClassField(clazz, fieldUTF, isStatic, einfo);
   utf8ConstRelease(fieldUTF);
 
@@ -264,7 +264,7 @@
 		}
 	}
 
-	sig = checkPtr(utf8ConstNew(signature, -1));
+	sig = checkPtr(utf8ConstFromString(signature));
 	mb = findMethodLocal(cc, constructor_name, sig);
 	utf8ConstRelease(sig);
 	if (mb == 0) {
@@ -376,12 +376,12 @@
 	assert(name != NULL);
 	assert(sig != NULL);
 
-	name_utf8 = utf8ConstNew(name, -1);
+	name_utf8 = utf8ConstFromString(name);
 	if (!name_utf8) {
 		postOutOfMemory(einfo);
 		return NULL;
 	}
-	sig_utf8 = utf8ConstNew(sig, -1);
+	sig_utf8 = utf8ConstFromString(sig);
 	if (!sig_utf8) {
 		utf8ConstRelease(name_utf8);
 		postOutOfMemory(einfo);
Index: kaffe/kaffe/kaffevm/utf8const.c
diff -u kaffe/kaffe/kaffevm/utf8const.c:1.51 kaffe/kaffe/kaffevm/utf8const.c:1.52
--- kaffe/kaffe/kaffevm/utf8const.c:1.51	Sat May 14 21:46:31 2005
+++ kaffe/kaffe/kaffevm/utf8const.c	Sat Apr 22 01:53:41 2006
@@ -87,25 +87,24 @@
 static int		utf8ConstHashValueInternal(const void *v);
 static int		utf8ConstCompare(const void *v1, const void *v2);
 
+Utf8Const *
+utf8ConstFromString(const char *s)
+{
+  size_t len = strlen(s);
+  return utf8ConstNew(s, len);
+}
+
 /*
  * Convert a non-terminated UTF-8 string into an interned Utf8Const.
  * Returns 0 if an malloc failed occurred.
  */
 Utf8Const *
-utf8ConstNew(const char *s, int slen)
+utf8ConstNew(const char *s, size_t len)
 {
-	size_t len;
 	Utf8Const *utf8, *temp;
 	int32 hash;
 	Utf8Const *fake;
 	char buf[200];
-
-	/* Automatic length finder */
-	if (slen < 0) {
-		len = strlen(s);
-	}else{
-		len = (unsigned int) slen;
-	}
 
 #ifdef KAFFE_VMDEBUG
 	assert(utf8ConstIsValidUtf8(s, len));
Index: kaffe/kaffe/kaffevm/utf8const.h
diff -u kaffe/kaffe/kaffevm/utf8const.h:1.5 kaffe/kaffe/kaffevm/utf8const.h:1.6
--- kaffe/kaffe/kaffevm/utf8const.h:1.5	Thu Apr 22 09:22:38 2004
+++ kaffe/kaffe/kaffevm/utf8const.h	Sat Apr 22 01:53:41 2006
@@ -16,9 +16,19 @@
 /* Initialize utf8const support system */
 extern void		  utf8ConstInit(void);
 
+/**
+ * Create a Utf8Const from a string. 
+ *
+ * The returned pointer remains valid until 
+ * Utf8ConstRelease() is called.
+ *
+ * @str UTF-8 encoded, '\0'-terminated string. 
+ */
+extern Utf8Const*	  utf8ConstFromString(const char* str);
+
 /* Create a Utf8Const from a UTF-8 encoded array. The returned pointer
    remains valid until Utf8ConstRelease() is called. */
-extern Utf8Const*	  utf8ConstNew(const char*, int);
+extern Utf8Const*	  utf8ConstNew(const char* str, size_t len);
 
 /* Add a reference to a Utf8Const */
 extern void		  utf8ConstAddRef(Utf8Const*);
Index: kaffe/kaffe/kaffevm/gcj/gcj-glue.c
diff -u kaffe/kaffe/kaffevm/gcj/gcj-glue.c:1.10 kaffe/kaffe/kaffevm/gcj/gcj-glue.c:1.11
--- kaffe/kaffe/kaffevm/gcj/gcj-glue.c:1.10	Thu Mar 30 17:39:16 2006
+++ kaffe/kaffe/kaffevm/gcj/gcj-glue.c	Sat Apr 22 01:53:41 2006
@@ -233,10 +233,10 @@
 	static 	char buf[1024];
 
         Method *mt = &CLASS_METHODS(c)[CLASS_NMETHODS(c)];
-	mt->name = utf8ConstNew(info->name, -1);
+	mt->name = utf8ConstFromString(info->name);
 
 	classname2pathname(info->signature, buf);
-	signature = utf8ConstNew(buf, -1);
+	signature = utf8ConstFromString(buf);
 
         METHOD_PSIG(mt) = parseSignature(signature, einfo);
 	utf8ConstRelease(signature);
@@ -334,7 +334,7 @@
                 fld = &CLASS_FIELDS(c)[info->idx + CLASS_NSFIELDS(c)];
         }
         fld->accflags = info->flags;
-	fld->name = utf8ConstNew(info->name, -1);
+	fld->name = utf8ConstFromString(info->name);
 
 	/* For now, that's true.  However, see
 	 * http://sourceware.cygnus.com/ml/java-discuss/1999-q4/msg00379.html
Index: kaffe/kaffe/kaffevm/jni/jni-string.c
diff -u kaffe/kaffe/kaffevm/jni/jni-string.c:1.15 kaffe/kaffe/kaffevm/jni/jni-string.c:1.16
--- kaffe/kaffe/kaffevm/jni/jni-string.c:1.15	Fri Aug 19 01:47:01 2005
+++ kaffe/kaffe/kaffevm/jni/jni-string.c	Sat Apr 22 01:53:41 2006
@@ -101,7 +101,7 @@
     if (!utf8ConstIsValidUtf8(data, len)) {
       str = NULL;
     } else {
-      utf8 = checkPtr(utf8ConstNew(data, (int)len));
+      utf8 = checkPtr(utf8ConstNew(data, len));
       str = utf8Const2Java(utf8);
       utf8ConstRelease(utf8);
       if (!str) {
Index: kaffe/kaffe/kaffevm/jni/jni.c
diff -u kaffe/kaffe/kaffevm/jni/jni.c:1.43 kaffe/kaffe/kaffevm/jni/jni.c:1.44
--- kaffe/kaffe/kaffevm/jni/jni.c:1.43	Sun Apr 16 07:20:15 2006
+++ kaffe/kaffe/kaffevm/jni/jni.c	Sat Apr 22 01:53:41 2006
@@ -180,7 +180,7 @@
 	classname2pathname (name, pathname);
 
 	/* create a new utf8 constant */
-	utf8 = utf8ConstNew(pathname, -1);
+	utf8 = utf8ConstFromString(pathname);
 
 	/* free the internal form of name */
 	KFREE(pathname);
@@ -607,7 +607,7 @@
 	BEGIN_EXCEPTION_HANDLING(NULL);
 
 	cls_local = unveil(cls);
-	utf8 = checkPtr(utf8ConstNew(name, -1));
+	utf8 = checkPtr(utf8ConstFromString(name));
 	fld = lookupClassField((Hjava_lang_Class*)cls_local, utf8, false,
 			       &info);
 	utf8ConstRelease(utf8);
@@ -653,7 +653,7 @@
 	BEGIN_EXCEPTION_HANDLING(NULL);
 
 	cls_local = unveil(cls);
-	utf8 = checkPtr(utf8ConstNew(name, -1));
+	utf8 = checkPtr(utf8ConstFromString(name));
 	fld = lookupClassField((Hjava_lang_Class*)cls_local, utf8, true, &info);
 	utf8ConstRelease(utf8);
 	if (fld == NULL) {
Index: kaffe/libraries/clib/management/JIT.c
diff -u kaffe/libraries/clib/management/JIT.c:1.10 kaffe/libraries/clib/management/JIT.c:1.11
--- kaffe/libraries/clib/management/JIT.c:1.10	Mon Dec 26 20:06:36 2005
+++ kaffe/libraries/clib/management/JIT.c	Sat Apr 22 01:53:42 2006
@@ -49,9 +49,9 @@
 	char* cname = stringJava2C(_cname);
 	char* mname = stringJava2C(_mname);
 	char* signature = stringJava2C(_signature);
-	Utf8Const* u8cname = utf8ConstNew(cname, -1);
-	Utf8Const* u8mname = utf8ConstNew(mname, -1);
-	Utf8Const* u8sig = utf8ConstNew(signature, -1);
+	Utf8Const* u8cname = utf8ConstFromString(cname);
+	Utf8Const* u8mname = utf8ConstFromString(mname);
+	Utf8Const* u8sig = utf8ConstFromString(signature);
 
 	/* 
 	dprintf("translating %s.%s%s\n", cname, mname, signature);
Index: kaffe/libraries/clib/native/ClassLoader.c
diff -u kaffe/libraries/clib/native/ClassLoader.c:1.52 kaffe/libraries/clib/native/ClassLoader.c:1.53
--- kaffe/libraries/clib/native/ClassLoader.c:1.52	Tue Mar 21 00:24:10 2006
+++ kaffe/libraries/clib/native/ClassLoader.c	Sat Apr 22 01:53:42 2006
@@ -225,7 +225,7 @@
 		throwException (throwable);
 	}
 
-	if( (c = utf8ConstNew(name, -1)) )
+	if( (c = utf8ConstFromString(name)) )
 	{
 		clazz = loadClass(c, NULL, &info);
 		if( clazz )
Index: kaffe/libraries/clib/net/InetAddressImpl.c
diff -u kaffe/libraries/clib/net/InetAddressImpl.c:1.33 kaffe/libraries/clib/net/InetAddressImpl.c:1.34
--- kaffe/libraries/clib/net/InetAddressImpl.c:1.33	Tue May 31 17:55:52 2005
+++ kaffe/libraries/clib/net/InetAddressImpl.c	Sat Apr 22 01:53:42 2006
@@ -77,7 +77,7 @@
 
   if (inetClass == NULL)
     {
-      Utf8Const *name = utf8ConstNew("java/net/InetAddress", -1);
+      Utf8Const *name = utf8ConstFromString("java/net/InetAddress");
       inetClass = loadClass(name, NULL, &einfo);
       utf8ConstRelease(name);
       assert(inetClass != NULL);
@@ -123,7 +123,7 @@
 
   if (SysInetClass == NULL)
     {
-      Utf8Const *name = utf8ConstNew("gnu/java/net/SysInetAddressImpl", -1);
+      Utf8Const *name = utf8ConstFromString("gnu/java/net/SysInetAddressImpl");
       SysInetClass = loadClass(name, NULL, &einfo);
       utf8ConstRelease(name);
       assert(SysInetClass != NULL);
===================================================================
Checking out kaffe/libraries/extensions/microsoft/clib/Delegate.c
RCS:  /home/cvs/kaffe/kaffe/libraries/extensions/microsoft/clib/Delegate.c,v
VERS: 1.7
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/extensions/microsoft/clib/Delegate.c	Sat Apr 22 02:01:09 2006
@@ -0,0 +1,134 @@
+/*
+ * com.ms.lang.Delegate.c
+ *
+ * Copyright (c) 1999
+ *      Transvirtual Technologies, Inc.  All rights reserved.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file.
+ */
+#include "config.h"
+#include "config-std.h"
+#include "config-mem.h"
+#include "gtypes.h"
+#include "classMethod.h"
+#include "lookup.h"
+#include "stringSupport.h"
+#include <jni.h>
+#include <native.h>
+#include "java_lang_reflect_Method.h"
+
+/* Copied from Class.c */
+static
+Hjava_lang_Class*
+makeReturn(Method* meth)
+{
+	errorInfo info;
+	Hjava_lang_Class* clazz;
+
+	clazz = getClassFromSignaturePart(METHOD_RET_TYPE(meth), meth->class->loader, &info);
+	if (clazz == 0) {
+		throwError(&info);
+	}
+	
+	return (clazz);
+}
+
+/* Copied from Class.c */
+static
+HArrayOfObject*
+makeParameters(Method* meth)
+{
+	int i;
+	HArrayOfObject* array;
+	errorInfo info;
+	Hjava_lang_Class* clazz;
+
+	array = (HArrayOfObject*)AllocObjectArray(METHOD_NARGS(meth),
+	    "Ljava/lang/Class;", 0);
+	for (i = 0; i < METHOD_NARGS(meth); ++i) {
+		clazz = getClassFromSignaturePart(METHOD_ARG_TYPE(meth, i),
+					      meth->class->loader, &info);
+		if (clazz == 0) {
+			throwError(&info);
+		}
+		unhand_array(array)->body[i] = &clazz->head;
+	}		
+
+        return (array);
+}
+
+/* Copied from Class.c */
+static
+HArrayOfObject*
+makeExceptions(Method* meth)
+{
+	int nr;
+	int i;
+	HArrayOfObject* array;
+	Hjava_lang_Class** ptr;
+
+	if( meth->ndeclared_exceptions == -1 )
+	{
+		meth = meth->declared_exceptions_u.remote_exceptions;
+	}
+	nr = meth->ndeclared_exceptions;
+	array = (HArrayOfObject*)AllocObjectArray(nr, "Ljava/lang/Class;", 0);
+	ptr = (Hjava_lang_Class**)&unhand_array(array)->body[0];
+	for (i = 0; i < nr; i++) {
+		errorInfo info;
+		Hjava_lang_Class* clazz;
+		clazz = getClass(meth->declared_exceptions[i], meth->class, 
+				&info);
+		if (clazz == 0) {
+			throwError(&info);
+		}
+		*ptr++ = clazz;
+	}
+	return (array);
+}
+
+
+/* We need to find the method corresponding to the name and signature
+ * given.
+ */
+jobject
+Java_com_ms_lang_Delegate_getMethod0(JNIEnv* env, jclass delegate, jobject o, jstring name, jstring sig)
+{
+	jboolean ncopy;
+	jboolean scopy;
+	jbyte* bname;
+	jbyte* bsig;
+	Method* m;
+	Hjava_lang_reflect_Method* meth;
+	Hjava_lang_Class* clazz;
+	Utf8Const* fname;
+	Utf8Const* fsig;
+
+	bname = (jbyte*)(*env)->GetStringUTFChars(env, name, &ncopy);
+	bsig = (jbyte*)(*env)->GetStringUTFChars(env, sig, &scopy);
+	clazz = (Hjava_lang_Class*)(*env)->GetObjectClass(env, o);
+
+	fname = utf8ConstFromString(bname);
+	fsig = utf8ConstFromString(bsig);
+
+	m = findMethodLocal(clazz, fname, fsig);
+
+	utf8ConstRelease(fname);
+	utf8ConstRelease(fsig);
+
+	meth = (Hjava_lang_reflect_Method*)
+	    AllocObject("java/lang/reflect/Method", 0);
+	unhand(meth)->clazz = clazz;
+	unhand(meth)->slot = m - CLASS_METHODS(clazz);
+	unhand(meth)->name = name;
+	unhand(meth)->parameterTypes = makeParameters(m);
+	unhand(meth)->exceptionTypes = makeExceptions(m);
+	unhand(meth)->returnType = makeReturn(m);
+
+	(*env)->ReleaseStringUTFChars(env, name, bname);
+	(*env)->ReleaseStringUTFChars(env, sig, bsig);
+
+	return (meth);
+}
+
===================================================================
Checking out kaffe/test/internal/jitBasic.c
RCS:  /home/cvs/kaffe/kaffe/test/internal/jitBasic.c,v
VERS: 1.10
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/test/internal/jitBasic.c	Sat Apr 22 02:01:09 2006
@@ -0,0 +1,288 @@
+/*
+ * jitBasic.c
+ *
+ * Copyright (c) 2003, 2004 University of Utah and the Flux Group.
+ * All rights reserved.
+ *
+ * This file is licensed under the terms of the GNU Public License.
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ *
+ * Contributed by the Flux Research Group, Department of Computer Science,
+ * University of Utah, http://www.cs.utah.edu/flux/
+ */
+
+#include "config.h"
+#include "object.h"
+#include "support.h"
+#include "utf8const.h"
+#include "classMethod.h"
+#include "stringParsing.h"
+
+#if !defined(TRANSLATOR)
+
+int internal_test(char *class_name)
+{
+	return( 0 );
+}
+
+#else
+
+#include <machine.h>
+#include <slots.h>
+#include <seq.h>
+#include <labels.h>
+#include <codeproto.h>
+#include <basecode.h>
+
+Method *findMethodNoSig(Hjava_lang_Class *cl, Utf8Const *name)
+{
+	Method *retval = 0;
+	int lpc;
+
+	assert(cl != 0);
+	assert(name != 0);
+
+	for( lpc = 0; (lpc < CLASS_NMETHODS(cl)) && !retval; lpc++ )
+	{
+		if( CLASS_METHODS(cl)[lpc].name == name )
+			retval = &CLASS_METHODS(cl)[lpc];
+	}
+
+	assert(retval != 0);
+	
+	return( retval );
+}
+
+#define MAX_TEST_FIELD_COMPONENTS 64
+
+struct testField {
+	char *tf_Name;
+	int tf_ComponentCount;
+	int tf_MethodIndex;
+	parsedString tf_Components[MAX_TEST_FIELD_COMPONENTS];
+};
+
+static
+int fieldComponentHandler(struct testField *tf)
+{
+	int retval = 1;
+
+	tf->tf_ComponentCount += 1;
+	tf->tf_Components[tf->tf_ComponentCount] = tf->tf_Components[0];
+	if( tf->tf_Components[0].len == 0 )
+		tf->tf_MethodIndex = tf->tf_ComponentCount + 1;
+	return( retval );
+}
+
+int parseTestField(struct testField *tf)
+{
+	return parseString(
+		tf->tf_Name,
+		SPO_NotEmpty,
+		  SPO_Do,
+		    SPO_String, &tf->tf_Components[0],
+		    SPO_While, "_", "",
+		    SPO_Handle, fieldComponentHandler, tf,
+		    SPO_End,
+		  SPO_End,
+		SPO_End);
+}
+
+int field2values(jvalue *dst, parsed_signature_t *ps, struct testField *tf)
+{
+	int lpc, retval = 1;
+
+	for( lpc = 1; (lpc <= ps->nargs) && retval; lpc++ )
+	{
+		parsedString *arg;
+		char *str;
+
+		arg = &tf->tf_Components[lpc + 1];
+		switch( ps->signature->data[ps->ret_and_args[lpc]] )
+		{
+		case 'Z':
+			dst[lpc - 1].z = !cmpPStrStr(arg, "true");
+			break;
+		case 'B':
+			dst[lpc - 1].b = (char)strtol(arg->data, 0, 0);
+			break;
+		case 'C':
+			dst[lpc - 1].c = arg->data[0];
+			break;
+		case 'S':
+			dst[lpc - 1].s = (short)strtol(arg->data, 0, 0);
+			break;
+		case 'I':
+			dst[lpc - 1].i = strtoul(arg->data, 0, 0);
+			break;
+		case 'J':
+#if defined(HAVE_STRTOULL)
+			dst[lpc - 1].j = (long long)strtoull(arg->data, 0, 0);
+#elif defined(HAVE_STRTOUQ)
+			dst[lpc - 1].j = (long long)strtouq(arg->data, 0, 0);
+#else
+#error "jitBasic needs either strtoull or strtouq."
+#endif
+			break;
+		case 'D':
+		case 'F':
+			if( (str = promoteParsedString(arg)) )
+			{
+				double value;
+				char *sep;
+				
+				if( (sep = strchr(str, 'd')) )
+				{
+					*sep = '.';
+				}
+				value = strtod(str, 0);
+				if( ps->signature->data[ps->ret_and_args[lpc]]
+				    == 'D' )
+				{
+					dst[lpc - 1].d = value;
+				}
+				else
+				{
+					dst[lpc - 1].f = (float)value;
+				}
+				gc_free(str);
+			}
+			else
+			{
+				retval = 0;
+			}
+			break;
+		default:
+			assert(0);
+			break;
+		}
+	}
+	return( retval );
+}
+
+int testMethod(Hjava_lang_Class *cl, Field *field)
+{
+	struct testField tf;
+	errorInfo einfo;
+	int retval = 0;
+
+	tf.tf_Name = (char *)field->name->data;
+	tf.tf_ComponentCount = 0;
+	if( parseTestField(&tf) )
+	{
+		Utf8Const *utf;
+		Method *meth;
+		
+		utf = utf8ConstFromString(tf.tf_Components[tf.tf_MethodIndex].data);
+		meth = findMethodNoSig(cl, utf);
+		if( translate(meth, &einfo) )
+		{
+			jvalue args[MAX_TEST_FIELD_COMPONENTS];
+			jvalue rc, actual;
+			void *methblock;
+
+			field2values(args, METHOD_PSIG(meth), &tf);
+			methblock = KGC_getObjectBase(main_collector,
+						     METHOD_NATIVECODE(meth));
+			memset(&rc, 0, sizeof(rc));
+			memset(&actual, 0, sizeof(actual));
+			KaffeVM_callMethodA(meth,
+				    METHOD_NATIVECODE(meth),
+				    0,
+				    args,
+				    &rc,
+				    0);
+			switch( field->bsize )
+			{
+			case sizeof(jbyte):
+				actual.i = ((char *)field->info.addr)[0];
+				break;
+			case sizeof(jshort):
+				actual.i = ((short *)field->info.addr)[0];
+				break;
+			case sizeof(jint):
+				memcpy(&actual.i,
+				       field->info.addr,
+				       field->bsize);
+				break;
+			case sizeof(jdouble):
+				memcpy(&actual.d,
+				       field->info.addr,
+				       field->bsize);
+				break;
+			default:
+				assert(0);
+				break;
+			}
+			if( !memcmp(&rc, &actual, sizeof(rc)) )
+			{
+				kaffe_dprintf("Success %08x\n", rc.i);
+				retval = 1;
+			}
+			else
+			{
+				kaffe_dprintf("Failure for %s, got: %08x %f\n"
+					      "  expected: %08x %f\n",
+					      field->name->data,
+					      rc.i, rc.d,
+					      actual.i, actual.d);
+			}
+		}
+		else
+		{
+			assert(0);
+		}
+	}
+	return( retval );
+}
+
+int internal_test(parsedString *ps)
+{
+	char *class_name;
+	int retval = 0;
+
+	if( (class_name = promoteParsedString(ps)) )
+	{
+		Hjava_lang_Class *cl;
+		errorInfo einfo;
+		int lpc;
+		
+		retval = 1;
+		loadStaticClass(&cl, class_name);
+		processClass(cl, CSTATE_COMPLETE, &einfo);
+		kaffe_dprintf("class: %s\n", cl->name->data);
+		for( lpc = 0; (lpc < CLASS_NSFIELDS(cl)) && retval; lpc++ )
+		{
+			Field *field;
+			uint32 expected_value;
+			
+			field = &CLASS_SFIELDS(cl)[lpc];
+
+			switch (field->bsize) {
+			case 1:
+			  expected_value = ((uint8 *)field->info.addr)[0];
+			  break;
+			case 2:
+			  expected_value = ((uint16 *)field->info.addr)[0];
+			  break;
+			case 4:
+			  expected_value = ((uint32 *)field->info.addr)[0];
+			  break;
+			default:
+			  expected_value = 0;
+			}
+                        kaffe_dprintf("  field: %s = 0x%08x\n",
+                                      field->name->data,
+				      expected_value);
+			if( !strncmp("test_", field->name->data, 5) )
+			{
+				retval = testMethod(cl, field);
+			}
+		}
+		gc_free(class_name);
+	}
+	return( retval );
+}
+
+#endif
Index: kaffe/test/internal/jit_stub.c
diff -u kaffe/test/internal/jit_stub.c:1.13 kaffe/test/internal/jit_stub.c:1.14
--- kaffe/test/internal/jit_stub.c:1.13	Mon Apr 17 17:58:16 2006
+++ kaffe/test/internal/jit_stub.c	Sat Apr 22 01:53:43 2006
@@ -124,20 +124,20 @@
 	initNative();
 	
 	/* Create the initialise and finalize names and signatures. */
-	init_name = utf8ConstNew("<clinit>", -1);
-	final_name = utf8ConstNew("finalize", -1);
-	void_signature = utf8ConstNew("()V", -1);
-	constructor_name = utf8ConstNew("<init>", -1);
-	Code_name = utf8ConstNew("Code", -1);
-	LineNumberTable_name = utf8ConstNew("LineNumberTable", -1);
-	LocalVariableTable_name = utf8ConstNew("LocalVariableTable", -1);
-	ConstantValue_name = utf8ConstNew("ConstantValue", -1);
-	Exceptions_name = utf8ConstNew("Exceptions", -1);
-	SourceFile_name = utf8ConstNew("SourceFile", -1);
-	InnerClasses_name = utf8ConstNew("InnerClasses", -1);
-	Synthetic_name = utf8ConstNew("Synthetic", -1);
-	Signature_name = utf8ConstNew("Signature", -1);
-	EnclosingMethod_name = utf8ConstNew("EnclosingMethod", -1);
+	init_name = utf8ConstFromString("<clinit>");
+	final_name = utf8ConstFromString("finalize");
+	void_signature = utf8ConstFromString("()V");
+	constructor_name = utf8ConstFromString("<init>");
+	Code_name = utf8ConstFromString("Code");
+	LineNumberTable_name = utf8ConstFromString("LineNumberTable");
+	LocalVariableTable_name = utf8ConstFromString("LocalVariableTable");
+	ConstantValue_name = utf8ConstFromString("ConstantValue");
+	Exceptions_name = utf8ConstFromString("Exceptions");
+	SourceFile_name = utf8ConstFromString("SourceFile");
+	InnerClasses_name = utf8ConstFromString("InnerClasses");
+	Synthetic_name = utf8ConstFromString("Synthetic");
+	Signature_name = utf8ConstFromString("Signature");
+	EnclosingMethod_name = utf8ConstFromString("EnclosingMethod");
 
 	if (!(init_name && final_name && void_signature &&
 	      constructor_name && Code_name && LineNumberTable_name &&




More information about the kaffe mailing list