Date: prev next · Thread: first prev next last
2014 Archives by date, by thread · List index


On Mon, Jun 23, 2014 at 01:07:14PM +0200, Stephan Bergmann wrote:
On 06/18/2014 10:58 PM, Lionel Elie Mamane wrote:
On Wed, Jun 18, 2014 at 05:04:02PM +0200, Stephan Bergmann wrote:

Short answer (from just browsing the top of FOO.patch): Use
css::uno::Reference<X> only for (C++ classes representing) UNO
interfaces, and use rtl::Reference<C> for C++ classes implementing
UNO objects.

Aha. This works. If you feel like explaining the C++-technical
reason behind why we need different Reference implementations for
the two cases... Feel free.

As C++ UNO for largely historic reasons does not use virtual
inheritance, (...) css::uno::XInterface is an ambiguous base class
of css::uri::XVndSunStarExpandUrlReference, so calling
pInterface->acquire() will not compile.

The trick is that we know that all compilers lay out the vtables in
roughly the same way: No matter how many types a given type X
derives from, a pointer to X points to a vtable containing function
pointers for X's first base (if any) followed by function pointers
for X's own members (if any).

Aren't we missing X's other bases here? There needs to be function
pointers for these, too, somewhere in the vtable. (I also understand
that changing the order of derivation changes the ABI.) I "guess" the
vtable is actually a depth-first left-to-right walk of the inheritance
graph.

So as long as X represents any UNO interface type, the
css::uno::Reference<X> ctor can do that dirty trick of reinterpret-casting
pInterface to css::uno::XInterface* (...)

Now, if you break the assumption that X represents a UNO interface type,
that reinterpret_cast trick potentially breaks down.

Do I understand right that:

1) UNO interface types are "carefully translated" to C++ so that
   (one of the multiple) css::uno::XInterface is always the first
   "ultimate base", so that its function pointers are always the first
   in the vtable. This is what makes the reinterpret_cast trick work.

2) UNO interface types don't use virtual inheritance, but the C++
   objects that implement them typically do, at least for the class
   that implements XInterface, and this is what ensures that all ways
   to call ->acquire do use the same reference counters.

   Or they carefully inherit only from one such XInterface
   implementation...

3) The UNO interface types are (purely) abstract (all their methods
   are " = 0;" in the class definition), but this has nothing to do
   with the discussed problem. This does not change the vtable
   layout.

-- 
Lionel

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.