diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-06-27 19:24:28 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-06-28 09:17:52 +0200 |
commit | cb3c65fb706cb1c7c9224222fd16875e924a9759 (patch) | |
tree | 79df89cd45f5e2c58e62a644412bec27b8b0048d | |
parent | 5b33bc443859d376efd578f070e3d3d81c93fd24 (diff) |
assert when SfxObjectItems are modified while in a pool
which has always been a problem, but becomes a more obvious problem when
I implement some upcoming optimisations
Change-Id: I8b0368b0b8e9a726c71d241841afeed3876281d9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169657
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
-rw-r--r-- | editeng/source/items/textitem.cxx | 4 | ||||
-rw-r--r-- | include/svl/cintitem.hxx | 8 | ||||
-rw-r--r-- | include/svl/custritm.hxx | 2 | ||||
-rw-r--r-- | include/svl/eitem.hxx | 4 | ||||
-rw-r--r-- | include/svl/flagitem.hxx | 2 | ||||
-rw-r--r-- | include/svl/intitem.hxx | 2 | ||||
-rw-r--r-- | include/svl/poolitem.hxx | 7 | ||||
-rw-r--r-- | include/svl/ptitem.hxx | 2 |
8 files changed, 14 insertions, 17 deletions
diff --git a/editeng/source/items/textitem.cxx b/editeng/source/items/textitem.cxx index 2bdfdd6890d9..34ca99d8fcd6 100644 --- a/editeng/source/items/textitem.cxx +++ b/editeng/source/items/textitem.cxx @@ -997,7 +997,7 @@ bool SvxFontHeightItem::HasMetrics() const void SvxFontHeightItem::SetHeight( sal_uInt32 nNewHeight, const sal_uInt16 nNewProp, MapUnit eUnit ) { - DBG_ASSERT( GetRefCount() == 0, "SetValue() with pooled item" ); + assert( !isPooled() && "SetHeight() with pooled item" ); ASSERT_CHANGE_REFCOUNTED_ITEM; if( MapUnit::MapRelative != eUnit ) @@ -1015,7 +1015,7 @@ void SvxFontHeightItem::SetHeight( sal_uInt32 nNewHeight, const sal_uInt16 nNewP void SvxFontHeightItem::SetHeight( sal_uInt32 nNewHeight, sal_uInt16 nNewProp, MapUnit eMetric, MapUnit eCoreMetric ) { - DBG_ASSERT( GetRefCount() == 0, "SetValue() with pooled item" ); + assert( !isPooled() && "SetValue() with pooled item" ); ASSERT_CHANGE_REFCOUNTED_ITEM; if( MapUnit::MapRelative != eMetric ) diff --git a/include/svl/cintitem.hxx b/include/svl/cintitem.hxx index 0b3da790d1ed..eef40f333240 100644 --- a/include/svl/cintitem.hxx +++ b/include/svl/cintitem.hxx @@ -56,7 +56,7 @@ public: inline void CntByteItem::SetValue(sal_uInt8 nTheValue) { - DBG_ASSERT(GetRefCount() == 0, "CntByteItem::SetValue(): Pooled item"); + assert( !isPooled() && "SetValue() with pooled item" ); m_nValue = nTheValue; } @@ -93,7 +93,7 @@ public: inline void CntUInt16Item::SetValue(sal_uInt16 nTheValue) { - DBG_ASSERT(GetRefCount() == 0, "CntUInt16Item::SetValue(): Pooled item"); + assert( !isPooled() && "SetValue() with pooled item" ); m_nValue = nTheValue; } @@ -130,7 +130,7 @@ public: inline void CntInt32Item::SetValue(sal_Int32 nTheValue) { - DBG_ASSERT(GetRefCount() == 0, "CntInt32Item::SetValue(): Pooled item"); + assert( !isPooled() && "SetValue() with pooled item" ); m_nValue = nTheValue; } @@ -167,7 +167,7 @@ public: inline void CntUInt32Item::SetValue(sal_uInt32 nTheValue) { - DBG_ASSERT(GetRefCount() == 0, "CntUInt32Item::SetValue(): Pooled item"); + assert( !isPooled() && "SetValue() with pooled item" ); m_nValue = nTheValue; } diff --git a/include/svl/custritm.hxx b/include/svl/custritm.hxx index 0251df2ca182..3e2d23eb8ee4 100644 --- a/include/svl/custritm.hxx +++ b/include/svl/custritm.hxx @@ -60,7 +60,7 @@ public: inline void CntUnencodedStringItem::SetValue(const OUString & rTheValue) { - assert(GetRefCount() == 0 && "cannot modify name of pooled item"); + assert( !isPooled() && "SetValue() with pooled item" ); m_aValue = rTheValue; } diff --git a/include/svl/eitem.hxx b/include/svl/eitem.hxx index 8e95bed00881..a75a329ba146 100644 --- a/include/svl/eitem.hxx +++ b/include/svl/eitem.hxx @@ -22,7 +22,7 @@ #include <svl/svldllapi.h> #include <svl/cenumitm.hxx> - +#include <cassert> template<typename EnumT> class SAL_DLLPUBLIC_RTTI SfxEnumItem : public SfxEnumItemInterface @@ -43,7 +43,7 @@ public: void SetValue(EnumT nTheValue) { - assert(GetRefCount() == 0 && "SfxEnumItem::SetValue(): Pooled item"); + assert( !isPooled() && "SetValue() with pooled item" ); m_nValue = nTheValue; } diff --git a/include/svl/flagitem.hxx b/include/svl/flagitem.hxx index 76226cb1aa80..221416986593 100644 --- a/include/svl/flagitem.hxx +++ b/include/svl/flagitem.hxx @@ -46,7 +46,7 @@ public: const IntlWrapper& ) const override; sal_uInt16 GetValue() const { return nVal; } void SetValue( sal_uInt16 nNewVal ) { - DBG_ASSERT( GetRefCount() == 0, "SetValue() with pooled item" ); + assert( !isPooled() && "SetValue() with pooled item" ); nVal = nNewVal; } bool GetFlag( sal_uInt8 nFlag ) const { return (nVal & ( 1<<nFlag)); } diff --git a/include/svl/intitem.hxx b/include/svl/intitem.hxx index f189388e748e..77cb540335a7 100644 --- a/include/svl/intitem.hxx +++ b/include/svl/intitem.hxx @@ -75,7 +75,7 @@ public: inline void SfxInt16Item::SetValue(sal_Int16 nTheValue) { - DBG_ASSERT(GetRefCount() == 0, "SfxInt16Item::SetValue(); Pooled item"); + assert( !isPooled() && "SetValue() with pooled item" ); m_nValue = nTheValue; } diff --git a/include/svl/poolitem.hxx b/include/svl/poolitem.hxx index 1cb667b5c90c..b1fc8280736c 100644 --- a/include/svl/poolitem.hxx +++ b/include/svl/poolitem.hxx @@ -503,6 +503,8 @@ public: bool isDynamicDefault() const { return m_bDynamicDefault; } bool isSetItem() const { return m_bIsSetItem; } bool isShareable() const { return m_bShareable; } + bool isPooled() const { return GetRefCount() > 0; } + // version that allows nullptrs static bool areSame(const SfxPoolItem* pItem1, const SfxPoolItem* pItem2); @@ -707,11 +709,6 @@ inline bool IsDefaultItem( const SfxPoolItem *pItem ) return pItem && (pItem->isStaticDefault() || pItem->isDynamicDefault()); } -inline bool IsPooledItem( const SfxPoolItem *pItem ) -{ - return pItem && pItem->GetRefCount() > 0; -} - SVL_DLLPUBLIC extern SfxPoolItem const * const INVALID_POOL_ITEM; SVL_DLLPUBLIC extern SfxPoolItem const * const DISABLED_POOL_ITEM; diff --git a/include/svl/ptitem.hxx b/include/svl/ptitem.hxx index 2ceb39410695..bb41ea916f45 100644 --- a/include/svl/ptitem.hxx +++ b/include/svl/ptitem.hxx @@ -47,7 +47,7 @@ public: const Point& GetValue() const { return aVal; } void SetValue( const Point& rNewVal ) { - DBG_ASSERT( GetRefCount() == 0, "SetValue() with pooled item" ); + assert( !isPooled() && "SetValue() with pooled item" ); aVal = rNewVal; } |