www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Messing with a class's v-table

reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
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
next sibling parent "Andrew Fedoniouk" <news terrainformatica.com> writes:
"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
prev sibling parent reply "Ben Hinkle" <bhinkle mathworks.com> writes:
"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
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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