[kaffe] various kaffeh bugfixes

Kurt Miller truk at optonline.net
Thu Jul 21 09:34:59 PDT 2005


This patch makes the following changes:
- adds constant suffixes to constant values (L, LL, f)
- changes CONSTANT_Long to print in decimal instead of hex
- fixes CONSTANT_Double on little endian and lp64 arches
- allows private static final constants to be output
- outputs #undef before any constant #define to fix cases
  where multiple defines are output with same name

I've tested this on OpenBSD/i386/macppc/sparc64. The
changes make the output of kaffeh much closer to javah.

Please review and commit if ok.

Thanks,
-Kurt

--- kaffe/kaffeh/support.c.orig	Tue Apr  5 13:45:53 2005
+++ kaffe/kaffeh/support.c	Thu Jul 21 11:43:32 2005
@@ -448,28 +448,45 @@ constValueToString(Hjava_lang_Class* thi
 	/* Pull the constant value for this field out of the constant pool */
 	switch (CLASS_CONST_TAG(this, idx)) {
 	case CONSTANT_Integer:
-		sprintf(cval, "%d", (int)CLASS_CONST_DATA(this, idx));
+		sprintf(cval, "%dL", (jint)CLASS_CONST_DATA(this, idx));
 		break;
 	case CONSTANT_Float:
-		sprintf(cval, "%.7e", *(float*)&CLASS_CONST_DATA(this,idx));
+	{
+		sprintf(cval, "%.7Ef", *(jfloat*)&CLASS_CONST_DATA(this,idx));
 		break;
+	}
 	case CONSTANT_Long:
+	{
 #if SIZEOF_VOID_P == 8
-		sprintf(cval, "0x%016lx", CLASS_CONST_DATA(this,idx));
+		sprintf(cval, "%ldLL", (jlong)CLASS_CONST_DATA(this,idx));
 #else
+		union { jint i[2]; jlong l; } u;
 #if defined(WORDS_BIGENDIAN)
-		sprintf(cval, "0x%08x%08x", CLASS_CONST_DATA(this,idx), CLASS_CONST_DATA(this,idx+1));
+		u.i[0] = (jint)CLASS_CONST_DATA(this,idx);
+		u.i[1] = (jint)CLASS_CONST_DATA(this,idx+1);
 #else
-		sprintf(cval, "0x%08x%08x", CLASS_CONST_DATA(this,idx+1), CLASS_CONST_DATA(this,idx));
+		u.i[0] = (jint)CLASS_CONST_DATA(this,idx+1);
+		u.i[1] = (jint)CLASS_CONST_DATA(this,idx);
 #endif
+		sprintf(cval, "%lldLL", u.l);
 #endif
 		break;
+	}
 	case CONSTANT_Double:
 	{
-		union { jint i[2]; jdouble d; } u;
-		u.i[0] = CLASS_CONST_DATA(this,idx);
-		u.i[1] = CLASS_CONST_DATA(this,idx+1);
-		sprintf(cval, "%.16e", u.d);
+		union { jint i[2]; jlong l; jdouble d; } u;
+#if SIZEOF_VOID_P == 8
+		u.l = (jlong)CLASS_CONST_DATA(this,idx);
+#else
+#if defined(WORDS_BIGENDIAN)
+		u.i[0] = (jint)CLASS_CONST_DATA(this,idx);
+		u.i[1] = (jint)CLASS_CONST_DATA(this,idx+1);
+#else
+		u.i[0] = (jint)CLASS_CONST_DATA(this,idx+1);
+		u.i[1] = (jint)CLASS_CONST_DATA(this,idx);
+#endif
+#endif
+		sprintf(cval, "%.16E", u.d);
 		break;
 	}
 	case CONSTANT_String:
@@ -487,19 +504,19 @@ setFieldValue(Hjava_lang_Class* this, Fi
 {
 	assert(f != NULL);
 
-	if ((f->accflags & (ACC_STATIC|ACC_PUBLIC|ACC_FINAL)) == (ACC_STATIC|ACC_PUBLIC|ACC_FINAL)) {
+	if ((f->accflags & (ACC_STATIC|ACC_FINAL)) == (ACC_STATIC|ACC_FINAL)) {
 		char cval[512];
 
 		constValueToString(this, idx, cval);
 
 		if (cval[0] != '\0') {
 			if (include != NULL) {
-				fprintf(include, "#define %s_%s %s\n",
-					className, f->name->data, cval);
+				fprintf(include, "#undef %s_%s\n#define %s_%s %s\n",
+					className, f->name->data, className, f->name->data, cval);
 			}
 			if (jni_include != NULL) {
-				fprintf(jni_include, "#define %s_%s %s\n",
-					className, f->name->data, cval);
+				fprintf(jni_include, "#undef %s_%s\n#define %s_%s %s\n",
+					className, f->name->data, className, f->name->data, cval);
 			}
 		}
 	}




More information about the kaffe mailing list