diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-04-10 14:11:40 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-04-13 16:06:00 +0900 |
commit | 4ff3f205408ff8bb413d69151105d301858136ba (patch) | |
tree | 0494fea3f4cdb82ec1d34e462438389dfea8b8da /include/ruby/backward | |
parent | a3f6f67967644f34226b4424227d2eec52fedd45 (diff) | |
download | ruby-4ff3f205408ff8bb413d69151105d301858136ba.tar.gz |
add #include guard hack
According to MSVC manual (*1), cl.exe can skip including a header file
when that:
- contains #pragma once, or
- starts with #ifndef, or
- starts with #if ! defined.
GCC has a similar trick (*2), but it acts more stricter (e. g. there
must be _no tokens_ outside of #ifndef...#endif).
Sun C lacked #pragma once for a looong time. Oracle Developer Studio
12.5 finally implemented it, but we cannot assume such recent version.
This changeset modifies header files so that each of them include
strictly one #ifndef...#endif. I believe this is the most portable way
to trigger compiler optimizations. [Bug #16770]
*1: https://docs.microsoft.com/en-us/cpp/preprocessor/once
*2: https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html
Diffstat (limited to 'include/ruby/backward')
-rw-r--r-- | include/ruby/backward/2/assume.h | 6 | ||||
-rw-r--r-- | include/ruby/backward/2/attributes.h | 6 | ||||
-rw-r--r-- | include/ruby/backward/2/bool.h | 6 | ||||
-rw-r--r-- | include/ruby/backward/2/extern.h | 11 | ||||
-rw-r--r-- | include/ruby/backward/2/gcc_version_since.h | 6 | ||||
-rw-r--r-- | include/ruby/backward/2/inttypes.h | 6 | ||||
-rw-r--r-- | include/ruby/backward/2/limits.h | 6 | ||||
-rw-r--r-- | include/ruby/backward/2/long_long.h | 11 | ||||
-rw-r--r-- | include/ruby/backward/2/r_cast.h | 6 | ||||
-rw-r--r-- | include/ruby/backward/2/rmodule.h | 7 | ||||
-rw-r--r-- | include/ruby/backward/2/stdalign.h | 6 | ||||
-rw-r--r-- | include/ruby/backward/2/stdarg.h | 6 | ||||
-rw-r--r-- | include/ruby/backward/classext.h | 15 | ||||
-rw-r--r-- | include/ruby/backward/cxxanyargs.hpp | 5 | ||||
-rw-r--r-- | include/ruby/backward/rubyio.h | 12 | ||||
-rw-r--r-- | include/ruby/backward/rubysig.h | 27 | ||||
-rw-r--r-- | include/ruby/backward/st.h | 12 | ||||
-rw-r--r-- | include/ruby/backward/util.h | 12 |
18 files changed, 118 insertions, 48 deletions
diff --git a/include/ruby/backward/2/assume.h b/include/ruby/backward/2/assume.h index 2be231093b..095a43876d 100644 --- a/include/ruby/backward/2/assume.h +++ b/include/ruby/backward/2/assume.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY_BACKWARD2_ASSUME_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD2_ASSUME_H +/** * @file * @author Ruby developers <ruby-core@ruby-lang.org> * @copyright This file is a part of the programming language Ruby. @@ -37,3 +39,5 @@ # define RB_LIKELY(x) (x) # define RB_UNLIKELY(x) (x) #endif + +#endif /* RUBY_BACKWARD2_ASSUME_H */ diff --git a/include/ruby/backward/2/attributes.h b/include/ruby/backward/2/attributes.h index 0735385292..043646eb4b 100644 --- a/include/ruby/backward/2/attributes.h +++ b/include/ruby/backward/2/attributes.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY_BACKWARD2_ATTRIBUTES_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD2_ATTRIBUTES_H +/** * @file * @author Ruby developers <ruby-core@ruby-lang.org> * @copyright This file is a part of the programming language Ruby. @@ -26,8 +28,6 @@ * - A: Don't know. Don't blame me. Backward compatibility is the key here. * I'm just preserving what they have been. */ -#ifndef RUBY_BACKWARD2_ATTRIBUTES_H -#define RUBY_BACKWARD2_ATTRIBUTES_H #include "ruby/3/config.h" #include "ruby/3/attr/alloc_size.h" #include "ruby/3/attr/cold.h" diff --git a/include/ruby/backward/2/bool.h b/include/ruby/backward/2/bool.h index 8c619b8215..b2cca2a206 100644 --- a/include/ruby/backward/2/bool.h +++ b/include/ruby/backward/2/bool.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY_BACKWARD2_BOOL_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD2_BOOL_H +/** * @file * @author Ruby developers <ruby-core@ruby-lang.org> * @copyright This file is a part of the programming language Ruby. @@ -31,3 +33,5 @@ #elif ! TRUE # error TRUE must be true #endif + +#endif /* RUBY_BACKWARD2_BOOL_H */ diff --git a/include/ruby/backward/2/extern.h b/include/ruby/backward/2/extern.h index e7018342ea..697c593000 100644 --- a/include/ruby/backward/2/extern.h +++ b/include/ruby/backward/2/extern.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY_BACKWARD2_EXTERN_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD2_EXTERN_H +/** * @file * @author Ruby developers <ruby-core@ruby-lang.org> * @copyright This file is a part of the programming language Ruby. @@ -24,10 +26,7 @@ * @brief Synonym of #RUBY_EXTERN. * @deprecated #EXTERN is deprecated, use #RUBY_EXTERN instead. */ -#ifdef EXTERN -# /* Stop bothering then. */ - -#elif defined __GNUC__ +#if defined __GNUC__ # define EXTERN \ _Pragma("message \"EXTERN is deprecated, use RUBY_EXTERN instead\""); \ RUBY_EXTERN @@ -43,3 +42,5 @@ # define EXTERN <-<-"EXTERN is deprecated, use RUBY_EXTERN instead"->-> #endif + +#endif /* RUBY_BACKWARD2_EXTERN_H */ diff --git a/include/ruby/backward/2/gcc_version_since.h b/include/ruby/backward/2/gcc_version_since.h index 4e2abc45f9..553b982147 100644 --- a/include/ruby/backward/2/gcc_version_since.h +++ b/include/ruby/backward/2/gcc_version_since.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY_BACKWARD2_GCC_VERSION_SINCE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD2_GCC_VERSION_SINCE_H +/** * @file * @author Ruby developers <ruby-core@ruby-lang.org> * @copyright This file is a part of the programming language Ruby. @@ -31,3 +33,5 @@ ((RUBY3_COMPILER_VERSION_MINOR == (y)) && \ (RUBY3_COMPILER_VERSION_PATCH == (z)))))) #endif + +#endif /* RUBY_BACKWARD2_GCC_VERSION_SINCE_H */ diff --git a/include/ruby/backward/2/inttypes.h b/include/ruby/backward/2/inttypes.h index 7e9b525a52..c6419bc7b3 100644 --- a/include/ruby/backward/2/inttypes.h +++ b/include/ruby/backward/2/inttypes.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY_BACKWARD2_INTTYPES_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD2_INTTYPES_H +/** * @file * @author Ruby developers <ruby-core@ruby-lang.org> * @copyright This file is a part of the programming language Ruby. @@ -126,3 +128,5 @@ # define PRIxSIZE PRI_SIZE_PREFIX"x" # define PRIXSIZE PRI_SIZE_PREFIX"X" #endif + +#endif /* RUBY_BACKWARD2_INTTYPES_H */ diff --git a/include/ruby/backward/2/limits.h b/include/ruby/backward/2/limits.h index 28eb1596a9..f003d86057 100644 --- a/include/ruby/backward/2/limits.h +++ b/include/ruby/backward/2/limits.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY_BACKWARD2_LIMITS_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD2_LIMITS_H +/** * @file * @author Ruby developers <ruby-core@ruby-lang.org> * @copyright This file is a part of the programming language Ruby. @@ -94,3 +96,5 @@ # define SSIZE_MAX SHRT_MAX # define SSIZE_MIN SHRT_MIN #endif + +#endif /* RUBY_BACKWARD2_LIMITS_H */ diff --git a/include/ruby/backward/2/long_long.h b/include/ruby/backward/2/long_long.h index 29b930625e..2a9b9e7f40 100644 --- a/include/ruby/backward/2/long_long.h +++ b/include/ruby/backward/2/long_long.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY_BACKWARD2_LONG_LONG_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD2_LONG_LONG_H +/** * @file * @author Ruby developers <ruby-core@ruby-lang.org> * @copyright This file is a part of the programming language Ruby. @@ -25,10 +27,7 @@ */ #include "ruby/3/config.h" -#if defined(LONG_LONG) -# /* Take that. */ - -#elif RUBY3_HAS_WARNING("-Wc++11-long-long") +#if RUBY3_HAS_WARNING("-Wc++11-long-long") # define HAVE_TRUE_LONG_LONG 1 # define LONG_LONG \ RUBY3_WARNING_PUSH() \ @@ -60,3 +59,5 @@ # error Remember to attach a detailed description of your environment. # error Thank you! #endif + +#endif /* RUBY3_BACKWARD2_LONG_LONG_H */ diff --git a/include/ruby/backward/2/r_cast.h b/include/ruby/backward/2/r_cast.h index ed529c8968..15f5339227 100644 --- a/include/ruby/backward/2/r_cast.h +++ b/include/ruby/backward/2/r_cast.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY_BACKWARD2_R_CAST_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD2_R_CAST_H +/** * @file * @author Ruby developers <ruby-core@ruby-lang.org> * @copyright This file is a part of the programming language Ruby. @@ -20,8 +22,6 @@ * * Nobody is actively using this macro. */ -#ifndef RUBY_BACKWARD2_R_CAST_H -#define RUBY_BACKWARD2_R_CAST_H #define R_CAST(st) (struct st*) #define RMOVED(obj) (R_CAST(RMoved)(obj)) #endif /* RUBY_BACKWARD2_R_CAST_H */ diff --git a/include/ruby/backward/2/rmodule.h b/include/ruby/backward/2/rmodule.h index bb0fc047a6..6b79636ac7 100644 --- a/include/ruby/backward/2/rmodule.h +++ b/include/ruby/backward/2/rmodule.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY_BACKWARD2_RMODULE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD2_RMODULE_H +/** * @file * @author Ruby developers <ruby-core@ruby-lang.org> * @copyright This file is a part of the programming language Ruby. @@ -22,9 +24,8 @@ * who is implementing the internals) could have used those macros for a while. * Kept public as-is here to keep some theoretical backwards compatibility. */ -#ifndef RMODULE_IV_TBL #define RMODULE_IV_TBL(m) RCLASS_IV_TBL(m) #define RMODULE_CONST_TBL(m) RCLASS_CONST_TBL(m) #define RMODULE_M_TBL(m) RCLASS_M_TBL(m) #define RMODULE_SUPER(m) RCLASS_SUPER(m) -#endif +#endif /* RUBY_BACKWARD2_RMODULE_H */ diff --git a/include/ruby/backward/2/stdalign.h b/include/ruby/backward/2/stdalign.h index 2d970edc9d..bdea030a41 100644 --- a/include/ruby/backward/2/stdalign.h +++ b/include/ruby/backward/2/stdalign.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY_BACKWARD2_STDALIGN_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD2_STDALIGN_H +/** * @file * @author Ruby developers <ruby-core@ruby-lang.org> * @copyright This file is a part of the programming language Ruby. @@ -24,3 +26,5 @@ #undef RUBY_ALIGNOF #define RUBY_ALIGNAS RUBY3_ALIGNAS #define RUBY_ALIGNOF RUBY3_ALIGNOF + +#endif /* RUBY_BACKWARD2_STDALIGN_H */ diff --git a/include/ruby/backward/2/stdarg.h b/include/ruby/backward/2/stdarg.h index 7b37bd4571..2270e66b77 100644 --- a/include/ruby/backward/2/stdarg.h +++ b/include/ruby/backward/2/stdarg.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY_BACKWARD2_STDARG_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD2_STDARG_H +/** * @file * @author Ruby developers <ruby-core@ruby-lang.org> * @copyright This file is a part of the programming language Ruby. @@ -41,3 +43,5 @@ #else #define ANYARGS #endif + +#endif /* RUBY_BACKWARD2_STDARG_H */ diff --git a/include/ruby/backward/classext.h b/include/ruby/backward/classext.h index 9d5747316a..61d05611bc 100644 --- a/include/ruby/backward/classext.h +++ b/include/ruby/backward/classext.h @@ -1,12 +1,19 @@ +#ifndef RUBY_BACKWARD_CLASSEXT_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD_CLASSEXT_H +/** + * @file + * @author Ruby developers <ruby-core@ruby-lang.org> + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + */ #if defined __GNUC__ #warning use of RClass internals is deprecated #elif defined _MSC_VER #pragma message("warning: use of RClass internals is deprecated") #endif -#ifndef RUBY_BACKWARD_CLASSEXT_H -#define RUBY_BACKWARD_CLASSEXT_H 1 - typedef struct rb_deprecated_classext_struct { VALUE super; } rb_deprecated_classext_t; @@ -15,4 +22,4 @@ typedef struct rb_deprecated_classext_struct { #define RCLASS_EXT(c) ((rb_deprecated_classext_t *)RCLASS(c)->ptr) #define RCLASS_SUPER(c) (RCLASS(c)->super) -#endif /* RUBY_BACKWARD_CLASSEXT_H */ +#endif /* RUBY_BACKWARD_CLASSEXT_H */ diff --git a/include/ruby/backward/cxxanyargs.hpp b/include/ruby/backward/cxxanyargs.hpp index 8fda5fe906..c30ab46f43 100644 --- a/include/ruby/backward/cxxanyargs.hpp +++ b/include/ruby/backward/cxxanyargs.hpp @@ -1,4 +1,5 @@ -/// \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY_BACKWARD_CXXANYARGS_HPP //-*-C++-*-vi:ft=cpp +#define RUBY_BACKWARD_CXXANYARGS_HPP /// @file /// @author \@shyouhei /// @copyright This file is a part of the programming language Ruby. @@ -9,8 +10,6 @@ /// meant to be a backwards compatibility shim. Please stick to /// C++ 98 and never use newer features, like `constexpr`. /// @brief Provides old prototypes for C++ programs. -#ifndef RUBY_BACKWARD_CXXANYARGS_HPP -#define RUBY_BACKWARD_CXXANYARGS_HPP #include "ruby/3/config.h" #include "ruby/3/intern/class.h" #include "ruby/3/intern/cont.h" diff --git a/include/ruby/backward/rubyio.h b/include/ruby/backward/rubyio.h index a6e3a7c78b..433f425988 100644 --- a/include/ruby/backward/rubyio.h +++ b/include/ruby/backward/rubyio.h @@ -1,6 +1,18 @@ +#ifndef RUBY_BACKWARD_RUBYIO_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD_RUBYIO_H +/** + * @file + * @author Ruby developers <ruby-core@ruby-lang.org> + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + */ #if defined __GNUC__ #warning use "ruby/io.h" instead of "rubyio.h" #elif defined _MSC_VER #pragma message("warning: use \"ruby/io.h\" instead of \"rubyio.h\"") #endif #include "ruby/io.h" + +#endif /* RUBY_BACKWARD_RUBYIO_H */ diff --git a/include/ruby/backward/rubysig.h b/include/ruby/backward/rubysig.h index 7a1ca35f20..b1645cdeb0 100644 --- a/include/ruby/backward/rubysig.h +++ b/include/ruby/backward/rubysig.h @@ -1,23 +1,20 @@ -/********************************************************************** - - rubysig.h - - - $Author$ - $Date$ - created at: Wed Aug 16 01:15:38 JST 1995 - - Copyright (C) 1993-2008 Yukihiro Matsumoto - -**********************************************************************/ - +#ifndef RUBYSIG_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBYSIG_H +/** + * @file + * @author $Author$ + * @date Wed Aug 16 01:15:38 JST 1995 + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + */ #if defined __GNUC__ #warning rubysig.h is obsolete #elif defined _MSC_VER #pragma message("warning: rubysig.h is obsolete") #endif -#ifndef RUBYSIG_H -#define RUBYSIG_H #include "ruby/ruby.h" #define RUBY_CRITICAL(statements) do {statements;} while (0) @@ -26,4 +23,4 @@ #define ALLOW_INTS do {CHECK_INTS;} while (0) #define CHECK_INTS rb_thread_check_ints() -#endif +#endif /* RUBYSIG_H */ diff --git a/include/ruby/backward/st.h b/include/ruby/backward/st.h index 3e36d44cf8..ad627e5e99 100644 --- a/include/ruby/backward/st.h +++ b/include/ruby/backward/st.h @@ -1,6 +1,18 @@ +#ifndef RUBY_BACKWARD_ST_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD_ST_H +/** + * @file + * @author Ruby developers <ruby-core@ruby-lang.org> + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + */ #if defined __GNUC__ #warning use "ruby/st.h" instead of bare "st.h" #elif defined _MSC_VER #pragma message("warning: use \"ruby/st.h\" instead of bare \"st.h\"") #endif #include "ruby/st.h" + +#endif /* RUBY_BACKWARD_ST_H */ diff --git a/include/ruby/backward/util.h b/include/ruby/backward/util.h index 11d32a2da8..1974fedbb5 100644 --- a/include/ruby/backward/util.h +++ b/include/ruby/backward/util.h @@ -1,6 +1,18 @@ +#ifndef RUBY_BACKWARD_UTIL_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY_BACKWARD_UTIL_H +/** + * @file + * @author Ruby developers <ruby-core@ruby-lang.org> + * @copyright This file is a part of the programming language Ruby. + * Permission is hereby granted, to either redistribute and/or + * modify this file, provided that the conditions mentioned in the + * file COPYING are met. Consult the file for details. + */ #if defined __GNUC__ #warning use "ruby/util.h" instead of bare "util.h" #elif defined _MSC_VER #pragma message("warning: use \"ruby/util.h\" instead of bare \"util.h\"") #endif #include "ruby/util.h" + +#endif /* RUBY_BACKWARD_UTIL_H */ |