[PATCH] tools/widl/header.c: Add a way to declare interface data members.

Max TenEyck Woodbury max at mtew.isa-geek.net
Sun Nov 11 18:10:37 CST 2012


On 11/11/2012 03:05 PM, Michael Stefaniuc wrote:
> On 11/11/2012 07:12 AM, Max TenEyck Woodbury wrote:
>> On 11/11/2012 01:01 AM, Nikolay Sivov wrote:
>>> On 11/11/2012 05:00, Max TenEyck Woodbury wrote:
>>>> I mentioned this a few days ago.  It would have helped if you had
>>>> raised this point then.
>>>>
>>>> As it stands, it is simply a way to adding data members to an aggregate
>>>> with an interface.
>>>
>>> Data members to an aggregate? What are you talking about and what it has
>>> to do with interface definition?
>>
>> An aggregate is a collection of information, like a class, struct or
>> union.
> 
> Your mixing up terminology.
> 
Please excuse the confusion.  I learned that usage when I worked for
DEC in the 1980's.

>> Some aggregates include 'interface's, a COM, OLE or RPC thingy.  The
>> interface can have only methods defined, but those methods might want
>> access to some additional data.  To get to that data, the method now
>> has to build a pointer to the containing aggregate and reference the
>> data through that pointer.  This introduces complications to the code
>> since the data may not be in same place in the aggregate in each
>> instance where the interface is used.  You need a slightly different
>> code sequence for each different place the method is needed.  However,
>> the source code will be virtually identical for each instance.
>>
>> This patch allows those aggregate data members associated with the
>> interface, which are not technically part of the interface, to be
>> placed in a fixed relation to the interfaces Vtbl pointer.
>> (Practically the Vtbl pointer is the interface.)  By establishing such
>> a relationship, the need to convert from the pointer to the interface
>> (specifically to its Vtbl pointer) to a pointer to its containing
>> aggregate in order to get to the relevant data is removed.
> 
> Please check how a C compiler is laying out structs in memory. In both
> cases the data is at a fixed offset (calculated at compile time) in
> relation to the interface.
> 
I believe you are confused here.  The relative addresses in the
original may change if changes are made to the aggregate.  If you want
to tell the compiler which aggregate member you want to use, you need
to use a pointer to the aggregate.  It has no way to figure out what
you are talking about unless you give it that without this hack.

>> Now, technically, the associated data is not part of the interface.  It
>> is part of the aggregate containing and implementing the interface.
>> Moving the declaration from the aggregate to the end of the struc for
>> the interface is a hack that lets simpler and more general code to be
>> generated.
>>
>> So, it's a hack, that you only use if you want to, to speed up
>> execution and simplify maintenance.
>>
> It is a hack that breaks the ABI (sizeof(interface) == sizeof(void*)),
> doesn't improves the generated code, doesn't simplify maintenance at
> all, quite the contrary. This sounds more like trolling than a serious
> attempt to improve Wine.
> 
That depends on exactly what you call the 'interface'.  If you call the
Vtbl the interface, the size does not change.  If you call the 'struct'
containing the Vtbl the interface (which someone else pointed out is
only an artifact of the implementation technique), it changes.  So, as
with most hacks, you have to be careful what you ask for.  I might
change my mind if you point out an existing non-contrived example of
using sizeof(<interface>) that this would break.

The real question is ;Could it be useful?'.  I think the answer is
'yes'.




More information about the wine-devel mailing list