Bug with ISO_C_BINDING on Mac OS?

Janus Weil janus@gcc.gnu.org
Sat Jun 1 12:19:00 GMT 2013


>>>     interface
>>>      function bzReadOpen (bzerror,f,verbosity,small,unused,nUnused) bind
>>> (c,NAME='BZ2_bzReadOpen')
>>>        use, intrinsic :: ISO_C_BINDING
>>>        integer(c_int),value :: f,verbosity,small,nUnused
>>>        integer(c_int) :: bzReadOpen,bzerror
>>>        type(c_ptr) :: unused
>>>      end function
>>>    end interface
>>
>> This one looks bogus as well. bzerror and f are both pointers (int * and
>> FILE *).
>>
>> For bzerror: I think you really should use "INTEGER(c_int)"  (w/o VALUE) -
>> that way you get a proper error return.
>
> This I'm doing already!
>
>
>> And for FILE *f: Here, you have to ensure that you pass all 64bits of the
>> result value of "fopen". Again, I would use a "TYPE(C_PTR),VALUE" which
>> reflects the black box best. But using an INTEGER(c_intptr_t),VALUE should
>> also work. (Cf. above for "fopen".)
>
> Ok, using TYPE(c_ptr) here, too.
>
>
> However, when the test case is updated accordingly (see attachment), I
> also end up with a valgrind error on Linux:
>
>  #1
>  #2
> ==19696== Invalid read of size 8
> ==19696==    at 0x5B17062: ferror (in /lib64/libc-2.17.so)
> ==19696==    by 0x4E3F097: BZ2_bzReadOpen (in /usr/lib64/libbz2.so.1.0.6)
> ==19696==    by 0x400B9F: MAIN__ (testBz2.f90:38)
> ==19696==    by 0x400C3C: main (testBz2.f90:42)
> ==19696==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
> ==19696==
>
> Program received signal SIGSEGV: Segmentation fault - invalid memory reference.


Ok, in fact it works (on Linux) if I remove the VALUE attribute for
all arguments (updated code attached). Will check if this also fixes
it on Mac OS ...

Cheers,
Janus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testBz2.f90
Type: application/octet-stream
Size: 1009 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20130601/2dd51d27/attachment.obj>


More information about the Fortran mailing list