This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: memory ownership for descriptors


I am writing a ctypes-based interface to gfortran; this allows
GFortran functions and subroutines to be called with NumPy
multidimensional arrays.? Passing arrays in already works.

The part I'm not sure about is how allocation is handled.? As far as I
can tell, the first word in the array descriptor is a pointer to
malloc'ed data.? GFortran must have conventions for when that pointer
gets allocated and freed.? Are those documented anywhere?

Is there some way of telling the GFortran runtime that the pointer is
shared with some other data structure and shouldn't get freed?

The third word in the descriptor is an integer indicating the type,
kind, and rank of the array?  I've figured out the common cases, but
is the precise meaning documented somewhere?

Thanks,
Tom

Two comments:

(1) For the future evolution of the GFortran array descriptor, ideal
would be if there were hooks in the array descriptor for allocation
and deallocation of its memory, as well as an extra void * for a
hook-related context; that way, it would actually be possible to have
Fortran interoperate with arbitrary arrays from other languages:
Fortran could be passed a C++ or NumPy numerical array and
allocate/deallocate/resize it without any data needing to be copied.

(2) I also looked at TR 29113 as a possible future solution, since it
defines standard C access to Fortran array descriptors, but it isn't
really a good solution since it doesn't allow ctypes-style transparent
access to existing Fortran libraries; access with TR 29113 always
seems to involve invoking the compiler.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]