From a225bddf67f4786c845193630d4ab20b99a2fc3a Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 28 Apr 2017 13:25:50 +0200 Subject: Update the alloca() support in QtQml qv4alloca_p.h dates from April 2013 and contained just the #includes, whereas the code in qtqmlglobal_p.h was introduced earlier this year in commit 87f016ea9eddc874d5cba7d79d0a487d5ef61761. This commit moves the macros to qv4alloca_p.h and centralizes the support there. This also updates the #include detection mechanism, by using QT_CONFIG(alloca_h) to determine which #include to use. See commit 98c1d516b7f7624f7fcd7b9046783e3903a6a42b in qtbase for more details. Task-number: QTBUG-59700 Started-by: Thiago Macieira Change-Id: Icd0e0d4b27cb4e5eb892fffd14b4b38005ce2ecb Reviewed-by: Thiago Macieira Reviewed-by: Lars Knoll --- src/qml/jsruntime/jsruntime.pri | 1 + src/qml/jsruntime/qv4alloca_p.h | 53 +++++++++++++++++++++++++++++++++++++---- src/qml/qtqmlglobal_p.h | 40 ------------------------------- 3 files changed, 49 insertions(+), 45 deletions(-) diff --git a/src/qml/jsruntime/jsruntime.pri b/src/qml/jsruntime/jsruntime.pri index 955cf585e4..76ac8d4a91 100644 --- a/src/qml/jsruntime/jsruntime.pri +++ b/src/qml/jsruntime/jsruntime.pri @@ -46,6 +46,7 @@ SOURCES += \ HEADERS += \ $$PWD/qv4global_p.h \ + $$PWD/qv4alloca_p.h \ $$PWD/qv4engine_p.h \ $$PWD/qv4context_p.h \ $$PWD/qv4math_p.h \ diff --git a/src/qml/jsruntime/qv4alloca_p.h b/src/qml/jsruntime/qv4alloca_p.h index 2f486988c1..c21878fa42 100644 --- a/src/qml/jsruntime/qv4alloca_p.h +++ b/src/qml/jsruntime/qv4alloca_p.h @@ -51,15 +51,58 @@ // We mean it. // -#include +#include -#if defined(Q_OS_WIN) +#if QT_CONFIG(alloca_h) +# include +#elif QT_CONFIG(alloca_malloc_h) # include -# ifndef __GNUC__ +// This does not matter unless compiling in strict standard mode. +# ifdef Q_OS_WIN # define alloca _alloca # endif -#elif !defined(Q_OS_BSD4) || defined(Q_OS_DARWIN) -# include +#else +# include +#endif + +// Define Q_ALLOCA_VAR macro to be used instead of #ifdeffing +// the occurrences of alloca() in case it's not supported. +// Q_ALLOCA_DECLARE and Q_ALLOCA_ASSIGN macros separate +// memory allocation from the declaration and RAII. +#define Q_ALLOCA_VAR(type, name, size) \ + Q_ALLOCA_DECLARE(type, name); \ + Q_ALLOCA_ASSIGN(type, name, size) + +#if QT_CONFIG(alloca) + +#define Q_ALLOCA_DECLARE(type, name) \ + type *name = 0 + +#define Q_ALLOCA_ASSIGN(type, name, size) \ + name = static_cast(alloca(size)) + +#else +QT_BEGIN_NAMESPACE +class Qt_AllocaWrapper +{ +public: + Qt_AllocaWrapper() { m_data = 0; } + ~Qt_AllocaWrapper() { free(m_data); } + void *data() { return m_data; } + void allocate(int size) { m_data = malloc(size); } +private: + void *m_data; +}; +QT_END_NAMESPACE + +#define Q_ALLOCA_DECLARE(type, name) \ + Qt_AllocaWrapper _qt_alloca_##name; \ + type *name = nullptr + +#define Q_ALLOCA_ASSIGN(type, name, size) \ + _qt_alloca_##name.allocate(size); \ + name = static_cast(_qt_alloca_##name.data()) + #endif #endif diff --git a/src/qml/qtqmlglobal_p.h b/src/qml/qtqmlglobal_p.h index 6547274d09..e9834ffc4c 100644 --- a/src/qml/qtqmlglobal_p.h +++ b/src/qml/qtqmlglobal_p.h @@ -55,46 +55,6 @@ #include #include -// Define Q_ALLOCA_VAR macro to be used instead of #ifdeffing -// the occurrences of alloca() in case it's not supported. -// Q_ALLOCA_DECLARE and Q_ALLOCA_ASSIGN macros separate -// memory allocation from the declaration and RAII. -#define Q_ALLOCA_VAR(type, name, size) \ - Q_ALLOCA_DECLARE(type, name); \ - Q_ALLOCA_ASSIGN(type, name, size) - -#if defined(QT_BOOTSTRAPPED) || QT_CONFIG(alloca) - -#define Q_ALLOCA_DECLARE(type, name) \ - type *name = 0 - -#define Q_ALLOCA_ASSIGN(type, name, size) \ - name = static_cast(alloca(size)) - -#else -QT_BEGIN_NAMESPACE -class Qt_AllocaWrapper -{ -public: - Qt_AllocaWrapper() { m_data = 0; } - ~Qt_AllocaWrapper() { free(m_data); } - void *data() { return m_data; } - void allocate(int size) { m_data = malloc(size); } -private: - void *m_data; -}; -QT_END_NAMESPACE - -#define Q_ALLOCA_DECLARE(type, name) \ - Qt_AllocaWrapper _qt_alloca_##name; \ - type *name = 0 - -#define Q_ALLOCA_ASSIGN(type, name, size) \ - _qt_alloca_##name.allocate(size); \ - name = static_cast(_qt_alloca_##name.data()) - -#endif - #define Q_QML_PRIVATE_EXPORT Q_QML_EXPORT #endif // QTQMLGLOBAL_P_H -- cgit v1.2.3