Bug 98838 - g77 isatty does not call f_init implicitly
g77 isatty does not call f_init implicitly
Product: Red Hat Linux
Classification: Retired
Component: gcc3 (Show other bugs)
i686 Linux
medium Severity low
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2003-07-09 09:50 EDT by nvwarr
Modified: 2007-04-18 12:55 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-10-05 20:46:38 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description nvwarr 2003-07-09 09:50:35 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20021003

Description of problem:
Using a main program in C and a subroutine in Fortran, where the Fortran
uses isatty without using any other Fortran I/O, results in a segmentation fault
at that point.

Inserting another Fortran I/O operation before the call to isatty works around
the problem. Alternatively, calling f_init explicitly from the C code before
calling the Fortran also works.

My problem occurs in a large complicated set of code mixing C and Fortran, but
the example below illustrates the problem.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1.Use a C main routine like:
#include <stdio.h>

int main(int argc, char **argv) {
   extern a_(int *result);
   int result = 0;
   printf("result = %d\n", result);

2.and a Fortran subroutine like:
      subroutine a(result)
      integer result

      result = 1
      if (isatty(6) .eqv. .true.) result = 2

3. g77 -o mytest mytest.c mytest.for
4. ./mytest

Actual Results:  Segmentation fault
Running with g77 -g and gdb:
#0  0x42069ab7 in fileno_unlocked () from /lib/i686/libc.so.6
#1  0x4003c337 in G77_fnum_0 () from /usr/lib/libg2c.so.0
#2  0x4003c6e8 in G77_isatty_0 () from /usr/lib/libg2c.so.0
#3  0x080484e8 in a_ (result=0xbffff454) at mytest.for:5
#4  0x080484af in main (argc=1, argv=0xbffff4a4) at mytest.c:8
#5  0x420158f7 in __libc_start_main () from /lib/i686/libc.so.6

Expected Results:  Should return "result = 1" or "result = 2" depending on
whether output
is redirected or not.

Additional info:

Inserting the line:
in the C code prior to calling the function "a_" works around the problem.

Or, inserting the line:
before the call to isatty in the Fortran also works around the problem, since
write implicitly calls f_init.

It is not a very serious bug, but one which proved rather hard to track down and
I suspect is probably easy to fix, so it would be nice to see it fixed.
Comment 1 nvwarr 2004-01-26 07:19:48 EST
The g77 developers have confirmed the bug and the fix is indeed easy.
Presumably it will be integrated into a future release.
Comment 2 Richard Henderson 2004-10-03 19:58:24 EDT
Still present in gcc 3.4.  Gfortran in gcc 4.0 appears to incorrectly
declare isatty as integer instead of logical.
Comment 3 Richard Henderson 2004-10-05 20:46:38 EDT
Correction: fixed in gcc 3.4.  Accidentally ran the previous test
against the installed 3.2 libg2c.so.

Note You need to log in before you can comment on or make changes to this bug.