Give DocumentEventHolder (aka EventHolder<DocumentEvent>) a key function

...that is not inline, so that RTTI and vtable are not emitted for each dynamic
library individually.  (Where they would be internal on macOS, which could break
optimized uses of dynamic_cast for that final class just checking vtable pointer
identity, as could happen for the dynamic_cast at
dbaccess/source/core/dataaccess/documenteventnotifier.cxx:232:51,

>   232 |         const DocumentEventHolder& rEventHolder = dynamic_cast< const DocumentEventHolder& >( _rEvent );
>       |                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And with the extern explicit template instantiation, EventHolder needs to be
SAL_DLLPUBLIC_TEMPLATE instead of just SAL_DLLPUBLIC_RTTI now, so that
Library_comphelper will export the DocumentEventHolder ctors and
DocumentEventHolder::getEventObject.)

(This would ideally have been caught by an upcoming improvement of
loplugin:dyncastvisibility, but might be complicated to check there for template
instantiations.)

Change-Id: I1e6280b185535968a870fbfadaff6238d38858e2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176547
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Tested-by: Jenkins
This commit is contained in:
Stephan Bergmann 2024-11-13 15:19:41 +01:00
parent cf42d70e8c
commit 86b86ac87e
3 changed files with 9 additions and 6 deletions

View file

@ -173,6 +173,8 @@ namespace comphelper
static std::vector<std::weak_ptr<AsyncEventNotifierAutoJoin>> g_Notifiers;
template class EventHolder<css::document::DocumentEvent>;
void JoinAsyncEventNotifiers()
{
std::vector<std::weak_ptr<AsyncEventNotifierAutoJoin>> notifiers;

View file

@ -40,9 +40,6 @@ namespace dbaccess
using namespace ::com::sun::star;
// DocumentEventHolder
typedef ::comphelper::EventHolder< DocumentEvent > DocumentEventHolder;
// DocumentEventNotifier_Impl
class DocumentEventNotifier_Impl : public ::comphelper::IEventProcessor
{
@ -218,7 +215,7 @@ namespace dbaccess
::comphelper::AsyncEventNotifierAutoJoin::launch(m_pEventBroadcaster);
}
}
m_pEventBroadcaster->addEvent( new DocumentEventHolder( _rEvent ), this );
m_pEventBroadcaster->addEvent( new comphelper::DocumentEventHolder( _rEvent ), this );
}
void DocumentEventNotifier_Impl::processEvent( const ::comphelper::AnyEvent& _rEvent )
@ -229,7 +226,7 @@ namespace dbaccess
if ( m_bDisposed )
return;
}
const DocumentEventHolder& rEventHolder = dynamic_cast< const DocumentEventHolder& >( _rEvent );
const comphelper::DocumentEventHolder& rEventHolder = dynamic_cast< const comphelper::DocumentEventHolder& >( _rEvent );
impl_notifyEvent_nothrow( rEventHolder.getEventObject() );
}

View file

@ -23,6 +23,7 @@
#include <sal/config.h>
#include <config_options.h>
#include <com/sun/star/document/DocumentEvent.hpp>
#include <comphelper/comphelperdllapi.h>
#include <rtl/ref.hxx>
#include <sal/types.h>
@ -199,7 +200,7 @@ namespace comphelper
/** AnyEvent derivee holding a foreign event instance
*/
template < typename EVENT_OBJECT >
class SAL_DLLPUBLIC_RTTI EventHolder final : public AnyEvent
class SAL_DLLPUBLIC_TEMPLATE EventHolder final : public AnyEvent
{
public:
typedef EVENT_OBJECT EventObjectType;
@ -216,6 +217,9 @@ namespace comphelper
const EventObjectType& getEventObject() const { return m_aEvent; }
};
extern template class EventHolder<css::document::DocumentEvent>;
using DocumentEventHolder = EventHolder<css::document::DocumentEvent>;
COMPHELPER_DLLPUBLIC void JoinAsyncEventNotifiers();
} // namespace comphelper