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:
Jędrzej Nowacki 2011-11-28 15:40:35 +01:00 committed by Qt by Nokia
parent 389538c2e7
commit e650859dc9
10 changed files with 40 additions and 49 deletions

View File

@ -373,23 +373,6 @@ namespace QT_NAMESPACE {}
Should be sorted most to least authoritative. 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 */ /* Symantec C++ is now Digital Mars */
#if defined(__DMC__) || defined(__SC__) #if defined(__DMC__) || defined(__SC__)
# define Q_CC_SYM # define Q_CC_SYM
@ -827,17 +810,23 @@ namespace QT_NAMESPACE {}
#ifndef Q_CONSTRUCTOR_FUNCTION #ifndef Q_CONSTRUCTOR_FUNCTION
# define Q_CONSTRUCTOR_FUNCTION0(AFUNC) \ # 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) # define Q_CONSTRUCTOR_FUNCTION(AFUNC) Q_CONSTRUCTOR_FUNCTION0(AFUNC)
#endif #endif
#ifndef Q_DESTRUCTOR_FUNCTION #ifndef Q_DESTRUCTOR_FUNCTION
# define Q_DESTRUCTOR_FUNCTION0(AFUNC) \ # define Q_DESTRUCTOR_FUNCTION0(AFUNC) \
class AFUNC ## __dest_class__ { \ namespace { \
public: \ static const struct AFUNC ## _dtor_class_ { \
inline AFUNC ## __dest_class__() { } \ inline AFUNC ## _dtor_class_() { } \
inline ~ AFUNC ## __dest_class__() { AFUNC(); } \ inline ~ AFUNC ## _dtor_class_() { AFUNC(); } \
} AFUNC ## __dest_instance__; } AFUNC ## _dtor_instance_; \
}
# define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC) # define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC)
#endif #endif

View File

@ -371,8 +371,8 @@ class Q_CORE_EXPORT QVariant
protected: protected:
friend inline bool qvariant_cast_helper(const QVariant &, QVariant::Type, void *); friend inline bool qvariant_cast_helper(const QVariant &, QVariant::Type, void *);
friend int qRegisterGuiVariant(); friend void qRegisterGuiVariant();
friend int qUnregisterGuiVariant(); friend void qUnregisterGuiVariant();
friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &); friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &);
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant &); friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant &);

View File

@ -126,8 +126,8 @@ QWindow *QGuiApplicationPrivate::focus_window = 0;
Q_GLOBAL_STATIC(QMutex, applicationFontMutex) Q_GLOBAL_STATIC(QMutex, applicationFontMutex)
QFont *QGuiApplicationPrivate::app_font = 0; QFont *QGuiApplicationPrivate::app_font = 0;
extern int qRegisterGuiVariant(); extern void qRegisterGuiVariant();
extern int qUnregisterGuiVariant(); extern void qUnregisterGuiVariant();
extern void qInitDrawhelperAsm(); extern void qInitDrawhelperAsm();
extern void qInitImageConversions(); extern void qInitImageConversions();

View File

