From 9e6e39c3512f7a962c44dc3729c98a0f8be90341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Wed, 8 Apr 2020 13:28:13 +0900 Subject: Merge pull request #2991 from shyouhei/ruby.h Split ruby.h --- include/ruby/3/attr/alloc_size.h | 32 +++++++++++ include/ruby/3/attr/artificial.h | 46 ++++++++++++++++ include/ruby/3/attr/cold.h | 38 +++++++++++++ include/ruby/3/attr/const.h | 52 ++++++++++++++++++ include/ruby/3/attr/constexpr.h | 91 ++++++++++++++++++++++++++++++++ include/ruby/3/attr/deprecated.h | 58 ++++++++++++++++++++ include/ruby/3/attr/diagnose_if.h | 41 ++++++++++++++ include/ruby/3/attr/enum_extensibility.h | 32 +++++++++++ include/ruby/3/attr/error.h | 32 +++++++++++ include/ruby/3/attr/flag_enum.h | 33 ++++++++++++ include/ruby/3/attr/forceinline.h | 41 ++++++++++++++ include/ruby/3/attr/format.h | 42 +++++++++++++++ include/ruby/3/attr/maybe_unused.h | 40 ++++++++++++++ include/ruby/3/attr/noalias.h | 58 ++++++++++++++++++++ include/ruby/3/attr/nodiscard.h | 48 +++++++++++++++++ include/ruby/3/attr/noexcept.h | 90 +++++++++++++++++++++++++++++++ include/ruby/3/attr/noinline.h | 36 +++++++++++++ include/ruby/3/attr/nonnull.h | 32 +++++++++++ include/ruby/3/attr/noreturn.h | 51 ++++++++++++++++++ include/ruby/3/attr/pure.h | 48 +++++++++++++++++ include/ruby/3/attr/restrict.h | 44 +++++++++++++++ include/ruby/3/attr/returns_nonnull.h | 36 +++++++++++++ include/ruby/3/attr/warning.h | 32 +++++++++++ include/ruby/3/attr/weakref.h | 32 +++++++++++ 24 files changed, 1085 insertions(+) create mode 100644 include/ruby/3/attr/alloc_size.h create mode 100644 include/ruby/3/attr/artificial.h create mode 100644 include/ruby/3/attr/cold.h create mode 100644 include/ruby/3/attr/const.h create mode 100644 include/ruby/3/attr/constexpr.h create mode 100644 include/ruby/3/attr/deprecated.h create mode 100644 include/ruby/3/attr/diagnose_if.h create mode 100644 include/ruby/3/attr/enum_extensibility.h create mode 100644 include/ruby/3/attr/error.h create mode 100644 include/ruby/3/attr/flag_enum.h create mode 100644 include/ruby/3/attr/forceinline.h create mode 100644 include/ruby/3/attr/format.h create mode 100644 include/ruby/3/attr/maybe_unused.h create mode 100644 include/ruby/3/attr/noalias.h create mode 100644 include/ruby/3/attr/nodiscard.h create mode 100644 include/ruby/3/attr/noexcept.h create mode 100644 include/ruby/3/attr/noinline.h create mode 100644 include/ruby/3/attr/nonnull.h create mode 100644 include/ruby/3/attr/noreturn.h create mode 100644 include/ruby/3/attr/pure.h create mode 100644 include/ruby/3/attr/restrict.h create mode 100644 include/ruby/3/attr/returns_nonnull.h create mode 100644 include/ruby/3/attr/warning.h create mode 100644 include/ruby/3/attr/weakref.h (limited to 'include/ruby/3/attr') diff --git a/include/ruby/3/attr/alloc_size.h b/include/ruby/3/attr/alloc_size.h new file mode 100644 index 0000000000..1b13e6f4a5 --- /dev/null +++ b/include/ruby/3/attr/alloc_size.h @@ -0,0 +1,32 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_ALLOC_SIZE. + */ +#include "ruby/3/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((alloc_size))` */ +#if defined(RUBY3_ATTR_ALLOC_SIZE) +# /* Take that. */ + +#elif RUBY3_HAS_ATTRIBUTE(alloc_size) +# define RUBY3_ATTR_ALLOC_SIZE(tuple) __attribute__((__alloc_size__ tuple)) + +#else +# define RUBY3_ATTR_ALLOC_SIZE(tuple) /* void */ +#endif diff --git a/include/ruby/3/attr/artificial.h b/include/ruby/3/attr/artificial.h new file mode 100644 index 0000000000..7b0acab2f6 --- /dev/null +++ b/include/ruby/3/attr/artificial.h @@ -0,0 +1,46 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_ARTIFICIAL. + * + * ### Q&A ### + * + * - Q: What is this attribute? I don't get what GCC manual is talking about. + * + * - A: In short it is an attribute to manipulate GDB backtraces. The + * attribute makes the best sense when it comes with + * __attribute__((always_inline)). When a function annotated with this + * attribute gets inlined, and when you somehow look at a backtrace which + * includes such inlined call site, then the backtrace shows the caller + * and not the callee. This is handy for instance when an identical + * function is inlined more than once in a single big function. On such + * case it gets vital to know where the inlining happened in the callee. + * See also https://stackoverflow.com/a/21936099 + */ +#include "ruby/3/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((artificial))` */ +#if defined(RUBY3_ATTR_ARTIFICIAL) +# /* Take that. */ + +#elif RUBY3_HAS_ATTRIBUTE(artificial) +# define RUBY3_ATTR_ARTIFICIAL() __attribute__((__artificial__)) + +#else +# define RUBY3_ATTR_ARTIFICIAL() /* void */ +#endif diff --git a/include/ruby/3/attr/cold.h b/include/ruby/3/attr/cold.h new file mode 100644 index 0000000000..6c1093d1ff --- /dev/null +++ b/include/ruby/3/attr/cold.h @@ -0,0 +1,38 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_COLD. + */ +#include "ruby/3/compiler_is.h" +#include "ruby/3/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((cold))` */ +#if defined(RUBY3_ATTR_COLD) +# /* Take that. */ + +#elif RUBY3_COMPILER_IS(SunPro) +# /* Recent SunPro has __has_attribute, and is borken. */ +# /* It reports it has attribute cold, reality isn't (warnings issued). */ +# define RUBY3_ATTR_COLD() /* void */ + +#elif RUBY3_HAS_ATTRIBUTE(cold) +# define RUBY3_ATTR_COLD() __attribute__((__cold__)) + +#else +# define RUBY3_ATTR_COLD() /* void */ +#endif diff --git a/include/ruby/3/attr/const.h b/include/ruby/3/attr/const.h new file mode 100644 index 0000000000..06372db0c2 --- /dev/null +++ b/include/ruby/3/attr/const.h @@ -0,0 +1,52 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_CONST. + */ +#include "ruby/3/compiler_since.h" +#include "ruby/3/has/attribute.h" +#include "ruby/3/has/declspec_attribute.h" + +/** Wraps (or simulates) `__attribute__((const))` */ +#if defined(RUBY3_ATTR_CONST) +# /* Take that. */ + +#elif RUBY3_HAS_ATTRIBUTE(const) +# define RUBY3_ATTR_CONST() __attribute__((__const__)) + +#elif RUBY3_HAS_DECLSPEC_ATTRIBUTE(noalias) +# /* If a function can be a const, that is also a noalias. */ +# define RUBY3_ATTR_CONST() __declspec(noalias) + +#elif RUBY3_COMPILER_SINCE(SunPro, 5, 10, 0) +# define RUBY3_ATTR_CONST() _Pragma("no_side_effect") + +#else +# define RUBY3_ATTR_CONST() /* void */ +#endif + +/** Enables #RUBY3_ATTR_CONST iff. #RUBY_NDEBUG. */ +#if defined(RUBY3_ATTR_CONST_ON_NDEBUG) +# /* Take that. */ + +#elif RUBY_NDEBUG +# define RUBY3_ATTR_CONST_ON_NDEBUG() RUBY3_ATTR_CONST() + +#else +# define RUBY3_ATTR_CONST_ON_NDEBUG() /* void */ +#endif diff --git a/include/ruby/3/attr/constexpr.h b/include/ruby/3/attr/constexpr.h new file mode 100644 index 0000000000..5c09bced49 --- /dev/null +++ b/include/ruby/3/attr/constexpr.h @@ -0,0 +1,91 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief #RUBY3_ATTR_CONSTEXPR. + */ +#include "ruby/3/has/feature.h" +#include "ruby/3/compiler_is.h" +#include "ruby/3/token_paste.h" + +/** @cond INTERNAL_MACRO*/ +#if defined(RUBY3_ATTR_CONSTEXPR) +# /* Take that. */ + +#elif ! defined(__cplusplus) +# /* Makes no sense. */ +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX11 0 +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX14 0 + +#elif defined(__cpp_constexpr) +# /* https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations */ +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX11 (__cpp_constexpr >= 200704L) +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX14 (__cpp_constexpr >= 201304L) + +#elif RUBY3_COMPILER_SINCE(MSVC, 19, 0, 0) +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX11 RUBY3_COMPILER_SINCE(MSVC, 19, 00, 00) +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX14 RUBY3_COMPILER_SINCE(MSVC, 19, 11, 00) + +#elif RUBY3_COMPILER_SINCE(SunPro, 5, 13, 0) +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX11 (__cplusplus >= 201103L) +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX14 (__cplusplus >= 201402L) + +#elif RUBY3_COMPILER_SINCE(GCC, 4, 9, 0) +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX11 (__cplusplus >= 201103L) +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX14 (__cplusplus >= 201402L) + +#elif RUBY3_HAS_FEATURE(cxx_relaxed_constexpr) +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX11 1 +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX14 1 + +#elif RUBY3_HAS_FEATURE(cxx_constexpr) +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX11 1 +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX14 0 + +#else +# /* :FIXME: icpc must have constexpr but don't know how to detect. */ +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX11 0 +# define RUBY3_HAS_ATTR_CONSTEXPR_CXX14 0 +#endif +/** @endcond */ + +/** Wraps (or simulates) C++11 `constexpr`. */ +#if defined(RUBY3_ATTR_CONSTEXPR) +# /* Take that. */ + +#elif RUBY3_HAS_ATTR_CONSTEXPR_CXX14 +# define RUBY3_ATTR_CONSTEXPR(_) constexpr + +#elif RUBY3_HAS_ATTR_CONSTEXPR_CXX11 +# define RUBY3_ATTR_CONSTEXPR(_) RUBY3_TOKEN_PASTE(RUBY3_ATTR_CONSTEXPR_, _) +# define RUBY3_ATTR_CONSTEXPR_CXX11 constexpr +# define RUBY3_ATTR_CONSTEXPR_CXX14 /* void */ + +#else +# define RUBY3_ATTR_CONSTEXPR(_) /* void */ +#endif + +/** Enables #RUBY3_ATTR_CONSTEXPR iff. #RUBY_NDEBUG. */ +#if defined(RUBY3_ATTR_CONSTEXPR_ON_NDEBUG) +# /* Take that. */ + +#elif RUBY_NDEBUG +# define RUBY3_ATTR_CONSTEXPR_ON_NDEBUG(_) RUBY3_ATTR_CONSTEXPR(_) + +#else +# define RUBY3_ATTR_CONSTEXPR_ON_NDEBUG(_) /* void */ +#endif diff --git a/include/ruby/3/attr/deprecated.h b/include/ruby/3/attr/deprecated.h new file mode 100644 index 0000000000..cea124e1fe --- /dev/null +++ b/include/ruby/3/attr/deprecated.h @@ -0,0 +1,58 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_DEPRECATED. + */ +#include "ruby/3/compiler_since.h" +#include "ruby/3/has/attribute.h" +#include "ruby/3/has/c_attribute.h" +#include "ruby/3/has/cpp_attribute.h" +#include "ruby/3/has/declspec_attribute.h" +#include "ruby/3/has/extension.h" + +/** Wraps (or simulates) `[[deprecated]]` */ +#if defined(RUBY3_ATTR_DEPRECATED) +# /* Take that. */ + +#elif RUBY3_HAS_EXTENSION(attribute_deprecated_with_message) +# define RUBY3_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg)) + +#elif RUBY3_COMPILER_SINCE(GCC, 4, 5, 0) +# define RUBY3_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg)) + +#elif RUBY3_COMPILER_SINCE(Intel, 13, 0, 0) +# define RUBY3_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg)) + +#elif RUBY3_HAS_ATTRIBUTE(deprecated) /* but not with message. */ +# define RUBY3_ATTR_DEPRECATED(msg) __attribute__((__deprecated__)) + +#elif RUBY3_COMPILER_SINCE(MSVC, 14, 0, 0) +# define RUBY3_ATTR_DEPRECATED(msg) __declspec(deprecated msg) + +#elif RUBY3_HAS_DECLSPEC_ATTRIBUTE(deprecated) +# define RUBY3_ATTR_DEPRECATED(msg) __declspec(deprecated) + +#elif RUBY3_HAS_CPP_ATTRIBUTE(deprecated) +# define RUBY3_ATTR_DEPRECATED(msg) [[deprecated msg]] + +#elif RUBY3_HAS_C_ATTRIBUTE(deprecated) +# define RUBY3_ATTR_DEPRECATED(msg) [[deprecated msg]] + +#else +# define RUBY3_ATTR_DEPRECATED(msg) /* void */ +#endif diff --git a/include/ruby/3/attr/diagnose_if.h b/include/ruby/3/attr/diagnose_if.h new file mode 100644 index 0000000000..88ad81ab2c --- /dev/null +++ b/include/ruby/3/attr/diagnose_if.h @@ -0,0 +1,41 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_DIAGNOSE_IF. + */ +#include "ruby/3/has/attribute.h" +#include "ruby/3/warning_push.h" + +/** Wraps (or simulates) `__attribute__((diagnose_if))` */ +#if defined(RUBY3_ATTR_DIAGNOSE_IF) +# /* Take that. */ + +#elif RUBY3_COMPILER_BEFORE(Clang, 5, 0, 0) +# /* https://bugs.llvm.org/show_bug.cgi?id=34319 */ +# define RUBY3_ATTR_DIAGNOSE_IF(_, __, ___) /* void */ + +#elif RUBY3_HAS_ATTRIBUTE(diagnose_if) +# define RUBY3_ATTR_DIAGNOSE_IF(_, __, ___) \ + RUBY3_WARNING_PUSH() \ + RUBY3_WARNING_IGNORED(-Wgcc-compat) \ + __attribute__((__diagnose_if__(_, __, ___))) \ + RUBY3_WARNING_POP() + +#else +# define RUBY3_ATTR_DIAGNOSE_IF(_, __, ___) /* void */ +#endif diff --git a/include/ruby/3/attr/enum_extensibility.h b/include/ruby/3/attr/enum_extensibility.h new file mode 100644 index 0000000000..2135736de7 --- /dev/null +++ b/include/ruby/3/attr/enum_extensibility.h @@ -0,0 +1,32 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief #RUBY3_ATTR_ENUM_EXTENSIBILITY. + */ +#include "ruby/3/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((enum_extensibility))` */ +#if defined(RUBY3_ATTR_ENUM_EXTENSIBILITY) +# /* Take that. */ + +#elif RUBY3_HAS_ATTRIBUTE(enum_extensibility) +# define RUBY3_ATTR_ENUM_EXTENSIBILITY(_) __attribute__((__enum_extensibility__(_))) + +#else +# define RUBY3_ATTR_ENUM_EXTENSIBILITY(_) /* void */ +#endif diff --git a/include/ruby/3/attr/error.h b/include/ruby/3/attr/error.h new file mode 100644 index 0000000000..15d9181fe2 --- /dev/null +++ b/include/ruby/3/attr/error.h @@ -0,0 +1,32 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_ERROR. + */ +#include "ruby/3/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((error))` */ +#if defined(RUBY3_ATTR_ERROR) +# /* Take that. */ + +#elif RUBY3_HAS_ATTRIBUTE(error) +# define RUBY3_ATTR_ERROR(msg) __attribute__((__error__ msg)) + +#else +# define RUBY3_ATTR_ERROR(msg) /* void */ +#endif diff --git a/include/ruby/3/attr/flag_enum.h b/include/ruby/3/attr/flag_enum.h new file mode 100644 index 0000000000..a026ab5de1 --- /dev/null +++ b/include/ruby/3/attr/flag_enum.h @@ -0,0 +1,33 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_FLAG_ENUM. + * @see https://clang.llvm.org/docs/AttributeReference.html#flag_enum + */ +#include "ruby/3/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((flag_enum)` */ +#if defined(RUBY3_ATTR_FLAG_ENUM) +# /* Take that. */ + +#elif RUBY3_HAS_ATTRIBUTE(flag_enum) +# define RUBY3_ATTR_FLAG_ENUM() __attribute__((__flag_enum__)) + +#else +# define RUBY3_ATTR_FLAG_ENUM() /* void */ +#endif diff --git a/include/ruby/3/attr/forceinline.h b/include/ruby/3/attr/forceinline.h new file mode 100644 index 0000000000..47d7d58147 --- /dev/null +++ b/include/ruby/3/attr/forceinline.h @@ -0,0 +1,41 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_FORCEINLINE. + */ +#include "ruby/3/compiler_since.h" +#include "ruby/3/has/attribute.h" + +/** + * Wraps (or simulates) `__forceinline`. MSVC complains on declarations like + * `static inline __forceinline void foo()`. It seems MSVC's `inline` and + * `__forceinline` are mutually exclusive. We have to mimic that behaviour for + * non-MSVC compilers. + */ +#if defined(RUBY3_ATTR_FORCEINLINE) +# /* Take that. */ + +#elif RUBY3_COMPILER_SINCE(MSVC, 12, 0, 0) +# define RUBY3_ATTR_FORCEINLINE() __forceinline + +#elif RUBY3_HAS_ATTRIBUTE(always_inline) +# define RUBY3_ATTR_FORCEINLINE() __attribute__((__always_inline__)) inline + +#else +# define RUBY3_ATTR_FORCEINLINE() inline +#endif diff --git a/include/ruby/3/attr/format.h b/include/ruby/3/attr/format.h new file mode 100644 index 0000000000..b41094f221 --- /dev/null +++ b/include/ruby/3/attr/format.h @@ -0,0 +1,42 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_FORMAT. + */ +#include "ruby/3/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((format))` */ +#if defined(RUBY3_ATTR_FORMAT) +# /* Take that. */ + +#elif RUBY3_HAS_ATTRIBUTE(format) +# define RUBY3_ATTR_FORMAT(x, y, z) __attribute__((__format__(x, y, z))) + +#else +# define RUBY3_ATTR_FORMAT(x, y, z) /* void */ +#endif + +#if defined(RUBY3_PRINTF_FORMAT) +# /* Take that. */ + +#elif defined(__MINGW_PRINTF_FORMAT) +# define RUBY3_PRINTF_FORMAT __MINGW_PRINTF_FORMAT + +#else +# define RUBY3_PRINTF_FORMAT __printf__ +#endif diff --git a/include/ruby/3/attr/maybe_unused.h b/include/ruby/3/attr/maybe_unused.h new file mode 100644 index 0000000000..3463dfb77a --- /dev/null +++ b/include/ruby/3/attr/maybe_unused.h @@ -0,0 +1,40 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_MAYBE_UNUSED. + */ +#include "ruby/3/has/attribute.h" +#include "ruby/3/has/c_attribute.h" +#include "ruby/3/has/cpp_attribute.h" + +/** Wraps (or simulates) `[[maybe_unused]]` */ +#if defined(RUBY3_ATTR_MAYBE_UNUSED) +# /* Take that. */ + +#elif RUBY3_HAS_CPP_ATTRIBUTE(maybe_unused) +# define RUBY3_ATTR_MAYBE_UNUSED() [[maybe_unused]] + +#elif RUBY3_HAS_C_ATTRIBUTE(maybe_unused) +# define RUBY3_ATTR_MAYBE_UNUSED() [[maybe_unused]] + +#elif RUBY3_HAS_ATTRIBUTE(unused) +# define RUBY3_ATTR_MAYBE_UNUSED() __attribute__((__unused__)) + +#else +# define RUBY3_ATTR_MAYBE_UNUSED() /* void */ +#endif diff --git a/include/ruby/3/attr/noalias.h b/include/ruby/3/attr/noalias.h new file mode 100644 index 0000000000..c15f1480cb --- /dev/null +++ b/include/ruby/3/attr/noalias.h @@ -0,0 +1,58 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_NOALIAS. + * + * ### Q&A ### + * + * - Q: There are seemingly similar attributes named #RUBY3_ATTR_CONST, + * #RUBY3_ATTR_PURE, and #RUBY3_ATTR_NOALIAS. What are the difference? + * + * - A: Allowed operations are different. + * + * - #RUBY3_ATTR_CONST ... Functions attributed by this are not allowed to + * read/write _any_ pointers at all (there are exceptional situations + * when reading a pointer is possible but forget that; they are too + * exceptional to be useful). Just remember that everything pointer- + * related are NG. + * + * - #RUBY3_ATTR_PURE ... Functions attributed by this can read any + * nonvolatile pointers, but no writes are allowed at all. The ability + * to read _any_ nonvolatile pointers makes it possible to mark ::VALUE- + * taking functions as being pure, as long as they are read-only. + * + * - #RUBY3_ATTR_NOALIAS ... Can both read/write, but only through pointers + * passed to the function as parameters. This is a typical situation + * when you create a C++ non-static member function which only concerns + * `this`. No global variables are allowed to read/write. So this is + * not a super-set of being pure. If you want to read something, that + * has to be passed to the function as a pointer. ::VALUE -taking + * functions thus cannot be attributed as such. + */ +#include "ruby/3/has/declspec_attribute.h" + +/** Wraps (or simulates) `__declspec((noalias))` */ +#if defined(RUBY3_ATTR_NOALIAS) +# /* Take that. */ + +#elif RUBY3_HAS_DECLSPEC_ATTRIBUTE(noalias) +# define RUBY3_ATTR_NOALIAS() __declspec(noalias) + +#else +# define RUBY3_ATTR_NOALIAS() /* void */ +#endif diff --git a/include/ruby/3/attr/nodiscard.h b/include/ruby/3/attr/nodiscard.h new file mode 100644 index 0000000000..00ef068422 --- /dev/null +++ b/include/ruby/3/attr/nodiscard.h @@ -0,0 +1,48 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_NODISCARD. + */ +#include "ruby/3/has/attribute.h" +#include "ruby/3/has/c_attribute.h" +#include "ruby/3/has/cpp_attribute.h" + +/** + * Wraps (or simulates) `[[nodiscard]]`. In C++ (at least since C++20) a + * nodiscard attribute can have a message why the result shall not be ignoed. + * However GCC attribute and SAL annotation cannot take them. + */ +#if defined(RUBY3_ATTR_NODISCARD) +# /* Take that. */ + +#elif RUBY3_HAS_CPP_ATTRIBUTE(nodiscard) +# define RUBY3_ATTR_NODISCARD() [[nodiscard]] + +#elif RUBY3_HAS_C_ATTRIBUTE(nodiscard) +# define RUBY3_ATTR_NODISCARD() [[nodiscard]] + +#elif RUBY3_HAS_ATTRIBUTE(warn_unused_result) +# define RUBY3_ATTR_NODISCARD() __attribute__((__warn_unused_result__)) + +#elif defined(_Check_return_) +# /* Take SAL definition. */ +# define RUBY3_ATTR_NODISCARD() _Check_return_ + +#else +# define RUBY3_ATTR_NODISCARD() /* void */ +#endif diff --git a/include/ruby/3/attr/noexcept.h b/include/ruby/3/attr/noexcept.h new file mode 100644 index 0000000000..c5db6b3e79 --- /dev/null +++ b/include/ruby/3/attr/noexcept.h @@ -0,0 +1,90 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_NOEXCEPT. + * + * This isn't actually an attribute in C++ but who cares... + * + * Mainly due to aesthetic reasons, this one is rarely used in the project. + * But can be handy on occasions, especially when a function's noexcept-ness + * depends on its calling functions. + * + * ### Q&A ### + * + * - Q: Can a function that raises Ruby exceptions be attributed `noexcept`? + * + * - A: Yes. `noexcept` is about C++ exceptions, not Ruby's. They don't + * interface each other. You can safely attribute a function that raises + * Ruby exceptions as `noexcept`. + * + * - Q: How, then, can I assert that a function I wrote doesn't raise any Ruby + * exceptions? + * + * - A: `__attribute__((__leaf__))` is for that purpose. A function attributed + * as leaf can still throw C++ exceptions, but not Ruby's. Note however, + * that it's extremely difficult -- if not impossible -- to assert that a + * function doesn't raise any Ruby exceptions at all. Use of that + * attribute is not recommended; mere mortals can't properly use that by + * hand. + * + * - Q: Does it make sense to attribute an inline function `noexcept`? + * + * - A: I thought so before. But no, I don't think they are useful any longer. + * + * - When an inline function attributed `noexcept` actually doesn't throw + * any exceptions at all: these days I don't see any difference in + * generated assembly by adding/removing this attribute. C++ compilers + * get smarter and smarter. Today they can infer if it actually throws + * or not without any annotations by humans (correct me if I'm wrong). + * + * - When an inline function attributed `noexcepr` actually _does_ throw an + * exception: they have to call `std::terminate` then (C++ standard + * mandates so). This means exception handling routines are actually + * enforced, not omitted. This doesn't impact runtime performance (The + * Itanium C++ ABI has zero-cost exception handling), but does impact on + * generated binary size. This is bad. + */ +#include "ruby/3/compiler_since.h" +#include "ruby/3/has/feature.h" + +/** Wraps (or simulates) C++11 `noexcept` */ +#if defined(RUBY3_ATTR_NOEXCEPT) +# /* Take that. */ + +#elif ! defined(__cplusplus) +# /* Doesn't make sense. */ +# define RUBY3_ATTR_NOEXCEPT(_) /* void */ + +#elif RUBY3_HAS_FEATURE(cxx_noexcept) +# define RUBY3_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) + +#elif defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__ +# define RUBY3_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) + +#elif defined(__INTEL_CXX11_MODE__) +# define RUBY3_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) + +#elif RUBY3_COMPILER_SINCE(MSVC, 19, 0, 0) +# define RUBY3_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) + +#elif __cplusplus >= 201103L +# define RUBY3_ATTR_NOEXCEPT(_) noexcept(noexcept(_)) + +#else +# define RUBY3_ATTR_NOEXCEPT(_) /* void */ +#endif diff --git a/include/ruby/3/attr/noinline.h b/include/ruby/3/attr/noinline.h new file mode 100644 index 0000000000..470043794a --- /dev/null +++ b/include/ruby/3/attr/noinline.h @@ -0,0 +1,36 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_NOINLINE. + */ +#include "ruby/3/has/attribute.h" +#include "ruby/3/has/declspec_attribute.h" + +/** Wraps (or simulates) `__declspec(noinline)` */ +#if defined(RUBY3_ATTR_NOINLINE) +# /* Take that. */ + +#elif RUBY3_HAS_DECLSPEC_ATTRIBUTE(noinline) +# define RUBY3_ATTR_NOINLINE() __declspec(noinline) + +#elif RUBY3_HAS_ATTRIBUTE(noinline) +# define RUBY3_ATTR_NOINLINE() __attribute__((__noinline__)) + +#else +# define RUBY3_ATTR_NOINLINE() /* void */ +#endif diff --git a/include/ruby/3/attr/nonnull.h b/include/ruby/3/attr/nonnull.h new file mode 100644 index 0000000000..fff90df55b --- /dev/null +++ b/include/ruby/3/attr/nonnull.h @@ -0,0 +1,32 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_NONNULL. + */ +#include "ruby/3/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((nonnull))` */ +#if defined(RUBY3_ATTR_NONNULL) +# /* Take that. */ + +#elif RUBY3_HAS_ATTRIBUTE(nonnull) +# define RUBY3_ATTR_NONNULL(list) __attribute__((__nonnull__ list)) + +#else +# define RUBY3_ATTR_NONNULL(list) /* void */ +#endif diff --git a/include/ruby/3/attr/noreturn.h b/include/ruby/3/attr/noreturn.h new file mode 100644 index 0000000000..c08c824947 --- /dev/null +++ b/include/ruby/3/attr/noreturn.h @@ -0,0 +1,51 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_NORETURN. + */ +#include "ruby/3/compiler_since.h" +#include "ruby/3/has/attribute.h" +#include "ruby/3/has/cpp_attribute.h" +#include "ruby/3/has/declspec_attribute.h" + +/** Wraps (or simulates) `[[noreturn]]` */ +#if defined(RUBY3_ATTR_NORETURN) +# /* Take that. */ + +#elif RUBY3_COMPILER_SINCE(SunPro, 5, 10, 0) +# define RUBY3_ATTR_NORETURN() _Pragma("does_not_return") + +#elif RUBY3_HAS_DECLSPEC_ATTRIBUTE(noreturn) +# define RUBY3_ATTR_NORETURN() __declspec(noreturn) + +#elif RUBY3_HAS_ATTRIBUTE(noreturn) +# define RUBY3_ATTR_NORETURN() __attribute__((__noreturn__)) + +#elif RUBY3_HAS_CPP_ATTRIBUTE(noreturn) +# define RUBY3_ATTR_NORETURN() [[noreturn]] + +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112) +# define RUBY3_ATTR_NORETURN() _Noreturn + +#elif defined(_Noreturn) +# /* glibc has this macro. */ +# define RUBY3_ATTR_NORETURN() _Noreturn + +#else +# define RUBY3_ATTR_NORETURN() /* void */ +#endif diff --git a/include/ruby/3/attr/pure.h b/include/ruby/3/attr/pure.h new file mode 100644 index 0000000000..8ae2e91fdf --- /dev/null +++ b/include/ruby/3/attr/pure.h @@ -0,0 +1,48 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_PURE. + */ +#include "ruby/3/compiler_since.h" +#include "ruby/3/has/attribute.h" +#include "ruby/assert.h" + +/** Wraps (or simulates) `__attribute__((pure))` */ +#if defined(RUBY3_ATTR_PURE) +# /* Take that. */ + +#elif RUBY3_HAS_ATTRIBUTE(pure) +# define RUBY3_ATTR_PURE() __attribute__((__pure__)) + +#elif RUBY3_COMPILER_SINCE(SunPro, 5, 10, 0) +# define RUBY3_ATTR_PURE() _Pragma("does_not_write_global_data") + +#else +# define RUBY3_ATTR_PURE() /* void */ +#endif + +/** Enables #RUBY3_ATTR_PURE iff. #RUBY_NDEBUG. */ +#if defined(RUBY3_ATTR_PURE_ON_NDEBUG) +# /* Take that. */ + +#elif RUBY_NDEBUG +# define RUBY3_ATTR_PURE_ON_NDEBUG() RUBY3_ATTR_PURE() + +#else +# define RUBY3_ATTR_PURE_ON_NDEBUG() /* void */ +#endif diff --git a/include/ruby/3/attr/restrict.h b/include/ruby/3/attr/restrict.h new file mode 100644 index 0000000000..cd753584dd --- /dev/null +++ b/include/ruby/3/attr/restrict.h @@ -0,0 +1,44 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_RESTRICT. + */ +#include "ruby/3/compiler_since.h" +#include "ruby/3/has/attribute.h" +#include "ruby/3/token_paste.h" + +/* :FIXME: config.h includes conflicting `#define restrict`. MSVC can be + * detected using `RUBY3_COMPILER_SINCE()`, but Clang & family cannot use + * `__has_declspec_attribute()` which involves macro substitution. */ + +/** Wraps (or simulates) `__declspec(restrict)` */ +#if defined(RUBY3_ATTR_RESTRICT) +# /* Take that. */ + +#elif RUBY3_COMPILER_SINCE(MSVC, 14, 0, 0) +# define RUBY3_ATTR_RESTRICT() __declspec(RUBY3_TOKEN_PASTE(re, strict)) + +#elif RUBY3_HAS_ATTRIBUTE(malloc) +# define RUBY3_ATTR_RESTRICT() __attribute__((__malloc__)) + +#elif RUBY3_COMPILER_SINCE(SunPro, 5, 10, 0) +# define RUBY3_ATTR_RESTRICT() _Pragma("returns_new_memory") + +#else +# define RUBY3_ATTR_RESTRICT() /* void */ +#endif diff --git a/include/ruby/3/attr/returns_nonnull.h b/include/ruby/3/attr/returns_nonnull.h new file mode 100644 index 0000000000..269df4de69 --- /dev/null +++ b/include/ruby/3/attr/returns_nonnull.h @@ -0,0 +1,36 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_RETURNS_NONNULL. + */ +#include "ruby/3/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((returns_nonnull))` */ +#if defined(RUBY3_ATTR_RETURNS_NONNULL) +# /* Take that. */ + +#elif defined(_Ret_nonnull_) +# /* Take SAL definition. */ +# define RUBY3_ATTR_RETURNS_NONNULL() _Ret_nonnull_ + +#elif RUBY3_HAS_ATTRIBUTE(returns_nonnull) +# define RUBY3_ATTR_RETURNS_NONNULL() __attribute__((__returns_nonnull__)) + +#else +# define RUBY3_ATTR_RETURNS_NONNULL() /* void */ +#endif diff --git a/include/ruby/3/attr/warning.h b/include/ruby/3/attr/warning.h new file mode 100644 index 0000000000..ebd86b3a07 --- /dev/null +++ b/include/ruby/3/attr/warning.h @@ -0,0 +1,32 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_WARNING. + */ +#include "ruby/3/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((warning))` */ +#if defined(RUBY3_ATTR_WARNING) +# /* Take that. */ + +#elif RUBY3_HAS_ATTRIBUTE(warning) +# define RUBY3_ATTR_WARNING(msg) __attribute__((__warning__ msg)) + +#else +# define RUBY3_ATTR_WARNING(msg) /* void */ +#endif diff --git a/include/ruby/3/attr/weakref.h b/include/ruby/3/attr/weakref.h new file mode 100644 index 0000000000..084f8b99dc --- /dev/null +++ b/include/ruby/3/attr/weakref.h @@ -0,0 +1,32 @@ +/** \noop-*-C++-*-vi:ft=cpp + * @file + * @author Ruby developers + * @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. + * @warning Symbols prefixed with either `RUBY3` or `ruby3` are + * implementation details. Don't take them as canon. They could + * rapidly appear then vanish. The name (path) of this header file + * is also an implementation detail. Do not expect it to persist + * at the place it is now. Developers are free to move it anywhere + * anytime at will. + * @note To ruby-core: remember that this header can be possibly + * recursively included from extension libraries written in C++. + * Do not expect for instance `__VA_ARGS__` is always available. + * We assume C99 for ruby itself but we don't assume languages of + * extension libraries. They could be written in C++98. + * @brief Defines #RUBY3_ATTR_WEAKREF. + */ +#include "ruby/3/has/attribute.h" + +/** Wraps (or simulates) `__attribute__((weakref))` */ +#if defined(RUBY3_ATTR_WEAKREF) +# /* Take that. */ + +#elif RUBY3_HAS_ATTRIBUTE(weakref) +# define RUBY3_ATTR_WEAKREF(sym) __attribute__((__weakref__(# sym))) + +#else +# define RUBY3_ATTR_WEAKREF(sym) /* void */ +#endif -- cgit v1.2.3