Jump to page: 1 2 3
Thread overview
[Issue 16197] Postblit not being called properly
[Issue 16197] [The D Bug Tracker]
Jun 23, 2016
Eyal
Jun 23, 2016
Eyal
Jun 23, 2016
David Nadlinger
[Issue 16197] Constructors/postblits and destructors don't match up for array initialisation
Jun 23, 2016
David Nadlinger
Jun 23, 2016
David Nadlinger
Jun 23, 2016
ZombineDev
Jun 23, 2016
Max Samukha
Jun 24, 2016
Sobirari Muhomori
May 12, 2017
Walter Bright
May 12, 2017
David Nadlinger
May 12, 2017
Walter Bright
May 12, 2017
Walter Bright
May 12, 2017
Eyal
May 12, 2017
Walter Bright
June 23, 2016
https://issues.dlang.org/show_bug.cgi?id=16197

--- Comment #1 from Eyal <eyal@weka.io> ---
Specifically, the call to slice bit-blits the elements into the array but does not call postblit!

--
June 23, 2016
https://issues.dlang.org/show_bug.cgi?id=16197

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[The D Bug Tracker]         |Postblit not being called
                   |                            |properly

--
June 23, 2016
https://issues.dlang.org/show_bug.cgi?id=16197

--- Comment #2 from Eyal <eyal@weka.io> ---
Oops, this is an ldc bug, not a dmd bug.

--
June 23, 2016
https://issues.dlang.org/show_bug.cgi?id=16197

David Nadlinger <code@klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@klickverbot.at

--- Comment #3 from David Nadlinger <code@klickverbot.at> ---
DMD from Git master (v2.072.0-devel-20e1c81) seems to call too many postblits/ctors, though, when initialising the Ctr instances and then assigning the Elem literals:
---
construct Ctr {
POSTBLIT -1 (7FFF5C07F598)
POSTBLIT -1 (7FFF5C07F59C)
POSTBLIT -1 (7FFF5C07F5A0)
}
assign arr {
CTOR 1 (7FFF5C07F5B4)
CTOR 2 (7FFF5C07F5C0)
CTOR 3 (7FFF5C07F5C4)
}
slice rval -> arr {
POSTBLIT 1 (7FFF5C07F5D0)
POSTBLIT 2 (7FFF5C07F5D4)
POSTBLIT 3 (7FFF5C07F5D8)
}
DTOR 3 (7FFF5C07F5D8)
DTOR 2 (7FFF5C07F5D4)
DTOR 1 (7FFF5C07F5D0)
arr rval -> arr {
POSTBLIT 1 (7FFF5C07F520)
POSTBLIT 2 (7FFF5C07F524)
POSTBLIT 3 (7FFF5C07F528)
}
DTOR 3 (7FFF5C07F5F0)
DTOR 2 (7FFF5C07F5EC)
DTOR 1 (7FFF5C07F5E8)
DTOR 3 (7FFF5C07F5A0)
DTOR 2 (7FFF5C07F59C)
DTOR 1 (7FFF5C07F598)
---

Note that the CTOR-created instances (7FFF5C07F5B4 and so on) are never
destructed.

(The output is from a slightly modified test case that prints the struct address in parens:

---
import std.stdio:writeln;

struct Elem {
    int x = -1;
    this(int x) { this.x = x; writeln("CTOR ", x, " (", cast(void*)&this, ")");
}
    this(this) { writeln("POSTBLIT ", x, " (", cast(void*)&this, ")"); }
    ~this()    { if (x!=-1) writeln("DTOR "    , x, " (", cast(void*)&this,
")"); }
}

struct Ctr {
    Elem[3] arr;
    Elem[] slice() { return arr; }
    Elem[3] arrVal() { return arr; }
}

void main() {
    writeln("construct Ctr {");
    auto p = Ctr();
    writeln("}");
    writeln("assign arr {");
    p.arr = [Elem(1), Elem(2), Elem(3)];
    writeln("}");
    {
        writeln("slice rval -> arr {");
        Elem[3] _arr = p.slice;
        writeln("}");
    }
    {
        writeln("arr rval -> arr {");
        Elem[3] _arr = p.arrVal();
        writeln("}");
    }
}
---
)

--
June 23, 2016
https://issues.dlang.org/show_bug.cgi?id=16197

David Nadlinger <code@klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Postblit not being called   |Constructors/postblits and
                   |properly                    |destructors don't match up
                   |                            |for array initialisation

--
June 23, 2016
https://issues.dlang.org/show_bug.cgi?id=16197

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #4 from Steven Schveighoffer <schveiguy@yahoo.com> ---
(In reply to David Nadlinger from comment #3)
> Note that the CTOR-created instances (7FFF5C07F5B4 and so on) are never
> destructed.

I don't think this is really a sign of anything, since the compiler is free to move around instances of the struct.

--
June 23, 2016
https://issues.dlang.org/show_bug.cgi?id=16197

--- Comment #5 from David Nadlinger <code@klickverbot.at> ---
(In reply to Steven Schveighoffer from comment #4)
> I don't think this is really a sign of anything, since the compiler is free to move around instances of the struct.

I'm not sure how to reconcile the number of ctor/postblit calls with the number of dtor calls, though.

--
June 23, 2016
https://issues.dlang.org/show_bug.cgi?id=16197

--- Comment #6 from Steven Schveighoffer <schveiguy@yahoo.com> ---
I'm not saying there's no issue here, just that the fact that you are not matching the addresses of the structs together doesn't necessarily mean anything bad. The compiler could be running the ctor on some piece of memory, and then just moving into the right spot without calling postblit or dtor (seems wasteful, but certainly legal).

BTW, things can likely get a lot clearer if we reduce the array size to 1. No reason to triple the output!

BTW, the postblit for the -1 values seems incorrect...

--
June 23, 2016
https://issues.dlang.org/show_bug.cgi?id=16197

ZombineDev <petar.p.kirov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |petar.p.kirov@gmail.com

--
June 23, 2016
https://issues.dlang.org/show_bug.cgi?id=16197

Max Samukha <maxsamukha@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxsamukha@gmail.com

--- Comment #7 from Max Samukha <maxsamukha@gmail.com> ---
(In reply to Steven Schveighoffer from comment #6)

> 
> BTW, the postblit for the -1 values seems incorrect...

Definitely incorrect (dmd):

struct Elem {
    int x = -1;
    this(this) { writeln("POSTBLIT ", x); }
    ~this()    { writeln("DTOR "    , x); }
}

struct Ctr {
    Elem[1] arr;
}

void main() {
    auto p = Ctr();
}

prints:

POSTBLIT DTOR


Should be either two destructors or no postblit. For "Elem arr" instead of "Elem[1] arr", only the destructor is correctly called once.

--
« First   ‹ Prev
1 2 3