[Libreoffice-commits] core.git: include/tools tools/source

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Thu Dec 24 21:48:54 UTC 2020


 include/tools/bigint.hxx        |   54 +++++++++++++++++++---------
 tools/source/generic/bigint.cxx |   77 ----------------------------------------
 2 files changed, 37 insertions(+), 94 deletions(-)

New commits:
commit ad9e04321df25824d2288a2ef1f4275f070f1cf7
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Thu Dec 24 14:23:34 2020 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Thu Dec 24 22:48:15 2020 +0100

    Revert "add sal*Int64 conversions to BigInt"
    
    This reverts commit 5dae4238ea6e21df42f4437a43d152954fc494fd, which appears to
    have ambiguitiy problems not only on Windows, but generally with 32-bit builds
    like <https://ci.libreoffice.org/job/gerrit_android_x86/1518/>:
    
    > /home/tdf/lode/jenkins/workspace/android_x86/tools/source/generic/bigint.cxx:501:18: error: conversion from 'int' to 'const BigInt' is ambiguous
    >         *this *= 10;
    >                  ^~
    > /home/tdf/lode/jenkins/workspace/android_x86/include/tools/bigint.hxx:58:5: note: candidate constructor
    >     BigInt(sal_Int32 nValue)
    >     ^
    > /home/tdf/lode/jenkins/workspace/android_x86/include/tools/bigint.hxx:66:5: note: candidate constructor
    >     BigInt( double nVal );
    >     ^
    > /home/tdf/lode/jenkins/workspace/android_x86/include/tools/bigint.hxx:67:5: note: candidate constructor
    >     BigInt( sal_uInt32 nVal );
    >     ^
    > /home/tdf/lode/jenkins/workspace/android_x86/include/tools/bigint.hxx:68:5: note: candidate constructor
    >     BigInt( sal_Int64 nVal );
    >     ^
    > /home/tdf/lode/jenkins/workspace/android_x86/include/tools/bigint.hxx:69:5: note: candidate constructor
    >     BigInt( sal_uInt64 nVal );
    >     ^
    
    Change-Id: I674b14c342ece3e170185b7ce2f34ccb8ff91c7a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108186
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/include/tools/bigint.hxx b/include/tools/bigint.hxx
index ecf7ba05b96a..a8d8575fb53b 100644
--- a/include/tools/bigint.hxx
+++ b/include/tools/bigint.hxx
@@ -63,23 +63,30 @@ public:
     {
     }
 
+#if SAL_TYPES_SIZEOFLONG == 4
+    BigInt(int nValue)
+        : nVal(nValue)
+        , nLen(0)
+        , bIsNeg(false)
+        , bIsBig(false)
+    {
+    }
+#endif
+
     BigInt( double nVal );
     BigInt( sal_uInt32 nVal );
     BigInt( sal_Int64 nVal );
-    BigInt( sal_uInt64 nVal );
     BigInt( const BigInt& rBigInt );
     BigInt( const OUString& rString );
-// for some conversions, MSVC does not see int as being equivalent to sal_Int*
-#ifdef _WIN32
-    BigInt( int nVal ) : BigInt(static_cast<sal_Int64>(nVal)) {}
-#endif
-    inline operator sal_Int16() const;
-    inline operator sal_uInt16() const;
-    inline operator sal_Int32() const;
+
+    operator        sal_Int16() const;
+    operator        sal_uInt16() const;
+    operator        sal_Int32() const;
     operator        sal_uInt32() const;
-    operator        sal_Int64() const;
-    operator        sal_uInt64() const;
     operator        double() const;
+#if SAL_TYPES_SIZEOFPOINTER == 8
+    operator        tools::Long() const;
+#endif
 
     bool            IsNeg() const;
     bool            IsZero() const;
@@ -94,13 +101,7 @@ public:
     BigInt&         operator /=( const BigInt& rVal );
     BigInt&         operator %=( const BigInt& rVal );
 
