Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-12

Inrerface delegation by class-type property: which way to go?

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sergei Gorelkin

Hello,

I tried to familiarize myself with the issues which must be resolved in order to get the interface delegation by class-type properties fixed.
It appears that the there are at least two ways to go: do it exactly like in Delphi, or do it another way :-)

Delphi way is more or less described in this attachment: http://bugs.freepascal.org/file_download.php?file_id=9100&type=bug

In case when an interface is delegated by class-type property, it uses specialized versions of wrapper code that call the interface getter (or read the field value). Since FPC generates interface wrappers at CPU-specific level in FPC, implementing it the same way seems to be quite painful (we actually need 3 more versions of tcg.g_intf_wrapper() code, multiplied by number of supported CPUs). Also, with this approach every call to a method of delegated interface goes through the getter, which has effect on performance if the getter is a function.

Alternative approach could look this way:
- extend TInterfaceEntry enumeration with 3 more members, something like etFieldValueClass, etStaticMethodResultClass, etVirtualMethodResultClass;
- fix the compiler to generate interface entries of those types when necessary;
- modify getinterfacebyentry() function: when the interface entry has one of abovementioned types, it treats its result as a class and jumps to its GetInterface method.

BUT, the problem with alternative approach is that it isn't clear what should happen when a class with delegated interfaces is typecasted to a delegated interface. A pointer to the interface can not be obtained by offsetting the instance pointer by constant amount (with Delphi approach, it can, because pointer to delegated interface is stored in the instance just like a regular interface). We'll have to generate the code which reads the field (or calls the getter) and offsets the result.

So, what would be other's opinions on this?

Regards,
Sergei

Reply by email

Paul Ishenin
to Sergei Gorelkin
Sergei Gorelkin wrote
So, what would be other's opinions on this?

I would choose the delphi way of implementation if it is known since some code can depend on implementation details as usual.

Best regards,
Paul Ishenin.

Reply by email