basic/source/sbx/sbxarray.cxx |    4 +++-
 include/sfx2/objsh.hxx        |    1 +
 include/tools/ref.hxx         |   35 ++++++++++++++++++-----------------
 sfx2/source/doc/objxtor.cxx   |    8 +++++++-
 tools/source/ref/ref.cxx      |    6 +++++-
 5 files changed, 34 insertions(+), 20 deletions(-)

New commits:
commit e5b0aa9a7c7f81c78164e70646831975b7b310f3
Author: Michael Stahl <mst...@redhat.com>
Date:   Tue Jul 29 18:06:06 2014 +0200

    basic: -Werror=sign-compare
    
    Change-Id: I7c776faa74a61b0d263c3b446972da9461b3d4f6

diff --git a/basic/source/sbx/sbxarray.cxx b/basic/source/sbx/sbxarray.cxx
index 67234f9..183b361 100644
--- a/basic/source/sbx/sbxarray.cxx
+++ b/basic/source/sbx/sbxarray.cxx
@@ -731,7 +731,9 @@ void SbxDimArray::Put32( SbxVariable* p, const sal_Int32* 
pIdx  )
 sal_uInt32 SbxDimArray::Offset32( SbxArray* pPar )
 {
 #ifndef DISABLE_SCRIPTING
-    if( m_vDimensions.empty() || !pPar || ( ( m_vDimensions.size() != ( 
pPar->Count() - 1 ) ) && SbiRuntime::isVBAEnabled() ) )
+    if (m_vDimensions.empty() || !pPar ||
+        ((m_vDimensions.size() != sal::static_int_cast<size_t>(pPar->Count() - 
1))
+            && SbiRuntime::isVBAEnabled()))
     {
         SetError( SbxERR_BOUNDS );
         return 0;
commit 666f8651b117f6124b7308586284102f798215ef
Author: Noel Grandin <n...@peralex.com>
Date:   Fri Jul 11 08:58:37 2014 +0200

    simplify "no delete" logic in SvRefBase
    
    by converting the bit munging to use bitfields.
    Remove unused return values.
    Add asserts to check that AddRef() is not called after the object
    is deleted.
    Fix the code in SfxObjectShell to not call AddRef() after
    SfxObjectShell is deleted.
    
    Change-Id: I3a3565a0bc45fc9d1d086222265ab8b8175818a7

diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index 1cb8e91..aa767ff 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -177,6 +177,7 @@ private:
                                                   // sal_False := new object
     bool                        bIsInGenerateThumbnail; //optimize thumbnail 
generate and store procedure to improve odt saving performance, i120030
 
+    bool                        CloseInternal();
 private:
     SAL_DLLPRIVATE void UpdateTime_Impl(const ::com::sun::star::uno::Reference<
         ::com::sun::star::document::XDocumentProperties> & i_xDocProps);
diff --git a/include/tools/ref.hxx b/include/tools/ref.hxx
index ed34f41..3b8b320 100644
--- a/include/tools/ref.hxx
+++ b/include/tools/ref.hxx
@@ -146,46 +146,47 @@ public:
 /** Classes that want to be referenced-counted via SvRef<T>, should extend 
this base class */
 class TOOLS_DLLPUBLIC SvRefBase
 {
-    static const sal_uIntPtr SV_NO_DELETE_REFCOUNT = 0x80000000;
-    sal_uIntPtr nRefCount;
+    // the only reason this is not bool is because MSVC cannot handle mixed 
type bitfields
+    unsigned int bNoDelete : 1;
+    unsigned int nRefCount : 31;
 
 protected:
     virtual         ~SvRefBase();
     virtual void    QueryDelete();
 
 public:
-                    SvRefBase()
-                    { nRefCount = SV_NO_DELETE_REFCOUNT; }
+                    SvRefBase() : bNoDelete(1), nRefCount(0) {}
 
-                    SvRefBase( const SvRefBase & /* rObj */ )
-                    { nRefCount = SV_NO_DELETE_REFCOUNT; }
+                    SvRefBase( const SvRefBase & /* rObj */ )  : bNoDelete(1), 
nRefCount(0) {}
 
     SvRefBase &     operator = ( const SvRefBase & )
                     { return *this; }
 
     void            RestoreNoDelete()
+                    { bNoDelete = 1; }
+
+    void            AddNextRef()
                     {
-                        if( nRefCount < SV_NO_DELETE_REFCOUNT )
-                            nRefCount += SV_NO_DELETE_REFCOUNT;
+                        assert( nRefCount < (1 << 30) && "Do not add refs to 
dead objects" );
+                        ++nRefCount;
                     }
 
-    sal_uIntPtr     AddNextRef()
-                    { return ++nRefCount; }
-
-    sal_uIntPtr     AddRef()
+    void            AddRef()
                     {
-                        if( nRefCount >= SV_NO_DELETE_REFCOUNT )
-                            nRefCount -= SV_NO_DELETE_REFCOUNT;
-                        return ++nRefCount;
+                        assert( nRefCount < (1 << 30) && "Do not add refs to 
dead objects" );
+                        if( bNoDelete )
+                            bNoDelete = 0;
+                        ++nRefCount;
                     }
 
     void            ReleaseRef()
                     {
-                        if( !--nRefCount )
+                        assert( nRefCount >= 1);
+                        if( --nRefCount == 0 && !bNoDelete)
                             QueryDelete();
                     }
 
-    sal_uIntPtr     GetRefCount() const
+    unsigned int    GetRefCount() const
                     { return nRefCount; }
 };
 
diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx
index a374578..409ce93 100644
--- a/sfx2/source/doc/objxtor.cxx
+++ b/sfx2/source/doc/objxtor.cxx
@@ -354,7 +354,7 @@ SfxObjectShell::~SfxObjectShell()
 
     // Never call GetInPlaceObject(), the access to the derivative branch
     // SfxInternObject is not allowed because of a compiler bug
-    SfxObjectShell::Close();
+    SfxObjectShell::CloseInternal();
     pImp->pBaseModel.set( NULL );
 
     DELETEX(AutoReloadTimer_Impl, pImp->pReloadTimer );
@@ -438,6 +438,12 @@ void SfxObjectShell::ViewAssigned()
 bool SfxObjectShell::Close()
 {
     SfxObjectShellRef aRef(this);
+    return CloseInternal();
+}
+
+// variant that does not take a reference to itself, so we can call it during 
object destruction
+bool SfxObjectShell::CloseInternal()
+{
     if ( !pImp->bClosing )
     {
         // Do not close if a progress is still running
diff --git a/tools/source/ref/ref.cxx b/tools/source/ref/ref.cxx
index 881a25a..3a6aa59 100644
--- a/tools/source/ref/ref.cxx
+++ b/tools/source/ref/ref.cxx
@@ -25,7 +25,11 @@ SvRefBase::~SvRefBase()
 
 void SvRefBase::QueryDelete()
 {
-    nRefCount = SV_NO_DELETE_REFCOUNT / 2;
+    bNoDelete = 0;
+    // I'm not sure about the original purpose of this line, but right now
+    // it serves the purpose that anything that attempts to do an AddRef()
+    // after an object is deleted will trip an assert.
+    nRefCount = 1 << 30;
     delete this;
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to