GTY and const

Zack Weinberg zack@codesourcery.com
Wed Dec 22 23:24:00 GMT 2004


Daniel Berlin <dberlin@dberlin.org> writes:

> On Tue, 2004-12-21 at 11:01 -0800, Zack Weinberg wrote:
>> Geoffrey Keating <geoffk@geoffk.org> writes:
>> 
>> >> > Would it be better to add a cast around the assignment or to make
>> >> > the GTY code handle const members?
>> >> 
>> >> I'd prefer that you improved gengtype.
>> >
>> > It's not gengtype, the problem really is that you cannot have const
>> > GCed memory, for the same underlying reasons that you cannot free() a
>> > const pointer.
>> 
>> No, that's just plain not true.  cpplib makes extensive use of 'const'
>> to indicate write-once data structures (they are initialized through a
>> non-const pointer, of course).  Those definitely can be GC memory.
>
> Right. There is a significant difference between what we need to walk
> for marking, and what we really need to GC allocate.

While what you say is true¹, this particular data structure needs to be
in GC memory not because it can point to other things that are in GC
memory, but because it's part of a precompiled header.

zw

¹ however, I am still sympathetic to the notion that GC-allocating
everything would be a good idea if we could just get a non-sucky GC
algorithm.  Remember that glorious time in the 3.1-3.3 timeframe when
we never had use-after-free bugs?



More information about the Gcc mailing list