From 0323253a7c67316cb96e4a64792ab4fe74aac1ca Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 1 Jun 2016 16:22:29 +0200 Subject: remove some manual ref-counting triggered when I noticed a class doing acquire() in the constructor and then release() in the destructor. found mostly by git grep -n -B5 -e '->release()' Change-Id: I96e43a3d30ffd9ae9a34275f24cd914d8f7b026f Reviewed-on: https://gerrit.libreoffice.org/25806 Tested-by: Jenkins Reviewed-by: Noel Grandin --- xmlscript/source/xmlflat_imexp/xmlbas_import.cxx | 44 +++++++++----------- xmlscript/source/xmlflat_imexp/xmlbas_import.hxx | 5 ++- xmlscript/source/xmllib_imexp/imp_share.hxx | 5 ++- xmlscript/source/xmllib_imexp/xmllib_import.cxx | 51 +++++++++--------------- xmlscript/source/xmlmod_imexp/imp_share.hxx | 5 ++- xmlscript/source/xmlmod_imexp/xmlmod_import.cxx | 23 +++-------- 6 files changed, 51 insertions(+), 82 deletions(-) (limited to 'xmlscript') diff --git a/xmlscript/source/xmlflat_imexp/xmlbas_import.cxx b/xmlscript/source/xmlflat_imexp/xmlbas_import.cxx index 736afd5a6829..7ef444abaeae 100644 --- a/xmlscript/source/xmlflat_imexp/xmlbas_import.cxx +++ b/xmlscript/source/xmlflat_imexp/xmlbas_import.cxx @@ -43,23 +43,15 @@ namespace xmlscript BasicElementBase::BasicElementBase( const OUString& rLocalName, const Reference< xml::input::XAttributes >& xAttributes, BasicElementBase* pParent, BasicImport* pImport ) - :m_pImport( pImport ) - ,m_pParent( pParent ) + :m_xImport( pImport ) + ,m_xParent( pParent ) ,m_aLocalName( rLocalName ) ,m_xAttributes( xAttributes ) { - if ( m_pImport ) - m_pImport->acquire(); - if ( m_pParent ) - m_pParent->acquire(); } BasicElementBase::~BasicElementBase() { - if ( m_pImport ) - m_pImport->release(); - if ( m_pParent ) - m_pParent->release(); } bool BasicElementBase::getBoolAttr( bool* pRet, const OUString& rAttrName, @@ -95,7 +87,7 @@ namespace xmlscript Reference< xml::input::XElement > BasicElementBase::getParent() throw (RuntimeException, std::exception) { - return static_cast< xml::input::XElement* >( m_pParent ); + return m_xParent.get(); } OUString BasicElementBase::getLocalName() @@ -108,8 +100,8 @@ namespace xmlscript throw (RuntimeException, std::exception) { sal_Int32 nId = -1; - if ( m_pImport ) - nId = m_pImport->XMLNS_UID; + if ( m_xImport.is() ) + nId = m_xImport->XMLNS_UID; return nId; } @@ -168,7 +160,7 @@ void BasicElementBase::processingInstruction( const OUString& /*rTarget*/, const { Reference< xml::input::XElement > xElement; - if ( nUid != m_pImport->XMLNS_UID ) + if ( nUid != m_xImport->XMLNS_UID ) { throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() ); } @@ -176,12 +168,12 @@ void BasicElementBase::processingInstruction( const OUString& /*rTarget*/, const { if ( xAttributes.is() ) { - OUString aName = xAttributes->getValueByUidName( m_pImport->XMLNS_UID, "name" ); + OUString aName = xAttributes->getValueByUidName( m_xImport->XMLNS_UID, "name" ); - OUString aStorageURL = xAttributes->getValueByUidName(m_pImport->XMLNS_XLINK_UID, "href" ); + OUString aStorageURL = xAttributes->getValueByUidName(m_xImport->XMLNS_XLINK_UID, "href" ); bool bReadOnly = false; - getBoolAttr( &bReadOnly,"readonly", xAttributes, m_pImport->XMLNS_UID ); + getBoolAttr( &bReadOnly,"readonly", xAttributes, m_xImport->XMLNS_UID ); if ( m_xLibContainer.is() ) { @@ -190,7 +182,7 @@ void BasicElementBase::processingInstruction( const OUString& /*rTarget*/, const Reference< container::XNameAccess > xLib( m_xLibContainer->createLibraryLink( aName, aStorageURL, bReadOnly ) ); if ( xLib.is() ) - xElement.set( new BasicElementBase( rLocalName, xAttributes, this, m_pImport ) ); + xElement.set( new BasicElementBase( rLocalName, xAttributes, this, m_xImport.get() ) ); } catch ( const container::ElementExistException& e ) { @@ -209,10 +201,10 @@ void BasicElementBase::processingInstruction( const OUString& /*rTarget*/, const if ( xAttributes.is() ) { - OUString aName = xAttributes->getValueByUidName( m_pImport->XMLNS_UID, "name" ); + OUString aName = xAttributes->getValueByUidName( m_xImport->XMLNS_UID, "name" ); bool bReadOnly = false; - getBoolAttr( &bReadOnly, "readonly", xAttributes, m_pImport->XMLNS_UID ); + getBoolAttr( &bReadOnly, "readonly", xAttributes, m_xImport->XMLNS_UID ); if ( m_xLibContainer.is() ) { @@ -230,7 +222,7 @@ void BasicElementBase::processingInstruction( const OUString& /*rTarget*/, const } if ( xLib.is() ) - xElement.set( new BasicEmbeddedLibraryElement( rLocalName, xAttributes, this, m_pImport, m_xLibContainer, aName, bReadOnly ) ); + xElement.set( new BasicEmbeddedLibraryElement( rLocalName, xAttributes, this, m_xImport.get(), m_xLibContainer, aName, bReadOnly ) ); } catch ( const lang::IllegalArgumentException& e ) { @@ -284,7 +276,7 @@ void BasicElementBase::processingInstruction( const OUString& /*rTarget*/, const { Reference< xml::input::XElement > xElement; - if ( nUid != m_pImport->XMLNS_UID ) + if ( nUid != m_xImport->XMLNS_UID ) { throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() ); } @@ -292,10 +284,10 @@ void BasicElementBase::processingInstruction( const OUString& /*rTarget*/, const { if ( xAttributes.is() ) { - OUString aName = xAttributes->getValueByUidName(m_pImport->XMLNS_UID, "name" ); + OUString aName = xAttributes->getValueByUidName(m_xImport->XMLNS_UID, "name" ); if ( m_xLib.is() && !aName.isEmpty() ) - xElement.set( new BasicModuleElement( rLocalName, xAttributes, this, m_pImport, m_xLib, aName ) ); + xElement.set( new BasicModuleElement( rLocalName, xAttributes, this, m_xImport.get(), m_xLib, aName ) ); } } else @@ -336,7 +328,7 @@ void BasicElementBase::processingInstruction( const OUString& /*rTarget*/, const Reference< xml::input::XElement > xElement; - if ( nUid != m_pImport->XMLNS_UID ) + if ( nUid != m_xImport->XMLNS_UID ) { throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() ); } @@ -347,7 +339,7 @@ void BasicElementBase::processingInstruction( const OUString& /*rTarget*/, const if ( xAttributes.is() ) { if ( m_xLib.is() && !m_aName.isEmpty() ) - xElement.set( new BasicSourceCodeElement( rLocalName, xAttributes, this, m_pImport, m_xLib, m_aName ) ); + xElement.set( new BasicSourceCodeElement( rLocalName, xAttributes, this, m_xImport.get(), m_xLib, m_aName ) ); } } else diff --git a/xmlscript/source/xmlflat_imexp/xmlbas_import.hxx b/xmlscript/source/xmlflat_imexp/xmlbas_import.hxx index 0eecb0dd1cd3..41219d7fb4c0 100644 --- a/xmlscript/source/xmlflat_imexp/xmlbas_import.hxx +++ b/xmlscript/source/xmlflat_imexp/xmlbas_import.hxx @@ -29,6 +29,7 @@ #include #include #include +#include namespace xmlscript { @@ -43,8 +44,8 @@ namespace xmlscript class BasicElementBase : public BasicElementBase_BASE { protected: - BasicImport* m_pImport; - BasicElementBase* m_pParent; + rtl::Reference m_xImport; + rtl::Reference m_xParent; OUString m_aLocalName; css::uno::Reference< css::xml::input::XAttributes > m_xAttributes; diff --git a/xmlscript/source/xmllib_imexp/imp_share.hxx b/xmlscript/source/xmllib_imexp/imp_share.hxx index a28fb2f7cd33..bf69df696386 100644 --- a/xmlscript/source/xmllib_imexp/imp_share.hxx +++ b/xmlscript/source/xmllib_imexp/imp_share.hxx @@ -32,6 +32,7 @@ #include #include +#include #include @@ -155,8 +156,8 @@ class LibElementBase : public ::cppu::WeakImplHelper< css::xml::input::XElement > { protected: - LibraryImport * _pImport; - LibElementBase * _pParent; + rtl::Reference mxImport; + rtl::Reference mxParent; OUString _aLocalName; css::uno::Reference< css::xml::input::XAttributes > _xAttributes; diff --git a/xmlscript/source/xmllib_imexp/xmllib_import.cxx b/xmlscript/source/xmllib_imexp/xmllib_import.cxx index 891919228d08..c81edf6f36c0 100644 --- a/xmlscript/source/xmllib_imexp/xmllib_import.cxx +++ b/xmlscript/source/xmllib_imexp/xmllib_import.cxx @@ -33,7 +33,7 @@ namespace xmlscript Reference< xml::input::XElement > LibElementBase::getParent() throw (RuntimeException, std::exception) { - return static_cast< xml::input::XElement * >( _pParent ); + return mxParent.get(); } OUString LibElementBase::getLocalName() @@ -45,7 +45,7 @@ OUString LibElementBase::getLocalName() sal_Int32 LibElementBase::getUid() throw (RuntimeException, std::exception) { - return _pImport->XMLNS_LIBRARY_UID; + return mxImport->XMLNS_LIBRARY_UID; } Reference< xml::input::XAttributes > LibElementBase::getAttributes() @@ -88,28 +88,15 @@ LibElementBase::LibElementBase( OUString const & rLocalName, Reference< xml::input::XAttributes > const & xAttributes, LibElementBase * pParent, LibraryImport * pImport ) - : _pImport( pImport ) - , _pParent( pParent ) + : mxImport( pImport ) + , mxParent( pParent ) , _aLocalName( rLocalName ) , _xAttributes( xAttributes ) { - _pImport->acquire(); - - if (_pParent) - { - _pParent->acquire(); - } } LibElementBase::~LibElementBase() { - _pImport->release(); - - if (_pParent) - { - _pParent->release(); - } - SAL_INFO("xmlscript.xmllib", "LibElementBase::~LibElementBase(): " << _aLocalName ); } @@ -182,7 +169,7 @@ Reference< xml::input::XElement > LibrariesElement::startChildElement( Reference< xml::input::XAttributes > const & xAttributes ) throw (xml::sax::SAXException, RuntimeException, std::exception) { - if (_pImport->XMLNS_LIBRARY_UID != nUid) + if (mxImport->XMLNS_LIBRARY_UID != nUid) { throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() ); } @@ -192,14 +179,14 @@ Reference< xml::input::XElement > LibrariesElement::startChildElement( LibDescriptor aDesc; aDesc.bLink = aDesc.bReadOnly = aDesc.bPasswordProtected = aDesc.bPreload = false; - aDesc.aName = xAttributes->getValueByUidName(_pImport->XMLNS_LIBRARY_UID, "name" ); - aDesc.aStorageURL = xAttributes->getValueByUidName( _pImport->XMLNS_XLINK_UID, "href" ); - getBoolAttr(&aDesc.bLink, "link", xAttributes, _pImport->XMLNS_LIBRARY_UID ); - getBoolAttr(&aDesc.bReadOnly, "readonly", xAttributes, _pImport->XMLNS_LIBRARY_UID ); - getBoolAttr(&aDesc.bPasswordProtected, "passwordprotected", xAttributes, _pImport->XMLNS_LIBRARY_UID ); + aDesc.aName = xAttributes->getValueByUidName(mxImport->XMLNS_LIBRARY_UID, "name" ); + aDesc.aStorageURL = xAttributes->getValueByUidName( mxImport->XMLNS_XLINK_UID, "href" ); + getBoolAttr(&aDesc.bLink, "link", xAttributes, mxImport->XMLNS_LIBRARY_UID ); + getBoolAttr(&aDesc.bReadOnly, "readonly", xAttributes, mxImport->XMLNS_LIBRARY_UID ); + getBoolAttr(&aDesc.bPasswordProtected, "passwordprotected", xAttributes, mxImport->XMLNS_LIBRARY_UID ); mLibDescriptors.push_back( aDesc ); - return new LibraryElement( rLocalName, xAttributes, this, _pImport ); + return new LibraryElement( rLocalName, xAttributes, this, mxImport.get() ); } else { @@ -210,13 +197,13 @@ Reference< xml::input::XElement > LibrariesElement::startChildElement( void LibrariesElement::endElement() throw (xml::sax::SAXException, RuntimeException, std::exception) { - sal_Int32 nLibCount = _pImport->mpLibArray->mnLibCount = (sal_Int32)mLibDescriptors.size(); - _pImport->mpLibArray->mpLibs = new LibDescriptor[ nLibCount ]; + sal_Int32 nLibCount = mxImport->mpLibArray->mnLibCount = (sal_Int32)mLibDescriptors.size(); + mxImport->mpLibArray->mpLibs = new LibDescriptor[ nLibCount ]; for( sal_Int32 i = 0 ; i < nLibCount ; i++ ) { const LibDescriptor& rLib = mLibDescriptors[i]; - _pImport->mpLibArray->mpLibs[i] = rLib; + mxImport->mpLibArray->mpLibs[i] = rLib; } } @@ -226,18 +213,18 @@ Reference< xml::input::XElement > LibraryElement::startChildElement( Reference< xml::input::XAttributes > const & xAttributes ) throw (xml::sax::SAXException, RuntimeException, std::exception) { - if (_pImport->XMLNS_LIBRARY_UID != nUid) + if (mxImport->XMLNS_LIBRARY_UID != nUid) { throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() ); } // library else if ( rLocalName == "element" ) { - OUString aValue( xAttributes->getValueByUidName(_pImport->XMLNS_LIBRARY_UID, "name" ) ); + OUString aValue( xAttributes->getValueByUidName(mxImport->XMLNS_LIBRARY_UID, "name" ) ); if (!aValue.isEmpty()) mElements.push_back( aValue ); - return new LibElementBase( rLocalName, xAttributes, this, _pImport ); + return new LibElementBase( rLocalName, xAttributes, this, mxImport.get() ); } else { @@ -254,9 +241,9 @@ void LibraryElement::endElement() for( sal_Int32 i = 0 ; i < nElementCount ; i++ ) pElementNames[i] = mElements[i]; - LibDescriptor* pLib = _pImport->mpLibDesc; + LibDescriptor* pLib = mxImport->mpLibDesc; if( !pLib ) - pLib = &static_cast< LibrariesElement* >( _pParent )->mLibDescriptors.back(); + pLib = &static_cast< LibrariesElement* >( mxParent.get() )->mLibDescriptors.back(); pLib->aElementNames = aElementNames; } diff --git a/xmlscript/source/xmlmod_imexp/imp_share.hxx b/xmlscript/source/xmlmod_imexp/imp_share.hxx index 05ca0944ce04..6a1bede592fb 100644 --- a/xmlscript/source/xmlmod_imexp/imp_share.hxx +++ b/xmlscript/source/xmlmod_imexp/imp_share.hxx @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -85,8 +86,8 @@ class ModuleElement : public ::cppu::WeakImplHelper< css::xml::input::XElement > { protected: - ModuleImport * _pImport; - ModuleElement * _pParent; + rtl::Reference mxImport; + rtl::Reference mxParent; OUString _aLocalName; css::uno::Reference< css::xml::input::XAttributes > _xAttributes; diff --git a/xmlscript/source/xmlmod_imexp/xmlmod_import.cxx b/xmlscript/source/xmlmod_imexp/xmlmod_import.cxx index f724ff7593ba..e9f9869ef6cf 100644 --- a/xmlscript/source/xmlmod_imexp/xmlmod_import.cxx +++ b/xmlscript/source/xmlmod_imexp/xmlmod_import.cxx @@ -33,7 +33,7 @@ namespace xmlscript Reference< xml::input::XElement > ModuleElement::getParent() throw (RuntimeException, std::exception) { - return static_cast< xml::input::XElement * >( _pParent ); + return mxParent.get(); } OUString ModuleElement::getLocalName() throw (RuntimeException, std::exception) @@ -43,7 +43,7 @@ OUString ModuleElement::getLocalName() sal_Int32 ModuleElement::getUid() throw (RuntimeException, std::exception) { - return _pImport->XMLNS_SCRIPT_UID; + return mxImport->XMLNS_SCRIPT_UID; } Reference< xml::input::XAttributes > ModuleElement::getAttributes() throw (RuntimeException, std::exception) @@ -73,7 +73,7 @@ void ModuleElement::processingInstruction( void ModuleElement::endElement() throw (xml::sax::SAXException, RuntimeException, std::exception) { - _pImport->mrModuleDesc.aCode = _strBuffer.makeStringAndClear(); + mxImport->mrModuleDesc.aCode = _strBuffer.makeStringAndClear(); } Reference< xml::input::XElement > ModuleElement::startChildElement( @@ -88,28 +88,15 @@ ModuleElement::ModuleElement( OUString const & rLocalName, Reference< xml::input::XAttributes > const & xAttributes, ModuleElement * pParent, ModuleImport * pImport ) - : _pImport( pImport ) - , _pParent( pParent ) + : mxImport( pImport ) + , mxParent( pParent ) , _aLocalName( rLocalName ) , _xAttributes( xAttributes ) { - _pImport->acquire(); - - if (_pParent) - { - _pParent->acquire(); - } } ModuleElement::~ModuleElement() { - _pImport->release(); - - if (_pParent) - { - _pParent->release(); - } - SAL_INFO("xmlscript.xmlmod", "ModuleElement::~ModuleElement(): " << _aLocalName ); } -- cgit