Jump to page: 1 2
Thread overview
[Issue 21693] extern(C++) class instance dtors are never called, breaking RAII
Mar 11, 2021
Dlang Bot
Mar 13, 2021
kinke
Mar 15, 2021
Dlang Bot
Mar 24, 2021
Dlang Bot
Apr 08, 2021
Dlang Bot
Apr 09, 2021
Dlang Bot
Apr 09, 2021
Dlang Bot
Dec 17, 2022
Iain Buclaw
March 11, 2021
https://issues.dlang.org/show_bug.cgi?id=21693

thomas.bockman@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |C++

--
March 11, 2021
https://issues.dlang.org/show_bug.cgi?id=21693

moonlightsentinel@disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |moonlightsentinel@disroot.o
                   |                            |rg
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #1 from moonlightsentinel@disroot.org ---
Potential solution for `scope` instances: https://github.com/dlang/dmd/pull/12265

--
March 11, 2021
https://issues.dlang.org/show_bug.cgi?id=21693

--- Comment #2 from Dlang Bot <dlang-bot@dlang.rocks> ---
@MoonlightSentinel updated dlang/dmd pull request #12265 "Issue 21693 - Lower scoped destruction of extern(C++) class to destroy" mentioning this issue:

- Issue 21693 - Lower scoped destruction of extern(C++) class to destroy

  Ensures proper RAII behaviour for stack allocated instances but doesn't
  affect the behaviour for heap allocated instances.

  The previous rewrite used `delete` which relies on `TypeInfo` and
  crashed at runtime. Using `object.destroy` circumvents this issue (and
  is also beneficial due to the deprecation of `delete`).

  `destroy` can be used instead of `delete` because the instances live on
  the heap and hence don't need to be deallocated.

https://github.com/dlang/dmd/pull/12265

--
March 13, 2021
https://issues.dlang.org/show_bug.cgi?id=21693

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke@gmx.net

--- Comment #3 from kinke <kinke@gmx.net> ---
The GC could presumably handle C++ classes like structs, where the TypeInfo_Struct pointer is stored after the struct instance IIRC. For C++ classes, it could store the D TypeInfo_Class pointer after the class instance (but note that class instances have no tail padding, so some padding might be needed for an aligned TypeInfo pointer).

--
March 15, 2021
https://issues.dlang.org/show_bug.cgi?id=21693

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #12265 "Issue 21693 - Lower scoped destruction of extern(C++) class to destroy/dtor call" was merged into stable:

- e28736c522d9c81acef9c66c1f02da4375f08207 by MoonlightSentinel:
  Issue 21693 - Lower scoped destruction of extern(C++) class to destroy

  Ensures proper RAII behaviour for stack allocated instances but doesn't
  affect the behaviour for heap allocated instances.

  The previous rewrite used `delete` which relies on `TypeInfo` and
  crashed at runtime. Using `object.destroy` circumvents this issue (and
  is also beneficial due to the deprecation of `delete`).

  `destroy` can be used instead of `delete` because the instances live on
  the heap and hence don't need to be deallocated.

- aa2147b836b129e835828a6e6faef363ed3255a8 by MoonlightSentinel:
  fixup! Issue 21693 - Lower scoped destruction of extern(C++) class to destroy

https://github.com/dlang/dmd/pull/12265

--
March 15, 2021
https://issues.dlang.org/show_bug.cgi?id=21693

--- Comment #5 from thomas.bockman@gmail.com ---
(In reply to kinke from comment #3)
> The GC could presumably handle C++ classes like structs, where the TypeInfo_Struct pointer is stored after the struct instance IIRC. For C++ classes, it could store the D TypeInfo_Class pointer after the class instance (but note that class instances have no tail padding, so some padding might be needed for an aligned TypeInfo pointer).

That would be fine. The maximum overhead would be less than (size_t.sizeof * 2), which is no big deal if it gets RAII working properly.

Is it necessary to store a TypeInfo pointer for every instance, though? Garbage collected instances would all be allocated on the D side, so I would think that the TypeInfo data could just be stored adjacent to D's copy of the vtable.

--
March 15, 2021
https://issues.dlang.org/show_bug.cgi?id=21693

thomas.bockman@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |major

--- Comment #6 from thomas.bockman@gmail.com ---
I'm dropping the priority from "critical" to "major" now that destruction is performed for `scope` instances, since the GC doesn't strictly guarantee deterministic destruction even for D class instances.

Thanks, @moonlightsentinel!

--
March 24, 2021
https://issues.dlang.org/show_bug.cgi?id=21693

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
@puneet updated dlang/dmd pull request #12302 "Fix issue 19192 - [wrong-code] [crashes] Covariant method interface <…" mentioning this issue:

- Issue 21693 - Lower scoped destruction of extern(C++) class to destroy/dtor
call (#12265)

  * Issue 21693 - Lower scoped destruction of extern(C++) class to destroy

  Ensures proper RAII behaviour for stack allocated instances but doesn't
  affect the behaviour for heap allocated instances.

  The previous rewrite used `delete` which relies on `TypeInfo` and
  crashed at runtime. Using `object.destroy` circumvents this issue (and
  is also beneficial due to the deprecation of `delete`).

  `destroy` can be used instead of `delete` because the instances live on
  the heap and hence don't need to be deallocated.

https://github.com/dlang/dmd/pull/12302

--
April 08, 2021
https://issues.dlang.org/show_bug.cgi?id=21693

--- Comment #8 from Dlang Bot <dlang-bot@dlang.rocks> ---
@MoonlightSentinel updated dlang/dmd pull request #12402 "Fix 21229 - Accept construction of union member as initialization" mentioning this issue:

- Issue 21693 - Lower scoped destruction of extern(C++) class to destroy/dtor
call (#12265)

  * Issue 21693 - Lower scoped destruction of extern(C++) class to destroy

  Ensures proper RAII behaviour for stack allocated instances but doesn't
  affect the behaviour for heap allocated instances.

  The previous rewrite used `delete` which relies on `TypeInfo` and
  crashed at runtime. Using `object.destroy` circumvents this issue (and
  is also beneficial due to the deprecation of `delete`).

  `destroy` can be used instead of `delete` because the instances live on
  the heap and hence don't need to be deallocated.

https://github.com/dlang/dmd/pull/12402

--
April 09, 2021
https://issues.dlang.org/show_bug.cgi?id=21693

--- Comment #9 from Dlang Bot <dlang-bot@dlang.rocks> ---
@MoonlightSentinel created dlang/dmd pull request #12408 "Merge stable into master" mentioning this issue:

- Issue 21693 - Lower scoped destruction of extern(C++) class to destroy/dtor
call (#12265)

  * Issue 21693 - Lower scoped destruction of extern(C++) class to destroy

  Ensures proper RAII behaviour for stack allocated instances but doesn't
  affect the behaviour for heap allocated instances.

  The previous rewrite used `delete` which relies on `TypeInfo` and
  crashed at runtime. Using `object.destroy` circumvents this issue (and
  is also beneficial due to the deprecation of `delete`).

  `destroy` can be used instead of `delete` because the instances live on
  the heap and hence don't need to be deallocated.

https://github.com/dlang/dmd/pull/12408

--
« First   ‹ Prev
1 2