ruby-changes:60759
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 13 Apr 2020 16:06:25 +0900 (JST)
Subject: [ruby-changes:60759] 4ff3f20540 (master): add #include guard hack
https://git.ruby-lang.org/ruby.git/commit/?id=4ff3f20540 From 4ff3f205408ff8bb413d69151105d301858136ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= <shyouhei@r...> Date: Fri, 10 Apr 2020 14:11:40 +0900 Subject: 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 diff --git a/addr2line.h b/addr2line.h index 4f6cf17..f09b665 100644 --- a/addr2line.h +++ b/addr2line.h @@ -1,3 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/addr2line.h#L1 +#ifndef RUBY_ADDR2LINE_H +#define RUBY_ADDR2LINE_H /********************************************************************** addr2line.h - @@ -8,9 +10,6 @@ https://github.com/ruby/ruby/blob/trunk/addr2line.h#L10 **********************************************************************/ -#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 1396651..e0d3690 100644 --- a/constant.h +++ b/constant.h @@ -1,3 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/constant.h#L1 +#ifndef CONSTANT_H +#define CONSTANT_H /********************************************************************** constant.h - @@ -8,8 +10,6 @@ https://github.com/ruby/ruby/blob/trunk/constant.h#L10 Copyright (C) 2009 Yusuke Endoh **********************************************************************/ -#ifndef CONSTANT_H -#define CONSTANT_H #include "ruby/ruby.h" #include "id_table.h" diff --git a/dln.h b/dln.h index 9570de8..d899963 100644 --- a/dln.h +++ b/dln.h @@ -1,3 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/dln.h#L1 +#ifndef DLN_H +#define DLN_H /********************************************************************** dln.h - @@ -9,8 +11,6 @@ https://github.com/ruby/ruby/blob/trunk/dln.h#L11 **********************************************************************/ -#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 baf7073..8457a7b 100644 --- a/encindex.h +++ b/encindex.h @@ -1,3 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/encindex.h#L1 +#ifndef RUBY_ENCINDEX_H +#define RUBY_ENCINDEX_H 1 /********************************************************************** encindex.h - @@ -9,8 +11,6 @@ https://github.com/ruby/ruby/blob/trunk/encindex.h#L11 **********************************************************************/ -#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 076b5ce..e530f4f 100644 --- a/include/ruby.h +++ b/include/ruby.h @@ -1,17 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby.h#L1 -/********************************************************************** - - 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 7c2aa05..7eff1b2 100644 --- a/include/ruby/3/anyargs.h +++ b/include/ruby/3/anyargs.h @@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/3/anyargs.h#L1 -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY3_ANYARGS_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY3_ANYARGS_H +/** * @file * @author Ruby developers <ruby-core@r...> * @copyright This file is a part of the programming language Ruby. @@ -65,8 +67,6 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/3/anyargs.h#L67 * `__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 *) https://github.com/ruby/ruby/blob/trunk/include/ruby/3/anyargs.h#L371 #endif -#endif /* RUBY3_ANYARGS_H */ +#endif /* RUBY3_ANYARGS_H */ diff --git a/include/ruby/3/arithmetic.h b/include/ruby/3/arithmetic.h index 366014a..5dcdfcd 100644 --- a/include/ruby/3/arithmetic.h +++ b/include/ruby/3/arithmetic.h @@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/3/arithmetic.h#L1 -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY3_ARITHMETIC_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY3_ARITHMETIC_H +/** * @file * @author Ruby developers <ruby-core@r...> * @copyright This file is a part of the programming language Ruby. @@ -33,3 +35,4 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/3/arithmetic.h#L35 #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 94329b7..03afa0a 100644 --- a/include/ruby/3/arithmetic/char.h +++ b/include/ruby/3/arithmetic/char.h @@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/3/arithmetic/char.h#L1 -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY3_ARITHMETIC_CHAR_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY3_ARITHMETIC_CHAR_H +/** * @file * @author Ruby developers <ruby-core@r...> * @copyright This file is a part of the programming language Ruby. @@ -18,8 +20,6 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/3/arithmetic/char.h#L20 * extension libraries. They could be written in C++98. * @brief Arithmetic conversion between C's `char` and Ruby's. */ -#ifndef RUBY3_ARITHMETIC_CHAR_H -#define RUBY3_ARITHMETIC_CHAR_H #include "ruby/3/arithmetic/int.h" /* NUM2INT is here, but */ #include "ruby/3/arithmetic/long.h" /* INT2FIX is here.*/ #include "ruby/3/attr/artificial.h" diff --git a/include/ruby/3/arithmetic/double.h b/include/ruby/3/arithmetic/double.h index 82e9fdc..4a37611 100644 --- a/include/ruby/3/arithmetic/double.h +++ b/include/ruby/3/arithmetic/double.h @@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/3/arithmetic/double.h#L1 -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY3_ARITHMETIC_DOUBLE_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY3_ARITHMETIC_DOUBLE_H +/** * @file * @author Ruby developers <ruby-core@r...> * @copyright This file is a part of the programming language Ruby. @@ -18,8 +20,6 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/3/arithmetic/double.h#L20 * extension libraries. They could be written in C++98. * @brief Arithmetic conversion between C's `double` and Ruby's. */ -#ifndef RUBY3_ARITHMETIC_DOUBLE_H -#define RUBY3_ARITHMETIC_DOUBLE_H #include "ruby/3/attr/pure.h" #include "ruby/3/dllexport.h" #include "ruby/3/value.h" diff --git a/include/ruby/3/arithmetic/fixnum.h b/include/ruby/3/arithmetic/fixnum.h index e995b5f..d7214e0 100644 --- a/include/ruby/3/arithmetic/fixnum.h +++ b/include/ruby/3/arithmetic/fixnum.h @@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/3/arithmetic/fixnum.h#L1 -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY3_ARITHMETIC_FIXNUM_H /*-*-C++-*-vi:se ft=cpp:*/ +#define RUBY3_ARITHMETIC_FIXNUM_H +/** * @file * @author Ruby developers <ruby-core@r...> * @copyright This file is a part of the programming language Ruby. @@ -18,8 +20,6 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/3/arithmetic/fixnum.h#L20 * extension libraries. They could be written in C++98. * @brief Handling of integers formerly known as Fixnums. */ -#ifndef RUBY3_ARITHMETIC_FIXNUM_H -#define RUBY3_ARITHMETIC_FIXNUM_H #include "ruby/backward/2/limits.h" #define FIXABLE RB_FIXABLE diff --git a/include/ruby/3/arithmetic/gid_t.h b/include/ruby/3/arithmetic/gid_t.h index ebdd4d2..7c4c1b0 100644 --- a/include/ruby/3/arithmetic/gid_t.h +++ b/include/ruby/3/arithmetic/gid_t.h @@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/3/arithmetic/gid_t.h#L1 -/** \noop-*-C++-*-vi:ft=cpp +#ifndef RUBY3_ARITHMETIC_GID_T_H (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/