digitalmars.D.bugs - Messing with a class's v-table
- Jarrett Billingsley (22/22) Jul 06 2005 This.. uhh, shouldn't be legal:
- Andrew Fedoniouk (8/30) Jul 06 2005 Yep, it should be declared as:
- Ben Hinkle (4/26) Jul 07 2005 presumably you can also set the entire vtbl to point somewhere else or
- Jarrett Billingsley (5/7) Jul 07 2005 I suppose so..
This.. uhh, shouldn't be legal: import std.stdio; class A { void fork() { writefln("hi"); } void knife() { writefln("maybe"); } } void main() { A.classinfo.vtbl[6]=A.classinfo.vtbl[7]; A a=new A; a.fork(); } Prints "maybe" (i.e. calls knife())! I know the classinfo is probably still kind of beta-ish, but I don't think we should be able to _modify_ it..
Jul 06 2005
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:dah8kn$2n0a$1 digitaldaemon.com...This.. uhh, shouldn't be legal: import std.stdio; class A { void fork() { writefln("hi"); } void knife() { writefln("maybe"); } } void main() { A.classinfo.vtbl[6]=A.classinfo.vtbl[7]; A a=new A; a.fork(); } Prints "maybe" (i.e. calls knife())! I know the classinfo is probably still kind of beta-ish, but I don't think we should be able to _modify_ it..Yep, it should be declared as: class ClassInfo : Object { } isn't it? :)
Jul 06 2005
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:dah8kn$2n0a$1 digitaldaemon.com...This.. uhh, shouldn't be legal: import std.stdio; class A { void fork() { writefln("hi"); } void knife() { writefln("maybe"); } } void main() { A.classinfo.vtbl[6]=A.classinfo.vtbl[7]; A a=new A; a.fork(); } Prints "maybe" (i.e. calls knife())! I know the classinfo is probably still kind of beta-ish, but I don't think we should be able to _modify_ it..presumably you can also set the entire vtbl to point somewhere else or change just about anything, no?
Jul 07 2005
"Ben Hinkle" <bhinkle mathworks.com> wrote in message news:dajc4r$18nt$1 digitaldaemon.com...presumably you can also set the entire vtbl to point somewhere else or change just about anything, no?I suppose so.. You would think that this stuff would be stored in a read-only section of the EXE!
Jul 07 2005