I customized object.d in -betterc mode and created NEW templates, with modules I can seemingly create classes without extern(C++) mode, and type conversions in function calls seem to work fine. But when destroy doesn't find a way to call the __xtdor() method of the corresponding subclass, is there any way to execute __xtdor() correctly
Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
November 06, 2023 How should class objects created in betterC be destroyed | ||||
---|---|---|---|---|
| ||||
November 06, 2023 Re: How should class objects created in betterC be destroyed | ||||
---|---|---|---|---|
| ||||
Posted in reply to zoe | On Monday, 6 November 2023 at 05:30:02 UTC, zoe wrote: >I customized object.d in -betterc mode and created NEW templates, with modules I can seemingly create classes without extern(C++) mode, and type conversions in function calls seem to work fine. But when destroy doesn't find a way to call the __xtdor() method of the corresponding subclass, is there any way to execute __xtdor() correctly Do you have the implementation somewhere? |
November 06, 2023 Re: How should class objects created in betterC be destroyed | ||||
---|---|---|---|---|
| ||||
Posted in reply to Imperatorn | On Monday, 6 November 2023 at 05:52:18 UTC, Imperatorn wrote: >On Monday, 6 November 2023 at 05:30:02 UTC, zoe wrote: >I customized object.d in -betterc mode and created NEW templates, with modules I can seemingly create classes without extern(C++) mode, and type conversions in function calls seem to work fine. But when destroy doesn't find a way to call the __xtdor() method of the corresponding subclass, is there any way to execute __xtdor() correctly Do you have the implementation somewhere? I just define an empty object class, select the object.d file at compile time, and you can use the class, and function parameters can also use the interface |
November 06, 2023 Re: How should class objects created in betterC be destroyed | ||||
---|---|---|---|---|
| ||||
Posted in reply to Imperatorn | On Monday, 6 November 2023 at 05:52:18 UTC, Imperatorn wrote: >On Monday, 6 November 2023 at 05:30:02 UTC, zoe wrote: >I customized object.d in -betterc mode and created NEW templates, with modules I can seemingly create classes without extern(C++) mode, and type conversions in function calls seem to work fine. But when destroy doesn't find a way to call the __xtdor() method of the corresponding subclass, is there any way to execute __xtdor() correctly Do you have the implementation somewhere? // app.d import core.stdc.stdio; interface L class Base : L void interfaceTest() ~this() class Test : Base ~this() public void test2(ref Base l) public void test() extern (C) int main() // object.d import core.stdc.stdlib; alias size_t = typeof(int.sizeof); alias sizediff_t = ptrdiff_t; // For backwards compatibility only. alias hash_t = size_t; // For backwards compatibility only. alias string = immutable(char)[]; T NEW(T, Args...)(auto ref Args args)
}(); void destroy(T)(ref T instance) free(cast(void*) instance); }(); class Object ~this() // dmd -betterC .\app.d .\object.d or ldmd2 -betterC -m64 .\app.d .\object.d |
November 06, 2023 Re: How should class objects created in betterC be destroyed | ||||
---|---|---|---|---|
| ||||
Posted in reply to zoe | Please tag your code accordingly, as is it's unreadable ```D // your code here ``` (tick the "Enable Markdown" too, next to the Send button) |
November 06, 2023 Re: How should class objects created in betterC be destroyed | ||||
---|---|---|---|---|
| ||||
Posted in reply to ryuukk_ | Here is how adam seems to be doing it: https://github.com/adamdruppe/webassembly/blob/731a7033174127c0a6dd4f23eabdb440adab286b/arsd-webassembly/object.d#L650-L681 Specially here:
and for interface:
But i suspect you'll have to implement the whole typeinfo |
November 06, 2023 Re: How should class objects created in betterC be destroyed | ||||
---|---|---|---|---|
| ||||
Posted in reply to zoe | On Monday, 6 November 2023 at 05:30:02 UTC, zoe wrote: >I customized object.d in -betterc mode and created NEW templates, with modules I can seemingly create classes without extern(C++) mode, and type conversions in function calls seem to work fine. But when destroy doesn't find a way to call the __xtdor() method of the corresponding subclass, is there any way to execute __xtdor() correctly Unfortunately, D classes cannot have virtual destructors, so TypeInfo is the only way to find the correct derived class destructor to call at runtime. I think the best you can do is implement your own virtual destructors, and your own
Of course, for classes that don't implement |
November 07, 2023 Re: How should class objects created in betterC be destroyed | ||||
---|---|---|---|---|
| ||||
Posted in reply to ryuukk_ | On Monday, 6 November 2023 at 16:08:41 UTC, ryuukk_ wrote: >Here is how adam seems to be doing it: https://github.com/adamdruppe/webassembly/blob/731a7033174127c0a6dd4f23eabdb440adab286b/arsd-webassembly/object.d#L650-L681 Specially here:
and for interface:
But i suspect you'll have to implement the whole typeinfo |