diff options
author | 卜部昌平 <[email protected]> | 2020-04-10 14:11:40 +0900 |
---|---|---|
committer | 卜部昌平 <[email protected]> | 2020-04-13 16:06:00 +0900 |
commit | 4ff3f205408ff8bb413d69151105d301858136ba (patch) | |
tree | 0494fea3f4cdb82ec1d34e462438389dfea8b8da | |
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
Notes:
Merged: https://github.com/ruby/ruby/pull/3023
255 files changed, 1141 insertions, 1038 deletions
diff --git a/addr2line.h b/addr2line.h index 4f6cf179ef..f09b665800 100644 --- a/addr2line.h +++ b/addr2line.h @@ -1,3 +1,5 @@ +#ifndef RUBY_ADDR2LINE_H +#define RUBY_ADDR2LINE_H /********************************************************************** addr2line.h - @@ -8,9 +10,6 @@ **********************************************************************/ -#ifndef RUBY_ADDR2LINE_H -#define RUBY_ADDR2LINE_H - #if (defined(USE_ELF) || defined(HAVE_MACH_O_LOADER_H)) void diff --git a/constant.h b/constant.h index 1396651e21..e0d36909e1 100644 --- a/constant.h +++ b/constant.h @@ -1,3 +1,5 @@ +#ifndef CONSTANT_H +#define CONSTANT_H /********************************************************************** constant.h - @@ -8,8 +10,6 @@ Copyright (C) 2009 Yusuke Endoh **********************************************************************/ -#ifndef CONSTANT_H -#define CONSTANT_H #include "ruby/ruby.h" #include "id_table.h" @@ -1,3 +1,5 @@ +#ifndef DLN_H +#define DLN_H /********************************************************************** dln.h - @@ -9,8 +11,6 @@ **********************************************************************/ -#ifndef DLN_H -#define DLN_H #include "ruby/defines.h" /* for RUBY_SYMBOL_EXPORT_BEGIN */ #ifdef __cplusplus diff --git a/encindex.h b/encindex.h index baf70735ec..8457a7b39f 100644 --- a/encindex.h +++ b/encindex.h @@ -1,3 +1,5 @@ +#ifndef RUBY_ENCINDEX_H +#define RUBY_ENCINDEX_H 1 /********************************************************************** encindex.h - @@ -9,8 +11,6 @@ **********************************************************************/ -#ifndef RUBY_ENCINDEX_H -#define RUBY_ENCINDEX_H 1 #include "ruby/encoding.h" /* rb_ascii8bit_encindex etc. */ #if defined(__cplusplus) extern "C" { diff --git a/include/ruby.h b/include/ruby.h index 076b5ce258..e530f4f0ad 100644 --- a/include/ruby.h +++ b/include/ruby.h @@ -1,17 +1,15 @@ -/********************************************************************** - - ruby.h - - - $Author$ - created at: Sun 10 12:06:15 Jun JST 2007 - - Copyright (C) 2007-2008 Yukihiro Matsumoto - -**********************************************************************/ - -#ifndef RUBY_H +#ifndef RUBY_H /*-*-C++-*-vi:se ft=cpp:*/ #define RUBY_H 1 - +/** + * @file + * @author $Author$ + * @date Sun 10 12:06:15 Jun JST 2007 + * @copyright 2007-2008 Yukihiro Matsumoto + * @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. + */ #define HAVE_RUBY_DEFINES_H 1 #define HAVE_RUBY_ENCODING_H 1 #define HAVE_RUBY_INTERN_H 1 diff --git a/include/ruby/3/anyargs.h b/include/ruby/3/anyargs.h index 7c2aa05c21..7eff1b2cc9 100644 --- a/include/ruby/3/anyargs.h +++ b/include/ruby/3/anyargs.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY3_ANYARGS_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY3_ANYARGS_H +/** * @file * @author Ruby developers <[email protected]> * @copyright This file is a part of the programming language Ruby. @@ -65,8 +67,6 @@ * `__builtin_types_compatible_p`, and in doing so we need to distinguish * ::rb_f_notimplement from others, by type. */ -#ifndef RUBY3_ANYARGS_H -#define RUBY3_ANYARGS_H #include "ruby/3/attr/maybe_unused.h" #include "ruby/3/attr/nonnull.h" #include "ruby/3/attr/weakref.h" @@ -371,4 +371,4 @@ RUBY3_ANYARGS_DECL(rb_define_method, VALUE, const char *) #endif -#endif /* RUBY3_ANYARGS_H */ +#endif /* RUBY3_ANYARGS_H */ diff --git a/include/ruby/3/arithmetic.h b/include/ruby/3/arithmetic.h index 366014ac77..5dcdfcd9e4 100644 --- a/include/ruby/3/arithmetic.h +++ b/include/ruby/3/arithmetic.h @@ -1,4 +1,6 @@ -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY3_ARITHMETIC_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY3_ARITHMETIC_H +/** * @file * @author Ruby developers <[email protected]> * @copyright This file is a part of the programming language Ruby. @@ -33,3 +35,4 @@ #include "ruby/3/arithmetic/size_t.h" #include "ruby/3/arithmetic/st_data_t.h" #include "ruby/3/arithmetic/uid_t.h" +#endif /* RUBY3_ARITHMETIC_H */ diff --git a/include/ruby/3/arithmetic/char.h b/include/ruby/3/arithmetic/char.h index 94329b7a9e..03afa0a406 100644 --- a/include/ruby/3/arithmetic/char.h +++ b/ |