This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: g77.f-torture/execute/io1.f failure on FreeBSD
- From: Loren James Rittle <rittle at latour dot rsch dot comm dot mot dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 4 Jan 2002 16:31:44 -0600 (CST)
- Subject: PATCH: g77.f-torture/execute/io1.f failure on FreeBSD
- Reply-to: rittle at labs dot mot dot com
Toon asked me about this new failure and suggested how/when it might
be broken. Here is the analysis and patch to fix it. Installed with
Toon's approval after additional testing at his request (off-list):
> This looks OK to me. Can you test it for another system than BSD or
> do I have to do that ?
The patch has now been tested on both sparc-sun-solaris2.7 and
i386-unknown-freebsd4.4 with no test suite regressions (fully rebuilt
libf2c with patch in already bootstrapped tree).
libf2c/configure finds that FreeBSD has:
#define HAVE_FSEEKO 1
#define HAVE_FTELLO 1
#define HAVE_FTRUNCATE 1
(For the record and as you may already know: As normally used,
configure only checks whether trivial C programs can link to learn
that functions exist. It does not ensure that prototypes for correct
compilation will always be provided by system headers under all the
configuration macros and compilation switches to be provided when
actually building code later. We have found this problem with
other gcc libraries.)
libI77/endfile.c arranges to include stdio.h (indirectly via fio.h)
but since _POSIX_SOURCE is defined in libI77/config.h, prototypes for
ftello() and ftello() are not declared by stdio.h (modern FreeBSD
system headers try very hard not to pollute the namespace when such
macros are declared) thus this line from endfile.c:
FSEEK(bf,0,SEEK_END);
passes a bad argument stack since the prototype would have expressed
that the second argument was an off_t not an int. The code in the
Fortran library to map to various sets of system routines (some of
which are non-standard) is somewhat fragile (when considering how
configure finds information about a system) and, without an overhaul
outside the scope of my ability, this is the best we can do.
* libI77/fio.h (FSEEK): Enforce type of second parameter to be
off_t when prototype is missing from system headers for the
non-standard function.
Index: fio.h
===================================================================
RCS file: /cvs/gcc/gcc/libf2c/libI77/fio.h,v
retrieving revision 1.6
diff -c -r1.6 fio.h
*** fio.h 2001/07/10 20:39:40 1.6
--- fio.h 2002/01/04 03:45:18
***************
*** 18,24 ****
/* Only use fseeko/ftello if they are both there. */
#if defined (HAVE_FSEEKO) && defined (HAVE_FTELLO)
! #define FSEEK fseeko
#define FTELL ftello
#else
#define FSEEK fseek
--- 18,28 ----
/* Only use fseeko/ftello if they are both there. */
#if defined (HAVE_FSEEKO) && defined (HAVE_FTELLO)
! /* The cast helps in any case where the fseeko() prototype is somehow missing
! (perhaps because _POSIX_SOURCE is defined and the system headers try
! to keep a clean namespace in that case) even though the autoconf test
! found the non-standard function via its trivial link test. */
! #define FSEEK(a,b,c) fseeko(a, (off_t) b, c)
#define FTELL ftello
#else
#define FSEEK fseek