@ -486,20 +486,18 @@ static const QMetaTypeInterface qVariantGuiHelper[] = {
#undef QT_IMPL_METATYPEINTERFACE_GUI_TYPES #undef QT_IMPL_METATYPEINTERFACE_GUI_TYPES
static const QVariant::Handler *qt_guivariant_last_handler = 0; static const QVariant::Handler *qt_guivariant_last_handler = 0;
int qRegisterGuiVariant() void qRegisterGuiVariant()
{ {
qt_guivariant_last_handler = QVariant::handler; qt_guivariant_last_handler = QVariant::handler;
QVariant::handler = &qt_gui_variant_handler; QVariant::handler = &qt_gui_variant_handler;
qMetaTypeGuiHelper = qVariantGuiHelper; qMetaTypeGuiHelper = qVariantGuiHelper;
return 1;
} }
Q_CONSTRUCTOR_FUNCTION(qRegisterGuiVariant) Q_CONSTRUCTOR_FUNCTION(qRegisterGuiVariant)
int qUnregisterGuiVariant() void qUnregisterGuiVariant()
{ {
QVariant::handler = qt_guivariant_last_handler; QVariant::handler = qt_guivariant_last_handler;
qMetaTypeGuiHelper = 0; qMetaTypeGuiHelper = 0;
return 1;
} }
Q_DESTRUCTOR_FUNCTION(qUnregisterGuiVariant) Q_DESTRUCTOR_FUNCTION(qUnregisterGuiVariant)

View File

@ -2166,14 +2166,12 @@ QDataStream &operator>>(QDataStream &stream, QPaintBufferCacheEntryV2 &entry)
return stream >> entry.bits; return stream >> entry.bits;
} }
static int qRegisterPaintBufferMetaTypes() static void qRegisterPaintBufferMetaTypes()
{ {
qRegisterMetaType<QPaintBufferCacheEntry>(); qRegisterMetaType<QPaintBufferCacheEntry>();
qRegisterMetaTypeStreamOperators<QPaintBufferCacheEntry>("QPaintBufferCacheEntry"); qRegisterMetaTypeStreamOperators<QPaintBufferCacheEntry>("QPaintBufferCacheEntry");
qRegisterMetaType<QPaintBufferCacheEntryV2>(); qRegisterMetaType<QPaintBufferCacheEntryV2>();
qRegisterMetaTypeStreamOperators<QPaintBufferCacheEntryV2>("QPaintBufferCacheEntryV2"); qRegisterMetaTypeStreamOperators<QPaintBufferCacheEntryV2>("QPaintBufferCacheEntryV2");
return 0; // something
} }
Q_CONSTRUCTOR_FUNCTION(qRegisterPaintBufferMetaTypes) Q_CONSTRUCTOR_FUNCTION(qRegisterPaintBufferMetaTypes)

View File

@ -64,18 +64,17 @@ template<> Q_INLINE_TEMPLATE QQuaternion _q_interpolate(const QQuaternion &f,con
return QQuaternion::slerp(f, t, progress); return QQuaternion::slerp(f, t, progress);
} }
static int qRegisterGuiGetInterpolator() static void qRegisterGuiGetInterpolator()
{ {
qRegisterAnimationInterpolator<QColor>(_q_interpolateVariant<QColor>); qRegisterAnimationInterpolator<QColor>(_q_interpolateVariant<QColor>);
qRegisterAnimationInterpolator<QVector2D>(_q_interpolateVariant<QVector2D>); qRegisterAnimationInterpolator<QVector2D>(_q_interpolateVariant<QVector2D>);
qRegisterAnimationInterpolator<QVector3D>(_q_interpolateVariant<QVector3D>); qRegisterAnimationInterpolator<QVector3D>(_q_interpolateVariant<QVector3D>);
qRegisterAnimationInterpolator<QVector4D>(_q_interpolateVariant<QVector4D>); qRegisterAnimationInterpolator<QVector4D>(_q_interpolateVariant<QVector4D>);
qRegisterAnimationInterpolator<QQuaternion>(_q_interpolateVariant<QQuaternion>); qRegisterAnimationInterpolator<QQuaternion>(_q_interpolateVariant<QQuaternion>);
return 1;
} }
Q_CONSTRUCTOR_FUNCTION(qRegisterGuiGetInterpolator) Q_CONSTRUCTOR_FUNCTION(qRegisterGuiGetInterpolator)
static int qUnregisterGuiGetInterpolator() static void qUnregisterGuiGetInterpolator()
{ {
// casts required by Sun CC 5.5 // casts required by Sun CC 5.5
qRegisterAnimationInterpolator<QColor>( qRegisterAnimationInterpolator<QColor>(
@ -88,8 +87,6 @@ static int qUnregisterGuiGetInterpolator()
(QVariant (*)(const QVector4D &, const QVector4D &, qreal))0); (QVariant (*)(const QVector4D &, const QVector4D &, qreal))0);
qRegisterAnimationInterpolator<QQuaternion>( qRegisterAnimationInterpolator<QQuaternion>(
(QVariant (*)(const QQuaternion &, const QQuaternion &, qreal))0); (QVariant (*)(const QQuaternion &, const QQuaternion &, qreal))0);
return 1;
} }
Q_DESTRUCTOR_FUNCTION(qUnregisterGuiGetInterpolator) Q_DESTRUCTOR_FUNCTION(qUnregisterGuiGetInterpolator)

