alloca: detect whether alloca.h exists

We can't depend on QT_HAS_INCLUDE for such an important functionality in
QtQml, so detect at configure time.

alloca() is not a POSIX function (it apparently first appeared in
Version 32V AT&T UNIX), so the actual header that defines it varies from
system to system. Clearly, if alloca.h exists, that's the one, so we try
it first. On most other systems that don't define it, it's in stdlib.h.
The only exception is Windows, where it's actually defined in malloc.h.

Task-number: QTBUG-59700
Started-by: Thiago Macieira <thiago.macieira@intel.com>
Change-Id: Icd0e0d4b27cb4e5eb892fffd14b4b2b389a4684e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Oswald Buddenhagen 2017-04-28 13:27:43 +02:00
parent fe04eade55
commit 98c1d516b7
3 changed files with 42 additions and 6 deletions

View File

@ -37,10 +37,17 @@
**
****************************************************************************/
#include <alloca.h>
#if defined(USE_ALLOCA_H)
# include <alloca.h>
# ifdef __QNXNTO__
// extra include needed in QNX7 to define NULL for the alloca() macro
#include <stdlib.h>
# include <stddef.h>
# endif
#elif defined(USE_MALLOC_H)
# include <malloc.h>
#else
# include <stdlib.h>
#endif
int main(int, char **)
{

View File

@ -406,11 +406,23 @@
"type": "compile",
"test": "unix/posix_fallocate"
},
"alloca": {
"label": "alloca()",
"alloca_stdlib_h": {
"label": "alloca() in stdlib.h",
"type": "compile",
"test": "common/alloca"
},
"alloca_h": {
"label": "alloca() in alloca.h",
"type": "compile",
"test": "common/alloca",
"args": "DEFINES+=USE_ALLOCA_H"
},
"alloca_malloc_h": {
"label": "alloca() in malloc.h",
"type": "compile",
"test": "common/alloca",
"args": "DEFINES+=USE_MALLOC_H"
},
"stack_protector": {
"label": "stack protection",
"type": "compilerSupportsFlag",
@ -900,9 +912,19 @@
"condition": "tests.posix_fallocate",
"output": [ "privateFeature" ]
},
"alloca_h": {
"label": "alloca.h",
"condition": "tests.alloca_h",
"output": [ "privateFeature" ]
},
"alloca_malloc_h": {
"label": "alloca() in malloc.h",
"condition": "!features.alloca_h && tests.alloca_malloc_h",
"output": [ "privateFeature" ]
},
"alloca": {
"label": "alloca()",
"condition": "tests.alloca",
"condition": "features.alloca_h || features.alloca_malloc_h || tests.alloca_stdlib_h",
"output": [ "privateFeature" ]
},
"stack-protector-strong": {

View File

@ -68,6 +68,13 @@
#define QT_CRYPTOGRAPHICHASH_ONLY_SHA1
#define QT_NO_DATASTREAM
#define QT_FEATURE_alloca 1
#define QT_FEATURE_alloca_h -1
#ifdef _WIN32
# define QT_FEATURE_alloca_malloc_h 1
#else
# define QT_FEATURE_alloca_malloc_h -1
#endif
#define QT_FEATURE_iconv -1
#define QT_FEATURE_icu -1
#define QT_FEATURE_journald -1