GDBserver
c++defs.h
Go to the documentation of this file.
1 #ifndef _GL_CXXDEFS_H
2 #define _GL_CXXDEFS_H
3 
4 /* Begin/end the GNULIB_NAMESPACE namespace. */
5 #if defined __cplusplus && defined GNULIB_NAMESPACE
6 # define _GL_BEGIN_NAMESPACE namespace GNULIB_NAMESPACE {
7 # define _GL_END_NAMESPACE }
8 #else
9 # define _GL_BEGIN_NAMESPACE
10 # define _GL_END_NAMESPACE
11 #endif
12 
13 /* The three most frequent use cases of these macros are:
14 
15  * For providing a substitute for a function that is missing on some
16  platforms, but is declared and works fine on the platforms on which
17  it exists:
18 
19  #if @GNULIB_FOO@
20  # if !@HAVE_FOO@
21  _GL_FUNCDECL_SYS (foo, ...);
22  # endif
23  _GL_CXXALIAS_SYS (foo, ...);
24  _GL_CXXALIASWARN (foo);
25  #elif defined GNULIB_POSIXCHECK
26  ...
27  #endif
28 
29  * For providing a replacement for a function that exists on all platforms,
30  but is broken/insufficient and needs to be replaced on some platforms:
31 
32  #if @GNULIB_FOO@
33  # if @REPLACE_FOO@
34  # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
35  # undef foo
36  # define foo rpl_foo
37  # endif
38  _GL_FUNCDECL_RPL (foo, ...);
39  _GL_CXXALIAS_RPL (foo, ...);
40  # else
41  _GL_CXXALIAS_SYS (foo, ...);
42  # endif
43  _GL_CXXALIASWARN (foo);
44  #elif defined GNULIB_POSIXCHECK
45  ...
46  #endif
47 
48  * For providing a replacement for a function that exists on some platforms
49  but is broken/insufficient and needs to be replaced on some of them and
50  is additionally either missing or undeclared on some other platforms:
51 
52  #if @GNULIB_FOO@
53  # if @REPLACE_FOO@
54  # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
55  # undef foo
56  # define foo rpl_foo
57  # endif
58  _GL_FUNCDECL_RPL (foo, ...);
59  _GL_CXXALIAS_RPL (foo, ...);
60  # else
61  # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
62  _GL_FUNCDECL_SYS (foo, ...);
63  # endif
64  _GL_CXXALIAS_SYS (foo, ...);
65  # endif
66  _GL_CXXALIASWARN (foo);
67  #elif defined GNULIB_POSIXCHECK
68  ...
69  #endif
70 */
71 
72 /* _GL_EXTERN_C declaration;
73  performs the declaration with C linkage. */
74 #if defined __cplusplus
75 # define _GL_EXTERN_C extern "C"
76 #else
77 # define _GL_EXTERN_C extern
78 #endif
79 
80 /* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
81  declares a replacement function, named rpl_func, with the given prototype,
82  consisting of return type, parameters, and attributes.
83  Example:
84  _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
85  _GL_ARG_NONNULL ((1)));
86  */
87 #define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
88  _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
89 #define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
90  _GL_EXTERN_C rettype rpl_func parameters_and_attributes
91 
92 /* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
93  declares the system function, named func, with the given prototype,
94  consisting of return type, parameters, and attributes.
95  Example:
96  _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
97  _GL_ARG_NONNULL ((1)));
98  */
99 #define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
100  _GL_EXTERN_C rettype func parameters_and_attributes
101 
102 /* _GL_CXXALIAS_RPL (func, rettype, parameters);
103  declares a C++ alias called GNULIB_NAMESPACE::func
104  that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
105  Example:
106  _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
107 
108  Wrapping rpl_func in an object with an inline conversion operator
109  avoids a reference to rpl_func unless GNULIB_NAMESPACE::func is
110  actually used in the program. */
111 #define _GL_CXXALIAS_RPL(func,rettype,parameters) \
112  _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
113 #if defined __cplusplus && defined GNULIB_NAMESPACE
114 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
115  namespace GNULIB_NAMESPACE \
116  { \
117  static const struct _gl_ ## func ## _wrapper \
118  { \
119  typedef rettype (*type) parameters; \
120  inline type rpl () const { return ::rpl_func; } \
121  inline operator type () const { return rpl (); } \
122  } func = {}; \
123  } \
124  _GL_EXTERN_C int _gl_cxxalias_dummy
125 #else
126 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
127  _GL_EXTERN_C int _gl_cxxalias_dummy
128 #endif
129 
130 /* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
131  is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
132  except that the C function rpl_func may have a slightly different
133  declaration. A cast is used to silence the "invalid conversion" error
134  that would otherwise occur. */
135 #if defined __cplusplus && defined GNULIB_NAMESPACE
136 # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
137  namespace GNULIB_NAMESPACE \
138  { \
139  static const struct _gl_ ## func ## _wrapper \
140  { \
141  typedef rettype (*type) parameters; \
142  inline type rpl () const \
143  { return reinterpret_cast<type>(::rpl_func); } \
144  inline operator type () const { return rpl (); } \
145  } func = {}; \
146  } \
147  _GL_EXTERN_C int _gl_cxxalias_dummy
148 #else
149 # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
150  _GL_EXTERN_C int _gl_cxxalias_dummy
151 #endif
152 
153 /* _GL_CXXALIAS_SYS (func, rettype, parameters);
154  declares a C++ alias called GNULIB_NAMESPACE::func
155  that redirects to the system provided function func, if GNULIB_NAMESPACE
156  is defined.
157  Example:
158  _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
159 
160  Wrapping func in an object with an inline conversion operator
161  avoids a reference to func unless GNULIB_NAMESPACE::func is
162  actually used in the program. */
163 #if defined __cplusplus && defined GNULIB_NAMESPACE
164 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
165  namespace GNULIB_NAMESPACE \
166  { \
167  static const struct _gl_ ## func ## _wrapper \
168  { \
169  typedef rettype (*type) parameters; \
170  inline type rpl () const { return ::func; } \
171  inline operator type () const { return rpl (); } \
172  } func = {}; \
173  } \
174  _GL_EXTERN_C int _gl_cxxalias_dummy
175 #else
176 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
177  _GL_EXTERN_C int _gl_cxxalias_dummy
178 #endif
179 
180 /* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
181  is like _GL_CXXALIAS_SYS (func, rettype, parameters);
182  except that the C function func may have a slightly different declaration.
183  A cast is used to silence the "invalid conversion" error that would
184  otherwise occur. */
185 #if defined __cplusplus && defined GNULIB_NAMESPACE
186 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
187  namespace GNULIB_NAMESPACE \
188  { \
189  static const struct _gl_ ## func ## _wrapper \
190  { \
191  typedef rettype (*type) parameters; \
192  inline type rpl () const \
193  { return reinterpret_cast<type>(::func); } \
194  inline operator type () const { return rpl (); }\
195  } func = {}; \
196  } \
197  _GL_EXTERN_C int _gl_cxxalias_dummy
198 #else
199 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
200  _GL_EXTERN_C int _gl_cxxalias_dummy
201 #endif
202 
203 /* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
204  is like _GL_CXXALIAS_SYS (func, rettype, parameters);
205  except that the C function is picked among a set of overloaded functions,
206  namely the one with rettype2 and parameters2. Two consecutive casts
207  are used to silence the "cannot find a match" and "invalid conversion"
208  errors that would otherwise occur. */
209 #if defined __cplusplus && defined GNULIB_NAMESPACE
210  /* The outer cast must be a reinterpret_cast.
211  The inner cast: When the function is defined as a set of overloaded
212  functions, it works as a static_cast<>, choosing the designated variant.
213  When the function is defined as a single variant, it works as a
214  reinterpret_cast<>. The parenthesized cast syntax works both ways. */
215 # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
216  namespace GNULIB_NAMESPACE \
217  { \
218  static const struct _gl_ ## func ## _wrapper \
219  { \
220  typedef rettype (*type) parameters; \
221  \
222  inline type rpl () const \
223  { return reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); }\
224  \
225  inline operator type () const { return rpl (); } \
226  } func = {}; \
227  } \
228  _GL_EXTERN_C int _gl_cxxalias_dummy
229 #else
230 # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
231  _GL_EXTERN_C int _gl_cxxalias_dummy
232 #endif
233 
234 /* _GL_CXXALIASWARN (func);
235  causes a warning to be emitted when ::func is used but not when
236  GNULIB_NAMESPACE::func is used. func must be defined without overloaded
237  variants. */
238 #if defined __cplusplus && defined GNULIB_NAMESPACE
239 # define _GL_CXXALIASWARN(func) \
240  _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
241 # define _GL_CXXALIASWARN_1(func,namespace) \
242  _GL_CXXALIASWARN_2 (func, namespace)
243 /* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
244  we enable the warning only when not optimizing. */
245 # if !__OPTIMIZE__
246 # define _GL_CXXALIASWARN_2(func,namespace) \
247  _GL_WARN_ON_USE (func, \
248  "The symbol ::" #func " refers to the system function. " \
249  "Use " #namespace "::" #func " instead.")
250 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
251 # define _GL_CXXALIASWARN_2(func,namespace) \
252  extern __typeof__ (func) func
253 # else
254 # define _GL_CXXALIASWARN_2(func,namespace) \
255  _GL_EXTERN_C int _gl_cxxalias_dummy
256 # endif
257 #else
258 # define _GL_CXXALIASWARN(func) \
259  _GL_EXTERN_C int _gl_cxxalias_dummy
260 #endif
261 
262 /* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
263  causes a warning to be emitted when the given overloaded variant of ::func
264  is used but not when GNULIB_NAMESPACE::func is used. */
265 #if defined __cplusplus && defined GNULIB_NAMESPACE
266 # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
267  _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
268  GNULIB_NAMESPACE)
269 # define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
270  _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
271 /* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
272  we enable the warning only when not optimizing. */
273 # if !__OPTIMIZE__
274 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
275  _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
276  "The symbol ::" #func " refers to the system function. " \
277  "Use " #namespace "::" #func " instead.")
278 # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
279 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
280  extern __typeof__ (func) func
281 # else
282 # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
283  _GL_EXTERN_C int _gl_cxxalias_dummy
284 # endif
285 #else
286 # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
287  _GL_EXTERN_C int _gl_cxxalias_dummy
288 #endif
289 
290 #endif /* _GL_CXXDEFS_H */