From 3813e236a8f48babaa850123e3a2a04e80713219 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 15 Mar 2010 14:38:03 +0100 Subject: different approach to fixing "the other" aliasing issue instead of copying the original value and constructing a Node later, construct a Node immediately and copy it later. Reviewed-by: thiago --- src/corelib/tools/qlist.h | 52 ++++++++++++++--------------------------------- 1 file changed, 15 insertions(+), 37 deletions(-) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index e3b8e1b..67f63f3 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -98,25 +98,6 @@ struct Q_CORE_EXPORT QListData { inline void **end() const { return d->array + d->end; } }; -////////////////////////////////////////////////////////////////////////////////// -// -// QtPodForSize and QtPodForType are internal and may change or go away any time. -// We mean it. -// -////////////////////////////////////////////////////////////////////////////////// -template struct QtPodForSize { - // This base type is rather obviously broken and cannot be made - // working due to alignment constraints. - // This doesn't matter as far as QList is concerned, as we are - // using this type only for QTypeInfo::isLarge == false. - typedef struct { } Type; -}; -template <> struct QtPodForSize<1> { typedef quint8 Type; }; -template <> struct QtPodForSize<2> { typedef quint16 Type; }; -template <> struct QtPodForSize<4> { typedef quint32 Type; }; -template <> struct QtPodForSize<8> { typedef quint64 Type; }; -template struct QtPodForType : QtPodForSize { }; - template class QList { @@ -529,16 +510,15 @@ Q_OUTOFLINE_TEMPLATE void QList::append(const T &t) QT_RETHROW; } } else { - typedef typename QtPodForType::Type PodNode; - PodNode cpy = *reinterpret_cast(&t); - Node *n = reinterpret_cast(p.append()); + Node *n, copy; + node_construct(©, t); // t might be a reference to an object in the array QT_TRY { - void *ptr = &cpy; - node_construct(n, *reinterpret_cast(ptr)); + n = reinterpret_cast(p.append());; } QT_CATCH(...) { - --d->end; + node_destruct(©); QT_RETHROW; } + *n = copy; } } } @@ -564,16 +544,15 @@ inline void QList::prepend(const T &t) QT_RETHROW; } } else { - typedef typename QtPodForType::Type PodNode; - PodNode cpy = *reinterpret_cast(&t); - Node *n = reinterpret_cast(p.prepend()); + Node *n, copy; + node_construct(©, t); // t might be a reference to an object in the array QT_TRY { - void *ptr = &cpy; - node_construct(n, *reinterpret_cast(ptr)); + n = reinterpret_cast(p.prepend());; } QT_CATCH(...) { - ++d->begin; + node_destruct(©); QT_RETHROW; } + *n = copy; } } } @@ -599,16 +578,15 @@ inline void QList::insert(int i, const T &t) QT_RETHROW; } } else { - typedef typename QtPodForType::Type PodNode; - PodNode cpy = *reinterpret_cast(&t); - Node *n = reinterpret_cast(p.insert(i)); + Node *n, copy; + node_construct(©, t); // t might be a reference to an object in the array QT_TRY { - void *ptr = &cpy; - node_construct(n, *reinterpret_cast(ptr)); + n = reinterpret_cast(p.insert(i));; } QT_CATCH(...) { - p.remove(i); + node_destruct(©); QT_RETHROW; } + *n = copy; } } } -- cgit v0.12