Thread overview
rt_finalize question
Jun 09, 2015
Oleg B
Jun 10, 2015
Oleg B
Jun 10, 2015
Kagamin
June 09, 2015
Hello. In object.di rt_finalize calls for class objects in destroy func.
I not found it in dmd source on github and not found in druntime sources.
I think rt_finalize must call dtors for object and base classes, but I think that's not all. Or if it all has it code logic problems?

void myDestroy(T)( T obj ) if( is( T == class ) )
{
    mixin( callDtor!( obj.stringof, TypeTuple!(T,BaseClassesTuple!T) ) );
}

string callDtor( string name, BCT... )() @property
{
    import std.string;
    static if( BCT.length == 1 ) return ""; // Object has no dtor
    else
        return format( "%s.%s.__dtor();\n", name, BCT[0].stringof.split(".")[$-1] ) ~
               callDtor!(name, BCT[1..$]);
}

function callDtor generate string like this

obj.C.__dtor();
obj.B.__dtor();
obj.A.__dtor();

for class model

class A{}
class B : A {}
class C : B {}

I want understand why destroy for class objects call extern(C) function rt_finalize (not pure, with gc, can except), and how it works (rt_finalize gets void*).
June 10, 2015
I found it

https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L1350

Creates new questions.
Why it's extern(C)?
What must do collectHandler function?
If I understand correctly monitor relates to multithreading control (Mutex?).
June 10, 2015
On Wednesday, 10 June 2015 at 00:04:16 UTC, Oleg B wrote:
> Why it's extern(C)?

For easy linking.

> What must do collectHandler function?

Looks like it overrides the destruction procedure.

> If I understand correctly monitor relates to multithreading control (Mutex?).

Yes.