www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - casting objects is not working across dll boundaries

Consider the following code:

module sharedInterface;

class A {}

module mainExecutable;
import sharedInterface;
import core.stdc.stdio;

extern(C)
{
   alias Object function() MakeObjectFunc;
}

__gshared MakeObjectFunc MakeObject;

void main(string[] args)
{
   //Load the dll with LoadLibrary and
   //get the address of MakeObject with GetProcAdress

   auto obj = cast(A)MakeObject();
   printf("obj = %x\n", cast(void*)obj);
}

module dll;

extern(C) export Object MakeObject()
{
   return new A();
}


The modules sharedInterface and mainExecutable are compiled into a 
executable. The modules dll and sharedInterface are compiled into a dll.

The exexutable will print
obj = 0x0

Because the _d_isbaseof2 in cast_.d does not work across dll boundaries.
It always uses the "is" operator for comparing two TypeInfo_Class 
objects, which breaks the dll support. Now this can be fixed, but it 
would require a full compare each time which would make casting 
significantly slower.

Should this be fixed or do we want to wait for a shared dll version of 
druntime?


I also found that inside Thread.remove

if( sm_tbeg == t )
   sm_tbeg = t.next;

Will crash across dll boundaries inside object_.d opEquals(Object, 
Object) because the vtable of one of the objects is invalid. Using the 
is operator instead of the compare fixed it for me.

Kind Regards
Benjamin Thaut
Dec 08 2012