Bug 98838 - g77 isatty does not call f_init implicitly
Summary: g77 isatty does not call f_init implicitly
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc3
Version: 8.0
Hardware: i686
OS: Linux
medium
low
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-07-09 13:50 UTC by nvwarr
Modified: 2007-04-18 16:55 UTC (History)
0 users

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2004-10-06 00:46:38 UTC
Embargoed:


Attachments (Terms of Use)

Description nvwarr 2003-07-09 13:50:35 UTC
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):
gcc-g77-3.2-7

How reproducible:
Always

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;
   
   a_(&result);
   printf("result = %d\n", result);
   return(0);
}

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

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

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:
f_init();
in the C code prior to calling the function "a_" works around the problem.

Or, inserting the line:
      write(*,'($)')
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 12:19:48 UTC
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 23:58:24 UTC
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-06 00:46:38 UTC
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.