From 86b86ac87ea0cc90249f156494c98c3c93e4f3fc Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 13 Nov 2024 15:19:41 +0100 Subject: [PATCH] Give DocumentEventHolder (aka EventHolder) 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 Tested-by: Jenkins --- comphelper/source/misc/asyncnotification.cxx | 2 ++ dbaccess/source/core/dataaccess/documenteventnotifier.cxx | 7 ++----- include/comphelper/asyncnotification.hxx | 6 +++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/comphelper/source/misc/asyncnotification.cxx b/comphelper/source/misc/asyncnotification.cxx index 697954de0bc1..68cd57388bcd 100644 --- a/comphelper/source/misc/asyncnotification.cxx +++ b/comphelper/source/misc/asyncnotification.cxx @@ -173,6 +173,8 @@ namespace comphelper static std::vector> g_Notifiers; + template class EventHolder; + void JoinAsyncEventNotifiers() { std::vector> notifiers; diff --git a/dbaccess/source/core/dataaccess/documenteventnotifier.cxx b/dbaccess/source/core/dataaccess/documenteventnotifier.cxx index 475b16c0b551..a5c678579253 100644 --- a/dbaccess/source/core/dataaccess/documenteventnotifier.cxx +++ b/dbaccess/source/core/dataaccess/documenteventnotifier.cxx @@ -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() ); } diff --git a/include/comphelper/asyncnotification.hxx b/include/comphelper/asyncnotification.hxx index 16b36593b963..ae241e4bc997 100644 --- a/include/comphelper/asyncnotification.hxx +++ b/include/comphelper/asyncnotification.hxx @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -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; + using DocumentEventHolder = EventHolder; + COMPHELPER_DLLPUBLIC void JoinAsyncEventNotifiers(); } // namespace comphelper