This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/31587] Module files shouldn't be updated if their content doesn't change
- From: "fxcoudert at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Apr 2007 22:15:14 -0000
- Subject: [Bug fortran/31587] Module files shouldn't be updated if their content doesn't change
- References: <bug-31587-10259@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #6 from fxcoudert at gcc dot gnu dot org 2007-04-16 23:15 -------
OK, I've researched the libiberty md5.c interface a bit and here's the first
half of a patch :) It computes the MD5 sum of the module file (except the
first 3 lines) and it writes it at the top, like this:
GFORTRAN module created from test_mod.f90 on Tue Apr 17 00:12:12 2007
MD5:18a257e13c90e3872b7b9400c2fc6e4b -- If you edit this, you'll get what you
deserve.
I checked that it gives the same result as the md5sum command on my linux box
:)
Index: module.c
===================================================================
--- module.c (revision 123388)
+++ module.c (working copy)
@@ -72,6 +72,7 @@
#include "arith.h"
#include "match.h"
#include "parse.h" /* FIXME */
+#include "md5.h"
#define MODULE_EXTENSION ".mod"
@@ -170,6 +171,9 @@
/* The FILE for the module we're reading or writing. */
static FILE *module_fp;
+/* MD5 context structure. */
+static struct md5_ctx ctx;
+
/* The name of the module we're reading (USE'ing) or writing. */
static char module_name[GFC_MAX_SYMBOL_LEN + 1];
@@ -1275,6 +1279,9 @@
if (fputc (out, module_fp) == EOF)
gfc_fatal_error ("Error writing modules file: %s", strerror (errno));
+ /* Add this to our MD5. */
+ md5_process_bytes (&out, sizeof (out), &ctx);
+
if (out != '\n')
module_column++;
else
@@ -3926,7 +3933,10 @@
int n;
char *filename, *p;
time_t now;
+ fpos_t md5_pos;
+ unsigned char md5_new[16]; /*, md5_old[16]; */
+
n = strlen (name) + strlen (MODULE_EXTENSION) + 1;
if (gfc_option.module_dir != NULL)
{
@@ -3959,8 +3969,14 @@
fprintf (module_fp, "GFORTRAN module created from %s on %s\n",
gfc_source_file, p);
- fputs ("If you edit this, you'll get what you deserve.\n\n", module_fp);
+ fputs ("MD5:", module_fp);
+ fgetpos (module_fp, &md5_pos);
+ fputs ("00000000000000000000000000000000 -- "
+ "If you edit this, you'll get what you deserve.\n\n", module_fp);
+ /* Initialize the MD5 context that will be used for output. */
+ md5_init_ctx (&ctx);
+
iomode = IO_OUTPUT;
strcpy (module_name, name);
@@ -3973,6 +3989,11 @@
write_char ('\n');
+ md5_finish_ctx (&ctx, md5_new);
+ fsetpos (module_fp, &md5_pos);
+ for (n = 0; n < 16; n++)
+ fprintf (module_fp, "%02x", md5_new[n]);
+
if (fclose (module_fp))
gfc_fatal_error ("Error writing module file '%s' for writing: %s",
filename, strerror (errno));
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31587