ruby-changes:59492
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Thu, 26 Dec 2019 20:45:45 +0900 (JST)
Subject: [ruby-changes:59492] b739a63eb4 (master): split internal.h into files
https://git.ruby-lang.org/ruby.git/commit/?id=b739a63eb4 From b739a63eb41f52d33c33f87ebc44dcf89762cc37 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, 29 Nov 2019 15:18:34 +0900 Subject: split internal.h into files One day, I could not resist the way it was written. I finally started to make the code clean. This changeset is the beginning of a series of housekeeping commits. It is a simple refactoring; split internal.h into files, so that we can divide and concur in the upcoming commits. No lines of codes are either added or removed, except the obvious file headers/footers. The generated binary is identical to the one before. diff --git a/gc.c b/gc.c index 131ffb8..6def78a 100644 --- a/gc.c +++ b/gc.c @@ -559,6 +559,12 @@ typedef struct gc_profile_record { https://github.com/ruby/ruby/blob/trunk/gc.c#L559 #endif } gc_profile_record; +struct RMoved { + VALUE flags; + VALUE destination; + VALUE next; +}; + #if defined(_MSC_VER) || defined(__CYGWIN__) #pragma pack(push, 1) /* magic for reducing sizeof(RVALUE): 24 -> 20 */ #endif diff --git a/internal.h b/internal.h index baefb36..853274e 100644 --- a/internal.h +++ b/internal.h @@ -21,2671 +21,69 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/internal.h#L21 #endif #endif -#ifdef HAVE_STDBOOL_H -# include <stdbool.h> -#else -# include "missing/stdbool.h" -#endif - -/* The most significant bit of the lower part of half-long integer. - * If sizeof(long) == 4, this is 0x8000. - * If sizeof(long) == 8, this is 0x80000000. - */ -#define HALF_LONG_MSB ((SIGNED_VALUE)1<<((SIZEOF_LONG*CHAR_BIT-1)/2)) +#include "internal/stdbool.h" +#include "internal/bits.h" #define LIKELY(x) RB_LIKELY(x) #define UNLIKELY(x) RB_UNLIKELY(x) -#ifndef MAYBE_UNUSED -# define MAYBE_UNUSED(x) x -#endif - -#ifndef WARN_UNUSED_RESULT -# define WARN_UNUSED_RESULT(x) x -#endif - -#ifndef __has_feature -# define __has_feature(x) 0 -#endif - -#ifndef __has_extension -# define __has_extension __has_feature -#endif - -#if 0 -#elif defined(NO_SANITIZE) && __has_feature(memory_sanitizer) -# define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) \ - NO_SANITIZE("memory", NO_SANITIZE("address", NOINLINE(x))) -#elif defined(NO_SANITIZE) -# define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) \ - NO_SANITIZE("address", NOINLINE(x)) -#elif defined(NO_SANITIZE_ADDRESS) -# define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) \ - NO_SANITIZE_ADDRESS(NOINLINE(x)) -#elif defined(NO_ADDRESS_SAFETY_ANALYSIS) -# define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) \ - NO_ADDRESS_SAFETY_ANALYSIS(NOINLINE(x)) -#else -# define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) x -#endif - -#if defined(NO_SANITIZE) && defined(__GNUC__) &&! defined(__clang__) -/* GCC warns about unknown sanitizer, which is annoying. */ -#undef NO_SANITIZE -#define NO_SANITIZE(x, y) \ - COMPILER_WARNING_PUSH; \ - COMPILER_WARNING_IGNORED(-Wattributes); \ - __attribute__((__no_sanitize__(x))) y; \ - COMPILER_WARNING_POP -#endif - -#ifndef NO_SANITIZE -# define NO_SANITIZE(x, y) y -#endif - -#ifdef HAVE_VALGRIND_MEMCHECK_H -# include <valgrind/memcheck.h> -# ifndef VALGRIND_MAKE_MEM_DEFINED -# define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE((p), (n)) -# endif -# ifndef VALGRIND_MAKE_MEM_UNDEFINED -# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE((p), (n)) -# endif -#else -# define VALGRIND_MAKE_MEM_DEFINED(p, n) 0 -# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0 -#endif +#include "internal/compilers.h" +#include "internal/sanitizers.h" #define numberof(array) ((int)(sizeof(array) / sizeof((array)[0]))) -#ifndef MJIT_HEADER - -#ifdef HAVE_SANITIZER_ASAN_INTERFACE_H -# include <sanitizer/asan_interface.h> -#endif - -#if !__has_feature(address_sanitizer) -# define __asan_poison_memory_region(x, y) -# define __asan_unpoison_memory_region(x, y) -# define __asan_region_is_poisoned(x, y) 0 -#endif - -#ifdef HAVE_SANITIZER_MSAN_INTERFACE_H -# if __has_feature(memory_sanitizer) -# include <sanitizer/msan_interface.h> -# endif -#endif - -#if !__has_feature(memory_sanitizer) -# define __msan_allocated_memory(x, y) ((void)(x), (void)(y)) -# define __msan_poison(x, y) ((void)(x), (void)(y)) -# define __msan_unpoison(x, y) ((void)(x), (void)(y)) -# define __msan_unpoison_string(x) ((void)(x)) -#endif - -/*! - * This function asserts that a (continuous) memory region from ptr to size - * being "poisoned". Both read / write access to such memory region are - * prohibited until properly unpoisoned. The region must be previously - * allocated (do not pass a freed pointer here), but not necessarily be an - * entire object that the malloc returns. You can punch hole a part of a - * gigantic heap arena. This is handy when you do not free an allocated memory - * region to reuse later: poison when you keep it unused, and unpoison when you - * reuse. - * - * \param[in] ptr pointer to the beginning of the memory region to poison. - * \param[in] size the length of the memory region to poison. - */ -static inline void -asan_poison_memory_region(const volatile void *ptr, size_t size) -{ - __msan_poison(ptr, size); - __asan_poison_memory_region(ptr, size); -} - -/*! - * This is a variant of asan_poison_memory_region that takes a VALUE. - * - * \param[in] obj target object. - */ -static inline void -asan_poison_object(VALUE obj) -{ - MAYBE_UNUSED(struct RVALUE *) ptr = (void *)obj; - asan_poison_memory_region(ptr, SIZEOF_VALUE); -} - -#if !__has_feature(address_sanitizer) -#define asan_poison_object_if(ptr, obj) ((void)(ptr), (void)(obj)) -#else -#define asan_poison_object_if(ptr, obj) do { \ - if (ptr) asan_poison_object(obj); \ - } while (0) -#endif - -/*! - * This function predicates if the given object is fully addressable or not. - * - * \param[in] obj target object. - * \retval 0 the given object is fully addressable. - * \retval otherwise pointer to first such byte who is poisoned. - */ -static inline void * -asan_poisoned_object_p(VALUE obj) -{ - MAYBE_UNUSED(struct RVALUE *) ptr = (void *)obj; - return __asan_region_is_poisoned(ptr, SIZEOF_VALUE); -} - -/*! - * This function asserts that a (formally poisoned) memory region from ptr to - * size is now addressable. Write access to such memory region gets allowed. - * However read access might or might not be possible depending on situations, - * because the region can have contents of previous usages. That information - * should be passed by the malloc_p flag. If that is true, the contents of the - * region is _not_ fully defined (like the return value of malloc behaves). - * Reading from there is NG; write something first. If malloc_p is false on - * the other hand, that memory region is fully defined and can be read - * immediately. - * - * \param[in] ptr pointer to the beginning of the memory region to unpoison. - * \param[in] size the length of the memory region. - * \param[in] malloc_p if the memory region is like a malloc's return value or not. - */ -static inline void -asan_unpoison_memory_region(const volatile void *ptr, size_t size, bool malloc_p) -{ - __asan_unpoison_memory_region(ptr, size); - if (malloc_p) { - __msan_allocated_memory(ptr, size); - } - else { - __msan_unpoison(ptr, size); - } -} - -/*! - * This is a variant of asan_unpoison_memory_region that takes a VALUE. - * - * \param[in] obj target object. - * \param[in] malloc_p if the memory region is like a malloc's return value or not. - */ -static inline void -asan_unpoison_object(VALUE obj, bool newobj_p) -{ - MAYBE_UNUSED(struct RVALUE *) ptr = (void *)obj; - asan_unpoison_memory_region(ptr, SIZEOF_VALUE, newobj_p); -} - -#endif - /* Prevent compiler from reordering access */ #define ACCESS_ONCE(type,x) (*((volatile type *)&(x))) -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define STATIC_ASSERT(name, expr) _Static_assert(expr, #name ": " #expr) -#elif GCC_VERSION_SINCE(4, 6, 0) || __has_extension(c_static_assert) -# define STATIC_ASSERT(name, expr) RB_GNUC_EXTENSION _Static_assert(expr, #name ": " #expr) -#else -# define STATIC_ASSERT(name, expr) typedef int static_assert_##name##_check[1 - 2*!(expr)] -#endif - -#define SIGNED_INTEGER_TYPE_P(int_type) (0 > ((int_type)0)-1) -#define SIGNED_INTEGER_MAX(sint_type) \ - (sint_type) \ - ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) | \ - ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) - 1)) -#define SIGNED_INTEGER_MIN(sint_type) (-SIGNED_INTEGER_MAX(sint_type)-1) -#define UNSIGNED_INTEGER_MAX(uint_type) (~(uint_type)0) - -#if SIGNEDNESS_OF_TIME_T < 0 /* signed */ -# define TIMET_MAX SIGNED_INTEGER_MAX(time_t) -# define TIMET_MIN SIGNED_INTEGER_MIN(time_t) -#elif SIGNEDNESS_OF_TIME_T > 0 /* unsigned */ -# define TIMET_MAX UNSIGNED_INTEGER_MAX(time_t) -# define TIMET_MIN ((time_t)0) -#endif -#define TIMET_MAX_PLUS_ONE (2*(double)(TIMET_MAX/2+1)) - -#ifdef HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW_P -#define MUL_OVERFLOW_P(a, b) \ - __builtin_mul_overflow_p((a), (b), (__typeof__(a * b))0) -#elif defined HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW -#define MUL_OVERFLOW_P(a, b) \ - RB_GNUC_EXTENSION_BLOCK(__typeof__(a) c; __builtin_mul_overflow((a), (b), &c)) -#endif - -#define MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) ( \ - (a) == 0 ? 0 : \ - (a) == -1 ? (b) < -(max) : \ - (a) > 0 ? \ - ((b) > 0 ? (max) / (a) < (b) : (min) / (a) > (b)) : \ - ((b) > 0 ? (min) / (a) < (b) : (max) / (a) > (b))) - -#ifdef HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW_P -/* __builtin_mul_overflow_p can take bitfield */ -/* and GCC permits bitfields for integers other than int */ -#define MUL_OVERFLOW_FIXNUM_P(a, b) RB_GNUC_EXTENSION_BLOCK( \ - struct { long fixnum : SIZEOF_LONG * CHAR_BIT - 1; } c; \ - __builtin_mul_overflow_p((a), (b), c.fixnum); \ -) -#else -#define MUL_OVERFLOW_FIXNUM_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, FIXNUM_MIN, FIXNUM_MAX) -#endif (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/