diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-06-16 14:13:33 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-07-05 17:40:20 +0200 |
commit | 9eed346b0b745f0598eefc572c789d58353b5e31 (patch) | |
tree | a3c3eaf7b0b924a5e9d63bf6e12667049ef927db /editeng | |
parent | 6209fcbdc694ca0ef22f157d3f5c5b74ed8c76c8 (diff) |
crash on exit of cppunit tests
rework EditEngineItemPools own their default items
and use a global weak_ptr to share them between instances
Change-Id: Ifda3619a175eba3fcad81918c71b16a4d6dd663a
Reviewed-on: https://gerrit.libreoffice.org/38885
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/editeng/editdoc.cxx | 5 | ||||
-rw-r--r-- | editeng/source/editeng/editdoc.hxx | 13 | ||||
-rw-r--r-- | editeng/source/editeng/eerdll.cxx | 166 | ||||
-rw-r--r-- | editeng/source/editeng/eerdll2.hxx | 18 |
4 files changed, 104 insertions, 98 deletions
diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx index cdd538a39f23..911073fa4eb6 100644 --- a/editeng/source/editeng/editdoc.cxx +++ b/editeng/source/editeng/editdoc.cxx @@ -3075,12 +3075,13 @@ EditEngineItemPool::EditEngineItemPool( bool bPersistenRefCounts ) SetVersionMap( 5, 3994, 4037, aV5Map ); SetVersionMap( 6, 3994, 4038, aV6Map ); - std::vector<SfxPoolItem*>* ppDefItems = EditDLL::Get().GetGlobalData()->GetDefItems(); - SetDefaults( ppDefItems ); + m_xDefItems = EditDLL::Get().GetGlobalData()->GetDefItems(); + SetDefaults(m_xDefItems->getDefaults()); } EditEngineItemPool::~EditEngineItemPool() { + ClearDefaults(); } SvStream& EditEngineItemPool::Store( SvStream& rStream ) const diff --git a/editeng/source/editeng/editdoc.hxx b/editeng/source/editeng/editdoc.hxx index 0984a6ffe9fa..5f490173a0e8 100644 --- a/editeng/source/editeng/editdoc.hxx +++ b/editeng/source/editeng/editdoc.hxx @@ -24,6 +24,7 @@ #include "editattr.hxx" #include "edtspell.hxx" +#include "eerdll2.hxx" #include <editeng/svxfont.hxx> #include <svl/itemset.hxx> #include <svl/style.hxx> @@ -832,18 +833,16 @@ inline EditCharAttrib* GetAttrib(CharAttribList::AttribsType& rAttribs, sal_Int3 void CheckOrderedList(const CharAttribList::AttribsType& rAttribs, bool bStart); - -// class EditEngineItemPool - class EditEngineItemPool : public SfxItemPool { +private: + std::shared_ptr<DefItems> m_xDefItems; public: - EditEngineItemPool( bool bPersistenRefCounts ); + EditEngineItemPool(bool bPersistenRefCounts); protected: - virtual ~EditEngineItemPool() override; + virtual ~EditEngineItemPool() override; public: - - virtual SvStream& Store( SvStream& rStream ) const override; + virtual SvStream& Store(SvStream& rStream) const override; }; #endif // INCLUDED_EDITENG_SOURCE_EDITENG_EDITDOC_HXX diff --git a/editeng/source/editeng/eerdll.cxx b/editeng/source/editeng/eerdll.cxx index 1cb7387c563f..8176096afafc 100644 --- a/editeng/source/editeng/eerdll.cxx +++ b/editeng/source/editeng/eerdll.cxx @@ -25,6 +25,7 @@ #include <vcl/settings.hxx> #include <com/sun/star/linguistic2/LanguageGuessing.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> + #include <comphelper/processfactory.hxx> #include <svl/solar.hrc> @@ -84,96 +85,95 @@ EditDLL& EditDLL::Get() return theEditDLL::get(); } -GlobalEditData::GlobalEditData() : - ppDefItems(nullptr) -{ } +DefItems::DefItems() +{ + ppDefItems = new std::vector<SfxPoolItem*>(EDITITEMCOUNT); + std::vector<SfxPoolItem*>& rDefItems = *ppDefItems; + + // Paragraph attributes: + SvxNumRule aDefaultNumRule( SvxNumRuleFlags::NONE, 0, false ); + + rDefItems[0] = new SvxFrameDirectionItem( SvxFrameDirection::Horizontal_LR_TB, EE_PARA_WRITINGDIR ); + rDefItems[1] = new SvXMLAttrContainerItem( EE_PARA_XMLATTRIBS ); + rDefItems[2] = new SvxHangingPunctuationItem(false, EE_PARA_HANGINGPUNCTUATION); + rDefItems[3] = new SvxForbiddenRuleItem(true, EE_PARA_FORBIDDENRULES); + rDefItems[4] = new SvxScriptSpaceItem( true, EE_PARA_ASIANCJKSPACING ); + rDefItems[5] = new SvxNumBulletItem( aDefaultNumRule, EE_PARA_NUMBULLET ); + rDefItems[6] = new SfxBoolItem( EE_PARA_HYPHENATE, false ); + rDefItems[7] = new SfxBoolItem( EE_PARA_BULLETSTATE, true ); + rDefItems[8] = new SvxLRSpaceItem( EE_PARA_OUTLLRSPACE ); + rDefItems[9] = new SfxInt16Item( EE_PARA_OUTLLEVEL, -1 ); + rDefItems[10] = new SvxBulletItem( EE_PARA_BULLET ); + rDefItems[11] = new SvxLRSpaceItem( EE_PARA_LRSPACE ); + rDefItems[12] = new SvxULSpaceItem( EE_PARA_ULSPACE ); + rDefItems[13] = new SvxLineSpacingItem( 0, EE_PARA_SBL ); + rDefItems[14] = new SvxAdjustItem( SvxAdjust::Left, EE_PARA_JUST ); + rDefItems[15] = new SvxTabStopItem( 0, 0, SvxTabAdjust::Left, EE_PARA_TABS ); + rDefItems[16] = new SvxJustifyMethodItem( SvxCellJustifyMethod::Auto, EE_PARA_JUST_METHOD ); + rDefItems[17] = new SvxVerJustifyItem( SVX_VER_JUSTIFY_STANDARD, EE_PARA_VER_JUST ); + + // Character attributes: + rDefItems[18] = new SvxColorItem( Color( COL_AUTO ), EE_CHAR_COLOR ); + rDefItems[19] = new SvxFontItem( EE_CHAR_FONTINFO ); + rDefItems[20] = new SvxFontHeightItem( 240, 100, EE_CHAR_FONTHEIGHT ); + rDefItems[21] = new SvxCharScaleWidthItem( 100, EE_CHAR_FONTWIDTH ); + rDefItems[22] = new SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT ); + rDefItems[23] = new SvxUnderlineItem( LINESTYLE_NONE, EE_CHAR_UNDERLINE ); + rDefItems[24] = new SvxCrossedOutItem( STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ); + rDefItems[25] = new SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC ); + rDefItems[26] = new SvxContourItem( false, EE_CHAR_OUTLINE ); + rDefItems[27] = new SvxShadowedItem( false, EE_CHAR_SHADOW ); + rDefItems[28] = new SvxEscapementItem( 0, 100, EE_CHAR_ESCAPEMENT ); + rDefItems[29] = new SvxAutoKernItem( false, EE_CHAR_PAIRKERNING ); + rDefItems[30] = new SvxKerningItem( 0, EE_CHAR_KERNING ); + rDefItems[31] = new SvxWordLineModeItem( false, EE_CHAR_WLM ); + rDefItems[32] = new SvxLanguageItem( LANGUAGE_DONTKNOW, EE_CHAR_LANGUAGE ); + rDefItems[33] = new SvxLanguageItem( LANGUAGE_DONTKNOW, EE_CHAR_LANGUAGE_CJK ); + rDefItems[34] = new SvxLanguageItem( LANGUAGE_DONTKNOW, EE_CHAR_LANGUAGE_CTL ); + rDefItems[35] = new SvxFontItem( EE_CHAR_FONTINFO_CJK ); + rDefItems[36] = new SvxFontItem( EE_CHAR_FONTINFO_CTL ); + rDefItems[37] = new SvxFontHeightItem( 240, 100, EE_CHAR_FONTHEIGHT_CJK ); + rDefItems[38] = new SvxFontHeightItem( 240, 100, EE_CHAR_FONTHEIGHT_CTL ); + rDefItems[39] = new SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK ); + rDefItems[40] = new SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL ); + rDefItems[41] = new SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CJK ); + rDefItems[42] = new SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CTL ); + rDefItems[43] = new SvxEmphasisMarkItem( FontEmphasisMark::NONE, EE_CHAR_EMPHASISMARK ); + rDefItems[44] = new SvxCharReliefItem( FontRelief::NONE, EE_CHAR_RELIEF ); + rDefItems[45] = new SfxVoidItem( EE_CHAR_RUBI_DUMMY ); + rDefItems[46] = new SvXMLAttrContainerItem( EE_CHAR_XMLATTRIBS ); + rDefItems[47] = new SvxOverlineItem( LINESTYLE_NONE, EE_CHAR_OVERLINE ); + rDefItems[48] = new SvxCaseMapItem( SvxCaseMap::NotMapped, EE_CHAR_CASEMAP ); + rDefItems[49] = new SfxGrabBagItem( EE_CHAR_GRABBAG ); + rDefItems[50] = new SvxBackgroundColorItem( Color( COL_AUTO ), EE_CHAR_BKGCOLOR ); + // Features + rDefItems[51] = new SfxVoidItem( EE_FEATURE_TAB ); + rDefItems[52] = new SfxVoidItem( EE_FEATURE_LINEBR ); + rDefItems[53] = new SvxCharSetColorItem( Color( COL_RED ), RTL_TEXTENCODING_DONTKNOW, EE_FEATURE_NOTCONV ); + rDefItems[54] = new SvxFieldItem( SvxFieldData(), EE_FEATURE_FIELD ); + + assert(EDITITEMCOUNT == 55 && "ITEMCOUNT changed, adjust DefItems!"); + + // Init DefFonts: + GetDefaultFonts( *static_cast<SvxFontItem*>(rDefItems[EE_CHAR_FONTINFO - EE_ITEMS_START]), + *static_cast<SvxFontItem*>(rDefItems[EE_CHAR_FONTINFO_CJK - EE_ITEMS_START]), + *static_cast<SvxFontItem*>(rDefItems[EE_CHAR_FONTINFO_CTL - EE_ITEMS_START]) ); +} -GlobalEditData::~GlobalEditData() +DefItems::~DefItems() { - // Destroy DefItems... - // Or simply keep them, since at end of execution?! - if ( ppDefItems ) - SfxItemPool::ReleaseDefaults( ppDefItems, true ); + SfxItemPool::ReleaseDefaults(ppDefItems, true); } -std::vector<SfxPoolItem*>* GlobalEditData::GetDefItems() +std::shared_ptr<DefItems> GlobalEditData::GetDefItems() { - if ( !ppDefItems ) + auto xDefItems = m_xDefItems.lock(); + if (!xDefItems) { - ppDefItems = new std::vector<SfxPoolItem*>(EDITITEMCOUNT); - std::vector<SfxPoolItem*>& rDefItems = *ppDefItems; - - // Paragraph attributes: - SvxNumRule aDefaultNumRule( SvxNumRuleFlags::NONE, 0, false ); - - rDefItems[0] = new SvxFrameDirectionItem( SvxFrameDirection::Horizontal_LR_TB, EE_PARA_WRITINGDIR ); - rDefItems[1] = new SvXMLAttrContainerItem( EE_PARA_XMLATTRIBS ); - rDefItems[2] = new SvxHangingPunctuationItem(false, EE_PARA_HANGINGPUNCTUATION); - rDefItems[3] = new SvxForbiddenRuleItem(true, EE_PARA_FORBIDDENRULES); - rDefItems[4] = new SvxScriptSpaceItem( true, EE_PARA_ASIANCJKSPACING ); - rDefItems[5] = new SvxNumBulletItem( aDefaultNumRule, EE_PARA_NUMBULLET ); - rDefItems[6] = new SfxBoolItem( EE_PARA_HYPHENATE, false ); - rDefItems[7] = new SfxBoolItem( EE_PARA_BULLETSTATE, true ); - rDefItems[8] = new SvxLRSpaceItem( EE_PARA_OUTLLRSPACE ); - rDefItems[9] = new SfxInt16Item( EE_PARA_OUTLLEVEL, -1 ); - rDefItems[10] = new SvxBulletItem( EE_PARA_BULLET ); - rDefItems[11] = new SvxLRSpaceItem( EE_PARA_LRSPACE ); - rDefItems[12] = new SvxULSpaceItem( EE_PARA_ULSPACE ); - rDefItems[13] = new SvxLineSpacingItem( 0, EE_PARA_SBL ); - rDefItems[14] = new SvxAdjustItem( SvxAdjust::Left, EE_PARA_JUST ); - rDefItems[15] = new SvxTabStopItem( 0, 0, SvxTabAdjust::Left, EE_PARA_TABS ); - rDefItems[16] = new SvxJustifyMethodItem( SvxCellJustifyMethod::Auto, EE_PARA_JUST_METHOD ); - rDefItems[17] = new SvxVerJustifyItem( SVX_VER_JUSTIFY_STANDARD, EE_PARA_VER_JUST ); - - // Character attributes: - rDefItems[18] = new SvxColorItem( Color( COL_AUTO ), EE_CHAR_COLOR ); - rDefItems[19] = new SvxFontItem( EE_CHAR_FONTINFO ); - rDefItems[20] = new SvxFontHeightItem( 240, 100, EE_CHAR_FONTHEIGHT ); - rDefItems[21] = new SvxCharScaleWidthItem( 100, EE_CHAR_FONTWIDTH ); - rDefItems[22] = new SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT ); - rDefItems[23] = new SvxUnderlineItem( LINESTYLE_NONE, EE_CHAR_UNDERLINE ); - rDefItems[24] = new SvxCrossedOutItem( STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ); - rDefItems[25] = new SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC ); - rDefItems[26] = new SvxContourItem( false, EE_CHAR_OUTLINE ); - rDefItems[27] = new SvxShadowedItem( false, EE_CHAR_SHADOW ); - rDefItems[28] = new SvxEscapementItem( 0, 100, EE_CHAR_ESCAPEMENT ); - rDefItems[29] = new SvxAutoKernItem( false, EE_CHAR_PAIRKERNING ); - rDefItems[30] = new SvxKerningItem( 0, EE_CHAR_KERNING ); - rDefItems[31] = new SvxWordLineModeItem( false, EE_CHAR_WLM ); - rDefItems[32] = new SvxLanguageItem( LANGUAGE_DONTKNOW, EE_CHAR_LANGUAGE ); - rDefItems[33] = new SvxLanguageItem( LANGUAGE_DONTKNOW, EE_CHAR_LANGUAGE_CJK ); - rDefItems[34] = new SvxLanguageItem( LANGUAGE_DONTKNOW, EE_CHAR_LANGUAGE_CTL ); - rDefItems[35] = new SvxFontItem( EE_CHAR_FONTINFO_CJK ); - rDefItems[36] = new SvxFontItem( EE_CHAR_FONTINFO_CTL ); - rDefItems[37] = new SvxFontHeightItem( 240, 100, EE_CHAR_FONTHEIGHT_CJK ); - rDefItems[38] = new SvxFontHeightItem( 240, 100, EE_CHAR_FONTHEIGHT_CTL ); - rDefItems[39] = new SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK ); - rDefItems[40] = new SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL ); - rDefItems[41] = new SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CJK ); - rDefItems[42] = new SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CTL ); - rDefItems[43] = new SvxEmphasisMarkItem( FontEmphasisMark::NONE, EE_CHAR_EMPHASISMARK ); - rDefItems[44] = new SvxCharReliefItem( FontRelief::NONE, EE_CHAR_RELIEF ); - rDefItems[45] = new SfxVoidItem( EE_CHAR_RUBI_DUMMY ); - rDefItems[46] = new SvXMLAttrContainerItem( EE_CHAR_XMLATTRIBS ); - rDefItems[47] = new SvxOverlineItem( LINESTYLE_NONE, EE_CHAR_OVERLINE ); - rDefItems[48] = new SvxCaseMapItem( SvxCaseMap::NotMapped, EE_CHAR_CASEMAP ); - rDefItems[49] = new SfxGrabBagItem( EE_CHAR_GRABBAG ); - rDefItems[50] = new SvxBackgroundColorItem( Color( COL_AUTO ), EE_CHAR_BKGCOLOR ); - // Features - rDefItems[51] = new SfxVoidItem( EE_FEATURE_TAB ); - rDefItems[52] = new SfxVoidItem( EE_FEATURE_LINEBR ); - rDefItems[53] = new SvxCharSetColorItem( Color( COL_RED ), RTL_TEXTENCODING_DONTKNOW, EE_FEATURE_NOTCONV ); - rDefItems[54] = new SvxFieldItem( SvxFieldData(), EE_FEATURE_FIELD ); - - assert(EDITITEMCOUNT == 55 && "ITEMCOUNT changed, adjust DefItems!"); - - // Init DefFonts: - GetDefaultFonts( *static_cast<SvxFontItem*>(rDefItems[EE_CHAR_FONTINFO - EE_ITEMS_START]), - *static_cast<SvxFontItem*>(rDefItems[EE_CHAR_FONTINFO_CJK - EE_ITEMS_START]), - *static_cast<SvxFontItem*>(rDefItems[EE_CHAR_FONTINFO_CTL - EE_ITEMS_START]) ); + xDefItems.reset(new DefItems); + m_xDefItems = xDefItems; } - - return ppDefItems; + return xDefItems; } rtl::Reference<SvxForbiddenCharactersTable> const & GlobalEditData::GetForbiddenCharsTable() diff --git a/editeng/source/editeng/eerdll2.hxx b/editeng/source/editeng/eerdll2.hxx index 75bfb2131ae7..6ef3c20d1d92 100644 --- a/editeng/source/editeng/eerdll2.hxx +++ b/editeng/source/editeng/eerdll2.hxx @@ -40,19 +40,25 @@ namespace editeng }; } +class DefItems +{ +public: + DefItems(); + std::vector<SfxPoolItem*>* getDefaults() { return ppDefItems; } + ~DefItems(); +private: + std::vector<SfxPoolItem*>* ppDefItems; +}; + class GlobalEditData { private: css::uno::Reference< css::linguistic2::XLanguageGuessing > xLanguageGuesser; - std::vector<SfxPoolItem*>* ppDefItems; - + std::weak_ptr<DefItems> m_xDefItems; rtl::Reference<SvxForbiddenCharactersTable> xForbiddenCharsTable; public: - GlobalEditData(); - ~GlobalEditData(); - - std::vector<SfxPoolItem*>* GetDefItems(); + std::shared_ptr<DefItems> GetDefItems(); rtl::Reference<SvxForbiddenCharactersTable> const & GetForbiddenCharsTable(); void SetForbiddenCharsTable( rtl::Reference<SvxForbiddenCharactersTable> const & xForbiddenChars ) { xForbiddenCharsTable = xForbiddenChars; } |