summaryrefslogtreecommitdiff
path: root/cppu
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-04-28 13:50:01 +0200
committerStephan Bergmann <sbergman@redhat.com>2020-04-28 15:07:45 +0200
commit679163845bd2f8b6de703f8fe704eb8912bc4ba4 (patch)
tree3bacb2d7758859b5bb052f34dcbaea89c485939d /cppu
parent8e7b61c48544b722b1cea41c9e2e6b1e01191be9 (diff)
tdf#115399: Don't kill pre-existing typelib_TypeDescription members
...in typelib_typedescription_register, in case they are already being referenced from elsewhere. Instead, only move from *ppNewDescription to pTDR->pType those members that were not yet initialized in the latter. Change-Id: I7620219d137f8dd7f24a0f4a04eda30669b6c5a9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93062 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'cppu')
-rw-r--r--cppu/CppunitTest_cppu_typelib.mk27
-rw-r--r--cppu/Module_cppu.mk1
-rw-r--r--cppu/qa/typelib.cxx293
-rw-r--r--cppu/source/typelib/typelib.cxx110
4 files changed, 415 insertions, 16 deletions
diff --git a/cppu/CppunitTest_cppu_typelib.mk b/cppu/CppunitTest_cppu_typelib.mk
new file mode 100644
index 000000000000..ba9236f61110
--- /dev/null
+++ b/cppu/CppunitTest_cppu_typelib.mk
@@ -0,0 +1,27 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,cppu_typelib))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,cppu_typelib, \
+ cppu/qa/typelib \
+))
+
+$(eval $(call gb_CppunitTest_use_api,cppu_typelib, \
+ udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,cppu_typelib, \
+ cppu \
+ sal \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,cppu_typelib))
+
+# vim: set noet sw=4 ts=4:
diff --git a/cppu/Module_cppu.mk b/cppu/Module_cppu.mk
index d5c47c88a2b6..17f6936f7878 100644
--- a/cppu/Module_cppu.mk
+++ b/cppu/Module_cppu.mk
@@ -27,6 +27,7 @@ $(eval $(call gb_Module_add_check_targets,cppu,\
CppunitTest_cppu_qa_reference \
CppunitTest_cppu_qa_unotype \
CppunitTest_cppu_test_cppumaker \
+ CppunitTest_cppu_typelib \
))
# vim: set noet sw=4 ts=4:
diff --git a/cppu/qa/typelib.cxx b/cppu/qa/typelib.cxx
new file mode 100644
index 000000000000..227e5731cc4f
--- /dev/null
+++ b/cppu/qa/typelib.cxx
@@ -0,0 +1,293 @@
+/* -*- 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/.
+ */
+
+#include <sal/config.h>
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <com/sun/star/io/XActiveDataSink.hpp>
+#include <com/sun/star/io/XTextInputStream.hpp>
+#include <com/sun/star/lang/EventObject.hpp>
+#include <com/sun/star/script/FinishReason.hpp>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Type.hxx>
+#include <com/sun/star/uno/XInterface.hpp>
+#include <cppu/unotype.hxx>
+#include <rtl/ustring.hxx>
+#include <sal/types.h>
+#include <typelib/typedescription.h>
+#include <typelib/typedescription.hxx>
+
+// Test that typelib_typedescription_register as called from typelib_typedescription_complete
+// returns a correct typelib_TypeDescription and keeps pointers from the original
+// typelib_TypeDescription intact (see tdf#115399 "Data race in typelib_typedescription_register").
+// This code uses sufficiently "obscure" types in typelib_static_*_type_init to make it unlikely
+// that they are already instantiated and registered with the type description manager, which might
+// cause inconsistencies.
+
+namespace
+{
+class Test : public CppUnit::TestFixture
+{
+public:
+ void testEnum()
+ {
+ typelib_TypeDescriptionReference* ref = nullptr;
+ typelib_static_enum_type_init(&ref, "com.sun.star.script.MemberType", 0);
+ CPPUNIT_ASSERT(ref != nullptr);
+ typelib_TypeDescription* td = ref->pType;
+ CPPUNIT_ASSERT(td != nullptr);
+ typelib_typedescription_acquire(td);
+ CPPUNIT_ASSERT(!td->bComplete);
+ auto t = reinterpret_cast<typelib_EnumTypeDescription*>(td);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), t->nDefaultEnumValue);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), t->nEnumValues);
+ CPPUNIT_ASSERT(t->ppEnumNames == nullptr);
+ CPPUNIT_ASSERT(t->pEnumValues == nullptr);
+ CPPUNIT_ASSERT(typelib_typedescription_complete(&td));
+ CPPUNIT_ASSERT(td != nullptr);
+ CPPUNIT_ASSERT(td->bComplete);
+ t = reinterpret_cast<typelib_EnumTypeDescription*>(td);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), t->nDefaultEnumValue);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(3), t->nEnumValues);
+ CPPUNIT_ASSERT(t->ppEnumNames != nullptr);
+ CPPUNIT_ASSERT_EQUAL(OUString("METHOD"), OUString::unacquired(&t->ppEnumNames[0]));
+ CPPUNIT_ASSERT_EQUAL(OUString("PROPERTY"), OUString::unacquired(&t->ppEnumNames[1]));
+ CPPUNIT_ASSERT_EQUAL(OUString("UNKNOWN"), OUString::unacquired(&t->ppEnumNames[2]));
+ CPPUNIT_ASSERT(t->pEnumValues != nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), t->pEnumValues[0]);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), t->pEnumValues[1]);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), t->pEnumValues[2]);
+ typelib_typedescription_release(td);
+ typelib_typedescriptionreference_release(ref);
+ }
+
+ void testStruct()
+ {
+ auto const t0 = cppu::UnoType<css::lang::EventObject>::get();
+ auto const t1 = cppu::UnoType<css::script::FinishReason>::get();
+ auto const t2 = cppu::UnoType<OUString>::get();
+ auto const t3 = cppu::UnoType<css::uno::Any>::get();
+ typelib_TypeDescriptionReference* ref = nullptr;
+ typelib_TypeDescriptionReference* members[3]
+ = { t1.getTypeLibType(), t2.getTypeLibType(), t3.getTypeLibType() };
+ typelib_static_struct_type_init(&ref, "com.sun.star.script.FinishEngineEvent",
+ t0.getTypeLibType(), 3, members, nullptr);
+ CPPUNIT_ASSERT(ref != nullptr);
+ typelib_TypeDescription* td = ref->pType;
+ CPPUNIT_ASSERT(td != nullptr);
+ typelib_typedescription_acquire(td);
+ CPPUNIT_ASSERT(!td->bComplete);
+ auto t = reinterpret_cast<typelib_StructTypeDescription*>(td);
+ CPPUNIT_ASSERT(css::uno::TypeDescription(&t->aBase.pBaseTypeDescription->aBase).equals(t0));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(3), t->aBase.nMembers);
+ auto const offsets = t->aBase.pMemberOffsets;
+ CPPUNIT_ASSERT(offsets != nullptr);
+ auto const typerefs = t->aBase.ppTypeRefs;
+ CPPUNIT_ASSERT(typerefs != nullptr);
+ CPPUNIT_ASSERT_EQUAL(t1, css::uno::Type(typerefs[0]));
+ CPPUNIT_ASSERT_EQUAL(t2, css::uno::Type(typerefs[1]));
+ CPPUNIT_ASSERT_EQUAL(t3, css::uno::Type(typerefs[2]));
+ CPPUNIT_ASSERT(t->aBase.ppMemberNames == nullptr);
+ CPPUNIT_ASSERT(t->pParameterizedTypes == nullptr);
+ CPPUNIT_ASSERT(typelib_typedescription_complete(&td));
+ CPPUNIT_ASSERT(td != nullptr);
+ CPPUNIT_ASSERT(td->bComplete);
+ t = reinterpret_cast<typelib_StructTypeDescription*>(td);
+ CPPUNIT_ASSERT(css::uno::TypeDescription(&t->aBase.pBaseTypeDescription->aBase).equals(t0));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(3), t->aBase.nMembers);
+ CPPUNIT_ASSERT(t->aBase.pMemberOffsets != nullptr);
+ CPPUNIT_ASSERT(t->aBase.ppTypeRefs != nullptr);
+ CPPUNIT_ASSERT_EQUAL(t1, css::uno::Type(t->aBase.ppTypeRefs[0]));
+ CPPUNIT_ASSERT_EQUAL(t2, css::uno::Type(t->aBase.ppTypeRefs[1]));
+ CPPUNIT_ASSERT_EQUAL(t3, css::uno::Type(t->aBase.ppTypeRefs[2]));
+ CPPUNIT_ASSERT(t->aBase.ppMemberNames != nullptr);
+ CPPUNIT_ASSERT_EQUAL(OUString("Finish"), OUString::unacquired(&t->aBase.ppMemberNames[0]));
+ CPPUNIT_ASSERT_EQUAL(OUString("ErrorMessage"),
+ OUString::unacquired(&t->aBase.ppMemberNames[1]));
+ CPPUNIT_ASSERT_EQUAL(OUString("Return"), OUString::unacquired(&t->aBase.ppMemberNames[2]));
+ CPPUNIT_ASSERT(t->pParameterizedTypes == nullptr);
+ // `offsets` and `typerefs` must still be valid:
+ CPPUNIT_ASSERT_EQUAL(t->aBase.pMemberOffsets[0], offsets[0]);
+ CPPUNIT_ASSERT_EQUAL(t->aBase.pMemberOffsets[1], offsets[1]);
+ CPPUNIT_ASSERT_EQUAL(t->aBase.pMemberOffsets[2], offsets[2]);
+ CPPUNIT_ASSERT_EQUAL(css::uno::Type(t->aBase.ppTypeRefs[0]), css::uno::Type(typerefs[0]));
+ CPPUNIT_ASSERT_EQUAL(css::uno::Type(t->aBase.ppTypeRefs[1]), css::uno::Type(typerefs[1]));
+ CPPUNIT_ASSERT_EQUAL(css::uno::Type(t->aBase.ppTypeRefs[2]), css::uno::Type(typerefs[2]));
+ typelib_typedescription_release(td);
+ typelib_typedescriptionreference_release(ref);
+ }
+
+ void testPolyStruct()
+ {
+ auto const t1 = cppu::UnoType<bool>::get();
+ auto const t2 = cppu::UnoType<sal_Int32>::get();
+ typelib_TypeDescriptionReference* ref = nullptr;
+ typelib_TypeDescriptionReference* members[2] = { t1.getTypeLibType(), t2.getTypeLibType() };
+ sal_Bool const param[2] = { false, true };
+ typelib_static_struct_type_init(&ref, "com.sun.star.beans.Optional<long>", nullptr, 2,
+ members, param);
+ CPPUNIT_ASSERT(ref != nullptr);
+ typelib_TypeDescription* td = ref->pType;
+ CPPUNIT_ASSERT(td != nullptr);
+ typelib_typedescription_acquire(td);
+ CPPUNIT_ASSERT(!td->bComplete);
+ auto t = reinterpret_cast<typelib_StructTypeDescription*>(td);
+ CPPUNIT_ASSERT(t->aBase.pBaseTypeDescription == nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), t->aBase.nMembers);
+ auto const offsets = t->aBase.pMemberOffsets;
+ CPPUNIT_ASSERT(offsets != nullptr);
+ auto const typerefs = t->aBase.ppTypeRefs;
+ CPPUNIT_ASSERT(typerefs != nullptr);
+ CPPUNIT_ASSERT_EQUAL(t1, css::uno::Type(typerefs[0]));
+ CPPUNIT_ASSERT_EQUAL(t2, css::uno::Type(typerefs[1]));
+ CPPUNIT_ASSERT(t->aBase.ppMemberNames == nullptr);
+ CPPUNIT_ASSERT(t->pParameterizedTypes != nullptr);
+ CPPUNIT_ASSERT_EQUAL(param[0], t->pParameterizedTypes[0]);
+ CPPUNIT_ASSERT_EQUAL(param[1], t->pParameterizedTypes[1]);
+ CPPUNIT_ASSERT(typelib_typedescription_complete(&td));
+ CPPUNIT_ASSERT(td != nullptr);
+ CPPUNIT_ASSERT(td->bComplete);
+ t = reinterpret_cast<typelib_StructTypeDescription*>(td);
+ CPPUNIT_ASSERT(t->aBase.pBaseTypeDescription == nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), t->aBase.nMembers);
+ CPPUNIT_ASSERT(t->aBase.pMemberOffsets != nullptr);
+ CPPUNIT_ASSERT(t->aBase.ppTypeRefs != nullptr);
+ CPPUNIT_ASSERT_EQUAL(t1, css::uno::Type(t->aBase.ppTypeRefs[0]));
+ CPPUNIT_ASSERT_EQUAL(t2, css::uno::Type(t->aBase.ppTypeRefs[1]));
+ CPPUNIT_ASSERT(t->aBase.ppMemberNames != nullptr);
+ CPPUNIT_ASSERT_EQUAL(OUString("IsPresent"),
+ OUString::unacquired(&t->aBase.ppMemberNames[0]));
+ CPPUNIT_ASSERT_EQUAL(OUString("Value"), OUString::unacquired(&t->aBase.ppMemberNames[1]));
+ CPPUNIT_ASSERT(t->pParameterizedTypes != nullptr);
+ CPPUNIT_ASSERT_EQUAL(param[0], t->pParameterizedTypes[0]);
+ CPPUNIT_ASSERT_EQUAL(param[1], t->pParameterizedTypes[1]);
+ // `offsets` and `typerefs` must still be valid:
+ CPPUNIT_ASSERT_EQUAL(t->aBase.pMemberOffsets[0], offsets[0]);
+ CPPUNIT_ASSERT_EQUAL(t->aBase.pMemberOffsets[1], offsets[1]);
+ CPPUNIT_ASSERT_EQUAL(css::uno::Type(t->aBase.ppTypeRefs[0]), css::uno::Type(typerefs[0]));
+ CPPUNIT_ASSERT_EQUAL(css::uno::Type(t->aBase.ppTypeRefs[1]), css::uno::Type(typerefs[1]));
+ typelib_typedescription_release(td);
+ typelib_typedescriptionreference_release(ref);
+ }
+
+ void testInterface()
+ {
+ auto const t0 = cppu::UnoType<css::uno::XInterface>::get();
+ typelib_TypeDescriptionReference* ref = nullptr;
+ typelib_TypeDescriptionReference* bases[1] = { t0.getTypeLibType() };
+ typelib_static_mi_interface_type_init(&ref, "com.sun.star.script.XTypeConverter", 1, bases);
+ CPPUNIT_ASSERT(ref != nullptr);
+ typelib_TypeDescription* td = ref->pType;
+ CPPUNIT_ASSERT(td != nullptr);
+ typelib_typedescription_acquire(td);
+ CPPUNIT_ASSERT(!td->bComplete);
+ auto t = reinterpret_cast<typelib_InterfaceTypeDescription*>(td);
+ CPPUNIT_ASSERT(css::uno::TypeDescription(&t->pBaseTypeDescription->aBase).equals(t0));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), t->nMembers);
+ CPPUNIT_ASSERT(t->ppMembers == nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), t->nAllMembers);
+ CPPUNIT_ASSERT(t->ppAllMembers == nullptr);
+ CPPUNIT_ASSERT(t->pMapMemberIndexToFunctionIndex == nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), t->nMapFunctionIndexToMemberIndex);
+ CPPUNIT_ASSERT(t->pMapFunctionIndexToMemberIndex == nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), t->nBaseTypes);
+ auto const basetypes = t->ppBaseTypes;
+ CPPUNIT_ASSERT(basetypes != nullptr);
+ CPPUNIT_ASSERT(css::uno::TypeDescription(&basetypes[0]->aBase).equals(t0));
+ CPPUNIT_ASSERT(typelib_typedescription_complete(&td));
+ CPPUNIT_ASSERT(td != nullptr);
+ CPPUNIT_ASSERT(td->bComplete);
+ t = reinterpret_cast<typelib_InterfaceTypeDescription*>(td);
+ CPPUNIT_ASSERT(css::uno::TypeDescription(&t->pBaseTypeDescription->aBase).equals(t0));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), t->nMembers);
+ CPPUNIT_ASSERT(t->ppMembers != nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), t->nAllMembers);
+ CPPUNIT_ASSERT(t->ppAllMembers != nullptr);
+ CPPUNIT_ASSERT(t->pMapMemberIndexToFunctionIndex != nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), t->nMapFunctionIndexToMemberIndex);
+ CPPUNIT_ASSERT(t->pMapFunctionIndexToMemberIndex != nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), t->nBaseTypes);
+ CPPUNIT_ASSERT(t->ppBaseTypes != nullptr);
+ CPPUNIT_ASSERT(css::uno::TypeDescription(&t->ppBaseTypes[0]->aBase).equals(t0));
+ // `basetypes` must still be valid:
+ CPPUNIT_ASSERT(
+ css::uno::TypeDescription(&basetypes[0]->aBase).equals(&t->ppBaseTypes[0]->aBase));
+ typelib_typedescription_release(td);
+ typelib_typedescriptionreference_release(ref);
+ }
+
+ void testMultiInterface()
+ {
+ auto const t1 = cppu::UnoType<css::io::XTextInputStream>::get();
+ auto const t2 = cppu::UnoType<css::io::XActiveDataSink>::get();
+ typelib_TypeDescriptionReference* ref = nullptr;
+ typelib_TypeDescriptionReference* bases[2] = { t1.getTypeLibType(), t2.getTypeLibType() };
+ typelib_static_mi_interface_type_init(&ref, "com.sun.star.io.XTextInputStream2", 2, bases);
+ CPPUNIT_ASSERT(ref != nullptr);
+ typelib_TypeDescription* td = ref->pType;
+ CPPUNIT_ASSERT(td != nullptr);
+ typelib_typedescription_acquire(td);
+ CPPUNIT_ASSERT(!td->bComplete);
+ auto t = reinterpret_cast<typelib_InterfaceTypeDescription*>(td);
+ CPPUNIT_ASSERT(css::uno::TypeDescription(&t->pBaseTypeDescription->aBase).equals(t1));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), t->nMembers);
+ CPPUNIT_ASSERT(t->ppMembers == nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), t->nAllMembers);
+ CPPUNIT_ASSERT(t->ppAllMembers == nullptr);
+ CPPUNIT_ASSERT(t->pMapMemberIndexToFunctionIndex == nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), t->nMapFunctionIndexToMemberIndex);
+ CPPUNIT_ASSERT(t->pMapFunctionIndexToMemberIndex == nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), t->nBaseTypes);
+ auto const basetypes = t->ppBaseTypes;
+ CPPUNIT_ASSERT(basetypes != nullptr);
+ CPPUNIT_ASSERT(css::uno::TypeDescription(&basetypes[0]->aBase).equals(t1));
+ CPPUNIT_ASSERT(css::uno::TypeDescription(&basetypes[1]->aBase).equals(t2));
+ CPPUNIT_ASSERT(typelib_typedescription_complete(&td));
+ CPPUNIT_ASSERT(td != nullptr);
+ CPPUNIT_ASSERT(td->bComplete);
+ t = reinterpret_cast<typelib_InterfaceTypeDescription*>(td);
+ CPPUNIT_ASSERT(css::uno::TypeDescription(&t->pBaseTypeDescription->aBase).equals(t1));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), t->nMembers);
+ CPPUNIT_ASSERT(t->ppMembers == nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(14), t->nAllMembers);
+ CPPUNIT_ASSERT(t->ppAllMembers != nullptr);
+ CPPUNIT_ASSERT(t->pMapMemberIndexToFunctionIndex != nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(14), t->nMapFunctionIndexToMemberIndex);
+ CPPUNIT_ASSERT(t->pMapFunctionIndexToMemberIndex != nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), t->nBaseTypes);
+ CPPUNIT_ASSERT(t->ppBaseTypes != nullptr);
+ CPPUNIT_ASSERT(css::uno::TypeDescription(&t->ppBaseTypes[0]->aBase).equals(t1));
+ CPPUNIT_ASSERT(css::uno::TypeDescription(&t->ppBaseTypes[1]->aBase).equals(t2));
+ // `basetypes` must still be valid:
+ CPPUNIT_ASSERT(
+ css::uno::TypeDescription(&basetypes[0]->aBase).equals(&t->ppBaseTypes[0]->aBase));
+ CPPUNIT_ASSERT(
+ css::uno::TypeDescription(&basetypes[1]->aBase).equals(&t->ppBaseTypes[1]->aBase));
+ typelib_typedescription_release(td);
+ typelib_typedescriptionreference_release(ref);
+ }
+
+ CPPUNIT_TEST_SUITE(Test);
+ CPPUNIT_TEST(testEnum);
+ CPPUNIT_TEST(testStruct);
+ CPPUNIT_TEST(testPolyStruct);
+ CPPUNIT_TEST(testInterface);
+ CPPUNIT_TEST(testMultiInterface);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/cppu/source/typelib/typelib.cxx b/cppu/source/typelib/typelib.cxx
index d1a503e4265b..e16c2eb90319 100644
--- a/cppu/source/typelib/typelib.cxx
+++ b/cppu/source/typelib/typelib.cxx
@@ -23,6 +23,7 @@
#include <cassert>
#include <list>
#include <set>
+#include <utility>
#include <vector>
#include <memory>
@@ -1486,23 +1487,100 @@ extern "C" void SAL_CALL typelib_typedescription_register(
if (pTDR->pType->pWeakRef) // if init
{
- typelib_typedescription_destructExtendedMembers( pTDR->pType );
+ switch (pTDR->pType->eTypeClass) {
+ case typelib_TypeClass_ENUM:
+ {
+ auto const src = reinterpret_cast<typelib_EnumTypeDescription *>(
+ *ppNewDescription);
+ auto const dst = reinterpret_cast<typelib_EnumTypeDescription *>(
+ pTDR->pType);
+ assert(dst->nEnumValues == 0);
+ assert(dst->ppEnumNames == nullptr);
+ assert(dst->pEnumValues == nullptr);
+ std::swap(src->nEnumValues, dst->nEnumValues);
+ std::swap(src->ppEnumNames, dst->ppEnumNames);
+ std::swap(src->pEnumValues, dst->pEnumValues);
+ break;
+ }
+ case typelib_TypeClass_STRUCT:
+ case typelib_TypeClass_EXCEPTION:
+ {
+ auto const src = reinterpret_cast<typelib_CompoundTypeDescription *>(
+ *ppNewDescription);
+ auto const dst = reinterpret_cast<typelib_CompoundTypeDescription *>(
+ pTDR->pType);
+ assert(
+ (dst->pBaseTypeDescription == nullptr)
+ == (src->pBaseTypeDescription == nullptr));
+ assert(dst->nMembers == src->nMembers);
+ assert((dst->pMemberOffsets == nullptr) == (dst->nMembers == 0));
+ assert((dst->ppTypeRefs == nullptr) == (dst->nMembers == 0));
+ assert(dst->ppMemberNames == nullptr);
+ assert(
+ pTDR->pType->eTypeClass != typelib_TypeClass_STRUCT
+ || ((reinterpret_cast<typelib_StructTypeDescription *>(
+ dst)->pParameterizedTypes
+ == nullptr)
+ == (reinterpret_cast<typelib_StructTypeDescription *>(
+ src)->pParameterizedTypes
+ == nullptr)));
+ std::swap(src->ppMemberNames, dst->ppMemberNames);
+ break;
+ }
+ case typelib_TypeClass_INTERFACE:
+ {
+ auto const src = reinterpret_cast<typelib_InterfaceTypeDescription *>(
+ *ppNewDescription);
+ auto const dst = reinterpret_cast<typelib_InterfaceTypeDescription *>(
+ pTDR->pType);
+ assert(
+ (dst->pBaseTypeDescription == nullptr)
+ == (src->pBaseTypeDescription == nullptr));
+ assert(dst->nMembers == 0);
+ assert(dst->ppMembers == nullptr);
+ assert(dst->nAllMembers == 0);
+ assert(dst->ppAllMembers == nullptr);
+ assert(dst->pMapMemberIndexToFunctionIndex == nullptr);
+ assert(dst->nMapFunctionIndexToMemberIndex == 0);
+ assert(dst->pMapFunctionIndexToMemberIndex == nullptr);
+ assert(dst->nBaseTypes == src->nBaseTypes);
+ assert((dst->ppBaseTypes == nullptr) == (src->ppBaseTypes == nullptr));
+ std::swap(src->nMembers, dst->nMembers);
+ std::swap(src->ppMembers, dst->ppMembers);
+ std::swap(src->nAllMembers, dst->nAllMembers);
+ std::swap(src->ppAllMembers, dst->ppAllMembers);
+ std::swap(
+ src->pMapMemberIndexToFunctionIndex,
+ dst->pMapMemberIndexToFunctionIndex);
+ std::swap(
+ src->nMapFunctionIndexToMemberIndex,
+ dst->nMapFunctionIndexToMemberIndex);
+ std::swap(
+ src->pMapFunctionIndexToMemberIndex,
+ dst->pMapFunctionIndexToMemberIndex);
+ break;
+ }
+ default:
+ assert(false); // this cannot happen
+ }
+ }
+ else
+ {
+ // pTDR->pType->pWeakRef == 0 means that the description is empty
+ // description is not weak and the not the same
+ sal_Int32 nSize = getDescriptionSize( (*ppNewDescription)->eTypeClass );
+
+ // copy all specific data for the descriptions
+ memcpy(
+ pTDR->pType +1,
+ *ppNewDescription +1,
+ nSize - sizeof(typelib_TypeDescription) );
+
+ memset(
+ *ppNewDescription +1,
+ 0,
+ nSize - sizeof( typelib_TypeDescription ) );
}
-
- // pTDR->pType->pWeakRef == 0 means that the description is empty
- // description is not weak and the not the same
- sal_Int32 nSize = getDescriptionSize( (*ppNewDescription)->eTypeClass );
-
- // copy all specific data for the descriptions
- memcpy(
- pTDR->pType +1,
- *ppNewDescription +1,
- nSize - sizeof(typelib_TypeDescription) );
-
- memset(
- *ppNewDescription +1,
- 0,
- nSize - sizeof( typelib_TypeDescription ) );
pTDR->pType->bComplete = (*ppNewDescription)->bComplete;
pTDR->pType->nSize = (*ppNewDescription)->nSize;