This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gcjx] Patch: FYI: .class error handling


I'm checking this in on the gcjx branch.

This cleans up the messages printed when an error occurs while
reading a class file.

Tom

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

	* factory.cc (open_zip_file): Updated.
	* reader/readbuffer.cc (read_byte_buffer): Updated.
	* reader/readbuffer.hh (read_byte_buffer::where): New field.
	(read_byte_buffer): Added argument.
	* reader/fdreader.cc (read_all): Use get_location.
	(get_mtime): Use get_location.
	* reader/mmapbuffer.cc (mmap_byte_buffer): Updated.
	* reader/mmapbuffer.hh (mmap_byte_buffer::where): New field.
	(mmap_byte_buffer): Added argument.
	* reader/reader.hh (reader::get_location): New method.
	* reader/classbytes.cc (apply): Don't print a newline.

Index: factory.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/Attic/factory.cc,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 factory.cc
--- factory.cc 12 Sep 2005 01:49:00 -0000 1.1.2.3
+++ factory.cc 20 Sep 2005 17:01:18 -0000
@@ -197,7 +197,7 @@
       throw make_error (oss.str ());
     }
 
-  archive = new mmap_byte_buffer (arch_fd);
+  archive = new mmap_byte_buffer (location (file.c_str ()), arch_fd);
   close (arch_fd);
 }
 
Index: reader/classbytes.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/reader/Attic/classbytes.cc,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 classbytes.cc
--- reader/classbytes.cc 13 Feb 2005 03:39:45 -0000 1.1.2.2
+++ reader/classbytes.cc 20 Sep 2005 17:01:18 -0000
@@ -42,8 +42,8 @@
     }
   catch (class_file_error &cfe)
     {
-      // fixme file name
-      std::cerr << global->get_compiler ()->get_name () << ": "
-		<< "while reading: " << cfe << std::endl;
+      // Note that the exception prints a newline for us, and includes
+      // the location.
+      std::cerr << global->get_compiler ()->get_name () << ": " << cfe;
     }
 }
Index: reader/fdreader.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/reader/Attic/fdreader.cc,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 fdreader.cc
--- reader/fdreader.cc 12 Sep 2005 01:49:00 -0000 1.1.2.2
+++ reader/fdreader.cc 20 Sep 2005 17:01:18 -0000
@@ -39,7 +39,7 @@
 {
   // FIXME: configury.
   note_read ();
-  return new mmap_byte_buffer (fd);
+  return new mmap_byte_buffer (get_location (), fd);
 }
 
 time_t
