4 /* The three most frequent use cases of these macros are:
6 * For providing a substitute for a function that is missing on some
7 platforms, but is declared and works fine on the platforms on which
12 _GL_FUNCDECL_SYS (foo, ...);
14 _GL_CXXALIAS_SYS (foo, ...);
15 _GL_CXXALIASWARN (foo);
16 #elif defined GNULIB_POSIXCHECK
20 * For providing a replacement for a function that exists on all platforms,
21 but is broken/insufficient and needs to be replaced on some platforms:
25 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
29 _GL_FUNCDECL_RPL (foo, ...);
30 _GL_CXXALIAS_RPL (foo, ...);
32 _GL_CXXALIAS_SYS (foo, ...);
34 _GL_CXXALIASWARN (foo);
35 #elif defined GNULIB_POSIXCHECK
39 * For providing a replacement for a function that exists on some platforms
40 but is broken/insufficient and needs to be replaced on some of them and
41 is additionally either missing or undeclared on some other platforms:
45 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
49 _GL_FUNCDECL_RPL (foo, ...);
50 _GL_CXXALIAS_RPL (foo, ...);
52 # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
53 _GL_FUNCDECL_SYS (foo, ...);
55 _GL_CXXALIAS_SYS (foo, ...);
57 _GL_CXXALIASWARN (foo);
58 #elif defined GNULIB_POSIXCHECK
63 /* _GL_EXTERN_C declaration;
64 performs the declaration with C linkage. */
65 #if defined __cplusplus
66 # define _GL_EXTERN_C extern "C"
68 # define _GL_EXTERN_C extern
71 /* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
72 declares a replacement function, named rpl_func, with the given prototype,
73 consisting of return type, parameters, and attributes.
75 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
76 _GL_ARG_NONNULL ((1)));
78 #define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
79 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
80 #define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
81 _GL_EXTERN_C rettype rpl_func parameters_and_attributes
83 /* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
84 declares the system function, named func, with the given prototype,
85 consisting of return type, parameters, and attributes.
87 _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
88 _GL_ARG_NONNULL ((1)));
90 #define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
91 _GL_EXTERN_C rettype func parameters_and_attributes
93 /* _GL_CXXALIAS_RPL (func, rettype, parameters);
94 declares a C++ alias called GNULIB_NAMESPACE::func
95 that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
97 _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
99 #define _GL_CXXALIAS_RPL(func,rettype,parameters) \
100 _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
101 #if defined __cplusplus && defined GNULIB_NAMESPACE
102 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
103 namespace GNULIB_NAMESPACE \
105 rettype (*const func) parameters = ::rpl_func; \
107 _GL_EXTERN_C int _gl_cxxalias_dummy
109 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
110 _GL_EXTERN_C int _gl_cxxalias_dummy
113 /* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
114 is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
115 except that the C function rpl_func may have a slightly different
116 declaration. A cast is used to silence the "invalid conversion" error
117 that would otherwise occur. */
118 #if defined __cplusplus && defined GNULIB_NAMESPACE
119 # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
120 namespace GNULIB_NAMESPACE \
122 rettype (*const func) parameters = \
123 reinterpret_cast<rettype(*)parameters>(::rpl_func); \
125 _GL_EXTERN_C int _gl_cxxalias_dummy
127 # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
128 _GL_EXTERN_C int _gl_cxxalias_dummy
131 /* _GL_CXXALIAS_SYS (func, rettype, parameters);
132 declares a C++ alias called GNULIB_NAMESPACE::func
133 that redirects to the system provided function func, if GNULIB_NAMESPACE
136 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
138 #if defined __cplusplus && defined GNULIB_NAMESPACE
139 /* If we were to write
140 rettype (*const func) parameters = ::func;
141 like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
142 better (remove an indirection through a 'static' pointer variable),
143 but then the _GL_CXXALIASWARN macro below would cause a warning not only
144 for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
145 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
146 namespace GNULIB_NAMESPACE \
148 static rettype (*func) parameters = ::func; \
150 _GL_EXTERN_C int _gl_cxxalias_dummy
152 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
153 _GL_EXTERN_C int _gl_cxxalias_dummy
156 /* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
157 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
158 except that the C function func may have a slightly different declaration.
159 A cast is used to silence the "invalid conversion" error that would
161 #if defined __cplusplus && defined GNULIB_NAMESPACE
162 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
163 namespace GNULIB_NAMESPACE \
165 static rettype (*func) parameters = \
166 reinterpret_cast<rettype(*)parameters>(::func); \
168 _GL_EXTERN_C int _gl_cxxalias_dummy
170 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
171 _GL_EXTERN_C int _gl_cxxalias_dummy
174 /* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
175 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
176 except that the C function is picked among a set of overloaded functions,
177 namely the one with rettype2 and parameters2. Two consecutive casts
178 are used to silence the "cannot find a match" and "invalid conversion"
179 errors that would otherwise occur. */
180 #if defined __cplusplus && defined GNULIB_NAMESPACE
181 /* The outer cast must be a reinterpret_cast.
182 The inner cast: When the function is defined as a set of overloaded
183 functions, it works as a static_cast<>, choosing the designated variant.
184 When the function is defined as a single variant, it works as a
185 reinterpret_cast<>. The parenthesized cast syntax works both ways. */
186 # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
187 namespace GNULIB_NAMESPACE \
189 static rettype (*func) parameters = \
190 reinterpret_cast<rettype(*)parameters>( \
191 (rettype2(*)parameters2)(::func)); \
193 _GL_EXTERN_C int _gl_cxxalias_dummy
195 # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
196 _GL_EXTERN_C int _gl_cxxalias_dummy
199 /* _GL_CXXALIASWARN (func);
200 causes a warning to be emitted when ::func is used but not when
201 GNULIB_NAMESPACE::func is used. func must be defined without overloaded
203 #if defined __cplusplus && defined GNULIB_NAMESPACE
204 # define _GL_CXXALIASWARN(func) \
205 _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
206 # define _GL_CXXALIASWARN_1(func,namespace) \
207 _GL_CXXALIASWARN_2 (func, namespace)
208 /* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
209 we enable the warning only when not optimizing. */
211 # define _GL_CXXALIASWARN_2(func,namespace) \
212 _GL_WARN_ON_USE (func, \
213 "The symbol ::" #func " refers to the system function. " \
214 "Use " #namespace "::" #func " instead.")
215 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
216 # define _GL_CXXALIASWARN_2(func,namespace) \
217 extern __typeof__ (func) func
219 # define _GL_CXXALIASWARN_2(func,namespace) \
220 _GL_EXTERN_C int _gl_cxxalias_dummy
223 # define _GL_CXXALIASWARN(func) \
224 _GL_EXTERN_C int _gl_cxxalias_dummy
227 /* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
228 causes a warning to be emitted when the given overloaded variant of ::func
229 is used but not when GNULIB_NAMESPACE::func is used. */
230 #if defined __cplusplus && defined GNULIB_NAMESPACE
231 # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
232 _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
234 # define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
235 _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
236 /* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
237 we enable the warning only when not optimizing. */
239 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
240 _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
241 "The symbol ::" #func " refers to the system function. " \
242 "Use " #namespace "::" #func " instead.")
243 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
244 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
245 extern __typeof__ (func) func
247 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
248 _GL_EXTERN_C int _gl_cxxalias_dummy
251 # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
252 _GL_EXTERN_C int _gl_cxxalias_dummy
255 #endif /* _GL_CXXDEFS_H */