Patch: name finder fixlets

Tom Tromey tromey@redhat.com
Fri Mar 14 22:51:00 GMT 2003


This fixes a couple NameFinder bugs.

First, we fail gracefully if the input stream is closed on us.
This can happen if you are running an ancient c++filt.

Second, we don't leak memory, and we allocate less memory in a common
case.

Andrew, what do you think?
I want to commit to trunk and branch.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* gnu/gcj/runtime/NameFinder.java (demangleName): Handle case
	where readLine returns null.
	* gnu/gcj/runtime/natNameFinder.cc (getExternalLabel): Return
	argument if there is no prefix.  Use _Jv_AllocBytes to avoid
	memory leak.  Use JvNewStringUTF to create string.

Index: gnu/gcj/runtime/NameFinder.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/runtime/NameFinder.java,v
retrieving revision 1.3.18.2
diff -u -r1.3.18.2 NameFinder.java
--- gnu/gcj/runtime/NameFinder.java 10 Mar 2003 19:34:30 -0000 1.3.18.2
+++ gnu/gcj/runtime/NameFinder.java 14 Mar 2003 22:48:59 -0000
@@ -1,5 +1,5 @@
 /* NameFinder.java -- Translates addresses to StackTraceElements.
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 
    This file is part of libgcj.
 
@@ -427,16 +427,22 @@
   private String demangleName(String s)
   {
     if (cppfilt != null)
-    {
-      try
-	{
-	  cppfiltOut.write(s);
-	  cppfiltOut.newLine();
-	  cppfiltOut.flush();
-	  return cppfiltIn.readLine();
-	}
-      catch (IOException ioe) { cppfilt.destroy(); cppfilt = null; }
-    }
+      {
+	try
+	  {
+	    cppfiltOut.write(s);
+	    cppfiltOut.newLine();
+	    cppfiltOut.flush();
+	    String name = cppfiltIn.readLine();
+	    if (name != null)
+	      s = name;
+	  }
+	catch (IOException ioe)
+	  {
+	    cppfilt.destroy();
+	    cppfilt = null;
+	  }
+      }
 
     return s;
   }
Index: gnu/gcj/runtime/natNameFinder.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/runtime/natNameFinder.cc,v
retrieving revision 1.3.18.1
diff -u -r1.3.18.1 natNameFinder.cc
--- gnu/gcj/runtime/natNameFinder.cc 10 Mar 2003 19:34:30 -0000 1.3.18.1
+++ gnu/gcj/runtime/natNameFinder.cc 14 Mar 2003 22:48:59 -0000
@@ -1,6 +1,6 @@
 // natNameFinder.cc - native helper methods for NameFinder.java
 
-/* Copyright (C) 2002  Free Software Foundation, Inc
+/* Copyright (C) 2002, 2003  Free Software Foundation, Inc
 
    This file is part of libgcj.
 
@@ -48,17 +48,19 @@
 
 #endif /* ! __USER_LABEL_PREFIX__ */
 
-java::lang::String*
-gnu::gcj::runtime::NameFinder::getExternalLabel (java::lang::String* name)
+java::lang::String *
+gnu::gcj::runtime::NameFinder::getExternalLabel (java::lang::String *name)
 {
+  jsize pfxLen = sizeof (LABEL_PREFIX) - 1;
+  if (pfxLen == 0)
+    return name;
+
   jsize nameLen = JvGetStringUTFLength (name);
-  jsize pfxLen = strlen (LABEL_PREFIX);
-  char *newName = (char *) JvMalloc (pfxLen + nameLen + 1);
-  *(newName + 0) = '\0';
+  char *newName = (char *) _Jv_AllocBytes (pfxLen + nameLen + 1);
   strcpy (newName, LABEL_PREFIX);
   JvGetStringUTFRegion (name, 0, nameLen, newName + pfxLen);
-  *(newName + pfxLen + nameLen) = '\0';
-  return JvNewStringLatin1 (newName);
+  newName[pfxLen + nameLen] = '\0';
+  return JvNewStringUTF (newName);
 }
 
 java::lang::String*



More information about the Java-patches mailing list