]> git.cworth.org Git - tar/blob - build-aux/c++defs.h
24b8d5db78598dd7b137e993df333acc587b1be3
[tar] / build-aux / c++defs.h
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* C++ compatible function declaration macros.
4    Copyright (C) 2010 Free Software Foundation, Inc.
5
6    This program is free software: you can redistribute it and/or modify it
7    under the terms of the GNU General Public License as published
8    by the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 #ifndef _GL_CXXDEFS_H
20 #define _GL_CXXDEFS_H
21
22 /* The three most frequent use cases of these macros are:
23
24    * For providing a substitute for a function that is missing on some
25      platforms, but is declared and works fine on the platforms on which
26      it exists:
27
28        #if @GNULIB_FOO@
29        # if !@HAVE_FOO@
30        _GL_FUNCDECL_SYS (foo, ...);
31        # endif
32        _GL_CXXALIAS_SYS (foo, ...);
33        _GL_CXXALIASWARN (foo);
34        #elif defined GNULIB_POSIXCHECK
35        ...
36        #endif
37
38    * For providing a replacement for a function that exists on all platforms,
39      but is broken/insufficient and needs to be replaced on some platforms:
40
41        #if @GNULIB_FOO@
42        # if @REPLACE_FOO@
43        #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
44        #   undef foo
45        #   define foo rpl_foo
46        #  endif
47        _GL_FUNCDECL_RPL (foo, ...);
48        _GL_CXXALIAS_RPL (foo, ...);
49        # else
50        _GL_CXXALIAS_SYS (foo, ...);
51        # endif
52        _GL_CXXALIASWARN (foo);
53        #elif defined GNULIB_POSIXCHECK
54        ...
55        #endif
56
57    * For providing a replacement for a function that exists on some platforms
58      but is broken/insufficient and needs to be replaced on some of them and
59      is additionally either missing or undeclared on some other platforms:
60
61        #if @GNULIB_FOO@
62        # if @REPLACE_FOO@
63        #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
64        #   undef foo
65        #   define foo rpl_foo
66        #  endif
67        _GL_FUNCDECL_RPL (foo, ...);
68        _GL_CXXALIAS_RPL (foo, ...);
69        # else
70        #  if !@HAVE_FOO@   or   if !@HAVE_DECL_FOO@
71        _GL_FUNCDECL_SYS (foo, ...);
72        #  endif
73        _GL_CXXALIAS_SYS (foo, ...);
74        # endif
75        _GL_CXXALIASWARN (foo);
76        #elif defined GNULIB_POSIXCHECK
77        ...
78        #endif
79 */
80
81 /* _GL_EXTERN_C declaration;
82    performs the declaration with C linkage.  */
83 #if defined __cplusplus
84 # define _GL_EXTERN_C extern "C"
85 #else
86 # define _GL_EXTERN_C extern
87 #endif
88
89 /* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
90    declares a replacement function, named rpl_func, with the given prototype,
91    consisting of return type, parameters, and attributes.
92    Example:
93      _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
94                                   _GL_ARG_NONNULL ((1)));
95  */
96 #define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
97   _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
98 #define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
99   _GL_EXTERN_C rettype rpl_func parameters_and_attributes
100
101 /* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
102    declares the system function, named func, with the given prototype,
103    consisting of return type, parameters, and attributes.
104    Example:
105      _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
106                                   _GL_ARG_NONNULL ((1)));
107  */
108 #define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
109   _GL_EXTERN_C rettype func parameters_and_attributes
110
111 /* _GL_CXXALIAS_RPL (func, rettype, parameters);
112    declares a C++ alias called GNULIB_NAMESPACE::func
113    that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
114    Example:
115      _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
116  */
117 #define _GL_CXXALIAS_RPL(func,rettype,parameters) \
118   _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
119 #if defined __cplusplus && defined GNULIB_NAMESPACE
120 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
121     namespace GNULIB_NAMESPACE                                \
122     {                                                         \
123       rettype (*const func) parameters = ::rpl_func;          \
124     }                                                         \
125     _GL_EXTERN_C int _gl_cxxalias_dummy
126 #else
127 # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
128     _GL_EXTERN_C int _gl_cxxalias_dummy
129 #endif
130
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
134    is defined.
135    Example:
136      _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
137  */
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                     \
147     {                                              \
148       static rettype (*func) parameters = ::func;  \
149     }                                              \
150     _GL_EXTERN_C int _gl_cxxalias_dummy
151 #else
152 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
153     _GL_EXTERN_C int _gl_cxxalias_dummy
154 #endif
155
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
160    otherwise occur.  */
161 #if defined __cplusplus && defined GNULIB_NAMESPACE
162 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
163     namespace GNULIB_NAMESPACE                          \
164     {                                                   \
165       static rettype (*func) parameters =               \
166         reinterpret_cast<rettype(*)parameters>(::func); \
167     }                                                   \
168     _GL_EXTERN_C int _gl_cxxalias_dummy
169 #else
170 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
171     _GL_EXTERN_C int _gl_cxxalias_dummy
172 #endif
173
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 # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
182     namespace GNULIB_NAMESPACE                                                \
183     {                                                                         \
184       static rettype (*func) parameters =                                     \
185         reinterpret_cast<rettype(*)parameters>(                               \
186           reinterpret_cast<rettype2(*)parameters2>(::func));                  \
187     }                                                                         \
188     _GL_EXTERN_C int _gl_cxxalias_dummy
189 #else
190 # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
191     _GL_EXTERN_C int _gl_cxxalias_dummy
192 #endif
193
194 /* _GL_CXXALIASWARN (func);
195    causes a warning to be emitted when ::func is used but not when
196    GNULIB_NAMESPACE::func is used.  */
197 #if defined __cplusplus && defined GNULIB_NAMESPACE
198 # define _GL_CXXALIASWARN(func) \
199    _GL_CXXALIASWARN1 (func, GNULIB_NAMESPACE)
200 # define _GL_CXXALIASWARN1(func,namespace) \
201    _GL_CXXALIASWARN2 (func, namespace)
202 # define _GL_CXXALIASWARN2(func,namespace) \
203    _GL_WARN_ON_USE (func, \
204                     "The symbol ::" #func " refers to the system function. " \
205                     "Use " #namespace "::" #func " instead.")
206 #else
207 # define _GL_CXXALIASWARN(func) \
208     _GL_EXTERN_C int _gl_cxxalias_dummy
209 #endif
210
211 #endif /* _GL_CXXDEFS_H */