OSDN Git Service

replace sizeof(void*) with QT_POINTER_SIZE
authorIvailo Monev <xakepa10@gmail.com>
Fri, 12 Feb 2021 22:18:36 +0000 (00:18 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Fri, 12 Feb 2021 22:35:15 +0000 (00:35 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
17 files changed:
src/3rdparty/javascriptcore/bytecode/CodeBlock.cpp
src/3rdparty/javascriptcore/runtime/Collector.cpp
src/3rdparty/javascriptcore/runtime/JSFunction.h
src/3rdparty/javascriptcore/runtime/JSObject.h
src/core/global/qglobal.h
src/core/kernel/qmetaobject.cpp
src/core/kernel/qobject.cpp
src/core/tools/qjsondocument.cpp
src/core/tools/qlist.cpp
src/core/tools/qlist.h
src/core/tools/qsharedpointer.h
src/gui/text/qtextengine.cpp
src/gui/text/qtextengine_p.h
src/script/bridge/qscriptdeclarativeclass.cpp
src/test/qtest_gui.h
src/test/qtestdata.cpp
tests/benchmarks/core/tools/qvector/qrawvector.h

index 698f560..8a1acd0 100644 (file)
@@ -107,7 +107,7 @@ static const char* regexpName(int re, RegExp* regexp)
 
 static UString pointerToSourceString(void* p)
 {
-    char buffer[2 + 2 * sizeof(void*) + 1]; // 0x [two characters per byte] \0
+    char buffer[2 + 2 * QT_POINTER_SIZE + 1]; // 0x [two characters per byte] \0
     snprintf(buffer, sizeof(buffer), "%p", p);
     return buffer;
 }
index ad3d46a..012e50b 100644 (file)
@@ -397,7 +397,7 @@ void NEVER_INLINE Heap::markCurrentThreadConservativelyInternal(MarkStack& markS
     markConservatively(markStack, stackPointer, stackBase);
 }
 
-#define REGISTER_BUFFER_ALIGNMENT Q_DECL_ALIGN(sizeof(void*))
+#define REGISTER_BUFFER_ALIGNMENT Q_DECL_ALIGN(QT_POINTER_SIZE)
 
 void Heap::markCurrentThreadConservatively(MarkStack& markStack)
 {
index de0eb2f..82b8ed4 100644 (file)
@@ -117,7 +117,7 @@ namespace JSC {
         {
             *WTF::bitwise_cast<NativeFunction*>(m_data) = func;
         }
-        unsigned char m_data[sizeof(void*)];
+        unsigned char m_data[QT_POINTER_SIZE];
     };
 
     JSFunction* asFunction(JSValue);
index 8e47686..e62779d 100644 (file)
@@ -202,7 +202,7 @@ namespace JSC {
         void allocatePropertyStorageInline(size_t oldSize, size_t newSize);
         bool isUsingInlineStorage() const { return m_structure->isUsingInlineStorage(); }
 
-        static const unsigned inlineStorageCapacity = sizeof(EncodedJSValue) == 2 * sizeof(void*) ? 4 : 3;
+        static const unsigned inlineStorageCapacity = sizeof(EncodedJSValue) == 2 * QT_POINTER_SIZE ? 4 : 3;
         static const unsigned nonInlineBaseStorageCapacity = 16;
 
         static PassRefPtr<Structure> createStructure(JSValue prototype)
index 9166799..b91f8f0 100644 (file)
@@ -425,7 +425,7 @@ typedef double qreal;
 class Q_CORE_EXPORT QSysInfo {
 public:
     enum Sizes {
-        WordSize = (sizeof(void *)<<3)
+        WordSize = (QT_POINTER_SIZE << 3)
     };
 
     enum Endian {
@@ -741,7 +741,7 @@ public:
         isPointer = false,
         isComplex = true,
         isStatic = true,
-        isLarge = (sizeof(T)>sizeof(void*))
+        isLarge = (sizeof(T) > QT_POINTER_SIZE)
     };
 };
 
@@ -779,7 +779,7 @@ public: \
     enum { \
         isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), \
         isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), \
-        isLarge = (sizeof(TYPE)>sizeof(void*)), \
+        isLarge = (sizeof(TYPE) > QT_POINTER_SIZE), \
         isPointer = false \
     }; \
     static inline const char *name() { return #TYPE; } \
index 7986e3c..35d47cd 100644 (file)
@@ -1603,7 +1603,7 @@ bool QMetaMethod::invoke(QObject *object,
         }
 
         int nargs = 1; // include return type
-        void **args = (void **) malloc(paramCount * sizeof(void *));
+        void **args = (void **) malloc(paramCount * QT_POINTER_SIZE);
         Q_CHECK_PTR(args);
         int *types = (int *) malloc(paramCount * sizeof(int));
         Q_CHECK_PTR(types);
index ce10f4e..554c0bb 100644 (file)
@@ -2798,9 +2798,9 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect
     int nargs = 1; // include return type
     while (c->argumentTypes[nargs-1])
         ++nargs;
-    int *types = (int *) malloc(nargs*sizeof(int));
+    int *types = (int *) ::malloc(nargs * sizeof(int));
     Q_CHECK_PTR(types);
-    void **args = (void **) malloc(nargs*sizeof(void *));
+    void **args = (void **) ::malloc(nargs * QT_POINTER_SIZE);
     Q_CHECK_PTR(args);
     types[0] = 0; // return type
     args[0] = Q_NULLPTR; // return value
index 3161765..49c4286 100644 (file)
@@ -216,7 +216,6 @@ QByteArray QJsonDocumentPrivate::mapToJson(const QVariantMap &jsonmap)
                 result += mapToJson(value.toMap());
                 break;
             }
-
             default: {
                 error = QCoreApplication::translate("QJsonDocument", "Unknown JSON type");
                 break;
index 835cf87..8505dfe 100644 (file)
@@ -42,7 +42,7 @@ QListData::Data QListData::shared_null = { QAtomicInt(1), 0, 0, 0, { 0 } };
 static int grow(int size)
 {
     // dear compiler: don't optimize me out.
-    volatile int x = qAllocMore(size * sizeof(void *), QListData::DataHeaderSize) / sizeof(void *);
+    volatile int x = qAllocMore(size * QT_POINTER_SIZE, QListData::DataHeaderSize) / QT_POINTER_SIZE;
     return x;
 }
 
@@ -62,7 +62,7 @@ QListData::Data *QListData::detach_grow(int *idx, int num)
     int l = x->end - x->begin;
     int nl = l + num;
     int alloc = grow(nl);
-    Data* t = static_cast<Data *>(malloc(DataHeaderSize + alloc * sizeof(void *)));
+    Data* t = static_cast<Data *>(malloc(DataHeaderSize + alloc * QT_POINTER_SIZE));
     Q_CHECK_PTR(t);
 
     t->ref = 1;
@@ -103,7 +103,7 @@ QListData::Data *QListData::detach_grow(int *idx, int num)
 QListData::Data *QListData::detach(int alloc)
 {
     Data *x = d;
-    Data* t = static_cast<Data *>(malloc(DataHeaderSize + alloc * sizeof(void *)));
+    Data* t = static_cast<Data *>(malloc(DataHeaderSize + alloc * QT_POINTER_SIZE));
     Q_CHECK_PTR(t);
 
     t->ref = 1;
@@ -139,7 +139,7 @@ void QListData::freeData(Data *data)
 void QListData::reallocData(int alloc)
 {
     Q_ASSERT(d->ref == 1);
-    Data *x = static_cast<Data *>(realloc(d, DataHeaderSize + alloc * sizeof(void *)));
+    Data *x = static_cast<Data *>(realloc(d, DataHeaderSize + alloc * QT_POINTER_SIZE));
     Q_CHECK_PTR(x);
 
     d = x;
@@ -158,7 +158,7 @@ void **QListData::append(int n)
         if (b - n >= 2 * d->alloc / 3) {
             // we have enough space. Just not at the end -> move it.
             e -= b;
-            ::memmove(d->array, d->array + b, e * sizeof(void *));
+            ::memmove(d->array, d->array + b, e * QT_POINTER_SIZE);
             d->begin = 0;
         } else {
             reallocData(grow(d->alloc + n));
@@ -192,7 +192,7 @@ void **QListData::prepend()
         else
             d->begin = d->alloc - d->end;
 
-        ::memmove(d->array + d->begin, d->array, d->end * sizeof(void *));
+        ::memmove(d->array + d->begin, d->array, d->end * QT_POINTER_SIZE);
         d->end += d->begin;
     }
     return d->array + --d->begin;
@@ -228,10 +228,10 @@ void **QListData::insert(int i)
 
     if (leftward) {
         --d->begin;
-        ::memmove(d->array + d->begin, d->array + d->begin + 1, i * sizeof(void *));
+        ::memmove(d->array + d->begin, d->array + d->begin + 1, i * QT_POINTER_SIZE);
     } else {
         ::memmove(d->array + d->begin + i + 1, d->array + d->begin + i,
-                  (size - i) * sizeof(void *));
+                  (size - i) * QT_POINTER_SIZE);
         ++d->end;
     }
     return d->array + d->begin + i;
@@ -243,11 +243,11 @@ void QListData::remove(int i)
     i += d->begin;
     if (i - d->begin < d->end - i) {
         if (int offset = i - d->begin)
-            ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *));
+            ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * QT_POINTER_SIZE);
         d->begin++;
     } else {
         if (int offset = d->end - i - 1)
-            ::memmove(d->array + i, d->array + i + 1, offset * sizeof(void *));
+            ::memmove(d->array + i, d->array + i + 1, offset * QT_POINTER_SIZE);
         d->end--;
     }
 }
