exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / malloc.in.h
blob3ca364cbe2c445a32b654d03baee6e631812197e
1 /* Substitute for and wrapper around <malloc.h>.
2 Copyright (C) 2020-2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 #if __GNUC__ >= 3
18 @PRAGMA_SYSTEM_HEADER@
19 #endif
20 @PRAGMA_COLUMNS@
22 #if defined _GL_ALREADY_INCLUDING_MALLOC_H
23 /* Special invocation convention:
24 - On Android we have a sequence of nested includes
25 <malloc.h> -> <stdio.h> -> <sys/stat.h> -> <time.h> -> <sys/time.h> ->
26 <sys/select.h> -> <signal.h> -> <pthread.h> -> <stdlib.h> -> "malloc.h"
27 In this situation, in C++ mode, the declaration of memalign might be used
28 before it actually occurs. */
30 #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_MALLOC_H@
32 #else
33 /* Normal invocation convention. */
35 #ifndef _@GUARD_PREFIX@_MALLOC_H
37 #define _GL_ALREADY_INCLUDING_MALLOC_H
39 /* The include_next requires a split double-inclusion guard. */
40 #if @HAVE_MALLOC_H@
41 # @INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_MALLOC_H@
42 #endif
44 #undef _GL_ALREADY_INCLUDING_MALLOC_H
46 #ifndef _@GUARD_PREFIX@_MALLOC_H
47 #define _@GUARD_PREFIX@_MALLOC_H
49 /* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_NOTHROW,
50 GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
51 #if !_GL_CONFIG_H_INCLUDED
52 #error "Please include config.h first."
53 #endif
55 /* Solaris declares memalign() in <stdlib.h>, not in <malloc.h>. */
56 #if defined __sun || defined __hpux
57 # include <stdlib.h>
58 #endif
60 /* Get size_t. */
61 #include <stddef.h>
64 /* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
66 #ifndef _GL_ATTRIBUTE_NOTHROW
67 # if defined __cplusplus
68 # if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major >= 4
69 # if __cplusplus >= 201103L
70 # define _GL_ATTRIBUTE_NOTHROW noexcept (true)
71 # else
72 # define _GL_ATTRIBUTE_NOTHROW throw ()
73 # endif
74 # else
75 # define _GL_ATTRIBUTE_NOTHROW
76 # endif
77 # else
78 # if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__
79 # define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
80 # else
81 # define _GL_ATTRIBUTE_NOTHROW
82 # endif
83 # endif
84 #endif
86 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
88 /* The definition of _GL_WARN_ON_USE is copied here. */
91 /* Make _GL_ATTRIBUTE_DEALLOC_FREE work, even though <stdlib.h> may not have
92 been included yet. */
93 #if @GNULIB_FREE_POSIX@
94 # if (@REPLACE_FREE@ && !defined free \
95 && !(defined __cplusplus && defined GNULIB_NAMESPACE))
96 /* We can't do '#define free rpl_free' here. */
97 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
98 _GL_EXTERN_C void rpl_free (void *) _GL_ATTRIBUTE_NOTHROW;
99 # else
100 _GL_EXTERN_C void rpl_free (void *);
101 # endif
102 # undef _GL_ATTRIBUTE_DEALLOC_FREE
103 # define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1)
104 # else
105 # if defined _MSC_VER && !defined free
106 _GL_EXTERN_C
107 # if defined _DLL
108 __declspec (dllimport)
109 # endif
110 void __cdecl free (void *);
111 # else
112 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
113 _GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW;
114 # else
115 _GL_EXTERN_C void free (void *);
116 # endif
117 # endif
118 # endif
119 #else
120 # if defined _MSC_VER && !defined free
121 _GL_EXTERN_C
122 # if defined _DLL
123 __declspec (dllimport)
124 # endif
125 void __cdecl free (void *);
126 # else
127 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
128 _GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW;
129 # else
130 _GL_EXTERN_C void free (void *);
131 # endif
132 # endif
133 #endif
136 /* Declare overridden functions. */
138 #if @GNULIB_MEMALIGN@
139 # if @REPLACE_MEMALIGN@
140 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
141 # undef memalign
142 # define memalign rpl_memalign
143 # endif
144 _GL_FUNCDECL_RPL (memalign, void *,
145 (size_t alignment, size_t size)
146 _GL_ATTRIBUTE_DEALLOC_FREE);
147 _GL_CXXALIAS_RPL (memalign, void *, (size_t alignment, size_t size));
148 # else
149 # if @HAVE_MEMALIGN@
150 # if __GNUC__ >= 11
151 /* For -Wmismatched-dealloc: Associate memalign with free or rpl_free. */
152 # if __GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2
153 _GL_FUNCDECL_SYS (memalign, void *,
154 (size_t alignment, size_t size)
155 _GL_ATTRIBUTE_NOTHROW
156 _GL_ATTRIBUTE_DEALLOC_FREE);
157 # else
158 _GL_FUNCDECL_SYS (memalign, void *,
159 (size_t alignment, size_t size)
160 _GL_ATTRIBUTE_DEALLOC_FREE);
161 # endif
162 # endif
163 _GL_CXXALIAS_SYS (memalign, void *, (size_t alignment, size_t size));
164 # endif
165 # endif
166 # if @HAVE_MEMALIGN@
167 _GL_CXXALIASWARN (memalign);
168 # endif
169 #else
170 # if __GNUC__ >= 11 && !defined memalign
171 /* For -Wmismatched-dealloc: Associate memalign with free or rpl_free. */
172 # if __GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2
173 _GL_FUNCDECL_SYS (memalign, void *,
174 (size_t alignment, size_t size)
175 _GL_ATTRIBUTE_NOTHROW
176 _GL_ATTRIBUTE_DEALLOC_FREE);
177 # else
178 _GL_FUNCDECL_SYS (memalign, void *,
179 (size_t alignment, size_t size)
180 _GL_ATTRIBUTE_DEALLOC_FREE);
181 # endif
182 # endif
183 # if defined GNULIB_POSIXCHECK
184 # undef memalign
185 # if HAVE_RAW_DECL_MEMALIGN
186 _GL_WARN_ON_USE (memalign, "memalign is not portable - "
187 "use gnulib module memalign for portability");
188 # endif
189 # endif
190 #endif
193 #endif /* _@GUARD_PREFIX@_MALLOC_H */
194 #endif /* _@GUARD_PREFIX@_MALLOC_H */
195 #endif