betterC: new operator

Petar Petar
Tue Nov 24 11:22:30 UTC 2020


On Tuesday, 24 November 2020 at 05:40:21 UTC, 9il wrote:
> On Sunday, 22 November 2020 at 11:54:01 UTC, Dibyendu Majumdar 
> wrote:
>> I had assumed that new operator is not available in betterC.
>>
>> But in following code, it seems the only way to initialize the 
>> object correctly ... is there another way I am missing? How 
>> should one cleanup objects?
>>
>> import core.stdc.stdio : printf;
>>
>> extern (C++) abstract class A {
>>     void sayHello();
>> }
>>
>> extern (C++) class B : A {
>>     override void sayHello() {
>>         printf("hello\n");
>>     }
>> }
>>
>> extern (C) void main() {
>>     scope b = new B;
>>     b.sayHello();
>> }
>
> Mir's RC classes doesn't use TypeInfo and DRuntime,
>
> http://mir-algorithm.libmir.org/mir_rc_ptr.html
>
> can be used from C++
>
> https://github.com/libmir/mir-algorithm/blob/master/include/mir/rcptr.h
>
> and C#
>
> https://github.com/libmir/mir.net

Nice! However, how do you initialize the vtbl of the extern (C++) 
class? I briefly had a look and mir.rc.ptr.createRC [1] calls 
mir.conv.emplace [2], which is a public import of 
core.lifetime.emplace, which as far as I can see uses typeinfo 
for that [3]. You also have a custom typeinfo implementation in 
mir.typeinfo [4], but I didn't see anything regarding 
initializing the vtbl pointer in there, just about the pointer to 
the destructor.

Anyway, impressive work on making the interoperability between D, 
C++ and .NET more seamless! As a former C# developer, mir.net 
looks much simpler to use then other marshaling techniques for 
e.g. C/C++. What is the relation between mir.net and autowrap's 
support for .NET [5]?

[1]: 
https://github.com/libmir/mir-algorithm/blob/2fa78ddb64d5343ae97a8d5acb0012a37d2ae558/source/mir/rc/ptr.d#L263

[2]: 
https://github.com/libmir/mir-core/blob/8568bf2fceb361ef7804161b1efc5a96e588c24c/source/mir/conv.d#L9

[3]: 
https://github.com/dlang/druntime/blob/b948c26b8d86be8f058bf538b75df4d422e2a98f/src/core/lifetime.d#L109

[4]: 
https://github.com/libmir/mir-algorithm/blob/2fa78ddb64d5343ae97a8d5acb0012a37d2ae558/source/mir/type_info.d#L17

[5]: 
https://github.com/symmetryinvestments/autowrap#generating-net-interfaces


More information about the Digitalmars-d mailing list