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.kaganski@collabora.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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: */
|
||||
Reference in New Issue
Block a user