Mercurial > hg > xemacs-beta
annotate src/compiler.h @ 5437:002cb5224e4f
Merge with 21.5 trunk.
| author | Mats Lidell <matsl@xemacs.org> |
|---|---|
| date | Mon, 15 Nov 2010 22:33:52 +0100 |
| parents | 308d34e9f07d |
| children | 574f0cded429 |
| rev | line source |
|---|---|
| 1743 | 1 /* Compiler-specific definitions for XEmacs. |
| 2 Copyright (C) 1998-1999, 2003 Free Software Foundation, Inc. | |
| 3 Copyright (C) 1994 Richard Mlynarik. | |
| 5046 | 4 Copyright (C) 1995, 1996, 2000-2004, 2010 Ben Wing. |
| 1743 | 5 |
| 6 This file is part of XEmacs. | |
| 7 | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5046
diff
changeset
|
8 XEmacs is free software: you can redistribute it and/or modify it |
| 1743 | 9 under the terms of the GNU General Public License as published by the |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5046
diff
changeset
|
10 Free Software Foundation, either version 3 of the License, or (at your |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5046
diff
changeset
|
11 option) any later version. |
| 1743 | 12 |
| 13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 16 for more details. | |
| 17 | |
| 18 You should have received a copy of the GNU General Public License | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5046
diff
changeset
|
19 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
| 1743 | 20 |
| 21 /* Synched up with: not in FSF. */ | |
| 22 | |
| 23 /* Authorship: | |
| 24 | |
| 25 NOT_REACHED, DOESNT_RETURN, PRINTF_ARGS by Richard Mlynarik, c. 1994. | |
| 26 RETURN_SANS_WARNING by Martin buchholz, 1998 or 1999. | |
| 27 Many changes and improvements by Jerry James, 2003. | |
| 28 Split out of lisp.h, reorganized, and modernized. | |
| 29 {BEGIN,END}_C_DECLS, NEED_GCC, GCC_VERSION | |
| 2286 | 30 ATTRIBUTE_MALLOC, ATTRIBUTE_CONST, ATTRIBUTE_PURE, UNUSED |
| 1743 | 31 */ |
| 32 | |
| 33 #ifndef INCLUDED_compiler_h | |
| 34 #define INCLUDED_compiler_h | |
| 35 | |
| 36 /* Define min() and max(). (Some compilers put them in strange places that | |
| 3025 | 37 won't be referenced by include files used by XEmacs, such as `macros.h' |
| 1743 | 38 under Solaris.) */ |
| 39 | |
| 40 #ifndef min | |
| 1748 | 41 # define min(a,b) (((a) <= (b)) ? (a) : (b)) |
| 1743 | 42 #endif |
| 43 #ifndef max | |
| 1748 | 44 # define max(a,b) (((a) > (b)) ? (a) : (b)) |
| 1743 | 45 #endif |
| 46 | |
| 47 /* Regular C complains about possible clobbering of local vars NOT declared | |
| 48 as volatile if there's a longjmp() in a function. C++ complains if such | |
| 49 vars ARE volatile; or more correctly, sans volatile no problem even when | |
| 50 you longjmp, avec volatile you get unfixable compile errors like | |
| 51 | |
| 52 /src/xemacs/lilfix/src/process-unix.c: In function `void | |
| 53 unix_send_process(Lisp_Object, lstream*)': | |
| 54 /src/xemacs/lilfix/src/process-unix.c:1577: no matching function for call to ` | |
| 55 Lisp_Object::Lisp_Object(volatile Lisp_Object&)' | |
| 56 /src/xemacs/lilfix/src/lisp-union.h:32: candidates are: | |
| 57 Lisp_Object::Lisp_Object(const Lisp_Object&) | |
| 58 */ | |
| 59 | |
| 60 #ifdef __cplusplus | |
| 1748 | 61 # define VOLATILE_IF_NOT_CPP |
| 1743 | 62 #else |
| 1748 | 63 # define VOLATILE_IF_NOT_CPP volatile |
| 1743 | 64 #endif |
| 65 | |
| 66 /* Avoid indentation problems when XEmacs sees the curly braces */ | |
| 67 #ifndef BEGIN_C_DECLS | |
| 68 # ifdef __cplusplus | |
| 69 # define BEGIN_C_DECLS extern "C" { | |
| 70 # define END_C_DECLS } | |
| 71 # else | |
| 72 # define BEGIN_C_DECLS | |
| 73 # define END_C_DECLS | |
| 74 # endif | |
| 75 #endif | |
| 76 | |
| 1748 | 77 /* Guard against older gccs that did not define all of these symbols */ |
| 78 #ifdef __GNUC__ | |
| 79 # ifndef __GNUC_MINOR__ | |
| 80 # define __GNUC_MINOR__ 0 | |
| 81 # endif | |
| 82 # ifndef __GNUC_PATCHLEVEL__ | |
| 83 # define __GNUC_PATCHLEVEL__ 0 | |
| 84 # endif | |
| 85 #endif /* __GNUC__ */ | |
| 1743 | 86 |
| 1748 | 87 /* Simplify testing for specific GCC versions. For non-GNU compilers, |
| 88 GCC_VERSION evaluates to zero. */ | |
| 1743 | 89 #ifndef NEED_GCC |
| 1748 | 90 # define NEED_GCC(major,minor,patch) (major * 1000000 + minor * 1000 + patch) |
| 1743 | 91 #endif /* NEED_GCC */ |
| 92 #ifndef GCC_VERSION | |
| 1748 | 93 # ifdef __GNUC__ |
| 94 # define GCC_VERSION NEED_GCC (__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) | |
| 95 # else | |
| 96 # define GCC_VERSION 0 | |
| 97 # endif /* __GNUC__ */ | |
| 1743 | 98 #endif /* GCC_VERSION */ |
| 99 | |
| 2500 | 100 #ifdef _MSC_VER |
| 101 #define MSC_VERSION _MSC_VER | |
| 102 #else | |
| 103 #define MSC_VERSION 0 | |
| 104 #endif | |
| 105 | |
| 1743 | 106 /* GCC < 2.6.0 could only declare one attribute per function. In that case, |
| 107 we define DOESNT_RETURN in preference to PRINTF_ARGS, which is only used | |
| 108 for checking args against the string spec. */ | |
| 109 #ifndef PRINTF_ARGS | |
| 110 # if (GCC_VERSION >= NEED_GCC (2, 6, 0)) | |
| 111 # define PRINTF_ARGS(string_index,first_to_check) \ | |
| 112 __attribute__ ((format (printf, string_index, first_to_check))) | |
| 113 # else | |
| 114 # define PRINTF_ARGS(string_index,first_to_check) | |
| 115 # endif /* GNUC */ | |
| 116 #endif | |
| 117 | |
| 2268 | 118 #ifndef DOESNT_RETURN_TYPE |
| 1743 | 119 # if (GCC_VERSION > NEED_GCC (0, 0, 0)) |
| 120 # if (GCC_VERSION >= NEED_GCC (2, 5, 0)) | |
| 2270 | 121 # ifndef __INTEL_COMPILER |
| 122 # define RETURN_NOT_REACHED(value) DO_NOTHING | |
| 123 # endif | |
| 2268 | 124 # define DOESNT_RETURN_TYPE(rettype) rettype |
| 125 # define DECLARE_DOESNT_RETURN_TYPE(rettype,decl) rettype decl \ | |
| 126 __attribute__ ((noreturn)) | |
| 1743 | 127 # else /* GCC_VERSION < NEED_GCC (2, 5, 0) */ |
| 2268 | 128 # define DOESNT_RETURN_TYPE(rettype) rettype volatile |
| 129 # define DECLARE_DOESNT_RETURN_TYPE(rettype,decl) rettype volatile decl | |
| 1743 | 130 # endif /* GCC_VERSION >= NEED_GCC (2, 5, 0) */ |
| 2500 | 131 # elif (MSC_VERSION >= 1200) |
| 132 /* MSVC 6.0 has a mechanism to declare functions which never return */ | |
| 133 # define DOESNT_RETURN_TYPE(rettype) __declspec(noreturn) rettype | |
| 134 # define DECLARE_DOESNT_RETURN_TYPE(rettype,decl) \ | |
| 135 __declspec(noreturn) rettype XCDECL decl | |
| 136 # if (MSC_VERSION >= 1300) | |
| 137 /* VC++ 7 issues warnings about return statements in __declspec(noreturn) | |
| 138 functions; this problem didn't exist under VC++ 6 */ | |
| 139 # define RETURN_NOT_REACHED(value) DO_NOTHING | |
| 140 # endif | |
| 141 # else /* not gcc, VC++ */ | |
| 2268 | 142 # define DOESNT_RETURN_TYPE(rettype) rettype |
| 143 # define DECLARE_DOESNT_RETURN_TYPE(rettype,decl) rettype decl | |
| 1743 | 144 # endif /* GCC_VERSION > NEED_GCC (0, 0, 0) */ |
| 2268 | 145 #endif /* DOESNT_RETURN_TYPE */ |
| 146 #ifndef DOESNT_RETURN | |
| 147 # define DOESNT_RETURN DOESNT_RETURN_TYPE (void) | |
| 148 # define DECLARE_DOESNT_RETURN(decl) DECLARE_DOESNT_RETURN_TYPE (void, decl) | |
| 1743 | 149 #endif /* DOESNT_RETURN */ |
| 150 | |
| 151 /* Another try to fix SunPro C compiler warnings */ | |
| 152 /* "end-of-loop code not reached" */ | |
| 153 /* "statement not reached */ | |
| 154 #if defined __SUNPRO_C || defined __USLC__ | |
| 1748 | 155 # define RETURN_SANS_WARNINGS if (1) return |
| 156 # define RETURN_NOT_REACHED(value) DO_NOTHING | |
| 1743 | 157 #endif |
| 158 | |
| 159 /* More ways to shut up compiler. This works in Fcommand_loop_1(), | |
| 160 where there's an infinite loop in a function returning a Lisp object. | |
| 161 */ | |
| 2500 | 162 #if (defined (_MSC_VER) && MSC_VERSION < 1300) || defined (__SUNPRO_C) || \ |
|
4759
aa5ed11f473b
Remove support for obsolete systems. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents:
4028
diff
changeset
|
163 defined (__SUNPRO_CC) |
| 1748 | 164 # define DO_NOTHING_DISABLING_NO_RETURN_WARNINGS if (0) return Qnil |
| 1743 | 165 #else |
| 1748 | 166 # define DO_NOTHING_DISABLING_NO_RETURN_WARNINGS DO_NOTHING |
| 1743 | 167 #endif |
| 168 | |
| 169 #ifndef RETURN_NOT_REACHED | |
| 1748 | 170 # define RETURN_NOT_REACHED(value) return (value) |
| 1743 | 171 #endif |
| 172 | |
| 173 #ifndef RETURN_SANS_WARNINGS | |
| 1748 | 174 # define RETURN_SANS_WARNINGS return |
| 1743 | 175 #endif |
| 176 | |
| 177 #ifndef DO_NOTHING | |
| 1748 | 178 # define DO_NOTHING do {} while (0) |
| 1743 | 179 #endif |
| 180 | |
| 181 #ifndef DECLARE_NOTHING | |
| 1748 | 182 # define DECLARE_NOTHING struct nosuchstruct |
| 1743 | 183 #endif |
| 184 | |
| 185 #ifndef ATTRIBUTE_MALLOC | |
| 186 # if (GCC_VERSION >= NEED_GCC (2, 96, 0)) | |
| 187 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) | |
| 188 # else | |
| 189 # define ATTRIBUTE_MALLOC | |
| 190 # endif /* GCC_VERSION >= NEED_GCC (2, 96, 0) */ | |
| 191 #endif /* ATTRIBUTE_MALLOC */ | |
| 192 | |
| 193 #ifndef ATTRIBUTE_PURE | |
| 194 # if (GCC_VERSION >= NEED_GCC (2, 96, 0)) | |
| 195 # define ATTRIBUTE_PURE __attribute__ ((pure)) | |
| 196 # else | |
| 197 # define ATTRIBUTE_PURE | |
| 198 # endif /* GCC_VERSION >= NEED_GCC (2, 96, 0) */ | |
| 199 #endif /* ATTRIBUTE_PURE */ | |
| 200 | |
| 201 #ifndef ATTRIBUTE_CONST | |
| 202 # if (GCC_VERSION >= NEED_GCC (2, 5, 0)) | |
| 203 # define ATTRIBUTE_CONST __attribute__ ((const)) | |
| 204 # define CONST_FUNC | |
| 205 # else | |
| 206 # define ATTRIBUTE_CONST | |
| 207 # define CONST_FUNC const | |
| 208 # endif /* GCC_VERSION >= NEED_GCC (2, 5, 0) */ | |
| 209 #endif /* ATTRIBUTE_CONST */ | |
| 210 | |
| 3094 | 211 /* |
| 212 NOTE: These macros MUST be named UNUSED (exactly) or something | |
| 213 prefixed with USED_IF_, or DEFUN docstrings will be parsed incorrectly. | |
| 214 See comments in make_docfile.c (write_c_args). You'd think that this | |
| 215 wouldn't happen, but unfortunately we do indeed have some arguments | |
| 216 of DEFUNs unused for GNU compatibility or because features are missing. | |
| 4028 | 217 |
| 218 #### At one time, __attribute__ ((unused)) confused G++. We don't know | |
| 219 which versions. Please report problems and fix conditionals. | |
| 220 #### A similar issue arose with the Intel CC. We know that v7 didn't | |
| 221 work and v9 does. Let us know if v8 works or not, please. | |
| 222 See <m34plsmh88.fsf@jerrypc.cs.usu.edu>. | |
| 3094 | 223 */ |
| 1743 | 224 #ifndef UNUSED_ARG |
| 2286 | 225 # define UNUSED_ARG(decl) unused_##decl |
| 226 #endif | |
| 227 #ifndef UNUSED | |
| 4028 | 228 # if defined(__GNUC__) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 800) |
| 2286 | 229 # define ATTRIBUTE_UNUSED __attribute__ ((unused)) |
| 1743 | 230 # else |
| 2286 | 231 # define ATTRIBUTE_UNUSED |
| 1743 | 232 # endif |
| 2286 | 233 # define UNUSED(decl) UNUSED_ARG (decl) ATTRIBUTE_UNUSED |
| 234 #endif /* UNUSED */ | |
| 1743 | 235 |
| 5046 | 236 /* Various macros for params/variables used or unused depending on |
| 237 config flags. */ | |
| 238 | |
| 239 #ifdef MULE | |
| 240 # define USED_IF_MULE(decl) decl | |
| 241 #else | |
| 242 # define USED_IF_MULE(decl) UNUSED (decl) | |
| 243 #endif | |
| 244 #ifdef HAVE_XFT | |
| 245 # define USED_IF_XFT(decl) decl | |
| 246 #else | |
| 247 # define USED_IF_XFT(decl) UNUSED (decl) | |
| 248 #endif | |
| 249 #ifdef HAVE_SCROLLBARS | |
| 250 # define USED_IF_SCROLLBARS(decl) decl | |
| 251 #else | |
| 252 # define USED_IF_SCROLLBARS(decl) UNUSED (decl) | |
| 253 #endif | |
| 254 #ifdef NEW_GC | |
| 255 # define USED_IF_NEW_GC(decl) decl | |
| 256 # define UNUSED_IF_NEW_GC(decl) UNUSED (decl) | |
| 257 #else | |
| 258 # define USED_IF_NEW_GC(decl) UNUSED (decl) | |
| 259 # define UNUSED_IF_NEW_GC(decl) decl | |
| 260 #endif | |
| 261 #ifdef HAVE_TTY | |
| 262 #define USED_IF_TTY(decl) decl | |
| 263 #else | |
| 264 #define USED_IF_TTY(decl) UNUSED (decl) | |
| 265 #endif | |
| 266 #ifdef HAVE_TOOLBARS | |
| 267 #define USED_IF_TOOLBARS(decl) decl | |
| 268 #else | |
| 269 #define USED_IF_TOOLBARS(decl) UNUSED (decl) | |
| 270 #endif | |
| 271 | |
|
4908
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
272 /* Declaration that variable or expression X is "used" to defeat |
|
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
273 "unused variable" warnings. DON'T DO THIS FOR PARAMETERS IF IT ALL |
|
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
274 POSSIBLE. Use an UNUSED() or USED_IF_*() declaration on the parameter |
|
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
275 instead. Don't do this for unused local variables that should really |
|
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
276 just be deleted. */ |
|
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
277 #define USED(x) ((void) (x)) |
|
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4860
diff
changeset
|
278 |
| 1743 | 279 #ifdef DEBUG_XEMACS |
| 1748 | 280 # define REGISTER |
| 281 # define register | |
| 1743 | 282 #else |
| 1748 | 283 # define REGISTER register |
| 1743 | 284 #endif |
| 285 | |
| 286 #if defined(HAVE_MS_WINDOWS) && defined(HAVE_SHLIB) | |
| 287 # ifdef EMACS_MODULE | |
| 288 # define MODULE_API __declspec(dllimport) | |
| 289 # else | |
| 290 # define MODULE_API __declspec(dllexport) | |
| 291 # endif | |
| 292 #else | |
| 293 # define MODULE_API | |
| 294 #endif | |
| 295 | |
| 2367 | 296 /* Under "strict-aliasing" assumptions, you're not necessarily allowed to |
| 297 access the same memory address as two different types. The proper way | |
| 298 around that is with a union. The macros below help out, e.g. the | |
| 299 definition of XE_MAKEPOINTS(val) is | |
| 300 | |
| 301 ANSI_ALIASING_TYPEDEF (POINTS, POINTS); | |
| 302 #define XE_MAKEPOINTS(l) ANSI_ALIASING_CAST (POINTS, l) | |
| 303 | |
| 304 replacing | |
| 305 | |
| 306 BAD!!! #define XE_MAKEPOINTS(l) (* (POINTS *) &(l)) | |
| 307 | |
| 308 On the other hand, if you are just casting from one pointer to the other | |
| 309 in order to pass a pointer to another function, it's probably OK to just | |
| 310 trick GCC by inserting an intermediate cast to (void *), to avoid | |
| 311 warnings about "dereferencing type-punned pointer". #### I don't know | |
| 312 how kosher this is, but do strict-aliasing rules really apply across | |
| 313 functions? | |
| 314 | |
| 315 Note that the input to e.g. VOIDP_CAST must be an lvalue (i.e. not | |
| 316 &(something)), but the value of the macro is also an lvalue, so in place | |
| 317 of `(void **) &foo' you could write `& VOIDP_CAST (foo)' if you are | |
| 318 subsequently dereferencing the value or don't feel comfortable doing a | |
| 319 trick like `(void **) (void *) &foo'. | |
| 320 | |
| 321 Unfortunately, it does not work to just define the union type on the fly in | |
| 322 the cast -- otherwise, we could avoid the need for a typedef. Or rather, | |
| 323 it does work under gcc but not under Visual C++. | |
| 324 | |
| 325 --ben | |
| 326 */ | |
| 327 | |
| 328 #define ANSI_ALIASING_TYPEDEF(name, type) typedef union { char c; type p; } *ANSI_ALIASING_##name | |
| 329 #define ANSI_ALIASING_CAST(name, val) (((ANSI_ALIASING_##name) &(val))->p) | |
| 330 ANSI_ALIASING_TYPEDEF (voidp, void *); | |
| 331 /* VOIDP_CAST: Cast an lvalue to (void *) in a way that is ANSI-aliasing | |
| 332 safe and will not result in GCC warnings. The result is still an | |
| 333 lvalue, so you can assign to it or take its address. */ | |
| 334 #define VOIDP_CAST(l) ANSI_ALIASING_CAST (voidp, l) | |
| 335 | |
| 1743 | 336 #endif /* INCLUDED_compiler_h */ |
