OSDN Git Service

Correct project name references in mingwrt source files.
[mingw/mingw-org-wsl.git] / mingwrt / include / alloca.h
1 /*
2  * alloca.h
3  *
4  * Declarations for the alloca() function API, conforming to both GNU and
5  * Microsoft's implementation conventions.
6  *
7  *
8  * $Id$
9  *
10  * Written by Keith Marshall <keith@users.osdn.me>
11  * Copyright (C) 2018, 2019, 2022, MinGW.OSDN Project
12  *
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the "Software"),
16  * to deal in the Software without restriction, including without limitation
17  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18  * and/or sell copies of the Software, and to permit persons to whom the
19  * Software is furnished to do so, subject to the following conditions:
20  *
21  * The above copyright notice and this permission notice (including the next
22  * paragraph) shall be included in all copies or substantial portions of the
23  * Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31  * DEALINGS IN THE SOFTWARE.
32  *
33  */
34 #ifndef _ALLOCA_H
35 #define _ALLOCA_H
36 /* Microsoft requires the alloca() API to be declared in <malloc.h>;
37  * GNU declares it in <alloca.h>, with default inclusion by <stdlib.h>
38  * when !__STRICT_ANSI__.  To achieve compatibility with both, we will
39  * define it in the GNU manner, conditionally including this file when
40  * reading <stdlib.h>, and UNCONDITIONALLY including it in <malloc.h>
41  */
42 #ifdef __GNUC__
43 #pragma GCC system_header
44 /* This implementation is unsupported, for any compiler other than GCC,
45  * (which is the standard MinGW compiler, in any case); all MinGW source
46  * may assume that <_mingw.h> has been included, so ensure that it is.
47  */
48 #include <_mingw.h>
49
50 /* We must also ensure that the "size_t" type definition is in scope;
51  * we may guarantee this, by selective inclusion from <stddef.h>
52  */
53 #define __need_size_t
54 #include <stddef.h>
55
56 _BEGIN_C_DECLS
57
58 /* Regardless of whether a GNU compatible alloca() implementation, or
59  * a MSVC compatible _alloca() implementation is required, it is always
60  * appropriate to delegate the call to GCC's __builtin_alloca(); we use
61  * a preprocessor macro, rather than an in-line function implementation,
62  * to delegate the call, because:
63  *
64  *  - older GCC versions do not permit in-lining of __builtin_alloca();
65  *
66  *  - more recent GCC versions generate marginally better code, for the
67  *    macro expansion, than they do for an in-line function expansion,
68  *    when compiling at optimization level -O0; (both implementation
69  *    choices result in identical code, at -O1 and higher);
70  *
71  *  - the usual argument for C++ namespace qualification, in the case of
72  *    an in-line function implementation, is unwarranted for alloca().
73  *
74  */
75 #if defined _GNU_SOURCE || ! defined _NO_OLDNAMES
76 /* This is the GNU standard API; it is also compatible with Microsoft's
77  * original, but now deprecated, OLDNAMES naming convention.
78  */
79 #undef alloca
80 void *alloca( size_t );
81 #define alloca( __request )  __builtin_alloca( __request )
82 #endif  /* _GNU_SOURCE || !_NO_OLDNAMES */
83
84 /* This represents the same API, but conforms to Microsoft's currently
85  * preferred naming convention.
86  */
87 #undef _alloca
88 void *_alloca( size_t );
89 #define _alloca( __request )  __builtin_alloca( __request )
90
91 _END_C_DECLS
92
93 #endif  /* __GNUC__ */
94 #endif  /* !_ALLOCA_H: $RCSfile$: end of file */