-// for some conversions, MSVC does not see int as being equivalent to sal_Int*
-#ifdef _WIN32
-    inline BigInt&  operator  =( int nValue ) { return operator=(static_cast<sal_Int64>(nValue)); }
-#endif
-    inline BigInt&  operator  =( sal_Int32 nValue );
-    inline BigInt&  operator  =( sal_Int64 nValue ) { return *this = BigInt(nValue); }
-    inline BigInt&  operator  =( sal_uInt64 nValue ) { return *this = BigInt(nValue); }
+    BigInt&         operator  =( sal_Int32 nValue );
 
     friend inline   BigInt operator +( const BigInt& rVal1, const BigInt& rVal2 );
     friend inline   BigInt operator -( const BigInt& rVal1, const BigInt& rVal2 );
@@ -142,6 +143,25 @@ inline BigInt::operator sal_Int32() const
     return 0;
 }
 
+inline BigInt::operator sal_uInt32() const
+{
+    if ( !bIsBig && nVal >= 0 )
+        return static_cast<sal_uInt32>(nVal);
+    assert(false && "out of range");
+    return 0;
+}
+
+#if SAL_TYPES_SIZEOFPOINTER == 8
+inline BigInt::operator tools::Long() const
+{
+    // Clamp to int32 since long is int32 on Windows.
+    if (!bIsBig)
+        return nVal;
+    assert(false && "out of range");
+    return 0;
+}
+#endif
+
 inline BigInt& BigInt::operator =( sal_Int32 nValue )
 {
     bIsBig = false;
diff --git a/tools/source/generic/bigint.cxx b/tools/source/generic/bigint.cxx
index 1239868b1432..62350a30c311 100644
--- a/tools/source/generic/bigint.cxx
+++ b/tools/source/generic/bigint.cxx
@@ -594,83 +594,6 @@ BigInt::BigInt( sal_Int64 nValue )
     }
 }
 
-BigInt::BigInt( sal_uInt64 nValue )
-    : nVal(0)
-{
-    bIsNeg = false;
-    nLen = 0;
-
-    if (nValue <= SAL_MAX_INT32)
-    {
-        bIsBig = false;
-        nVal   = static_cast<sal_Int32>(nValue);
-    }
-    else
-    {
-        bIsBig  = true;
-        for (int i = 0; (i != sizeof(sal_uInt64) / 2) && (nValue != 0); ++i)
-        {
-            nNum[i] = static_cast<sal_uInt16>(nValue & 0xffffUL);
-            nValue = nValue >> 16;
-            ++nLen;
-        }
-    }
-}
-
-BigInt::operator sal_uInt32() const
-{
-    if ( !bIsBig )
-    {
-        assert(nVal >= 0 && "out of range");
-        return static_cast<sal_uInt32>(nVal);
-    }
-    else
-    {
-        assert(nLen <= 2 && "out of range");
-        assert(!bIsNeg && "out of range");
-
-        int     i = nLen-1;
-        sal_uInt32 nRet = nNum[i];
-
-        while ( i )
-        {
-            nRet = nRet << 16;
-            i--;
-            nRet |= nNum[i];
-        }
-
-        return nRet;
-    }
-}
-
-BigInt::operator sal_Int64() const
-{
-    if ( !bIsBig )
-    {
-        return nVal;
-    }
-    else
-    {
-        assert(nLen <= 4 && "out of range");
-        assert((nLen < 4 || nNum[4] <= SAL_MAX_INT16) && "out of range");
-
-        int     i = nLen-1;
-        sal_Int64 nRet = nNum[i];
-
-        while ( i )
-        {
-            nRet = nRet << 16;
-            i--;
-            nRet |= nNum[i];
-        }
-
-        if ( bIsNeg )
-            nRet *= -1;
-
-        return nRet;
-    }
-}
-
 BigInt::operator double() const
 {
     if ( !bIsBig )


More information about the Libreoffice-commits mailing list