Finally Got GCJ 3.4 Working Under MingW

Mohan Embar gnustuff@thisiscool.com
Sun May 11 21:38:00 GMT 2003


Lars,

>So far, this problem has chewed up and spit out both Lars and me...

...but I fought back and ate this problem alive. It was one of the
most gruesome, hideous debugging experiences I've had.

I've attached the patches (apply from libjava) as well as included
them in the text of this email. I'm not going to comment on them
at length because I'm too burned out and only want to unblock
people wanting to try out GCJ 3.4 on MingW. I'll submit official
patches with explanations later.

Ranjit, the natFileDescriptorWin32.cc will only work for console
file handles for >=WinNT 5.0 as per the SDK documentation, so
we'll need another approach, which might mean unconditionally
returning true.

You need to apply these two patches on top of all the other ones.

Patch 1:
---------------------------------------------------------8<------------------------------------------------
Index: java/io/natFileDescriptorWin32.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/io/natFileDescriptorWin32.cc,v
retrieving revision 1.12
diff -u -2 -r1.12 natFileDescriptorWin32.cc
--- java/io/natFileDescriptorWin32.cc	11 Feb 2003 20:55:26 -0000	1.12
+++ java/io/natFileDescriptorWin32.cc	11 May 2003 18:04:39 -0000
@@ -72,6 +72,11 @@
 jboolean
 java::io::FileDescriptor::valid (void) {
-  BY_HANDLE_FILE_INFORMATION info;
-  return GetFileInformationByHandle ((HANDLE)fd, &info) != 0;
+  /* As with UNIX, a "file" descriptor can be one of
+     a gazillion possible underlying things like a pipe
+     or socket, so we can't get too fancy here. */
+  DWORD dwFlags;
+  HANDLE h = (HANDLE) fd;
+  return !!GetHandleInformation (h, &dwFlags);
+    // FIXME: this will only work for WinNT > 5.0
 }
---------------------------------------------------------8<------------------------------------------------

Patch 2:
---------------------------------------------------------8<------------------------------------------------
Index: java/lang/natClass.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/lang/natClass.cc,v
retrieving revision 1.61
diff -u -2 -r1.61 natClass.cc
--- java/lang/natClass.cc	29 Mar 2003 20:17:02 -0000	1.61
+++ java/lang/natClass.cc	11 May 2003 12:29:04 -0000
@@ -96,15 +96,10 @@
     = new gnu::gcj::runtime::StackTrace(4);
   java::lang::Class *klass = NULL;
-  try
-    {
-      for (int i = 1; !klass; i++)
-	{
-	  klass = t->classAt (i);
-	}
-      loader = klass->getClassLoader();
-    }
-  catch (::java::lang::ArrayIndexOutOfBoundsException *e)
+  for (int i = 1; !klass && i < t->length (); i++)
     {
+      klass = t->classAt (i);
     }
+  if (klass)
+    loader = klass->getClassLoader ();
 
   return forName (className, true, loader);
Index: java/lang/natRuntime.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/lang/natRuntime.cc,v
retrieving revision 1.36
diff -u -2 -r1.36 natRuntime.cc
--- java/lang/natRuntime.cc	26 Mar 2003 22:31:52 -0000	1.36
+++ java/lang/natRuntime.cc	11 May 2003 12:29:05 -0000
@@ -171,23 +171,16 @@
       ClassLoader *look = NULL;
       gnu::gcj::runtime::StackTrace *t = new gnu::gcj::runtime::StackTrace(10);
-      try
-      	{
-	  for (int i = 0; i < 10; ++i)
-	    {
-	      jclass klass = t->classAt(i);
-	      if (klass != NULL)
-		{
-		  ClassLoader *loader = klass->getClassLoaderInternal();
-		  if (loader != NULL && loader != sys)
-		    {
-		      look = loader;
-		      break;
-		    }
-		}
-	    }
-	}
-      catch (::java::lang::ArrayIndexOutOfBoundsException *e)
-	{
-	}
+      for (int i = 0; !look && i < t->length(); ++i)
+        {
+          jclass klass = t->classAt(i);
+          if (klass != NULL)
+            {
+              ClassLoader *loader = klass->getClassLoaderInternal();
+              if (loader != NULL && loader != sys)
+                {
+                  look = loader;
+                }
+            }
+        }
 
       if (look != NULL)
Index: java/util/natResourceBundle.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/util/natResourceBundle.cc,v
retrieving revision 1.7
diff -u -2 -r1.7 natResourceBundle.cc
--- java/util/natResourceBundle.cc	21 Jan 2003 21:16:46 -0000	1.7
+++ java/util/natResourceBundle.cc	11 May 2003 12:29:08 -0000
@@ -24,18 +24,12 @@
 {
   gnu::gcj::runtime::StackTrace *t = new gnu::gcj::runtime::StackTrace(6);
-  try
-    {
-      /* Frame 0 is this method, frame 1 is getBundle, so starting at
-	 frame 2 we might see the user's class.  FIXME: should account
-	 for reflection, JNI, etc, here.  */
-      for (int i = 2; ; ++i)
-	{
-	  jclass klass = t->classAt(i);
-	  if (klass != NULL)
-	    return klass->getClassLoaderInternal();
-	}
-    }
-  catch (::java::lang::ArrayIndexOutOfBoundsException *e)
+  /* Frame 0 is this method, frame 1 is getBundle, so starting at
+     frame 2 we might see the user's class.  FIXME: should account
+     for reflection, JNI, etc, here.  */
+  for (int i = 2; i < t->length (); ++i)
     {
+      jclass klass = t->classAt (i);
+      if (klass != NULL)
+        return klass->getClassLoaderInternal ();
     }
   return NULL;
---------------------------------------------------------8<------------------------------------------------

-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: noaiobe.diff
Type: application/octet-stream
Size: 3282 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java/attachments/20030511/b51e4b33/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fdvalid2.diff
Type: application/octet-stream
Size: 864 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java/attachments/20030511/b51e4b33/attachment-0001.obj>


More information about the Java mailing list