Postblit bug

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Sat Oct 18 06:48:44 PDT 2014


Am Sat, 18 Oct 2014 08:28:40 +0000
schrieb "monarch_dodra" <monarchdodra at gmail.com>:

> > Consider that when passing a variable you can always remove
> > top level const-ness because a copy is made. This holds for
> > returns, parameters, assignments, ...
> > Post-blit is no different. The issue as I see it, is that D
> > doesn't have strong support for this notion of head-mutable or
> 
> D has it for primitives, such as pointers, slices...
> 
> > else it would work with this type during post-blit:
> >
> > struct S
> > {
> >      immutable(int)* p;
> >      this(this)
> >      {
> >          ++*p;
> >      }
> > }
> 
> Unsure how that's relevant? This code looks wrong to me no matter 
> how you look at it?

This is the only relevant point to discuss. The act of
blitting is a shallow copy. Hence while the copy is created
there is no risk in modifying its bits. Hence the proposal to
make make it mutable.

But then you added deepness in form of a pointer to the
structure that a shallow copy doesn't cover.

So I concluded that the issue with making postblit mutable is
that it removes immutable transitively through pointers,
while for a shallow copy it must be shallow, too. That's just a
basic observation. The imaginary struct I showed is the result
of that. It only removes the top level immutable from the
struct and would error out as you try modify the dereferenced
immutable(int) while reassignment would work.

-- 
Marco



More information about the Digitalmars-d mailing list