aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@qt.io>2017-04-28 13:25:50 +0200
committerJani Heikkinen <jani.heikkinen@qt.io>2017-05-10 11:32:47 +0000
commita225bddf67f4786c845193630d4ab20b99a2fc3a (patch)
tree032b2bed9711778d2e5fbab954844c6a18db9b0a
parent9921b48c83490b450241d6c172f1375ab4efb6b1 (diff)
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 <thiago.macieira@intel.com> Change-Id: Icd0e0d4b27cb4e5eb892fffd14b4b38005ce2ecb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/qml/jsruntime/jsruntime.pri1
-rw-r--r--src/qml/jsruntime/qv4alloca_p.h53
-rw-r--r--src/qml/qtqmlglobal_p.h40
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 <qglobal.h>
+#include <QtCore/private/qglobal_p.h>
-#if defined(Q_OS_WIN)
+#if QT_CONFIG(alloca_h)
+# include <alloca.h>
+#elif QT_CONFIG(alloca_malloc_h)
# include <malloc.h>
-# 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 <alloca.h>
+#else
+# include <stdlib.h>
+#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<type*>(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<type*>(_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 <QtQml/private/qtqml-config_p.h>
#include <QtQml/qtqmlglobal.h>
-// 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<type*>(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<type*>(_qt_alloca_##name.data())
-
-#endif
-
#define Q_QML_PRIVATE_EXPORT Q_QML_EXPORT
#endif // QTQMLGLOBAL_P_H