swig-fortran / swig

This fork of SWIG creates Fortran wrapper code from C++ headers.
http://www.swig.org
Other
42 stars 11 forks source link

Fundamental pointer types are mapped to type(C_PTR) dummy arguments when using %fortranbindc #125

Closed rcoacci closed 5 years ago

rcoacci commented 5 years ago

For some reason, %fortranbindc is mapping fundamental pointer types (int*, long*, etc) as type(C_PTR) dummy arguments.

For example:

%fortranbindc;
int example2_f2(int *b);

Generates:

function example2_f2(b) &
bind(C, name="example2_f2") &
result(fresult)
use, intrinsic :: ISO_C_BINDING
type(C_PTR) :: b
integer(C_INT) :: fresult
end function

Where I expected it to generate:

function example2_f2(b) &
bind(C, name="example2_f2") &
result(fresult)
use, intrinsic :: ISO_C_BINDING
integer(C_INT) :: b          ! Note the absence of the "value" keyword.
integer(C_INT) :: fresult
end function

I know there is almost no way to tell if an int* is just an inout argument or an array, but I believe the most sensible thing to do would be to generate an inout dummy, not an arbitrary pointer. Or at most, generate a dimension(*), target dummy (i.e. assume pointers are arrays of unknown size, which size 1 is an special case)?

sethrj commented 5 years ago

Ack, I think this is an unintended side effect of #123 . I'm looking into it and will increase testing. Thanks for pointing this out!

sethrj commented 5 years ago

Closed by #129 !