www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - rt_finalize question

reply "Oleg B" <code.viator gmail.com> writes:
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*).
Jun 09 2015
parent reply "Oleg B" <code.viator gmail.com> writes:
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?).
Jun 09 2015
parent "Kagamin" <spam here.lot> writes:
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.
Jun 10 2015