Re: [patch] [3/5] Types reference counting [make_function_type-objfile]

Ulrich Weigand
2009-06-26T17:36:47Z

Tom Tromey wrote:
> >>>>> "Ulrich" == Ulrich Weigand <uweigand@de.ibm.com> writes:
>
> Ulrich> Mostly. We still can have the case were TYPE_OBJFILE(A) is NULL but
> Ulrich> TYPE_OBJFILE(B) is non-NULL, for example where A is a temporary array
> Ulrich> and B the element type.
>
> Ulrich> The way I see the invariant is
> Ulrich> If Type A references Type B *and* A is objfile-associated
> Ulrich> *then* B must be associated to the same objfile
>
> Suppose we have A as an array type with a NULL objfile, and with
> element type B, which has an objfile.
>
> If we have a convenience variable of type A, and the objfile is
> deleted, I don't think preserve_values will copy type B. That is
> because we only check the value's immediate objfile to decide whether
> we need to do a type copy.

Hmm, good point.

> Therefore it seems to me that the invariant must be TYPE_OBJFILE(A) ==
> TYPE_OBJFILE(B), for all related types A and B.

I'm not sure how to best implement this invariant -- we *need* to support
the case of a temporary array of pre-existing element types (e.g. for
value_slice etc.) ...

We don't want to allocate the temporary array types per-objfile, because
then they will not be subject to garbage collection (and if the user does
something that causes a lot of those arrays to be generated before the
objfile is unloaded, this could cause a significant leak).

I guess we could force the element type to be copied at the time the
array type is allocated. In the alternative, we could change
preserve_values to do the recursive check even if the main type is
not objfile-associated.

Bye,