aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libgfortran/ChangeLog11
-rw-r--r--libgfortran/io/unit.c39
-rw-r--r--libgfortran/libgfortran.h3
-rw-r--r--libgfortran/runtime/error.c14
4 files changed, 67 insertions, 0 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index fc31e65..55fe2e5 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,5 +1,16 @@
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
* io/write.c (output_float): Calculate ndigits correctly for large
numbered formats that must pad zeros before the decimal point.
diff --git a/libgfortran/io/unit.c b/libgfortran/io/unit.c
index c468510..9297af0 100644
--- a/libgfortran/io/unit.c
+++ b/libgfortran/io/unit.c
@@ -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
diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h
index d42302a..e0801a1 100644
--- a/libgfortran/libgfortran.h
+++ b/libgfortran/libgfortran.h
@@ -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));
diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c
index bd3c306..959a44b 100644
--- a/libgfortran/runtime/error.c
+++ b/libgfortran/runtime/error.c
@@ -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);
}