Thread overview | ||||||
---|---|---|---|---|---|---|
|
October 24, 2006 delegate type info? | ||||
---|---|---|---|---|
| ||||
Is it possible at all to retrieve whether a given delegate is a delegate literal or from an object, that is if the .ptr property points to an Object or not? |
October 24, 2006 Re: delegate type info? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lutger Attachments: | Lutger schrieb am 2006-10-24: > Is it possible at all to retrieve whether a given delegate is a delegate literal or from an object, that is if the .ptr property points to an Object or not? Yes, the solution however is implementation defined. # import internal.gc.gcbits; # import internal.gc.gclinux; # import internal.gc.gcx; # import std.utf; # import std.gc; # # template delegatePointsToObject(T){ # static assert(is(T == delegate)); # bool delegatePointsToObject(T x){ # gc_t handle = cast(gc_t) getGCHandle(); # Gcx* engine = handle.gcx; # Pool* pool = engine.findPool(x.ptr); # if(!pool){ # return false; # } # # Object o = cast(Object) x.ptr; # if(!o){ # return false; # } # # ClassInfo ci = o.classinfo; # if(!ci){ # return false; # } # if(ci.name.length > (1 << 12)){ # return false; # } # try{ # std.utf.validate(ci.name); # }catch{ # return false; # } # # return true; # } # } usage sample: # interface I{ # void bar(); # } # # class C : I{ # void bar(){ # writefln("hallo"); # } # } # # import std.stdio; # int main(){ # C c = new C(); # I i = c; # # char[] foo(){ return null; } # # writefln("delegate points to object:"); # writefln("object\t\t%s", delegatePointsToObject(&c.bar)); # writefln("interface\t%s", delegatePointsToObject(&i.bar)); # writefln("nested function\t%s", delegatePointsToObject(&foo)); # # return 0; # } Thomas |
October 27, 2006 Re: delegate type info? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kuehne | Thomas Kuehne wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Lutger schrieb am 2006-10-24:
>> Is it possible at all to retrieve whether a given delegate is a delegate literal or from an object, that is if the .ptr property points to an Object or not?
>
> Yes, the solution however is implementation defined.
>
> <awesome hack>
Wow thanks. You sure know a lot about the internals, it's the .name ptr right that does the trick right? Does it work with GDC?
|
October 29, 2006 Re: delegate type info? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lutger Attachments: | Lutger schrieb am 2006-10-27:
> Thomas Kuehne wrote:
>>
>> Lutger schrieb am 2006-10-24:
>>> Is it possible at all to retrieve whether a given delegate is a delegate literal or from an object, that is if the .ptr property points to an Object or not?
>>
>> Yes, the solution however is implementation defined.
>>
>> <awesome hack>
>
> Wow thanks. You sure know a lot about the internals, it's the .name ptr right that does the trick right? Does it work with GDC?
It should work with GDC when GPhobos catches up with DMD-0.170's Phobos.
Thomas
|
Copyright © 1999-2021 by the D Language Foundation