[Patch, fortran-dev] ALLOCATE statements with CLASS variables

Janus Weil janus@gcc.gnu.org
Thu Sep 24 12:59:00 GMT 2009


Hi all,

here is yet another version of the ALLOCATE patch. I now moved all the
initialization code form resolve_allocate_expr to gfc_trans_allocate,
where the whole thing can be done a bit simpler (and one avoids
certain problems).

For this I had to make 'expr_to_initialize' non-static. Consequently,
I should probably add a 'gfc_' prefix to its name.

The SIZE problem is still not solved (see below), but I added a
warning for the problematic cases (which is triggered by Salvatore's
code, for example). I haven't checked in detail if the second problem
I mentioned earlier persists.

Maybe I will just commit the patch in the attached form today, and
take care of the remaining problems later.


>> We have an intrinsic function SIZEOF (which is a GNU extension, but
>> that does not matter), so couldn't we just insert code to call this,
>> with 'y' as the argument, and use the result as the size to allocate?
>> Problem is: I can't figure out how to do this properly ...
>
> It's known as a vtable!  This can contain, amongst other things
> derived type sizes, parentage, typebound procedures and so on.

Actually this was not what I meant. I was thinking of a way to
determine the allocated size of the source variable (or rather of
source.$data) at runtime. However, SIZEOF cannot be used, since it
operates at compile time of course (this I forgot).

Looking for an alternative, I found 'malloc_usable_size' (from glibc),
which should be able to do the job. Is this an option we might
consider? A possible problem here might be portability(?).

Other than that, I can think of no real alternative to a full vtable
implementation (as Paul suggested).

Err, maybe one: Extending our CLASS container, to hold not only
"$data" and "$vindex", but also an additional field called "$size",
which would mean 'the size of the $data field'. Question is whether
we'll need a vtable anyways.

Opinions?

Cheers,
Janus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: allocate_0924.diff
Type: text/x-diff
Size: 14375 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20090924/4e2bfff4/attachment.bin>


More information about the Fortran mailing list