Skip to content

Commit

Permalink
Streamline the template specialization of QESDP's dtor
Browse files Browse the repository at this point in the history
Declaring and implementing out of line a specialization for
QESDP's destructor is needed if we have an implicitly shared
type and we want to provide an inline move constructor for it.

The code is however a bit heavy on the eyes, and the full
implementation for the destructor must be provided (read:
copy and pasted) -- the specialization destructor cannot
just "reuse" the one from the primary template.

This patch adds a few macros to streamline the above, so
that we can start using the same pattern in more places.
These macros are completely private for the moment being;
we don't want to push this solution for our users.

Port QPixmap to the new macros.

Change-Id: Ia6a51ad988483e44c9d97c0eca2fb003b6bd21e3
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
dangelog committed Oct 5, 2020
1 parent 099f756 commit 54232d6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions bin/syncqt.pl
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ sub classNames {
$line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE(_[A-Z]+)*[\r\n]*$/); #qt macro
$line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro
$line .= ";" if($line =~ m/^QT_WARNING_(PUSH|POP|DISABLE_\w+\(.*\))[\r\n]*$/); # qt macros
$line .= ";" if($line =~ m/^QT_DECLARE_QE?SDP_SPECIALIZATION_DTOR(_WITH_EXPORT)?\(.*\)[\r\n]*$/); # qt macros
$$requires = $1 if ($line =~ m/^QT_REQUIRE_CONFIG\((.*)\);[\r\n]*$/);
$parsable .= " " . $line;
}
Expand Down
26 changes: 26 additions & 0 deletions src/corelib/tools/qshareddata.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,32 @@ Q_INLINE_TEMPLATE size_t qHash(const QExplicitlySharedDataPointer<T> &ptr, size_
template<typename T> Q_DECLARE_TYPEINFO_BODY(QSharedDataPointer<T>, Q_MOVABLE_TYPE);
template<typename T> Q_DECLARE_TYPEINFO_BODY(QExplicitlySharedDataPointer<T>, Q_MOVABLE_TYPE);

#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR(Class) \
template<> QSharedDataPointer<Class>::~QSharedDataPointer();

#define QT_DECLARE_QSDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro) \
template<> ExportMacro QSharedDataPointer<Class>::~QSharedDataPointer();

#define QT_DEFINE_QSDP_SPECIALIZATION_DTOR(Class) \
template<> QSharedDataPointer<Class>::~QSharedDataPointer() \
{ \
if (d && !d->ref.deref()) \
delete d; \
}

#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR(Class) \
template<> QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer();

#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro) \
template<> ExportMacro QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer();

#define QT_DEFINE_QESDP_SPECIALIZATION_DTOR(Class) \
template<> QExplicitlySharedDataPointer<Class>::~QExplicitlySharedDataPointer() \
{ \
if (d && !d->ref.deref()) \
delete d; \
}

QT_END_NAMESPACE

#endif // QSHAREDDATA_H
5 changes: 2 additions & 3 deletions src/gui/image/qpixmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,8 @@ QPixmap::QPixmap(const QPixmap &pixmap)
\sa swap() operator=(QPixmap&&)
*/
template<>
QExplicitlySharedDataPointer<QPlatformPixmap>::~QExplicitlySharedDataPointer()
{ if (d && !d->ref.deref()) delete d; }

QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QPlatformPixmap)

/*!
Constructs a pixmap from the given \a xpm data, which must be a
Expand Down
2 changes: 1 addition & 1 deletion src/gui/image/qpixmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class QImageReader;
class QColor;
class QVariant;
class QPlatformPixmap;
template<> Q_GUI_EXPORT QExplicitlySharedDataPointer<QPlatformPixmap>::~QExplicitlySharedDataPointer();
QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QPlatformPixmap, Q_GUI_EXPORT)

class Q_GUI_EXPORT QPixmap : public QPaintDevice
{
Expand Down

0 comments on commit 54232d6

Please sign in to comment.