Bug 18953 – Win32: extern(C++) struct destructor not called correctly through runtime

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2018-06-07T05:45:54Z
Last change time
2018-06-25T20:13:21Z
Keywords
C++, industry
Assigned to
Manu
Creator
Rainer Schuetze

Comments

Comment #0 by r.sagitario — 2018-06-07T05:45:54Z
import core.stdc.stdio; extern(C++) struct S { int x; ~this() { printf("~S %x\n", x); } } void main() { S[] arr = new S[3]; arr[1].x = 1; arr[2].x = 2; arr.length = 1; assumeSafeAppend(arr); // destroys arr[1] and arr[2] printf("done\n"); // arr[0] destroyed by final GC later } The expected output is: ~S 2 ~S 1 done ~S 0 Works for win64, but for win32 (both -m32 and -m32mscoff) I get ~S c0b831ff ~S c0b831ff done ~S c0b831ff
Comment #1 by r.sagitario — 2018-06-07T05:57:06Z
Probalby happens because TypeInfo_Struct.destroy doesn't use the expected __thiscall calling convention: https://github.com/dlang/druntime/blob/master/src/object.d#L2010
Comment #2 by turkeyman — 2018-06-07T06:13:45Z
This sounds like a job for that proposal you had where assigning a C++ method to a delegate would imply a shim function to perform the adaptation. I don't really know how/where to hack that in, would you mind looking into that?
Comment #3 by turkeyman — 2018-06-15T07:12:33Z
Was this fixed by your last merged patch?
Comment #4 by r.sagitario — 2018-06-15T07:22:08Z
I added a test for this in some iteration, but it seemed it failed/crashed on Linux, so I removed it immediately to not complicate the PR. I'll open a new PR with a test case...
Comment #5 by github-bugzilla — 2018-06-25T20:13:15Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/3a4707b4b15743ff4a068fe5ac6b983b6ce042c4 fix issue 18953 - extern(C++) struct destructor not called correctly through runtime Win32 already fixed by d08e0fb3bff6767bd28516f53393083d86f63045 other 32-bit platforms have the same issue https://github.com/dlang/dmd/commit/f95b301a78a4124904e85622f63215b8ce248e67 Merge pull request #8359 from rainers/issue18953 fix issue 18953 - 32-bit: extern(C++) struct destructor not called cor…