Improve Q_CONSTRUCTOR_FUNCTION and Q_DESTRUCTOR_FUNCTION macros.
By adding anonymous namespace and static linkage we are reducing visibility of implementation of these macros. This patch also fixes warning about a declared but unused variable which was issued by gcc 4.6 for Q_CONSTRUCTOR_FUNCTION. Change-Id: I2cb70ad4c93f6f77e5518420abcce6fd4cadccfa Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com> Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
This commit is contained in:
parent
389538c2e7
commit
e650859dc9
@ -373,23 +373,6 @@ namespace QT_NAMESPACE {}
|
||||
Should be sorted most to least authoritative.
|
||||
*/
|
||||
|
||||
#if defined(__ghs)
|
||||
# define Q_OUTOFLINE_TEMPLATE inline
|
||||
|
||||
/* the following are necessary because the GHS C++ name mangling relies on __*/
|
||||
# define Q_CONSTRUCTOR_FUNCTION0(AFUNC) \
|
||||
static const int AFUNC ## _init_variable_ = AFUNC();
|
||||
# define Q_CONSTRUCTOR_FUNCTION(AFUNC) Q_CONSTRUCTOR_FUNCTION0(AFUNC)
|
||||
# define Q_DESTRUCTOR_FUNCTION0(AFUNC) \
|
||||
class AFUNC ## _dest_class_ { \
|
||||
public: \
|
||||
inline AFUNC ## _dest_class_() { } \
|
||||
inline ~ AFUNC ## _dest_class_() { AFUNC(); } \
|
||||
} AFUNC ## _dest_instance_;
|
||||
# define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC)
|
||||
|
||||
#endif
|
||||
|
||||
/* Symantec C++ is now Digital Mars */
|
||||
#if defined(__DMC__) || defined(__SC__)
|
||||
# define Q_CC_SYM
|
||||
@ -827,17 +810,23 @@ namespace QT_NAMESPACE {}
|
||||
|
||||
#ifndef Q_CONSTRUCTOR_FUNCTION
|
||||
# define Q_CONSTRUCTOR_FUNCTION0(AFUNC) \
|
||||
static const int AFUNC ## __init_variable__ = AFUNC();
|
||||
namespace { \
|
||||
static const struct AFUNC ## _ctor_class_ { \
|
||||
inline AFUNC ## _ctor_class_() { AFUNC(); } \
|
||||
} AFUNC ## _ctor_instance_; \
|
||||
}
|
||||
|
||||
# define Q_CONSTRUCTOR_FUNCTION(AFUNC) Q_CONSTRUCTOR_FUNCTION0(AFUNC)
|
||||
#endif
|
||||
|
||||
#ifndef Q_DESTRUCTOR_FUNCTION
|
||||
# define Q_DESTRUCTOR_FUNCTION0(AFUNC) \
|
||||
class AFUNC ## __dest_class__ { \
|
||||
public: \
|
||||
inline AFUNC ## __dest_class__() { } \
|
||||
inline ~ AFUNC ## __dest_class__() { AFUNC(); } \
|
||||
} AFUNC ## __dest_instance__;
|
||||
namespace { \
|
||||
static const struct AFUNC ## _dtor_class_ { \
|
||||
inline AFUNC ## _dtor_class_() { } \
|
||||
inline ~ AFUNC ## _dtor_class_() { AFUNC(); } \
|
||||
} AFUNC ## _dtor_instance_; \
|
||||
}
|
||||
# define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC)
|
||||
#endif
|
||||
|
||||
|
@ -371,8 +371,8 @@ class Q_CORE_EXPORT QVariant
|
||||
|
||||
protected:
|
||||
friend inline bool qvariant_cast_helper(const QVariant &, QVariant::Type, void *);
|
||||
friend int qRegisterGuiVariant();
|
||||
friend int qUnregisterGuiVariant();
|
||||
friend void qRegisterGuiVariant();
|
||||
friend void qUnregisterGuiVariant();
|
||||
friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &);
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant &);
|
||||
|
@ -126,8 +126,8 @@ QWindow *QGuiApplicationPrivate::focus_window = 0;
|
||||
Q_GLOBAL_STATIC(QMutex, applicationFontMutex)
|
||||
QFont *QGuiApplicationPrivate::app_font = 0;
|
||||
|
||||
extern int qRegisterGuiVariant();
|
||||
extern int qUnregisterGuiVariant();
|
||||
extern void qRegisterGuiVariant();
|
||||
extern void qUnregisterGuiVariant();
|
||||
extern void qInitDrawhelperAsm();
|
||||
extern void qInitImageConversions();
|
||||
|
||||
|
@ -486,20 +486,18 @@ static const QMetaTypeInterface qVariantGuiHelper[] = {
|
||||
#undef QT_IMPL_METATYPEINTERFACE_GUI_TYPES
|
||||
|
||||
static const QVariant::Handler *qt_guivariant_last_handler = 0;
|
||||
int qRegisterGuiVariant()
|
||||
void qRegisterGuiVariant()
|
||||
{
|
||||
qt_guivariant_last_handler = QVariant::handler;
|
||||
QVariant::handler = &qt_gui_variant_handler;
|
||||
qMetaTypeGuiHelper = qVariantGuiHelper;
|
||||
return 1;
|
||||
}
|
||||
Q_CONSTRUCTOR_FUNCTION(qRegisterGuiVariant)
|
||||
|
||||
int qUnregisterGuiVariant()
|
||||
void qUnregisterGuiVariant()
|
||||
{
|
||||
QVariant::handler = qt_guivariant_last_handler;
|
||||
qMetaTypeGuiHelper = 0;
|
||||
return 1;
|
||||
}
|
||||
Q_DESTRUCTOR_FUNCTION(qUnregisterGuiVariant)
|
||||
|
||||
|
@ -2166,14 +2166,12 @@ QDataStream &operator>>(QDataStream &stream, QPaintBufferCacheEntryV2 &entry)
|
||||
return stream >> entry.bits;
|
||||
}
|
||||
|
||||
static int qRegisterPaintBufferMetaTypes()
|
||||
static void qRegisterPaintBufferMetaTypes()
|
||||
{
|
||||
qRegisterMetaType<QPaintBufferCacheEntry>();
|
||||
qRegisterMetaTypeStreamOperators<QPaintBufferCacheEntry>("QPaintBufferCacheEntry");
|
||||
qRegisterMetaType<QPaintBufferCacheEntryV2>();
|
||||
qRegisterMetaTypeStreamOperators<QPaintBufferCacheEntryV2>("QPaintBufferCacheEntryV2");
|
||||
|
||||
return 0; // something
|
||||
}
|
||||
|
||||
Q_CONSTRUCTOR_FUNCTION(qRegisterPaintBufferMetaTypes)
|
||||
|
@ -64,18 +64,17 @@ template<> Q_INLINE_TEMPLATE QQuaternion _q_interpolate(const QQuaternion &f,con
|
||||
return QQuaternion::slerp(f, t, progress);
|
||||
}
|
||||
|
||||
static int qRegisterGuiGetInterpolator()
|
||||
static void qRegisterGuiGetInterpolator()
|
||||
{
|
||||
qRegisterAnimationInterpolator<QColor>(_q_interpolateVariant<QColor>);
|
||||
qRegisterAnimationInterpolator<QVector2D>(_q_interpolateVariant<QVector2D>);
|
||||
qRegisterAnimationInterpolator<QVector3D>(_q_interpolateVariant<QVector3D>);
|
||||
qRegisterAnimationInterpolator<QVector4D>(_q_interpolateVariant<QVector4D>);
|
||||
qRegisterAnimationInterpolator<QQuaternion>(_q_interpolateVariant<QQuaternion>);
|
||||
return 1;
|
||||
}
|
||||
Q_CONSTRUCTOR_FUNCTION(qRegisterGuiGetInterpolator)
|
||||
|
||||
static int qUnregisterGuiGetInterpolator()
|
||||
static void qUnregisterGuiGetInterpolator()
|
||||
{
|
||||
// casts required by Sun CC 5.5
|
||||
qRegisterAnimationInterpolator<QColor>(
|
||||
@ -88,8 +87,6 @@ static int qUnregisterGuiGetInterpolator()
|
||||
(QVariant (*)(const QVector4D &, const QVector4D &, qreal))0);
|
||||
qRegisterAnimationInterpolator<QQuaternion>(
|
||||
(QVariant (*)(const QQuaternion &, const QQuaternion &, qreal))0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
Q_DESTRUCTOR_FUNCTION(qUnregisterGuiGetInterpolator)
|
||||
|
||||
|
@ -859,8 +859,8 @@ QApplication::QApplication(Display *dpy, int &argc, char **argv,
|
||||
#endif // Q_WS_X11
|
||||
|
||||
#ifndef QT_NO_STATEMACHINE
|
||||
extern int qRegisterGuiStateMachine();
|
||||
extern int qUnregisterGuiStateMachine();
|
||||
void qRegisterGuiStateMachine();
|
||||
void qUnregisterGuiStateMachine();
|
||||
#endif
|
||||
|
||||
/*!
|
||||
|
@ -151,19 +151,17 @@ static const QMetaTypeInterface qVariantWidgetsHelper[] = {
|
||||
|
||||
extern Q_GUI_EXPORT const QVariant::Handler *qt_widgets_variant_handler;
|
||||
|
||||
int qRegisterWidgetsVariant()
|
||||
void qRegisterWidgetsVariant()
|
||||
{
|
||||
qt_widgets_variant_handler = &widgets_handler;
|
||||
qMetaTypeWidgetsHelper = qVariantWidgetsHelper;
|
||||
return 1;
|
||||
}
|
||||
Q_CONSTRUCTOR_FUNCTION(qRegisterWidgetsVariant)
|
||||
|
||||
int qUnregisterWidgetsVariant()
|
||||
void qUnregisterWidgetsVariant()
|
||||
{
|
||||
qt_widgets_variant_handler = 0;
|
||||
qMetaTypeWidgetsHelper = 0;
|
||||
return 1;
|
||||
}
|
||||
Q_DESTRUCTOR_FUNCTION(qUnregisterWidgetsVariant)
|
||||
|
||||
|
@ -474,18 +474,16 @@ const QStateMachinePrivate::Handler qt_gui_statemachine_handler = {
|
||||
};
|
||||
|
||||
static const QStateMachinePrivate::Handler *qt_guistatemachine_last_handler = 0;
|
||||
int qRegisterGuiStateMachine()
|
||||
void qRegisterGuiStateMachine()
|
||||
{
|
||||
qt_guistatemachine_last_handler = QStateMachinePrivate::handler;
|
||||
QStateMachinePrivate::handler = &qt_gui_statemachine_handler;
|
||||
return 1;
|
||||
}
|
||||
Q_CONSTRUCTOR_FUNCTION(qRegisterGuiStateMachine)
|
||||
|
||||
int qUnregisterGuiStateMachine()
|
||||
void qUnregisterGuiStateMachine()
|
||||
{
|
||||
QStateMachinePrivate::handler = qt_guistatemachine_last_handler;
|
||||
return 1;
|
||||
}
|
||||
Q_DESTRUCTOR_FUNCTION(qUnregisterGuiStateMachine)
|
||||
|
||||
|
@ -53,6 +53,7 @@ private slots:
|
||||
void qtry();
|
||||
void checkptr();
|
||||
void qstaticassert();
|
||||
void qConstructorFunction();
|
||||
};
|
||||
|
||||
void tst_QGlobal::qIsNull()
|
||||
@ -353,5 +354,17 @@ void tst_QGlobal::qstaticassert()
|
||||
QVERIFY(true); // if the test compiles it has passed.
|
||||
}
|
||||
|
||||
static int qConstructorFunctionValue;
|
||||
static void qConstructorFunctionCtor()
|
||||
{
|
||||
qConstructorFunctionValue = 123;
|
||||
}
|
||||
Q_CONSTRUCTOR_FUNCTION(qConstructorFunctionCtor);
|
||||
|
||||
void tst_QGlobal::qConstructorFunction()
|
||||
{
|
||||
QCOMPARE(qConstructorFunctionValue, 123);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QGlobal)
|
||||
#include "tst_qglobal.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user