View File

@ -859,8 +859,8 @@ QApplication::QApplication(Display *dpy, int &argc, char **argv,
#endif // Q_WS_X11 #endif // Q_WS_X11
#ifndef QT_NO_STATEMACHINE #ifndef QT_NO_STATEMACHINE
extern int qRegisterGuiStateMachine(); void qRegisterGuiStateMachine();
extern int qUnregisterGuiStateMachine(); void qUnregisterGuiStateMachine();
#endif #endif
/*! /*!

View File

@ -151,19 +151,17 @@ static const QMetaTypeInterface qVariantWidgetsHelper[] = {
extern Q_GUI_EXPORT const QVariant::Handler *qt_widgets_variant_handler; extern Q_GUI_EXPORT const QVariant::Handler *qt_widgets_variant_handler;
int qRegisterWidgetsVariant() void qRegisterWidgetsVariant()
{ {
qt_widgets_variant_handler = &widgets_handler; qt_widgets_variant_handler = &widgets_handler;
qMetaTypeWidgetsHelper = qVariantWidgetsHelper; qMetaTypeWidgetsHelper = qVariantWidgetsHelper;
return 1;
} }
Q_CONSTRUCTOR_FUNCTION(qRegisterWidgetsVariant) Q_CONSTRUCTOR_FUNCTION(qRegisterWidgetsVariant)
int qUnregisterWidgetsVariant() void qUnregisterWidgetsVariant()
{ {
qt_widgets_variant_handler = 0; qt_widgets_variant_handler = 0;
qMetaTypeWidgetsHelper = 0; qMetaTypeWidgetsHelper = 0;
return 1;
} }
Q_DESTRUCTOR_FUNCTION(qUnregisterWidgetsVariant) Q_DESTRUCTOR_FUNCTION(qUnregisterWidgetsVariant)

View File

@ -474,18 +474,16 @@ const QStateMachinePrivate::Handler qt_gui_statemachine_handler = {
}; };
static const QStateMachinePrivate::Handler *qt_guistatemachine_last_handler = 0; static const QStateMachinePrivate::Handler *qt_guistatemachine_last_handler = 0;
int qRegisterGuiStateMachine() void qRegisterGuiStateMachine()
{ {
qt_guistatemachine_last_handler = QStateMachinePrivate::handler; qt_guistatemachine_last_handler = QStateMachinePrivate::handler;
QStateMachinePrivate::handler = &qt_gui_statemachine_handler; QStateMachinePrivate::handler = &qt_gui_statemachine_handler;
return 1;
} }
Q_CONSTRUCTOR_FUNCTION(qRegisterGuiStateMachine) Q_CONSTRUCTOR_FUNCTION(qRegisterGuiStateMachine)
int qUnregisterGuiStateMachine() void qUnregisterGuiStateMachine()
{ {
QStateMachinePrivate::handler = qt_guistatemachine_last_handler; QStateMachinePrivate::handler = qt_guistatemachine_last_handler;
return 1;
} }
Q_DESTRUCTOR_FUNCTION(qUnregisterGuiStateMachine) Q_DESTRUCTOR_FUNCTION(qUnregisterGuiStateMachine)

View File

@ -53,6 +53,7 @@ private slots:
void qtry(); void qtry();
void checkptr(); void checkptr();
void qstaticassert(); void qstaticassert();
void qConstructorFunction();
}; };
void tst_QGlobal::qIsNull() void tst_QGlobal::qIsNull()
@ -353,5 +354,17 @@ void tst_QGlobal::qstaticassert()
QVERIFY(true); // if the test compiles it has passed. 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) QTEST_MAIN(tst_QGlobal)
#include "tst_qglobal.moc" #include "tst_qglobal.moc"