@@ -47,8 +47,8 @@
 {
   struct stat stat_buf;
   if (fstat (fd, &stat_buf) != 0 || ! S_ISREG (stat_buf.st_mode))
-    // fixme wrong exception, should include perror, etc.
-    throw class_file_error (LOCATION_UNKNOWN,
+    // FIXME should include perror.
+    throw class_file_error (get_location (),
 			    "couldn't stat or not a regular file");
   return stat_buf.st_mtime;
 }
Index: reader/mmapbuffer.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/reader/Attic/mmapbuffer.cc,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 mmapbuffer.cc
--- reader/mmapbuffer.cc 13 Jan 2005 03:18:36 -0000 1.1.2.1
+++ reader/mmapbuffer.cc 20 Sep 2005 17:01:18 -0000
@@ -1,6 +1,6 @@
 // Implementation of mmap()-based buffer.
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -28,19 +28,19 @@
 
 #include "reader/mmapbuffer.hh"
 
-mmap_byte_buffer::mmap_byte_buffer (int fd)
+mmap_byte_buffer::mmap_byte_buffer (const location &w, int fd)
+  : where (w)
 {
   struct stat stat_buf;
   if (fstat (fd, &stat_buf) != 0 || ! S_ISREG (stat_buf.st_mode))
-    // fixme wrong exception, should include perror, etc.
-    throw class_file_error (LOCATION_UNKNOWN,
-			    "couldn't stat or not a regular file");
+    // FIXME: should include perror.
+    throw class_file_error (where, "couldn't stat or not a regular file");
 
   length = stat_buf.st_size;
   data = (uint8 *) mmap (NULL, length, PROT_READ, MAP_SHARED, fd, 0);
   if (data == (uint8 *) -1)
-    // fixme wrong exception, should include perror, etc.
-    throw class_file_error (LOCATION_UNKNOWN, "couldn't mmap");
+    // FIXME should include perror.
+    throw class_file_error (where, "couldn't mmap");
 }
 
 mmap_byte_buffer::~mmap_byte_buffer ()
Index: reader/mmapbuffer.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/reader/Attic/mmapbuffer.hh,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 mmapbuffer.hh
--- reader/mmapbuffer.hh 13 Jan 2005 03:18:36 -0000 1.1.2.1
+++ reader/mmapbuffer.hh 20 Sep 2005 17:01:18 -0000
@@ -1,6 +1,6 @@
 // A buffer that mmap()s its contents.
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -26,11 +26,14 @@
 
 class mmap_byte_buffer : public byte_buffer
 {
+  // Location for error reporting.
+  location where;
+
 public:
 
   /// Create a new mmap buffer given a file descriptor.
   /// fixme document the exception thrown on error.
-  mmap_byte_buffer (int);
+  mmap_byte_buffer (const location &, int);
 
   /// Destructor for this buffer.
   ~mmap_byte_buffer ();
Index: reader/readbuffer.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/reader/Attic/readbuffer.cc,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 readbuffer.cc
--- reader/readbuffer.cc 13 Jan 2005 03:18:36 -0000 1.1.2.1
+++ reader/readbuffer.cc 20 Sep 2005 17:01:18 -0000
@@ -1,6 +1,6 @@
 // Implementation of a buffer that read()s its contents.
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -27,19 +27,19 @@
 #include "typedefs.hh"
 #include "reader/readbuffer.hh"
 
-read_byte_buffer::read_byte_buffer (int fd)
+read_byte_buffer::read_byte_buffer (const location &w, int fd)
+  : where (w)
 {
   struct stat stat_buf;
   if (fstat (fd, &stat_buf) != 0 || ! S_ISREG (stat_buf.st_mode))
-    // fixme wrong exception, should include perror, etc.
-    throw class_file_error (LOCATION_UNKNOWN,
-			    "couldn't stat or not a regular file");
+    // FIXME should include perror.
+    throw class_file_error (where, "couldn't stat or not a regular file");
 
   length = stat_buf.st_size;
   data = new uint8[length];
   if ((unsigned long) read (fd, data, length) != length)
-    // fixme wrong exception, should include perror, etc.
-    throw class_file_error (LOCATION_UNKNOWN, "read error");
+    // FIXME should include perror.
+    throw class_file_error (where, "read error");
 }
 
 read_byte_buffer::~read_byte_buffer ()
Index: reader/readbuffer.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/reader/Attic/readbuffer.hh,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 readbuffer.hh
--- reader/readbuffer.hh 13 Jan 2005 03:18:36 -0000 1.1.2.1
+++ reader/readbuffer.hh 20 Sep 2005 17:01:18 -0000
@@ -1,6 +1,6 @@
 // Buffer that reads from a file descriptor.
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -26,11 +26,14 @@
 
 class read_byte_buffer : public byte_buffer
 {
+  // Location for error reporting.
+  location where;
+
 public:
 
   /// Create a new read()-based buffer given a file descriptor.
   /// fixme document the exception thrown on error.
-  read_byte_buffer (int);
+  read_byte_buffer (const location &, int);
 
   /// Destructor for this buffer.
   ~read_byte_buffer ();
Index: reader/reader.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/reader/Attic/reader.hh,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 reader.hh
--- reader/reader.hh 12 Sep 2005 01:49:00 -0000 1.1.2.2
+++ reader/reader.hh 20 Sep 2005 17:01:18 -0000
@@ -45,6 +45,11 @@
     global->get_compiler ()->note_file_read (filename);
   }
 
+  location get_location ()
+  {
+    return location (filename.c_str ());
+  }
+
 public:
 
   virtual ~reader ()


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]