Bug? NVI functions can't call normal interface functions?

Maxim Fomin maxim at maxim-fomin.ru
Sun Mar 17 06:54:27 PDT 2013


Yes, this is a bug.

The funny thing here is that instead TimedApp.fun(), 
object.Object.toString() is called due to shift error in virtual 
table offset jumping. I guess due to interfaces' ABI a class 
instance isn't passed properly. Using

     override string toString()
     {
         printf("bzzzz\n");
         return "";
     }

reveals the bug. Valgrind also doesn't detect error like this. 
Vtable storage layout may explain where bug comes from:

_D4main8TimedApp6__vtblZ:
	dd	offset FLAT:_D4main8TimedApp7__ClassZ at 64
	db	000h,000h,000h,000h	;....
	dd	offset FLAT:_D6object6Object8toStringMFZAya at 64
	db	000h,000h,000h,000h	;....
	dd	offset FLAT:_D6object6Object6toHashMFNbNeZm at 64
	db	000h,000h,000h,000h	;....
	dd	offset FLAT:_D6object6Object5opCmpMFC6ObjectZi at 64
	db	000h,000h,000h,000h	;....
	dd	offset FLAT:_D6object6Object8opEqualsMFC6ObjectZb at 64
	db	000h,000h,000h,000h	;....
	dd	offset FLAT:_D6object6Object8opEqualsMFC6ObjectC6ObjectZb at 64
	db	000h,000h,000h,000h	;....
	dd	offset FLAT:_D4main8TimedApp3funMFZi at 64
	db	000h,000h,000h,000h	;....


I remember Don was posting similar issue but do not remember the 
#.


More information about the Digitalmars-d mailing list