Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qv4alloca_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
5#ifndef QV4_ALLOCA_H
6#define QV4_ALLOCA_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/private/qglobal_p.h>
20
21#include <stdlib.h>
22#if __has_include(<alloca.h>)
23# include <alloca.h>
24#endif
25#if __has_include(<malloc.h>)
26# include <malloc.h>
27#endif
28
29#ifdef Q_CC_MSVC
30// This does not matter unless compiling in strict standard mode.
31# define alloca _alloca
32#endif
33
34// Define Q_ALLOCA_VAR macro to be used instead of #ifdeffing
35// the occurrences of alloca() in case it's not supported.
36// Q_ALLOCA_DECLARE and Q_ALLOCA_ASSIGN macros separate
37// memory allocation from the declaration and RAII.
38#define Q_ALLOCA_VAR(type, name, size)
39 Q_ALLOCA_DECLARE(type, name);
40 Q_ALLOCA_ASSIGN(type, name, size)
41
42#ifdef alloca
43
44#define Q_ALLOCA_DECLARE(type, name)
45 type *name = 0
46
47#define Q_ALLOCA_ASSIGN(type, name, size)
48 name = static_cast<type*>(alloca(size))
49
50#else
51# include <memory>
52
53#define Q_ALLOCA_DECLARE(type, name)
54 std::unique_ptr<char[]> _qt_alloca_##name;
55 type *name = nullptr
56
57#define Q_ALLOCA_ASSIGN(type, name, size)
58 do {
59 _qt_alloca_##name.reset(new char[size]);
60 name = reinterpret_cast<type*>(_qt_alloca_##name.get());
61 } while (false)
62
63#endif
64
65#endif
#define __has_include(x)
#define Q_ALLOCA_ASSIGN(type, name, size)
Definition qv4alloca_p.h:57
#define Q_ALLOCA_DECLARE(type, name)
Definition qv4alloca_p.h:53