digitalmars.D - C++ interop; object destruction
- Manu via Digitalmars-d (29/29) Jun 22 2017 How do I properly implement object destruction of extern(C++) classes (w...
- Nicholas Wilson (3/8) Jun 22 2017 I take it you tried calling super.~this() already? that would be
- ketmar (3/12) Jun 22 2017 that won't work, 'cause `~this` is not a valid symbol. yet `super.__dtor...
- Nicholas Wilson (2/6) Jun 22 2017 Also didn't Ethan come up with a solution for this for Binderoo?
- Manu via Digitalmars-d (3/11) Jun 22 2017 I'm not sure...
- Nicholas Wilson (5/21) Jun 22 2017 I'm pretty sure he manually constructs the vtbl and inserts the
- Danni Coy via Digitalmars-d (3/8) Jun 22 2017 He is mapping C++ classes onto D structs IIRC.
- Manu via Digitalmars-d (6/28) Jun 22 2017 I do that, but that doesn't mean the destructors work. object.destroy()
- Manu via Digitalmars-d (3/14) Jun 22 2017 Oh yeah that's right, that's a totally different ball-game :)
How do I properly implement object destruction of extern(C++) classes (with
virtual destructors)?
I'm not going to embarrass myself by pasting some of my attempts to achieve
this goal to date.
I've asked before, but I've never yet seen a sufficiently solution to this
problem.
Situation:
I have a C++ base class expressed by an extern(C++) class.
C++ base class has virtual destructor.
I derive both C++ and D classes from this base class, they must each
destruct properly in their own right (object.destroy() crashes).
D passes base class pointers of D-derived classes to C++, and C++ calls the
virtual destructor.
D receives C++-derived classes by base class pointer, and needs to call the
virtual destructor (attempting to use object.destroy() crashes).
Forget about memory allocation, that's a separate (and solved) problem. The
only concern is proper destruction.
Can anyone who has had success in this space demonstrate how to structure
such code that will work?
Here is a C++ base class:
class Base
{
virtual ~Base() { printf("destructing base"); }
};
I leave the rest of the puzzle as a clean slate. My attempts are all
disasters.
Note: I am happy to re-implement the C++ base class destructors on the D
size, as I expect that's necessary when derived D classes want to call
their base destructors.
Jun 22 2017
On Thursday, 22 June 2017 at 12:52:26 UTC, Manu wrote:How do I properly implement object destruction of extern(C++) classes (with virtual destructors)? I'm not going to embarrass myself by pasting some of my attempts to achieve this goal to date.I take it you tried calling super.~this() already? that would be my first thought.
Jun 22 2017
Nicholas Wilson wrote:On Thursday, 22 June 2017 at 12:52:26 UTC, Manu wrote:that won't work, 'cause `~this` is not a valid symbol. yet `super.__dtor()` will work.How do I properly implement object destruction of extern(C++) classes (with virtual destructors)? I'm not going to embarrass myself by pasting some of my attempts to achieve this goal to date.I take it you tried calling super.~this() already? that would be my first thought.
Jun 22 2017
On Thursday, 22 June 2017 at 12:52:26 UTC, Manu wrote:How do I properly implement object destruction of extern(C++) classes (with virtual destructors)? [...]Also didn't Ethan come up with a solution for this for Binderoo?
Jun 22 2017
On 23 June 2017 at 09:32, Nicholas Wilson via Digitalmars-d < digitalmars-d puremagic.com> wrote:On Thursday, 22 June 2017 at 12:52:26 UTC, Manu wrote:I'm not sure...How do I properly implement object destruction of extern(C++) classes (with virtual destructors)? [...]Also didn't Ethan come up with a solution for this for Binderoo?
Jun 22 2017
On Friday, 23 June 2017 at 00:33:55 UTC, Manu wrote:On 23 June 2017 at 09:32, Nicholas Wilson via Digitalmars-d < digitalmars-d puremagic.com> wrote:I'm pretty sure he manually constructs the vtbl and inserts the virtual function into it, so it should just be a case of calling the virtual destructor. Have a look at this DConf 2017 talk.On Thursday, 22 June 2017 at 12:52:26 UTC, Manu wrote:I'm not sure...How do I properly implement object destruction of extern(C++) classes (with virtual destructors)? [...]Also didn't Ethan come up with a solution for this for Binderoo?
Jun 22 2017
On Fri, Jun 23, 2017 at 10:52 AM, Nicholas Wilson via Digitalmars-d < digitalmars-d puremagic.com> wrote:He is mapping C++ classes onto D structs IIRC.I'm pretty sure he manually constructs the vtbl and inserts the virtual function into it, so it should just be a case of calling the virtual destructor. Have a look at this DConf 2017 talk.
Jun 22 2017
On 23 June 2017 at 10:52, Nicholas Wilson via Digitalmars-d < digitalmars-d puremagic.com> wrote:On Friday, 23 June 2017 at 00:33:55 UTC, Manu wrote:I do that, but that doesn't mean the destructors work. object.destroy() just crashes. Believe me, I've been messing with this a lot. The answer to this email is some code that satisfies the criteria, I've tried a lot of things.On 23 June 2017 at 09:32, Nicholas Wilson via Digitalmars-d < digitalmars-d puremagic.com> wrote: On Thursday, 22 June 2017 at 12:52:26 UTC, Manu wrote:I'm pretty sure he manually constructs the vtbl and inserts the virtual function into it, so it should just be a case of calling the virtual destructor. Have a look at this DConf 2017 talk.How do I properly implement object destruction of extern(C++) classesI'm not sure...(with virtual destructors)? [...]Also didn't Ethan come up with a solution for this for Binderoo?
Jun 22 2017
On 23 June 2017 at 13:45, Danni Coy via Digitalmars-d < digitalmars-d puremagic.com> wrote:On Fri, Jun 23, 2017 at 10:52 AM, Nicholas Wilson via Digitalmars-d < digitalmars-d puremagic.com> wrote:Oh yeah that's right, that's a totally different ball-game :)He is mapping C++ classes onto D structs IIRC.I'm pretty sure he manually constructs the vtbl and inserts the virtual function into it, so it should just be a case of calling the virtual destructor. Have a look at this DConf 2017 talk.
Jun 22 2017









ketmar <ketmar ketmar.no-ip.org> 