A Riddle: what is wrong with this code using std.array.Appender?

Meta jared771 at gmail.com
Mon Mar 25 18:48:43 UTC 2019


On Monday, 25 March 2019 at 18:39:26 UTC, H. S. Teoh wrote:
> On Mon, Mar 25, 2019 at 06:21:12PM +0000, Meta via 
> Digitalmars-d wrote:
>> On Monday, 25 March 2019 at 17:32:13 UTC, Steven Schveighoffer 
>> wrote:
> [...]
>> > I have a feeling it's an aliasing thing -- like every app 
>> > member in every class points at the same IMPL struct.
> [...]
>> I find that a bit strange, since you'd think that Appender 
>> would initialize its payload on the first append; and it seems 
>> like it does if you look at the code (in 
>> Appender.ensureAddable). I'm not sure how it shakes out that 
>> the two Appenders end up sharing the same memory.
>
> This is pretty bad; two Appenders sharing the same memory could 
> potentially be exploited to break immutable.
>
>
> T

Yes, this part of the language *needs* to be changed if D is 
going to claim that it's memory safe. Either things such as:

struct Test
{
     Object o = new Object();
}

needs to be disallowed, or the semantics need to be changed.


More information about the Digitalmars-d mailing list