December 07, 2017
On Thursday, 7 December 2017 at 14:59:57 UTC, Steven Schveighoffer wrote:
> The object is constructed here: [...]

Thanks for the pointers, you've saved me a lot of time :)

> On a side note however, you really shouldn't change data in a ClassInfo at all, and probably the compiler shouldn't let you!

This experiment is related to an ongoing discussion with Walter, Andrei and Ali on extending D with general mechanisms to better support libraries like openmethods. I will post in Studies soon.
December 07, 2017
On Thursday, 7 December 2017 at 15:09:45 UTC, Jean-Louis Leroy wrote:
> On Thursday, 7 December 2017 at 14:59:57 UTC, Steven Schveighoffer wrote:
>> The object is constructed here: [...]
>
> Thanks for the pointers, you've saved me a lot of time :)
>
>> On a side note however, you really shouldn't change data in a ClassInfo at all, and probably the compiler shouldn't let you!
>
> This experiment is related to an ongoing discussion with Walter, Andrei and Ali on extending D with general mechanisms to better support libraries like openmethods. I will post in Studies soon.

Cool:

import std.stdio;

class Foo {
  abstract void report();
}

class Bar : Foo {
  override void report() { writeln("I'm fine!"); }
}

void main() {
  auto oldPtr = Bar.classinfo.vtbl.ptr;
  Bar.classinfo.vtbl.reserve(1000);
  Bar.classinfo.vtbl.ptr[Bar.classinfo.vtbl.length] = cast(void*) 0x123456;
  writeln(oldPtr != Bar.classinfo.vtbl.ptr); // true
  *cast(void***) Bar.classinfo.m_init.ptr = Bar.classinfo.vtbl.ptr;
  Foo foo = new Bar();
  writeln(oldPtr == *cast(void***)foo); // false
  foo.report(); // I'm fine!
  writeln((*cast(void***)foo)[Bar.classinfo.vtbl.length]); // 123456
}

December 07, 2017
On 12/7/17 10:21 AM, Jean-Louis Leroy wrote:
> Bar.classinfo.vtbl.ptr[Bar.classinfo.vtbl.length] = cast(void*) 0x123456;

This is a buffer overflow, why are you doing this specifically?

-Steve
December 07, 2017
On Thursday, 7 December 2017 at 15:34:09 UTC, Steven Schveighoffer wrote:
> On 12/7/17 10:21 AM, Jean-Louis Leroy wrote:
>> Bar.classinfo.vtbl.ptr[Bar.classinfo.vtbl.length] = cast(void*) 0x123456;
>
> This is a buffer overflow, why are you doing this specifically?
>
> -Steve

It's not an overflow because of the call to `reserve`. It is part of an experiment related to supporting user-defined per-class metadata by extending the vtable.
December 07, 2017
On 12/7/17 10:45 AM, Jean-Louis Leroy wrote:
> On Thursday, 7 December 2017 at 15:34:09 UTC, Steven Schveighoffer wrote:
>> On 12/7/17 10:21 AM, Jean-Louis Leroy wrote:
>>> Bar.classinfo.vtbl.ptr[Bar.classinfo.vtbl.length] = cast(void*) 0x123456;
>>
>> This is a buffer overflow, why are you doing this specifically?
>>
>> -Steve
> 
> It's not an overflow because of the call to `reserve`. It is part of an experiment related to supporting user-defined per-class metadata by extending the vtable.

Ah, ok.

Take care, I'm not sure that the classinfo instances are scanned by the GC. Might be better to use C malloc.

-Steve
December 08, 2017
On 2017-12-07 16:09, Jean-Louis Leroy wrote:

> This experiment is related to an ongoing discussion with Walter, Andrei and Ali on extending D with general mechanisms to better support libraries like openmethods. I will post in Studies soon.

Modifying the vtable can be useful for mocking and stubbing methods as well.

-- 
/Jacob Carlborg
December 08, 2017
On Friday, 8 December 2017 at 14:59:12 UTC, Jacob Carlborg wrote:
> On 2017-12-07 16:09, Jean-Louis Leroy wrote:
>
>> This experiment is related to an ongoing discussion with Walter, Andrei and Ali on extending D with general mechanisms to better support libraries like openmethods. I will post in Studies soon.
>
> Modifying the vtable can be useful for mocking and stubbing methods as well.

Indeed. The initial vtable is in read only memory, but the re-allocated one is writeable.
1 2
Next ›   Last »