Comparing method pointers ("of object") with "=" compares only the pointer to code
Original Reporter info from Mantis: Michalis @michaliskambi
-
Reporter name: Michalis Kamburelis
Original Reporter info from Mantis: Michalis @michaliskambi
- Reporter name: Michalis Kamburelis
Description:
When comparing method pointers with "=", it seems that only the code pointer is compared. This means that e.g.
@M1.Foo = @M2.Foo
or
P1 := @M1.Foo;
P2 := @M2.Foo;
... P1 = P2 ...
returns true if Foo above refers to the same method in the same class. Even when M1 and M2 are different instances of the same class.
For methods, it seems natural that also a pointer to object instance should be compared.
Observed with FPC 2.2.0, 2.2.2 and trunk (11559) on Linux i386 with objfpc mode. I couldn't make this test compile with Kylix 3 or FPC in delphi compat mode.
(Workaround is to cast to TMethod type and compare Data and Code, like
(TMethod(@M1.Foo).Code = TMethod(@M2.Foo).Code) and
(TMethod(@M1.Foo).Data = TMethod(@M2.Foo).Data)
).
Simple testcase attached.
Mantis conversion info:
- Mantis ID: 11868
- OS: Debian GNU/Linux
- OS Build: (testing)
- Platform: i386
- Version: 2.2.2