[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: m4-1.4.10 breaking autoconf?

From: Eric Blake
Subject: Re: m4-1.4.10 breaking autoconf?
Date: Sat, 21 Jul 2007 22:27:04 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070716 Thunderbird/ Mnenhy/

Hash: SHA1

According to Eric Blake on 7/21/2007 10:06 PM:
> I'm hoping that you can see the temporary files, and that the file sizes
> look reasonable (since I tested this on CVS head instead of 1.4.10, the
> numbers will be slightly different).  At which point we will know that it
> is something to do with how m4 reopens the temp files on your system
> during the final dump of all pending diversions.

Nevermind - I finally figured it out!  POSIX states "a ``file position
indicator'' associated with the stream is positioned at the start (byte
number 0) of the file, unless the file is opened with append mode, in
which case it is implementation-defined whether the file position
indicator is initially positioned at the beginning or end of the file."
And I was using fopen(tmpname, "a+").  In m4 1.4.9, it was followed by a
rewind(), but that is inherently unsafe (since rewind() can lose data on a
flush error, but clears the stream error indicator anyway), so I deleted
it in m4 1.4.10.  The difference between my system and yours, then, must
be that NetBSD opens files in append mode with the file descriptor at the
last byte instead of the first byte of the file, and hence, does not read
any data unless we add an explicit seek.  I never saw the bug because my
system always opens files at offset 0 (even in append mode), delaying the
seek to the end until the first write.

This is the patch, I'm still working on a testsuite addition:

2007-07-21  Eric Blake  <address@hidden>

        Fix failure on NetBSD.
        * src/output.c (m4_tmpopen): Explicitly reset append-mode stream
        position to byte 0.
        * NEWS: Document this fix.
        Reported by Thomas Klausner.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

Index: NEWS
RCS file: /sources/m4/m4/NEWS,v
retrieving revision
diff -u -p -r1. NEWS
--- NEWS        10 Jul 2007 20:47:19 -0000
+++ NEWS        22 Jul 2007 04:23:16 -0000
@@ -4,7 +4,9 @@ Foundation, Inc.
 Version 1.4.11 - ?? ??? 2007, by ????  (CVS version 1.4.10a)
-* No user visible changes yet...
+* Fix regression introduced in 1.4.9 in the `divert' builtin when more
+  than 512 kibibytes are saved in diversions on platforms like NetBSD
+  where fopen with mode "a+" seeks to the end of the file.
 Version 1.4.10 - 09 Jul 2007, by Eric Blake  (CVS version 1.4.9c)
Index: src/output.c
RCS file: /sources/m4/m4/src/Attic/output.c,v
retrieving revision
diff -u -p -r1. output.c
--- src/output.c        5 Jul 2007 03:53:08 -0000
+++ src/output.c        22 Jul 2007 04:23:17 -0000
@@ -252,6 +252,11 @@ m4_tmpopen (int divnum)
   else if (set_cloexec_flag (fileno (file), true) != 0)
     M4ERROR ((warning_status, errno,
              "Warning: cannot protect diversion across forks"));
+  /* POSIX states that it is undefined whether an append stream starts
+     at offset 0 or at the end.  We want the beginning.  */
+  else if (fseeko (file, 0, SEEK_SET) != 0)
+    M4ERROR ((EXIT_FAILURE, errno,
+             "cannot seek to beginning of diversion"));
   return file;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]