@@ -259,11 +259,11 @@ void QListData::remove(int i, int n)
     int middle = i + n/2;
     if (middle - d->begin < d->end - middle) {
         ::memmove(d->array + d->begin + n, d->array + d->begin,
-                   (i - d->begin) * sizeof(void*));
+                   (i - d->begin) * QT_POINTER_SIZE);
         d->begin += n;
     } else {
         ::memmove(d->array + i, d->array + i + n,
-                   (d->end - i - n) * sizeof(void*));
+                   (d->end - i - n) * QT_POINTER_SIZE);
         d->end -= n;
     }
 }
@@ -280,26 +280,26 @@ void QListData::move(int from, int to)
 
     if (from < to) {
         if (d->end == d->alloc || 3 * (to - from) < 2 * (d->end - d->begin)) {
-            ::memmove(d->array + from, d->array + from + 1, (to - from) * sizeof(void *));
+            ::memmove(d->array + from, d->array + from + 1, (to - from) * QT_POINTER_SIZE);
         } else {
             // optimization
             if (int offset = from - d->begin)
-                ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *));
+                ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * QT_POINTER_SIZE);
             if (int offset = d->end - (to + 1))
-                ::memmove(d->array + to + 2, d->array + to + 1, offset * sizeof(void *));
+                ::memmove(d->array + to + 2, d->array + to + 1, offset * QT_POINTER_SIZE);
             ++d->begin;
             ++d->end;
             ++to;
         }
     } else {
         if (d->begin == 0 || 3 * (from - to) < 2 * (d->end - d->begin)) {
-            ::memmove(d->array + to + 1, d->array + to, (from - to) * sizeof(void *));
+            ::memmove(d->array + to + 1, d->array + to, (from - to) * QT_POINTER_SIZE);
         } else {
             // optimization
             if (int offset = to - d->begin)
-                ::memmove(d->array + d->begin - 1, d->array + d->begin, offset * sizeof(void *));
+                ::memmove(d->array + d->begin - 1, d->array + d->begin, offset * QT_POINTER_SIZE);
             if (int offset = d->end - (from + 1))
-                ::memmove(d->array + from, d->array + from + 1, offset * sizeof(void *));
+                ::memmove(d->array + from, d->array + from + 1, offset * QT_POINTER_SIZE);
             --d->begin;
             --d->end;
             --to;
index e076844..6769d1c 100644 (file)
@@ -49,7 +49,7 @@ struct Q_CORE_EXPORT QListData {
         int alloc, begin, end;
         void *array[1];
     };
-    enum { DataHeaderSize = sizeof(Data) - sizeof(void *) };
+    enum { DataHeaderSize = sizeof(Data) - QT_POINTER_SIZE };
 
     Data *detach(int alloc);
     Data *detach_grow(int *i, int n);
index 3dffc3a..0376004 100644 (file)
@@ -193,7 +193,7 @@ namespace QtSharedPointer {
             inline CustomDeleter(T *p, Deleter d) : deleter(d), ptr(p) {}
         };
         CustomDeleter extra;
-        // sizeof(CustomDeleter) = sizeof(Deleter) + sizeof(void*)
+        // sizeof(CustomDeleter) = sizeof(Deleter) + QT_POINTER_SIZE
         // for Deleter = function pointer:  8 (32-bit) / 16 (64-bit)
         // for Deleter = PMF: 12 (32-bit) / 24 (64-bit)  (GCC)
 
index 696a9bc..69eaf9b 100644 (file)
@@ -1272,7 +1272,7 @@ void QTextEngine::itemize() const
     QBidiControl control(rtl);
 
     if (ignore) {
-        memset(analysis, 0, length*sizeof(QScriptAnalysis));
+        ::memset(analysis, 0, length * sizeof(QScriptAnalysis));
         if (option.textDirection() == Qt::RightToLeft) {
             for (int i = 0; i < length; ++i)
                 analysis[i].bidiLevel = 1;
@@ -1957,9 +1957,9 @@ QTextEngine::LayoutData::LayoutData(const QString &str, void **stack_memory, int
 {
     allocated = _allocated;
 
-    int space_charAttributes = sizeof(HB_CharAttributes)*string.length()/sizeof(void*) + 1;
-    int space_logClusters = sizeof(unsigned short)*string.length()/sizeof(void*) + 1;
-    available_glyphs = ((int)allocated - space_charAttributes - space_logClusters)*(int)sizeof(void*)/(int)QGlyphLayout::spaceNeededForGlyphLayout(1);
+    int space_charAttributes = sizeof(HB_CharAttributes) * string.length() / QT_POINTER_SIZE + 1;
+    int space_logClusters = sizeof(unsigned short) * string.length() / QT_POINTER_SIZE + 1;
+    available_glyphs = (allocated - space_charAttributes - space_logClusters) * QT_POINTER_SIZE / QGlyphLayout::spaceNeededForGlyphLayout(1);
 
     if (available_glyphs < str.length()) {
         // need to allocate on the heap
@@ -1976,7 +1976,7 @@ QTextEngine::LayoutData::LayoutData(const QString &str, void **stack_memory, int
         void *m = memory + space_charAttributes + space_logClusters;
         glyphLayout = QGlyphLayout(reinterpret_cast<char *>(m), str.length());
         glyphLayout.clear();
-        memset(memory, 0, space_charAttributes*sizeof(void *));
+        ::memset(memory, 0, space_charAttributes * QT_POINTER_SIZE);
     }
     used = 0;
     hasBidi = false;
@@ -1987,7 +1987,7 @@ QTextEngine::LayoutData::LayoutData(const QString &str, void **stack_memory, int
 QTextEngine::LayoutData::~LayoutData()
 {
     if (!memory_on_stack)
-        free(memory);
+        ::free(memory);
     memory = 0;
 }
 
@@ -1999,9 +1999,9 @@ bool QTextEngine::LayoutData::reallocate(int totalGlyphs)
         return true;
     }
 
-    int space_charAttributes = sizeof(HB_CharAttributes)*string.length()/sizeof(void*) + 1;
-    int space_logClusters = sizeof(unsigned short)*string.length()/sizeof(void*) + 1;
-    int space_glyphs = QGlyphLayout::spaceNeededForGlyphLayout(totalGlyphs)/sizeof(void*) + 2;
+    int space_charAttributes = sizeof(HB_CharAttributes) * string.length() / QT_POINTER_SIZE + 1;
+    int space_logClusters = sizeof(unsigned short) * string.length() / QT_POINTER_SIZE + 1;
+    int space_glyphs = QGlyphLayout::spaceNeededForGlyphLayout(totalGlyphs) / QT_POINTER_SIZE + 2;
 
     int newAllocated = space_charAttributes + space_glyphs + space_logClusters;
     // These values can be negative if the length of string/glyphs causes overflow,
@@ -2012,13 +2012,13 @@ bool QTextEngine::LayoutData::reallocate(int totalGlyphs)
         return false;
     }
 
-    void **newMem = (void **)::realloc(memory_on_stack ? 0 : memory, newAllocated*sizeof(void *));
+    void **newMem = (void **)::realloc(memory_on_stack ? 0 : memory, newAllocated * QT_POINTER_SIZE);
     if (!newMem) {
         layoutState = LayoutFailed;
         return false;
     }
     if (memory_on_stack)
-        memcpy(newMem, memory, allocated*sizeof(void *));
+        memcpy(newMem, memory, allocated * QT_POINTER_SIZE);
     memory = newMem;
     memory_on_stack = false;
 
@@ -2029,7 +2029,7 @@ bool QTextEngine::LayoutData::reallocate(int totalGlyphs)
 
     const int space_preGlyphLayout = space_charAttributes + space_logClusters;
     if (allocated < space_preGlyphLayout)
-        memset(memory + allocated, 0, (space_preGlyphLayout - allocated)*sizeof(void *));
+        memset(memory + allocated, 0, (space_preGlyphLayout - allocated) * QT_POINTER_SIZE);
 
     glyphLayout.grow(reinterpret_cast<char *>(m), totalGlyphs);
 
index e758567..7ad0036 100644 (file)
@@ -235,18 +235,18 @@ private:
     typedef QVarLengthArray<void *> Array;
 public:
     QVarLengthGlyphLayoutArray(int totalGlyphs)
-        : Array(spaceNeededForGlyphLayout(totalGlyphs) / sizeof(void *) + 1)
+        : Array(spaceNeededForGlyphLayout(totalGlyphs) / QT_POINTER_SIZE + 1)
         , QGlyphLayout(reinterpret_cast<char *>(Array::data()), totalGlyphs)
     {
-        memset(Array::data(), 0, Array::size() * sizeof(void *));
+        memset(Array::data(), 0, Array::size() * QT_POINTER_SIZE);
     }
 
     void resize(int totalGlyphs)
     {
-        Array::resize(spaceNeededForGlyphLayout(totalGlyphs) / sizeof(void *) + 1);
+        Array::resize(spaceNeededForGlyphLayout(totalGlyphs) / QT_POINTER_SIZE + 1);
 
         *((QGlyphLayout *)this) = QGlyphLayout(reinterpret_cast<char *>(Array::data()), totalGlyphs);
-        memset(Array::data(), 0, Array::size() * sizeof(void *));
+        memset(Array::data(), 0, Array::size() * QT_POINTER_SIZE);
     }
 };
 
@@ -263,7 +263,7 @@ private:
     void *buffer[(N * (sizeof(HB_Glyph) + sizeof(HB_GlyphAttributes)
                 + sizeof(QFixed) + sizeof(QFixed) + sizeof(QFixedPoint)
                 + sizeof(QGlyphJustification)))
-                    / sizeof(void *) + 1];
+                    / QT_POINTER_SIZE + 1];
 };
 
 struct QScriptItem;
@@ -588,7 +588,7 @@ private:
 
 class QStackTextEngine : public QTextEngine {
 public:
-    enum { MemSize = 256*40/sizeof(void *) };
+    enum { MemSize = 256 * 40 / QT_POINTER_SIZE };
     QStackTextEngine(const QString &string, const QFont &f);
     LayoutData _layoutData;
     void *_memory[MemSize];
index 02035f3..23aba23 100644 (file)
@@ -185,7 +185,7 @@ QString QScriptDeclarativeClass::PersistentIdentifier::toString() const
 QScriptDeclarativeClass::QScriptDeclarativeClass(QScriptEngine *engine)
 : d_ptr(new QScriptDeclarativeClassPrivate)
 {
-    Q_ASSERT(sizeof(void*) == sizeof(JSC::Identifier));
+    Q_ASSERT(sizeof(JSC::Identifier) == QT_POINTER_SIZE);
     d_ptr->engine = engine;
 }
 
index 62714fe..c87cbfc 100644 (file)
@@ -47,7 +47,7 @@ template<>
 inline bool qCompare(QIcon const &t1, QIcon const &t2, const char *actual, const char *expected,
                     const char *file, int line)
 {
-    QTEST_ASSERT(sizeof(QIcon) == sizeof(void *));
+    QTEST_ASSERT(sizeof(QIcon) == QT_POINTER_SIZE);
     return qCompare<void *>(*reinterpret_cast<void * const *>(&t1),
                    *reinterpret_cast<void * const *>(&t2), actual, expected, file, line);
 }
index d447dcb..5c09d17 100644 (file)
@@ -48,7 +48,7 @@ QTestData::QTestData(const char *tag, QTestTable *parent)
     d->tag = qstrdup(tag);
     d->parent = parent;
     d->data = new void *[parent->elementCount()];
-    memset(d->data, 0, parent->elementCount() * sizeof(void*));
+    memset(d->data, 0, parent->elementCount() * QT_POINTER_SIZE);
 }
 
 QTestData::~QTestData()
index 4468bb7..55415a9 100644 (file)
@@ -250,11 +250,7 @@ private:
     }
     static inline int alignOfTypedData()
     {
-#ifdef Q_ALIGNOF
-        return qMax<int>(sizeof(void*), Q_ALIGNOF(Data));
-#else
-        return 0;
-#endif
+        return qMax<int>(QT_POINTER_SIZE, Q_ALIGNOF(Data));
     }
 
 public: