cppuhelper/source/compbase.cxx | 41 +------------------------------------ cppuhelper/source/implbase_ex.cxx | 4 ++- cppuhelper/source/type_entries.hxx | 22 +++++++++++++++++++ 3 files changed, 27 insertions(+), 40 deletions(-)
New commits: commit c2ffb93c7258aae9039148b8f8765cdbb73d8901 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Feb 19 13:35:26 2025 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sat Feb 22 09:35:16 2025 +0100 Deduplicate getTypeEntries in cppuhelper Also makes sure that the code initializing the struct uses the same mutex. There is also a duplicating code in comphelper/source/misc/compbase.cxx; however, to deduplicate also that, we would need to export the function. Change-Id: I145ea21d5c20536bab887ad55c69b74e7aeeb239 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181865 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/cppuhelper/source/compbase.cxx b/cppuhelper/source/compbase.cxx index ed4909b71106..3444c516dc0a 100644 --- a/cppuhelper/source/compbase.cxx +++ b/cppuhelper/source/compbase.cxx @@ -11,6 +11,8 @@ #include <sal/log.hxx> #include <osl/diagnose.h> +#include "type_entries.hxx" + namespace cppuhelper { WeakComponentImplHelperBase2::~WeakComponentImplHelperBase2() {} @@ -78,45 +80,6 @@ static bool td_equals(typelib_TypeDescriptionReference const* pTDR1, || OUString::unacquired(&pTDR1->pTypeName) == OUString::unacquired(&pTDR2->pTypeName)); } -static cppu::type_entry* getTypeEntries(cppu::class_data* cd) -{ - cppu::type_entry* pEntries = cd->m_typeEntries; - if (!cd->m_storedTypeRefs) // not inited? - { - static std::mutex aMutex; - std::scoped_lock guard(aMutex); - if (!cd->m_storedTypeRefs) // not inited? - { - // get all types - for (sal_Int32 n = cd->m_nTypes; n--;) - { - cppu::type_entry* pEntry = &pEntries[n]; - css::uno::Type const& rType = (*pEntry->m_type.getCppuType)(nullptr); - OSL_ENSURE(rType.getTypeClass() == css::uno::TypeClass_INTERFACE, - "### wrong helper init: expected interface!"); - OSL_ENSURE( - !isXInterface(rType.getTypeLibType()->pTypeName), - "### want to implement XInterface: template argument is XInterface?!?!?!"); - if (rType.getTypeClass() != css::uno::TypeClass_INTERFACE) - { - OUString msg("type \"" + rType.getTypeName() + "\" is no interface type!"); - SAL_WARN("cppuhelper", msg); - throw css::uno::RuntimeException(msg); - } - // ref is statically held by getCppuType() - pEntry->m_type.typeRef = rType.getTypeLibType(); - } - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); - cd->m_storedTypeRefs = true; - } - } - else - { - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); - } - return pEntries; -} - static void* makeInterface(sal_IntPtr nOffset, void* that) { return (static_cast<char*>(that) + nOffset); diff --git a/cppuhelper/source/implbase_ex.cxx b/cppuhelper/source/implbase_ex.cxx index 3f88feb97dd1..99b8a8d9b39a 100644 --- a/cppuhelper/source/implbase_ex.cxx +++ b/cppuhelper/source/implbase_ex.cxx @@ -22,6 +22,8 @@ #include <cppuhelper/compbase_ex.hxx> #include <cppuhelper/implbase_ex.hxx> +#include "type_entries.hxx" + #include <com/sun/star/uno/RuntimeException.hpp> #include <mutex> @@ -61,7 +63,7 @@ static bool td_equals( OUString::unacquired(&pTDR1->pTypeName) == OUString::unacquired(&pTDR2->pTypeName)); } -static type_entry * getTypeEntries( class_data * cd ) +type_entry * getTypeEntries( class_data * cd ) { type_entry * pEntries = cd->m_typeEntries; if (! cd->m_storedTypeRefs) // not inited? diff --git a/cppuhelper/source/type_entries.hxx b/cppuhelper/source/type_entries.hxx new file mode 100644 index 000000000000..501c1fe2c774 --- /dev/null +++ b/cppuhelper/source/type_entries.hxx @@ -0,0 +1,22 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <sal/config.h> + +#include <cppuhelper/implbase_ex.hxx> + +namespace cppu +{ +type_entry* getTypeEntries(class_data* cd); + +} // namespace cppu + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */