]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2007-06-24 Jerry DeLisle <jvdelisle@gcc.gnu.org>
authorjvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 24 Jun 2007 22:56:21 +0000 (22:56 +0000)
committerjvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 24 Jun 2007 22:56:21 +0000 (22:56 +0000)
PR libgfortran/32456
* runtime/error.c (show_locus): Update to emit the unit number
and file name involved with the error.  Use new function
filename_from_unit.
* libgfortran.h (filename_from_unit): Declare new function.
* io/unit.c (init_units): Set the unit file name for stdin, stdout,
and stderr for use later in error reporting.
(filename_from_unit): Add this new function.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@125989 138bc75d-0d04-0410-961f-82ee72b054a4

libgfortran/ChangeLog
libgfortran/io/unit.c
libgfortran/libgfortran.h
libgfortran/runtime/error.c

index fc31e65a6ec8f2ef8c269f96d37b741beab7ee19..55fe2e5f188a8f55df03f30ef80d01a7b6ab0dfa 100644 (file)
@@ -1,3 +1,14 @@
+2007-06-24  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/32456
+       * runtime/error.c (show_locus): Update to emit the unit number
+       and file name involved with the error.  Use new function
+       filename_from_unit.
+       * libgfortran.h (filename_from_unit): Declare new function.
+       * io/unit.c (init_units): Set the unit file name for stdin, stdout,
+       and stderr for use later in error reporting.
+       (filename_from_unit): Add this new function.
+
 2007-06-24  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libgfortran/32446
index c468510b8752b58caeb11353fad7b747770340da..9297af0852138650755542c828e43f96fdf65e58 100644 (file)
@@ -84,6 +84,12 @@ __gthread_mutex_t unit_lock = __GTHREAD_MUTEX_INIT;
 __gthread_mutex_t unit_lock;
 #endif
 
+/* We use these filenames for error reporting.  */
+
+static char stdin_name[] = "stdin";
+static char stdout_name[] = "stdout";
+static char stderr_name[] = "stderr";
+
 /* This implementation is based on Stefan Nilsson's article in the
  * July 1997 Doctor Dobb's Journal, "Treaps in Java". */
 
@@ -506,6 +512,10 @@ init_units (void)
       u->recl = options.default_recl;
       u->endfile = NO_ENDFILE;
 
+      u->file_len = strlen (stdin_name);
+      u->file = get_mem (u->file_len);
+      memmove (u->file, stdin_name, u->file_len);
+    
       __gthread_mutex_unlock (&u->lock);
     }
 
@@ -524,6 +534,10 @@ init_units (void)
 
       u->recl = options.default_recl;
       u->endfile = AT_ENDFILE;
+    
+      u->file_len = strlen (stdout_name);
+      u->file = get_mem (u->file_len);
+      memmove (u->file, stdout_name, u->file_len);
 
       __gthread_mutex_unlock (&u->lock);
     }
@@ -544,6 +558,10 @@ init_units (void)
       u->recl = options.default_recl;
       u->endfile = AT_ENDFILE;
 
+      u->file_len = strlen (stderr_name);
+      u->file = get_mem (u->file_len);
+      memmove (u->file, stderr_name, u->file_len);
+
       __gthread_mutex_unlock (&u->lock);
     }
 
@@ -665,3 +683,24 @@ update_position (gfc_unit *u)
   else
     u->flags.position = POSITION_ASIS;
 }
+
+
+/* filename_from_unit()-- If the unit_number exists, return a pointer to the
+   name of the associated file, otherwise return the empty string.  The caller
+   must free memory allocated for the filename string.  */
+
+char *
+filename_from_unit (int unit_number)
+{
+  char *filename;
+  gfc_unit *u = NULL;
+  u = find_unit (unit_number);
+  if (u != NULL)
+    {
+      filename = (char *) get_mem (u->file_len + 1);
+      unpack_filename (filename, u->file, u->file_len);
+      return filename;
+    }
+  else
+    return (char *) NULL;
+}
\ No newline at end of file
index d42302a3002f1015dbfdc33d5acca0092b6477af..e0801a14d1635d157809b9155de4dd533523cc67 100644 (file)
@@ -683,6 +683,9 @@ extern int st_printf (const char *, ...)
   __attribute__ ((format (printf, 1, 2)));
 internal_proto(st_printf);
 
+extern char * filename_from_unit (int);
+internal_proto(filename_from_unit);
+
 /* stop.c */
 
 extern void stop_numeric (GFC_INTEGER_4) __attribute__ ((noreturn));
index bd3c306bc2f4e3b8e00d1729953d59e7fd55e1bf..959a44b97d129446fb61d72fcc9277e76873af5b 100644 (file)
@@ -248,8 +248,22 @@ st_sprintf (char *buffer, const char *format, ...)
 void
 show_locus (st_parameter_common *cmp)
 {
+  static char *filename;
+
   if (!options.locus || cmp == NULL || cmp->filename == NULL)
     return;
+  
+  if (cmp->unit > 0)
+    {
+      filename = filename_from_unit (cmp->unit);
+      if (filename != NULL)
+       {
+         st_printf ("At line %d of file %s (unit = %d, file = '%s')\n",
+                  (int) cmp->line, cmp->filename, cmp->unit, filename);
+         free_mem (filename);
+       }
+      return;
+    }
 
   st_printf ("At line %d of file %s\n", (int) cmp->line, cmp->filename);
 }