[Issue 10966] New: Leaked destruction in static array postblit

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 5 00:26:57 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10966

           Summary: Leaked destruction in static array postblit
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: monarchdodra at gmail.com


--- Comment #0 from monarchdodra at gmail.com 2013-09-05 00:26:54 PDT ---
This is a study of what happens in a static array, if a postblit throws. Tested
with 2.063 and 2.063.2:

The "caught" issue is that if we are doing "1-element to N-element" postblit,
then the "so-far contructed" objects will not be destroyed:

//----
import std.stdio;

int k;

struct S
{
    int a;
    this(this)
    {
        writef("postblitting %s... ", a);
        if (k++ == 2)
        {
            writefln("FAILED!");
            throw new Exception("BOOM!");
        }
        a += 10;
        writefln("OK => %s", a);
    }
    ~this()
    {
        writefln("destroying %s", a);
    }
}

void main()
{
    S s0     = S(0);
    S[4] ss1 = [S(1), S(2), S(3), S(4)];
    S[4] ss2  =
        ss1; //Case N to N
        //s0; //Case 1 to N
}
//----

Version N to N:
//----
ostblitting 1... OK => 11
postblitting 2... OK => 12
postblitting 3... FAILED!
destroying 12
destroying 11
destroying 4
destroying 3
destroying 2
destroying 1
destroying 0
//----
Comment: This behavior is correct: Two items have been constructed, they are
both destructed.

Version 1 to N:
//----
ostblitting 1... OK => 11
postblitting 2... OK => 12
postblitting 3... FAILED!
destroying 4
destroying 3
destroying 2
destroying 1
destroying 0
//----
Comment: This behavior is IN-correct: Two items have been constructed (11 and
12), yet neither gets destroyed.

########################

If I may, I think the "root" issue is that the way static array postblit is
implemented is wrong ("eg, the call to typeid(S[4]).postblit"). Currently, all
it does is "call postblit 1 by 1, until it succeeds or fails". If it fails
though, it then relies on the compiler to know which single items in the array
have been constructed, and then destroy them individually.

It should be the postblit itself that deconstructs the "so-far-built" items in
the array.

For the compiler, there should be 1 and only 1 item: The array. It's state
should be binary: Built or not built. Period. A related issue (I'm about to
file) is how static array assignment works.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list