This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: gcjh compatibility
- From: Tom Tromey <tromey at redhat dot com>
- To: GCJ-patches <java-patches at gcc dot gnu dot org>
- Cc: GNU Classpath Patches <classpath-patches at gnu dot org>
- Date: 16 Mar 2007 16:27:56 -0600
- Subject: Patch: FYI: gcjh compatibility
- Reply-to: tromey at redhat dot com
I'm checking this in on the gcc trunk, the RH 4.1 branch, and to
Classpath.
Andrew noticed that in something like:
cd java/lang
gcjh -classpath . String
... the new gcjh would make java/lang/String.h, whereas the old one
would make String.h. This broke some existing Makefiles.
This patch changes gcjh to be compatible with the old version.
Tom
2007-03-16 Tom Tromey <tromey@redhat.com>
* tools/gnu/classpath/tools/javah/JniStubPrinter.java
(printClass): Added filename argument.
* tools/gnu/classpath/tools/javah/JniIncludePrinter.java
(printClass): Added filename argument.
* tools/gnu/classpath/tools/javah/CniIncludePrinter.java
(printClass): Use user's file name.
* tools/gnu/classpath/tools/javah/CniStubPrinter.java
(printClass): Use user's file name.
* tools/gnu/classpath/tools/javah/Printer.java (printClass): Added
filename argument.
* tools/gnu/classpath/tools/javah/Main.java (getParser): Fix '-v'
argument order.
(writeHeaders): Use a HashMap.
(run): Put class name into HashMap for writeHeaders.
Index: tools/gnu/classpath/tools/javah/CniStubPrinter.java
===================================================================
--- tools/gnu/classpath/tools/javah/CniStubPrinter.java (revision 122887)
+++ tools/gnu/classpath/tools/javah/CniStubPrinter.java (working copy)
@@ -1,5 +1,5 @@
/* CniStubPrinter.java - Generate a CNI stub file
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -90,12 +90,12 @@
return new CniPrintStream(fos);
}
- public void printClass(ClassWrapper klass) throws IOException
+ public void printClass(File filename, ClassWrapper klass) throws IOException
{
if (! klass.hasNativeMethod())
return;
String className = klass.name.replaceAll("/", "::");
- CniPrintStream out = (CniPrintStream) getPrintStream(klass.name + ".cc",
+ CniPrintStream out = (CniPrintStream) getPrintStream(filename + ".cc",
klass);
if (out == null)
return;
Index: tools/gnu/classpath/tools/javah/CniIncludePrinter.java
===================================================================
--- tools/gnu/classpath/tools/javah/CniIncludePrinter.java (revision 122887)
+++ tools/gnu/classpath/tools/javah/CniIncludePrinter.java (working copy)
@@ -1,5 +1,5 @@
/* CniIncludePrinter.java - generate CNI header files
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -63,14 +63,14 @@
return new PrintStream(fos);
}
- public void printClass(ClassWrapper klass) throws IOException
+ public void printClass(File filename, ClassWrapper klass) throws IOException
{
// Never write Object or Class. This is a hack, maybe
// the user would like to see what they look like...
if (klass.name.equals("java/lang/Object")
|| klass.name.equals("java/lang/Class"))
return;
- PrintStream ps = getPrintStream(klass.name + ".h", klass);
+ PrintStream ps = getPrintStream(filename + ".h", klass);
if (ps == null)
return;
ps.println();
Index: tools/gnu/classpath/tools/javah/JniStubPrinter.java
===================================================================
--- tools/gnu/classpath/tools/javah/JniStubPrinter.java (revision 122887)
+++ tools/gnu/classpath/tools/javah/JniStubPrinter.java (working copy)
@@ -1,5 +1,5 @@
/* JniStubPrinter.java - Generate JNI stub files
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -71,8 +71,9 @@
return new JniPrintStream(classpath, fos, klass);
}
- public void printClass(ClassWrapper klass) throws IOException
+ public void printClass(File filename, ClassWrapper klass) throws IOException
{
+ // Note that we ignore the filename here.
if (! klass.hasNativeMethod())
return;
String xname = JniHelper.mangle(klass.name);
Index: tools/gnu/classpath/tools/javah/Printer.java
===================================================================
--- tools/gnu/classpath/tools/javah/Printer.java (revision 122887)
+++ tools/gnu/classpath/tools/javah/Printer.java (working copy)
@@ -1,5 +1,5 @@
/* Print.java - abstract base class for printing classes
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -95,7 +95,8 @@
this.force = force;
}
- public abstract void printClass(ClassWrapper klass) throws IOException;
+ public abstract void printClass(File filename, ClassWrapper klass)
+ throws IOException;
protected abstract void writePreambleImpl(PrintStream ps);
Index: tools/gnu/classpath/tools/javah/Main.java
===================================================================
--- tools/gnu/classpath/tools/javah/Main.java (revision 122887)
+++ tools/gnu/classpath/tools/javah/Main.java (working copy)
@@ -58,6 +58,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map;
import org.objectweb.asm.ClassReader;
@@ -254,7 +255,7 @@
cni = true;
}
});
- result.add(new Option('v', "verbose", "Set verbose mode")
+ result.add(new Option("verbose", 'v', "Set verbose mode")
{
public void parsed(String arg0) throws OptionException
{
@@ -309,16 +310,18 @@
return result;
}
- private void writeHeaders(ArrayList klasses, Printer printer)
+ private void writeHeaders(HashMap klasses, Printer printer)
throws IOException
{
- Iterator i = klasses.iterator();
+ Iterator i = klasses.entrySet().iterator();
while (i.hasNext())
{
- ClassWrapper klass = (ClassWrapper) i.next();
+ Map.Entry e = (Map.Entry) i.next();
+ File filename = (File) e.getKey();
+ ClassWrapper klass = (ClassWrapper) e.getValue();
if (verbose)
- System.err.println("[writing " + klass + "]");
- printer.printClass(klass);
+ System.err.println("[writing " + klass + " as " + filename + "]");
+ printer.printClass(filename, klass);
}
}
@@ -376,19 +379,21 @@
}
Iterator i = klasses.iterator();
- ArrayList results = new ArrayList();
+ HashMap results = new HashMap();
while (i.hasNext())
{
// Let user specify either kind of class name or a
// file name.
Object item = i.next();
ClassWrapper klass;
+ File filename;
if (item instanceof File)
{
// Load class from file.
if (verbose)
System.err.println("[reading file " + item + "]");
- klass = getClass((File) item);
+ filename = (File) item;
+ klass = getClass(filename);
}
else
{
@@ -396,9 +401,12 @@
String className = ((String) item).replace('.', '/');
if (verbose)
System.err.println("[reading class " + className + "]");
+ // Use the name the user specified, even if it is
+ // different from the ultimate class name.
+ filename = new File(className);
klass = getClass(className);
}
- results.add(klass);
+ results.put(filename, klass);
}
writeHeaders(results, printer);
@@ -436,7 +444,8 @@
String resource = name.replace('.', '/') + ".class";
URL url = loader.findResource(resource);
if (url == null)
- throw new IOException("can't find class file " + resource);
+ throw new IOException("can't find class file " + resource
+ + " in " + loader);
InputStream is = url.openStream();
ClassWrapper result = readClass(is);
classMap.put(name, result);
Index: tools/gnu/classpath/tools/javah/JniIncludePrinter.java
===================================================================
--- tools/gnu/classpath/tools/javah/JniIncludePrinter.java (revision 122887)
+++ tools/gnu/classpath/tools/javah/JniIncludePrinter.java (working copy)
@@ -107,8 +107,9 @@
return new JniPrintStream(classpath, fos, klass);
}
- public void printClass(ClassWrapper klass) throws IOException
+ public void printClass(File filename, ClassWrapper klass) throws IOException
{
+ // Note that we ignore the filename here.
String xname = JniHelper.mangle(klass.name);
JniPrintStream out
= (JniPrintStream) getPrintStream(klass.name.replace('/', '_') + ".h",