diff options
author | 卜部昌平 <[email protected]> | 2020-04-10 14:11:40 +0900 |
---|---|---|
committer | 卜部昌平 <[email protected]> | 2020-04-13 16:06:00 +0900 |
commit | 4ff3f205408ff8bb413d69151105d301858136ba () | |
tree | 0494fea3f4cdb82ec1d34e462438389dfea8b8da /include/ruby/backward | |
parent | a3f6f67967644f34226b4424227d2eec52fedd45 (diff) |
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
Notes: Merged: https://.com/ruby/ruby/pull/3023
-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
@@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp * @file * @author Ruby developers <[email protected]> * @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 @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp * @file * @author Ruby developers <[email protected]> * @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" @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp * @file * @author Ruby developers <[email protected]> * @copyright This file is a part of the programming language Ruby. @@ -31,3 +33,5 @@ #elif ! TRUE # error TRUE must be true #endif @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp * @file * @author Ruby developers <[email protected]> * @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__ # 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 @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp * @file * @author Ruby developers <[email protected]> * @copyright This file is a part of the programming language Ruby. @@ -31,3 +33,5 @@ ((RUBY3_COMPILER_VERSION_MINOR == (y)) && \ (RUBY3_COMPILER_VERSION_ == (z)))))) #endif @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp * @file * @author Ruby developers <[email protected]> * @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 @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp * @file * @author Ruby developers <[email protected]> * @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 @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp * @file * @author Ruby developers <[email protected]> * @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") # 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 @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp * @file * @author Ruby developers <[email protected]> * @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 */ @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp * @file * @author Ruby developers <[email protected]> * @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 @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp * @file * @author Ruby developers <[email protected]> * @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 @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp * @file * @author Ruby developers <[email protected]> * @copyright This file is a part of the programming language Ruby. @@ -41,3 +43,5 @@ #else #define ANYARGS #endif @@ -1,12 +1,19 @@ #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 */ @@ -1,4 +1,5 @@ -/// \noop-*-C++-*-vi:ft=cpp /// @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 s 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" @@ -1,6 +1,18 @@ #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" @@ -1,23 +1,20 @@ -/********************************************************************** - - rubysig.h - - - $Author$ - $Date$ - created at: Wed Aug 16 01:15:38 JST 1995 - - Copyright (C) 1993-2008 Yukihiro Matsumoto - -**********************************************************************/ - #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 @@ -1,6 +1,18 @@ #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" @@ -1,6 +1,18 @@ #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" |