Thread overview | ||||||
---|---|---|---|---|---|---|
|
July 06, 2005 Messing with a class's v-table | ||||
---|---|---|---|---|
| ||||
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.. |
July 06, 2005 Re: Messing with a class's v-table | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | "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 { void* #[] vtbl; // virtual function pointer table } isn't it? :) |
July 07, 2005 Re: Messing with a class's v-table | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | "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? |
July 07, 2005 Re: Messing with a class's v-table | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | "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! |
Copyright © 1999-2021 by the D Language Foundation