kanayago 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +261 -0
 - data/README.md +1 -1
 - data/Rakefile +5 -48
 - data/ext/kanayago/extconf.rb +8 -0
 - data/ext/kanayago/kanayago.c +30 -185
 - data/ext/kanayago/scope_node.c +2 -16
 - data/ext/kanayago/variable_node.c +2 -1
 - data/lib/kanayago/call_node.rb +19 -0
 - data/lib/kanayago/constant_node.rb +15 -0
 - data/lib/kanayago/literal_node.rb +4 -0
 - data/lib/kanayago/scope_node.rb +14 -0
 - data/lib/kanayago/statement_node.rb +16 -0
 - data/lib/kanayago/variable_node.rb +4 -0
 - data/lib/kanayago/version.rb +1 -1
 - data/lib/kanayago.rb +3 -16
 - data/script/setup_parser.rb +136 -0
 - metadata +6 -64
 - data/ext/kanayago/ccan/check_type/check_type.h +0 -63
 - data/ext/kanayago/ccan/container_of/container_of.h +0 -142
 - data/ext/kanayago/ccan/list/list.h +0 -791
 - data/ext/kanayago/ccan/str/str.h +0 -17
 - data/ext/kanayago/constant.h +0 -53
 - data/ext/kanayago/id.h +0 -354
 - data/ext/kanayago/id_table.h +0 -54
 - data/ext/kanayago/include/ruby/st.h +0 -199
 - data/ext/kanayago/internal/array.h +0 -154
 - data/ext/kanayago/internal/basic_operators.h +0 -65
 - data/ext/kanayago/internal/bignum.h +0 -245
 - data/ext/kanayago/internal/bits.h +0 -650
 - data/ext/kanayago/internal/compile.h +0 -34
 - data/ext/kanayago/internal/compilers.h +0 -107
 - data/ext/kanayago/internal/complex.h +0 -29
 - data/ext/kanayago/internal/encoding.h +0 -39
 - data/ext/kanayago/internal/error.h +0 -251
 - data/ext/kanayago/internal/fixnum.h +0 -185
 - data/ext/kanayago/internal/gc.h +0 -358
 - data/ext/kanayago/internal/hash.h +0 -194
 - data/ext/kanayago/internal/imemo.h +0 -322
 - data/ext/kanayago/internal/io.h +0 -163
 - data/ext/kanayago/internal/namespace.h +0 -81
 - data/ext/kanayago/internal/numeric.h +0 -275
 - data/ext/kanayago/internal/parse.h +0 -131
 - data/ext/kanayago/internal/rational.h +0 -71
 - data/ext/kanayago/internal/re.h +0 -33
 - data/ext/kanayago/internal/ruby_parser.h +0 -125
 - data/ext/kanayago/internal/sanitizers.h +0 -346
 - data/ext/kanayago/internal/serial.h +0 -23
 - data/ext/kanayago/internal/set_table.h +0 -70
 - data/ext/kanayago/internal/static_assert.h +0 -16
 - data/ext/kanayago/internal/string.h +0 -203
 - data/ext/kanayago/internal/symbol.h +0 -46
 - data/ext/kanayago/internal/thread.h +0 -112
 - data/ext/kanayago/internal/variable.h +0 -74
 - data/ext/kanayago/internal/vm.h +0 -136
 - data/ext/kanayago/internal/warnings.h +0 -16
 - data/ext/kanayago/internal.h +0 -105
 - data/ext/kanayago/lex.c +0 -302
 - data/ext/kanayago/method.h +0 -271
 - data/ext/kanayago/node.c +0 -446
 - data/ext/kanayago/node.h +0 -122
 - data/ext/kanayago/node_name.inc +0 -224
 - data/ext/kanayago/parse.c +0 -27377
 - data/ext/kanayago/parse.h +0 -244
 - data/ext/kanayago/parser_bits.h +0 -564
 - data/ext/kanayago/parser_node.h +0 -32
 - data/ext/kanayago/parser_st.c +0 -165
 - data/ext/kanayago/parser_st.h +0 -162
 - data/ext/kanayago/parser_value.h +0 -106
 - data/ext/kanayago/probes.h +0 -4
 - data/ext/kanayago/ruby_assert.h +0 -14
 - data/ext/kanayago/ruby_atomic.h +0 -66
 - data/ext/kanayago/ruby_parser.c +0 -1137
 - data/ext/kanayago/rubyparser.h +0 -1394
 - data/ext/kanayago/shape.h +0 -444
 - data/ext/kanayago/st.c +0 -3223
 - data/ext/kanayago/symbol.h +0 -116
 - data/ext/kanayago/thread_pthread.h +0 -175
 - data/ext/kanayago/universal_parser.c +0 -211
 - data/ext/kanayago/vm_core.h +0 -2349
 - data/ext/kanayago/vm_opts.h +0 -67
 
| 
         @@ -1,346 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #ifndef INTERNAL_SANITIZERS_H                            /*-*-C-*-vi:se ft=c:*/
         
     | 
| 
       2 
     | 
    
         
            -
            #define INTERNAL_SANITIZERS_H
         
     | 
| 
       3 
     | 
    
         
            -
            /**
         
     | 
| 
       4 
     | 
    
         
            -
             * @author     Ruby developers <ruby-core@ruby-lang.org>
         
     | 
| 
       5 
     | 
    
         
            -
             * @copyright  This  file  is   a  part  of  the   programming  language  Ruby.
         
     | 
| 
       6 
     | 
    
         
            -
             *             Permission  is hereby  granted,  to  either redistribute  and/or
         
     | 
| 
       7 
     | 
    
         
            -
             *             modify this file, provided that  the conditions mentioned in the
         
     | 
| 
       8 
     | 
    
         
            -
             *             file COPYING are met.  Consult the file for details.
         
     | 
| 
       9 
     | 
    
         
            -
             * @brief      Internal header for ASAN / MSAN / etc.
         
     | 
| 
       10 
     | 
    
         
            -
             */
         
     | 
| 
       11 
     | 
    
         
            -
            #include "ruby/internal/config.h"
         
     | 
| 
       12 
     | 
    
         
            -
            #include "internal/compilers.h" /* for __has_feature */
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
            #ifdef HAVE_VALGRIND_MEMCHECK_H
         
     | 
| 
       15 
     | 
    
         
            -
            # include <valgrind/memcheck.h>
         
     | 
| 
       16 
     | 
    
         
            -
            #endif
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
            #ifdef HAVE_SANITIZER_ASAN_INTERFACE_H
         
     | 
| 
       19 
     | 
    
         
            -
            # if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
         
     | 
| 
       20 
     | 
    
         
            -
            #  define RUBY_ASAN_ENABLED
         
     | 
| 
       21 
     | 
    
         
            -
            #  include <sanitizer/asan_interface.h>
         
     | 
| 
       22 
     | 
    
         
            -
            # endif
         
     | 
| 
       23 
     | 
    
         
            -
            #endif
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
            #ifdef HAVE_SANITIZER_MSAN_INTERFACE_H
         
     | 
| 
       26 
     | 
    
         
            -
            # if __has_feature(memory_sanitizer)
         
     | 
| 
       27 
     | 
    
         
            -
            #  define RUBY_MSAN_ENABLED
         
     | 
| 
       28 
     | 
    
         
            -
            #  include <sanitizer/msan_interface.h>
         
     | 
| 
       29 
     | 
    
         
            -
            # endif
         
     | 
| 
       30 
     | 
    
         
            -
            #endif
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
            #ifdef HAVE_SANITIZER_TSAN_INTERFACE_H
         
     | 
| 
       33 
     | 
    
         
            -
            # if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)
         
     | 
| 
       34 
     | 
    
         
            -
            #  define RUBY_TSAN_ENABLED
         
     | 
| 
       35 
     | 
    
         
            -
            #  include <sanitizer/tsan_interface.h>
         
     | 
| 
       36 
     | 
    
         
            -
            # endif
         
     | 
| 
       37 
     | 
    
         
            -
            #endif
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
            #include "ruby/internal/stdbool.h"     /* for bool */
         
     | 
| 
       40 
     | 
    
         
            -
            #include "ruby/ruby.h"          /* for VALUE */
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
            #if 0
         
     | 
| 
       43 
     | 
    
         
            -
            #elif defined(RUBY_ASAN_ENABLED) && defined(RUBY_MSAN_ENABLED)
         
     | 
| 
       44 
     | 
    
         
            -
            # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) \
         
     | 
| 
       45 
     | 
    
         
            -
                __attribute__((__no_sanitize__("memory, address"), __noinline__)) x
         
     | 
| 
       46 
     | 
    
         
            -
            #elif defined(RUBY_ASAN_ENABLED)
         
     | 
| 
       47 
     | 
    
         
            -
            # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) \
         
     | 
| 
       48 
     | 
    
         
            -
                __attribute__((__no_sanitize__("address"), __noinline__)) x
         
     | 
| 
       49 
     | 
    
         
            -
            #elif defined(RUBY_MSAN_ENABLED)
         
     | 
| 
       50 
     | 
    
         
            -
                # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) \
         
     | 
| 
       51 
     | 
    
         
            -
                __attribute__((__no_sanitize__("memory"), __noinline__)) x
         
     | 
| 
       52 
     | 
    
         
            -
            #elif defined(RUBY_TSAN_ENABLED)
         
     | 
| 
       53 
     | 
    
         
            -
            # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) \
         
     | 
| 
       54 
     | 
    
         
            -
                __attribute__((__no_sanitize__("thread"), __noinline__)) x
         
     | 
| 
       55 
     | 
    
         
            -
            #elif defined(NO_SANITIZE_ADDRESS)
         
     | 
| 
       56 
     | 
    
         
            -
            # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) \
         
     | 
| 
       57 
     | 
    
         
            -
                NO_SANITIZE_ADDRESS(NOINLINE(x))
         
     | 
| 
       58 
     | 
    
         
            -
            #elif defined(NO_ADDRESS_SAFETY_ANALYSIS)
         
     | 
| 
       59 
     | 
    
         
            -
            # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) \
         
     | 
| 
       60 
     | 
    
         
            -
                NO_ADDRESS_SAFETY_ANALYSIS(NOINLINE(x))
         
     | 
| 
       61 
     | 
    
         
            -
            #else
         
     | 
| 
       62 
     | 
    
         
            -
            # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) x
         
     | 
| 
       63 
     | 
    
         
            -
            #endif
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
            #if defined(NO_SANITIZE) && RBIMPL_COMPILER_IS(GCC)
         
     | 
| 
       66 
     | 
    
         
            -
            /* GCC warns about unknown sanitizer, which is annoying. */
         
     | 
| 
       67 
     | 
    
         
            -
            # include "internal/warnings.h"
         
     | 
| 
       68 
     | 
    
         
            -
            # undef NO_SANITIZE
         
     | 
| 
       69 
     | 
    
         
            -
            # define NO_SANITIZE(x, y) \
         
     | 
| 
       70 
     | 
    
         
            -
                COMPILER_WARNING_PUSH \
         
     | 
| 
       71 
     | 
    
         
            -
                COMPILER_WARNING_IGNORED(-Wattributes) \
         
     | 
| 
       72 
     | 
    
         
            -
                __attribute__((__no_sanitize__(x))) y; \
         
     | 
| 
       73 
     | 
    
         
            -
                COMPILER_WARNING_POP \
         
     | 
| 
       74 
     | 
    
         
            -
                y
         
     | 
| 
       75 
     | 
    
         
            -
            #endif
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
            #ifndef NO_SANITIZE
         
     | 
| 
       78 
     | 
    
         
            -
            # define NO_SANITIZE(x, y) y
         
     | 
| 
       79 
     | 
    
         
            -
            #endif
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
            #ifndef RUBY_ASAN_ENABLED
         
     | 
| 
       82 
     | 
    
         
            -
            # define __asan_poison_memory_region(x, y)
         
     | 
| 
       83 
     | 
    
         
            -
            # define __asan_unpoison_memory_region(x, y)
         
     | 
| 
       84 
     | 
    
         
            -
            # define __asan_region_is_poisoned(x, y) 0
         
     | 
| 
       85 
     | 
    
         
            -
            # define __asan_get_current_fake_stack() NULL
         
     | 
| 
       86 
     | 
    
         
            -
            # define __asan_addr_is_in_fake_stack(fake_stack, slot, start, end) NULL
         
     | 
| 
       87 
     | 
    
         
            -
            #endif
         
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
            #ifndef RUBY_MSAN_ENABLED
         
     | 
| 
       90 
     | 
    
         
            -
            # define __msan_allocated_memory(x, y) ((void)(x), (void)(y))
         
     | 
| 
       91 
     | 
    
         
            -
            # define __msan_poison(x, y) ((void)(x), (void)(y))
         
     | 
| 
       92 
     | 
    
         
            -
            # define __msan_unpoison(x, y) ((void)(x), (void)(y))
         
     | 
| 
       93 
     | 
    
         
            -
            # define __msan_unpoison_string(x) ((void)(x))
         
     | 
| 
       94 
     | 
    
         
            -
            #endif
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
            #ifdef VALGRIND_MAKE_READABLE
         
     | 
| 
       97 
     | 
    
         
            -
            # define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE((p), (n))
         
     | 
| 
       98 
     | 
    
         
            -
            #endif
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
            #ifdef VALGRIND_MAKE_WRITABLE
         
     | 
| 
       101 
     | 
    
         
            -
            # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE((p), (n))
         
     | 
| 
       102 
     | 
    
         
            -
            #endif
         
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
            #ifndef VALGRIND_MAKE_MEM_DEFINED
         
     | 
| 
       105 
     | 
    
         
            -
            # define VALGRIND_MAKE_MEM_DEFINED(p, n) 0
         
     | 
| 
       106 
     | 
    
         
            -
            #endif
         
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
            #ifndef VALGRIND_MAKE_MEM_UNDEFINED
         
     | 
| 
       109 
     | 
    
         
            -
            # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0
         
     | 
| 
       110 
     | 
    
         
            -
            #endif
         
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
            /**
         
     | 
| 
       113 
     | 
    
         
            -
             * This function asserts that a (continuous) memory region from ptr to size
         
     | 
| 
       114 
     | 
    
         
            -
             * being "poisoned".  Both read / write access to such memory region are
         
     | 
| 
       115 
     | 
    
         
            -
             * prohibited until properly unpoisoned.  The region must be previously
         
     | 
| 
       116 
     | 
    
         
            -
             * allocated (do not pass a freed pointer here), but not necessarily be an
         
     | 
| 
       117 
     | 
    
         
            -
             * entire object that the malloc returns.  You can punch hole a part of a
         
     | 
| 
       118 
     | 
    
         
            -
             * gigantic heap arena.  This is handy when you do not free an allocated memory
         
     | 
| 
       119 
     | 
    
         
            -
             * region to reuse later: poison when you keep it unused, and unpoison when you
         
     | 
| 
       120 
     | 
    
         
            -
             * reuse.
         
     | 
| 
       121 
     | 
    
         
            -
             *
         
     | 
| 
       122 
     | 
    
         
            -
             * @param[in]  ptr   pointer to the beginning of the memory region to poison.
         
     | 
| 
       123 
     | 
    
         
            -
             * @param[in]  size  the length of the memory region to poison.
         
     | 
| 
       124 
     | 
    
         
            -
             */
         
     | 
| 
       125 
     | 
    
         
            -
            static inline void
         
     | 
| 
       126 
     | 
    
         
            -
            asan_poison_memory_region(const volatile void *ptr, size_t size)
         
     | 
| 
       127 
     | 
    
         
            -
            {
         
     | 
| 
       128 
     | 
    
         
            -
                __msan_poison(ptr, size);
         
     | 
| 
       129 
     | 
    
         
            -
                __asan_poison_memory_region(ptr, size);
         
     | 
| 
       130 
     | 
    
         
            -
            }
         
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
            #ifdef RUBY_ASAN_ENABLED
         
     | 
| 
       133 
     | 
    
         
            -
            #define asan_poison_object_if(ptr, obj) do { \
         
     | 
| 
       134 
     | 
    
         
            -
                    if (ptr) rb_asan_poison_object(obj); \
         
     | 
| 
       135 
     | 
    
         
            -
                } while (0)
         
     | 
| 
       136 
     | 
    
         
            -
            #else
         
     | 
| 
       137 
     | 
    
         
            -
            #define asan_poison_object_if(ptr, obj) ((void)(ptr), (void)(obj))
         
     | 
| 
       138 
     | 
    
         
            -
            #endif
         
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
            #ifdef RUBY_ASAN_ENABLED
         
     | 
| 
       141 
     | 
    
         
            -
            RUBY_SYMBOL_EXPORT_BEGIN
         
     | 
| 
       142 
     | 
    
         
            -
            /**
         
     | 
| 
       143 
     | 
    
         
            -
             * This is a variant of asan_poison_memory_region that takes a VALUE.
         
     | 
| 
       144 
     | 
    
         
            -
             *
         
     | 
| 
       145 
     | 
    
         
            -
             * @param[in]  obj   target object.
         
     | 
| 
       146 
     | 
    
         
            -
             */
         
     | 
| 
       147 
     | 
    
         
            -
            void rb_asan_poison_object(VALUE obj);
         
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
            /**
         
     | 
| 
       150 
     | 
    
         
            -
             * This function predicates if the given object is fully addressable or not.
         
     | 
| 
       151 
     | 
    
         
            -
             *
         
     | 
| 
       152 
     | 
    
         
            -
             * @param[in]  obj        target object.
         
     | 
| 
       153 
     | 
    
         
            -
             * @retval     0          the given object is fully addressable.
         
     | 
| 
       154 
     | 
    
         
            -
             * @retval     otherwise  pointer to first such byte who is poisoned.
         
     | 
| 
       155 
     | 
    
         
            -
             */
         
     | 
| 
       156 
     | 
    
         
            -
            void *rb_asan_poisoned_object_p(VALUE obj);
         
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
       158 
     | 
    
         
            -
            /**
         
     | 
| 
       159 
     | 
    
         
            -
             * This is a variant of asan_unpoison_memory_region that takes a VALUE.
         
     | 
| 
       160 
     | 
    
         
            -
             *
         
     | 
| 
       161 
     | 
    
         
            -
             * @param[in]  obj       target object.
         
     | 
| 
       162 
     | 
    
         
            -
             * @param[in]  malloc_p  if the memory region is like a malloc's return value or not.
         
     | 
| 
       163 
     | 
    
         
            -
             */
         
     | 
| 
       164 
     | 
    
         
            -
            void rb_asan_unpoison_object(VALUE obj, bool newobj_p);
         
     | 
| 
       165 
     | 
    
         
            -
             
     | 
| 
       166 
     | 
    
         
            -
            RUBY_SYMBOL_EXPORT_END
         
     | 
| 
       167 
     | 
    
         
            -
            #else
         
     | 
| 
       168 
     | 
    
         
            -
            # define rb_asan_poison_object(obj) ((void)obj)
         
     | 
| 
       169 
     | 
    
         
            -
            # define rb_asan_poisoned_object_p(obj) ((void)obj, NULL)
         
     | 
| 
       170 
     | 
    
         
            -
            # define rb_asan_unpoison_object(obj, newobj_p) ((void)obj, (void)newobj_p)
         
     | 
| 
       171 
     | 
    
         
            -
            #endif
         
     | 
| 
       172 
     | 
    
         
            -
             
     | 
| 
       173 
     | 
    
         
            -
            /**
         
     | 
| 
       174 
     | 
    
         
            -
             * This function asserts that a (formally poisoned) memory region from ptr to
         
     | 
| 
       175 
     | 
    
         
            -
             * size is now addressable.  Write access to such memory region gets allowed.
         
     | 
| 
       176 
     | 
    
         
            -
             * However read access might or might not be possible depending on situations,
         
     | 
| 
       177 
     | 
    
         
            -
             * because the region can have contents of previous usages.  That information
         
     | 
| 
       178 
     | 
    
         
            -
             * should be passed by the malloc_p flag.  If that is true, the contents of the
         
     | 
| 
       179 
     | 
    
         
            -
             * region is _not_ fully defined (like the return value of malloc behaves).
         
     | 
| 
       180 
     | 
    
         
            -
             * Reading from there is NG; write something first.  If malloc_p is false on
         
     | 
| 
       181 
     | 
    
         
            -
             * the other hand, that memory region is fully defined and can be read
         
     | 
| 
       182 
     | 
    
         
            -
             * immediately.
         
     | 
| 
       183 
     | 
    
         
            -
             *
         
     | 
| 
       184 
     | 
    
         
            -
             * @param[in]  ptr       pointer to the beginning of the memory region to unpoison.
         
     | 
| 
       185 
     | 
    
         
            -
             * @param[in]  size      the length of the memory region.
         
     | 
| 
       186 
     | 
    
         
            -
             * @param[in]  malloc_p  if the memory region is like a malloc's return value or not.
         
     | 
| 
       187 
     | 
    
         
            -
             */
         
     | 
| 
       188 
     | 
    
         
            -
            static inline void
         
     | 
| 
       189 
     | 
    
         
            -
            asan_unpoison_memory_region(const volatile void *ptr, size_t size, bool malloc_p)
         
     | 
| 
       190 
     | 
    
         
            -
            {
         
     | 
| 
       191 
     | 
    
         
            -
                __asan_unpoison_memory_region(ptr, size);
         
     | 
| 
       192 
     | 
    
         
            -
                if (malloc_p) {
         
     | 
| 
       193 
     | 
    
         
            -
                    __msan_allocated_memory(ptr, size);
         
     | 
| 
       194 
     | 
    
         
            -
                }
         
     | 
| 
       195 
     | 
    
         
            -
                else {
         
     | 
| 
       196 
     | 
    
         
            -
                    __msan_unpoison(ptr, size);
         
     | 
| 
       197 
     | 
    
         
            -
                }
         
     | 
| 
       198 
     | 
    
         
            -
            }
         
     | 
| 
       199 
     | 
    
         
            -
             
     | 
| 
       200 
     | 
    
         
            -
            static inline void *
         
     | 
| 
       201 
     | 
    
         
            -
            asan_unpoison_object_temporary(VALUE obj)
         
     | 
| 
       202 
     | 
    
         
            -
            {
         
     | 
| 
       203 
     | 
    
         
            -
                void *ptr = rb_asan_poisoned_object_p(obj);
         
     | 
| 
       204 
     | 
    
         
            -
                rb_asan_unpoison_object(obj, false);
         
     | 
| 
       205 
     | 
    
         
            -
                return ptr;
         
     | 
| 
       206 
     | 
    
         
            -
            }
         
     | 
| 
       207 
     | 
    
         
            -
             
     | 
| 
       208 
     | 
    
         
            -
            static inline void *
         
     | 
| 
       209 
     | 
    
         
            -
            asan_poison_object_restore(VALUE obj, void *ptr)
         
     | 
| 
       210 
     | 
    
         
            -
            {
         
     | 
| 
       211 
     | 
    
         
            -
                if (ptr) {
         
     | 
| 
       212 
     | 
    
         
            -
                    rb_asan_poison_object(obj);
         
     | 
| 
       213 
     | 
    
         
            -
                }
         
     | 
| 
       214 
     | 
    
         
            -
                return NULL;
         
     | 
| 
       215 
     | 
    
         
            -
            }
         
     | 
| 
       216 
     | 
    
         
            -
             
     | 
| 
       217 
     | 
    
         
            -
            #define asan_unpoisoning_object(obj) \
         
     | 
| 
       218 
     | 
    
         
            -
                for (void *poisoned = asan_unpoison_object_temporary(obj), \
         
     | 
| 
       219 
     | 
    
         
            -
                          *unpoisoning = &poisoned; /* flag to loop just once */ \
         
     | 
| 
       220 
     | 
    
         
            -
                     unpoisoning; \
         
     | 
| 
       221 
     | 
    
         
            -
                     unpoisoning = asan_poison_object_restore(obj, poisoned))
         
     | 
| 
       222 
     | 
    
         
            -
             
     | 
| 
       223 
     | 
    
         
            -
             
     | 
| 
       224 
     | 
    
         
            -
            static inline void *
         
     | 
| 
       225 
     | 
    
         
            -
            asan_unpoison_memory_region_temporary(void *ptr, size_t len)
         
     | 
| 
       226 
     | 
    
         
            -
            {
         
     | 
| 
       227 
     | 
    
         
            -
                void *poisoned_ptr = __asan_region_is_poisoned(ptr, len);
         
     | 
| 
       228 
     | 
    
         
            -
                asan_unpoison_memory_region(ptr, len, false);
         
     | 
| 
       229 
     | 
    
         
            -
                return poisoned_ptr;
         
     | 
| 
       230 
     | 
    
         
            -
            }
         
     | 
| 
       231 
     | 
    
         
            -
             
     | 
| 
       232 
     | 
    
         
            -
            static inline void *
         
     | 
| 
       233 
     | 
    
         
            -
            asan_poison_memory_region_restore(void *ptr, size_t len, void *poisoned_ptr)
         
     | 
| 
       234 
     | 
    
         
            -
            {
         
     | 
| 
       235 
     | 
    
         
            -
                if (poisoned_ptr) {
         
     | 
| 
       236 
     | 
    
         
            -
                    asan_poison_memory_region(ptr, len);
         
     | 
| 
       237 
     | 
    
         
            -
                }
         
     | 
| 
       238 
     | 
    
         
            -
                return NULL;
         
     | 
| 
       239 
     | 
    
         
            -
            }
         
     | 
| 
       240 
     | 
    
         
            -
             
     | 
| 
       241 
     | 
    
         
            -
            #define asan_unpoisoning_memory_region(ptr, len) \
         
     | 
| 
       242 
     | 
    
         
            -
                for (void *poisoned = asan_unpoison_memory_region_temporary(ptr, len), \
         
     | 
| 
       243 
     | 
    
         
            -
                          *unpoisoning = &poisoned; /* flag to loop just once */ \
         
     | 
| 
       244 
     | 
    
         
            -
                     unpoisoning; \
         
     | 
| 
       245 
     | 
    
         
            -
                     unpoisoning = asan_poison_memory_region_restore(ptr, len, poisoned))
         
     | 
| 
       246 
     | 
    
         
            -
             
     | 
| 
       247 
     | 
    
         
            -
            /**
         
     | 
| 
       248 
     | 
    
         
            -
             * Checks if the given pointer is on an ASAN fake stack. If so, it returns the
         
     | 
| 
       249 
     | 
    
         
            -
             * address this variable has on the real frame; if not, it returns the origin
         
     | 
| 
       250 
     | 
    
         
            -
             * address unmodified.
         
     | 
| 
       251 
     | 
    
         
            -
             *
         
     | 
| 
       252 
     | 
    
         
            -
             * n.b. - _dereferencing_ the returned address is meaningless and should not
         
     | 
| 
       253 
     | 
    
         
            -
             * be done; even though ASAN reserves space for the variable in both the real and
         
     | 
| 
       254 
     | 
    
         
            -
             * fake stacks, the _value_ of that variable is only in the fake stack.
         
     | 
| 
       255 
     | 
    
         
            -
             *
         
     | 
| 
       256 
     | 
    
         
            -
             * n.b. - this only works for addresses passed in from local variables on the same
         
     | 
| 
       257 
     | 
    
         
            -
             * thread, because the ASAN fake stacks are threadlocal.
         
     | 
| 
       258 
     | 
    
         
            -
             *
         
     | 
| 
       259 
     | 
    
         
            -
             * @param[in] slot  the address of some local variable
         
     | 
| 
       260 
     | 
    
         
            -
             * @retval          a pointer to something from that frame on the _real_ machine stack
         
     | 
| 
       261 
     | 
    
         
            -
             */
         
     | 
| 
       262 
     | 
    
         
            -
            static inline void *
         
     | 
| 
       263 
     | 
    
         
            -
            asan_get_real_stack_addr(void* slot)
         
     | 
| 
       264 
     | 
    
         
            -
            {
         
     | 
| 
       265 
     | 
    
         
            -
                VALUE *addr;
         
     | 
| 
       266 
     | 
    
         
            -
                addr = __asan_addr_is_in_fake_stack(__asan_get_current_fake_stack(), slot, NULL, NULL);
         
     | 
| 
       267 
     | 
    
         
            -
                return addr ? addr : slot;
         
     | 
| 
       268 
     | 
    
         
            -
            }
         
     | 
| 
       269 
     | 
    
         
            -
             
     | 
| 
       270 
     | 
    
         
            -
            /**
         
     | 
| 
       271 
     | 
    
         
            -
             * Gets the current thread's fake stack handle, which can be passed into get_fake_stack_extents
         
     | 
| 
       272 
     | 
    
         
            -
             *
         
     | 
| 
       273 
     | 
    
         
            -
             * @retval An opaque value which can be passed to asan_get_fake_stack_extents
         
     | 
| 
       274 
     | 
    
         
            -
             */
         
     | 
| 
       275 
     | 
    
         
            -
            static inline void *
         
     | 
| 
       276 
     | 
    
         
            -
            asan_get_thread_fake_stack_handle(void)
         
     | 
| 
       277 
     | 
    
         
            -
            {
         
     | 
| 
       278 
     | 
    
         
            -
                return __asan_get_current_fake_stack();
         
     | 
| 
       279 
     | 
    
         
            -
            }
         
     | 
| 
       280 
     | 
    
         
            -
             
     | 
| 
       281 
     | 
    
         
            -
            /**
         
     | 
| 
       282 
     | 
    
         
            -
             * Checks if the given VALUE _actually_ represents a pointer to an ASAN fake stack.
         
     | 
| 
       283 
     | 
    
         
            -
             *
         
     | 
| 
       284 
     | 
    
         
            -
             * If the given slot _is_ actually a reference to an ASAN fake stack, and that fake stack
         
     | 
| 
       285 
     | 
    
         
            -
             * contains the real values for the passed-in range of machine stack addresses, returns true
         
     | 
| 
       286 
     | 
    
         
            -
             * and the range of the fake stack through the outparams.
         
     | 
| 
       287 
     | 
    
         
            -
             *
         
     | 
| 
       288 
     | 
    
         
            -
             * Otherwise, returns false, and sets the outparams to NULL.
         
     | 
| 
       289 
     | 
    
         
            -
             *
         
     | 
| 
       290 
     | 
    
         
            -
             * Note that this function expects "start" to be > "end" on downward-growing stack architectures;
         
     | 
| 
       291 
     | 
    
         
            -
             *
         
     | 
| 
       292 
     | 
    
         
            -
             * @param[in]  thread_fake_stack_handle  The asan fake stack reference for the thread we're scanning
         
     | 
| 
       293 
     | 
    
         
            -
             * @param[in]  slot                      The value on the machine stack we want to inspect
         
     | 
| 
       294 
     | 
    
         
            -
             * @param[in]  machine_stack_start       The extents of the real machine stack on which slot lives
         
     | 
| 
       295 
     | 
    
         
            -
             * @param[in]  machine_stack_end         The extents of the real machine stack on which slot lives
         
     | 
| 
       296 
     | 
    
         
            -
             * @param[out] fake_stack_start_out      The extents of the fake stack which contains real VALUEs
         
     | 
| 
       297 
     | 
    
         
            -
             * @param[out] fake_stack_end_out        The extents of the fake stack which contains real VALUEs
         
     | 
| 
       298 
     | 
    
         
            -
             * @return                               Whether slot is a pointer to a fake stack for the given machine stack range
         
     | 
| 
       299 
     | 
    
         
            -
            */
         
     | 
| 
       300 
     | 
    
         
            -
             
     | 
| 
       301 
     | 
    
         
            -
            static inline bool
         
     | 
| 
       302 
     | 
    
         
            -
            asan_get_fake_stack_extents(void *thread_fake_stack_handle, VALUE slot,
         
     | 
| 
       303 
     | 
    
         
            -
                                        void *machine_stack_start, void *machine_stack_end,
         
     | 
| 
       304 
     | 
    
         
            -
                                        void **fake_stack_start_out, void **fake_stack_end_out)
         
     | 
| 
       305 
     | 
    
         
            -
            {
         
     | 
| 
       306 
     | 
    
         
            -
                /* the ifdef is needed here to suppress a warning about fake_frame_{start/end} being
         
     | 
| 
       307 
     | 
    
         
            -
                   uninitialized if __asan_addr_is_in_fake_stack is an empty macro */
         
     | 
| 
       308 
     | 
    
         
            -
            #ifdef RUBY_ASAN_ENABLED
         
     | 
| 
       309 
     | 
    
         
            -
                void *fake_frame_start;
         
     | 
| 
       310 
     | 
    
         
            -
                void *fake_frame_end;
         
     | 
| 
       311 
     | 
    
         
            -
                void *real_stack_frame = __asan_addr_is_in_fake_stack(
         
     | 
| 
       312 
     | 
    
         
            -
                    thread_fake_stack_handle, (void *)slot, &fake_frame_start, &fake_frame_end
         
     | 
| 
       313 
     | 
    
         
            -
                );
         
     | 
| 
       314 
     | 
    
         
            -
                if (real_stack_frame) {
         
     | 
| 
       315 
     | 
    
         
            -
                    bool in_range;
         
     | 
| 
       316 
     | 
    
         
            -
            #if STACK_GROW_DIRECTION < 0
         
     | 
| 
       317 
     | 
    
         
            -
                    in_range = machine_stack_start >= real_stack_frame && real_stack_frame >= machine_stack_end;
         
     | 
| 
       318 
     | 
    
         
            -
            #else
         
     | 
| 
       319 
     | 
    
         
            -
                    in_range = machine_stack_start <= real_stack_frame && real_stack_frame <= machine_stack_end;
         
     | 
| 
       320 
     | 
    
         
            -
            #endif
         
     | 
| 
       321 
     | 
    
         
            -
                    if (in_range) {
         
     | 
| 
       322 
     | 
    
         
            -
                        *fake_stack_start_out = fake_frame_start;
         
     | 
| 
       323 
     | 
    
         
            -
                        *fake_stack_end_out = fake_frame_end;
         
     | 
| 
       324 
     | 
    
         
            -
                        return true;
         
     | 
| 
       325 
     | 
    
         
            -
                    }
         
     | 
| 
       326 
     | 
    
         
            -
                }
         
     | 
| 
       327 
     | 
    
         
            -
            #endif
         
     | 
| 
       328 
     | 
    
         
            -
                *fake_stack_start_out = 0;
         
     | 
| 
       329 
     | 
    
         
            -
                *fake_stack_end_out = 0;
         
     | 
| 
       330 
     | 
    
         
            -
                return false;
         
     | 
| 
       331 
     | 
    
         
            -
            }
         
     | 
| 
       332 
     | 
    
         
            -
             
     | 
| 
       333 
     | 
    
         
            -
            extern const char ruby_asan_default_options[];
         
     | 
| 
       334 
     | 
    
         
            -
             
     | 
| 
       335 
     | 
    
         
            -
            #ifdef RUBY_ASAN_ENABLED
         
     | 
| 
       336 
     | 
    
         
            -
            /* Compile in the ASAN options Ruby needs, rather than relying on environment variables, so
         
     | 
| 
       337 
     | 
    
         
            -
             * that even tests which fork ruby with a clean environment will run ASAN with the right
         
     | 
| 
       338 
     | 
    
         
            -
             * settings */
         
     | 
| 
       339 
     | 
    
         
            -
            # undef RUBY__ASAN_DEFAULT_OPTIONS
         
     | 
| 
       340 
     | 
    
         
            -
            # define RUBY__ASAN_DEFAULT_OPTIONS \
         
     | 
| 
       341 
     | 
    
         
            -
                RBIMPL_SYMBOL_EXPORT_BEGIN() \
         
     | 
| 
       342 
     | 
    
         
            -
                const char * __asan_default_options(void) {return ruby_asan_default_options;} \
         
     | 
| 
       343 
     | 
    
         
            -
                RBIMPL_SYMBOL_EXPORT_END()
         
     | 
| 
       344 
     | 
    
         
            -
            #endif
         
     | 
| 
       345 
     | 
    
         
            -
             
     | 
| 
       346 
     | 
    
         
            -
            #endif /* INTERNAL_SANITIZERS_H */
         
     | 
| 
         @@ -1,23 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #ifndef INTERNAL_SERIAL_H                                /*-*-C-*-vi:se ft=c:*/
         
     | 
| 
       2 
     | 
    
         
            -
            #define INTERNAL_SERIAL_H
         
     | 
| 
       3 
     | 
    
         
            -
            /**
         
     | 
| 
       4 
     | 
    
         
            -
             * @author     Ruby developers <ruby-core@ruby-lang.org>
         
     | 
| 
       5 
     | 
    
         
            -
             * @copyright  This  file  is   a  part  of  the   programming  language  Ruby.
         
     | 
| 
       6 
     | 
    
         
            -
             *             Permission  is hereby  granted,  to  either redistribute  and/or
         
     | 
| 
       7 
     | 
    
         
            -
             *             modify this file, provided that  the conditions mentioned in the
         
     | 
| 
       8 
     | 
    
         
            -
             *             file COPYING are met.  Consult the file for details.
         
     | 
| 
       9 
     | 
    
         
            -
             * @brief      Internal header for rb_serial_t.
         
     | 
| 
       10 
     | 
    
         
            -
             */
         
     | 
| 
       11 
     | 
    
         
            -
            #include "ruby/internal/config.h"      /* for HAVE_LONG_LONG */
         
     | 
| 
       12 
     | 
    
         
            -
            #include "ruby/defines.h"       /* for LONG_LONG */
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
            #ifndef HAVE_LONG_LONG
         
     | 
| 
       15 
     | 
    
         
            -
            # error need C99+
         
     | 
| 
       16 
     | 
    
         
            -
            #endif
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
            typedef unsigned LONG_LONG rb_serial_t;
         
     | 
| 
       19 
     | 
    
         
            -
            #define SERIALT2NUM ULL2NUM
         
     | 
| 
       20 
     | 
    
         
            -
            #define PRI_SERIALT_PREFIX PRI_LL_PREFIX
         
     | 
| 
       21 
     | 
    
         
            -
            #define SIZEOF_SERIAL_T SIZEOF_LONG_LONG
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
            #endif /* INTERNAL_SERIAL_H */
         
     | 
| 
         @@ -1,70 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #ifndef INTERNAL_SET_TABLE_H
         
     | 
| 
       2 
     | 
    
         
            -
            #define INTERNAL_SET_TABLE_H
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            #include "include/ruby/st.h"
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            struct set_table_entry;
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            typedef struct set_table_entry set_table_entry;
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
            struct set_table {
         
     | 
| 
       11 
     | 
    
         
            -
                /* Cached features of the table -- see st.c for more details.  */
         
     | 
| 
       12 
     | 
    
         
            -
                unsigned char entry_power, bin_power, size_ind;
         
     | 
| 
       13 
     | 
    
         
            -
                /* How many times the table was rebuilt.  */
         
     | 
| 
       14 
     | 
    
         
            -
                unsigned int rebuilds_num;
         
     | 
| 
       15 
     | 
    
         
            -
                const struct st_hash_type *type;
         
     | 
| 
       16 
     | 
    
         
            -
                /* Number of entries currently in the table.  */
         
     | 
| 
       17 
     | 
    
         
            -
                st_index_t num_entries;
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                /* Start and bound index of entries in array entries.
         
     | 
| 
       20 
     | 
    
         
            -
                   entries_starts and entries_bound are in interval
         
     | 
| 
       21 
     | 
    
         
            -
                   [0,allocated_entries].  */
         
     | 
| 
       22 
     | 
    
         
            -
                st_index_t entries_start, entries_bound;
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                /**
         
     | 
| 
       25 
     | 
    
         
            -
                 * Array of size 2^entry_power.
         
     | 
| 
       26 
     | 
    
         
            -
                 * Followed by st_index_t *bins, Array of bins used for access by keys.
         
     | 
| 
       27 
     | 
    
         
            -
                 */
         
     | 
| 
       28 
     | 
    
         
            -
                set_table_entry *entries;
         
     | 
| 
       29 
     | 
    
         
            -
            };
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
            typedef struct set_table set_table;
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
            typedef int set_foreach_callback_func(st_data_t, st_data_t);
         
     | 
| 
       34 
     | 
    
         
            -
            typedef int set_foreach_check_callback_func(st_data_t, st_data_t, int);
         
     | 
| 
       35 
     | 
    
         
            -
            typedef int set_update_callback_func(st_data_t *key, st_data_t arg, int existing);
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
            #define set_table_size rb_set_table_size
         
     | 
| 
       38 
     | 
    
         
            -
            size_t rb_set_table_size(const struct set_table *tbl);
         
     | 
| 
       39 
     | 
    
         
            -
            #define set_init_table_with_size rb_set_init_table_with_size
         
     | 
| 
       40 
     | 
    
         
            -
            set_table *rb_set_init_table_with_size(set_table *tab, const struct st_hash_type *, st_index_t);
         
     | 
| 
       41 
     | 
    
         
            -
            #define set_init_numtable rb_set_init_numtable
         
     | 
| 
       42 
     | 
    
         
            -
            set_table *rb_set_init_numtable(void);
         
     | 
| 
       43 
     | 
    
         
            -
            #define set_init_numtable_with_size rb_set_init_numtable_with_size
         
     | 
| 
       44 
     | 
    
         
            -
            set_table *rb_set_init_numtable_with_size(st_index_t size);
         
     | 
| 
       45 
     | 
    
         
            -
            #define set_table_delete rb_set_table_delete
         
     | 
| 
       46 
     | 
    
         
            -
            int rb_set_table_delete(set_table *, st_data_t *); /* returns 0:notfound 1:deleted */
         
     | 
| 
       47 
     | 
    
         
            -
            #define set_insert rb_set_insert
         
     | 
| 
       48 
     | 
    
         
            -
            int rb_set_insert(set_table *, st_data_t);
         
     | 
| 
       49 
     | 
    
         
            -
            #define set_table_lookup rb_set_table_lookup
         
     | 
| 
       50 
     | 
    
         
            -
            int rb_set_table_lookup(set_table *, st_data_t);
         
     | 
| 
       51 
     | 
    
         
            -
            #define set_foreach_with_replace rb_set_foreach_with_replace
         
     | 
| 
       52 
     | 
    
         
            -
            int rb_set_foreach_with_replace(set_table *tab, set_foreach_check_callback_func *func, set_update_callback_func *replace, st_data_t arg);
         
     | 
| 
       53 
     | 
    
         
            -
            #define set_table_foreach rb_set_table_foreach
         
     | 
| 
       54 
     | 
    
         
            -
            int rb_set_table_foreach(set_table *, set_foreach_callback_func *, st_data_t);
         
     | 
| 
       55 
     | 
    
         
            -
            #define set_foreach_check rb_set_foreach_check
         
     | 
| 
       56 
     | 
    
         
            -
            int rb_set_foreach_check(set_table *, set_foreach_check_callback_func *, st_data_t, st_data_t);
         
     | 
| 
       57 
     | 
    
         
            -
            #define set_keys rb_set_keys
         
     | 
| 
       58 
     | 
    
         
            -
            st_index_t rb_set_keys(set_table *table, st_data_t *keys, st_index_t size);
         
     | 
| 
       59 
     | 
    
         
            -
            #define set_free_table rb_set_free_table
         
     | 
| 
       60 
     | 
    
         
            -
            void rb_set_free_table(set_table *);
         
     | 
| 
       61 
     | 
    
         
            -
            #define set_table_clear rb_set_table_clear
         
     | 
| 
       62 
     | 
    
         
            -
            void rb_set_table_clear(set_table *);
         
     | 
| 
       63 
     | 
    
         
            -
            #define set_copy rb_set_copy
         
     | 
| 
       64 
     | 
    
         
            -
            set_table *rb_set_copy(set_table *new_table, set_table *old_table);
         
     | 
| 
       65 
     | 
    
         
            -
            #define set_memsize rb_set_memsize
         
     | 
| 
       66 
     | 
    
         
            -
            PUREFUNC(size_t rb_set_memsize(const set_table *));
         
     | 
| 
       67 
     | 
    
         
            -
            #define set_compact_table rb_set_compact_table
         
     | 
| 
       68 
     | 
    
         
            -
            void set_compact_table(set_table *tab);
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
            #endif
         
     | 
| 
         @@ -1,16 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #ifndef INTERNAL_STATIC_ASSERT_H                         /*-*-C-*-vi:se ft=c:*/
         
     | 
| 
       2 
     | 
    
         
            -
            #define INTERNAL_STATIC_ASSERT_H
         
     | 
| 
       3 
     | 
    
         
            -
            /**
         
     | 
| 
       4 
     | 
    
         
            -
             * @author     Ruby developers <ruby-core@ruby-lang.org>
         
     | 
| 
       5 
     | 
    
         
            -
             * @copyright  This  file  is   a  part  of  the   programming  language  Ruby.
         
     | 
| 
       6 
     | 
    
         
            -
             *             Permission  is hereby  granted,  to  either redistribute  and/or
         
     | 
| 
       7 
     | 
    
         
            -
             *             modify this file, provided that  the conditions mentioned in the
         
     | 
| 
       8 
     | 
    
         
            -
             *             file COPYING are met.  Consult the file for details.
         
     | 
| 
       9 
     | 
    
         
            -
             * @brief      C11 shim for _Static_assert.
         
     | 
| 
       10 
     | 
    
         
            -
             */
         
     | 
| 
       11 
     | 
    
         
            -
            #include "ruby/internal/static_assert.h"
         
     | 
| 
       12 
     | 
    
         
            -
            #ifndef STATIC_ASSERT
         
     | 
| 
       13 
     | 
    
         
            -
            # define STATIC_ASSERT RBIMPL_STATIC_ASSERT
         
     | 
| 
       14 
     | 
    
         
            -
            #endif
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            #endif /* INTERNAL_STATIC_ASSERT_H */
         
     | 
| 
         @@ -1,203 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #ifndef INTERNAL_STRING_H                                /*-*-C-*-vi:se ft=c:*/
         
     | 
| 
       2 
     | 
    
         
            -
            #define INTERNAL_STRING_H
         
     | 
| 
       3 
     | 
    
         
            -
            /**
         
     | 
| 
       4 
     | 
    
         
            -
             * @author     Ruby developers <ruby-core@ruby-lang.org>
         
     | 
| 
       5 
     | 
    
         
            -
             * @copyright  This  file  is   a  part  of  the   programming  language  Ruby.
         
     | 
| 
       6 
     | 
    
         
            -
             *             Permission  is hereby  granted,  to  either redistribute  and/or
         
     | 
| 
       7 
     | 
    
         
            -
             *             modify this file, provided that  the conditions mentioned in the
         
     | 
| 
       8 
     | 
    
         
            -
             *             file COPYING are met.  Consult the file for details.
         
     | 
| 
       9 
     | 
    
         
            -
             * @brief      Internal header for String.
         
     | 
| 
       10 
     | 
    
         
            -
             */
         
     | 
| 
       11 
     | 
    
         
            -
            #include "ruby/internal/config.h"
         
     | 
| 
       12 
     | 
    
         
            -
            #include <stddef.h>             /* for size_t */
         
     | 
| 
       13 
     | 
    
         
            -
            #include "internal/compilers.h" /* for __has_builtin */
         
     | 
| 
       14 
     | 
    
         
            -
            #include "ruby/internal/stdbool.h"     /* for bool */
         
     | 
| 
       15 
     | 
    
         
            -
            #include "ruby/encoding.h"      /* for rb_encoding */
         
     | 
| 
       16 
     | 
    
         
            -
            #include "ruby/ruby.h"          /* for VALUE */
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
            #define STR_SHARED                  FL_USER0 /* = ELTS_SHARED */
         
     | 
| 
       19 
     | 
    
         
            -
            #define STR_NOEMBED                 FL_USER1
         
     | 
| 
       20 
     | 
    
         
            -
            #define STR_CHILLED                 (FL_USER2 | FL_USER3)
         
     | 
| 
       21 
     | 
    
         
            -
            #define STR_CHILLED_LITERAL         FL_USER2
         
     | 
| 
       22 
     | 
    
         
            -
            #define STR_CHILLED_SYMBOL_TO_S     FL_USER3
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
            enum ruby_rstring_private_flags {
         
     | 
| 
       25 
     | 
    
         
            -
                RSTRING_CHILLED = STR_CHILLED,
         
     | 
| 
       26 
     | 
    
         
            -
            };
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
            #ifdef rb_fstring_cstr
         
     | 
| 
       29 
     | 
    
         
            -
            # undef rb_fstring_cstr
         
     | 
| 
       30 
     | 
    
         
            -
            #endif
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
            /* string.c */
         
     | 
| 
       33 
     | 
    
         
            -
            VALUE rb_str_dup_m(VALUE str);
         
     | 
| 
       34 
     | 
    
         
            -
            VALUE rb_fstring(VALUE);
         
     | 
| 
       35 
     | 
    
         
            -
            VALUE rb_fstring_cstr(const char *str);
         
     | 
| 
       36 
     | 
    
         
            -
            VALUE rb_fstring_enc_new(const char *ptr, long len, rb_encoding *enc);
         
     | 
| 
       37 
     | 
    
         
            -
            int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p);
         
     | 
| 
       38 
     | 
    
         
            -
            int rb_str_symname_p(VALUE);
         
     | 
| 
       39 
     | 
    
         
            -
            VALUE rb_str_quote_unprintable(VALUE);
         
     | 
| 
       40 
     | 
    
         
            -
            char *rb_str_fill_terminator(VALUE str, const int termlen);
         
     | 
| 
       41 
     | 
    
         
            -
            void rb_str_change_terminator_length(VALUE str, const int oldtermlen, const int termlen);
         
     | 
| 
       42 
     | 
    
         
            -
            VALUE rb_str_locktmp_ensure(VALUE str, VALUE (*func)(VALUE), VALUE arg);
         
     | 
| 
       43 
     | 
    
         
            -
            VALUE rb_str_chomp_string(VALUE str, VALUE chomp);
         
     | 
| 
       44 
     | 
    
         
            -
            VALUE rb_external_str_with_enc(VALUE str, rb_encoding *eenc);
         
     | 
| 
       45 
     | 
    
         
            -
            VALUE rb_str_cat_conv_enc_opts(VALUE newstr, long ofs, const char *ptr, long len,
         
     | 
| 
       46 
     | 
    
         
            -
                                           rb_encoding *from, int ecflags, VALUE ecopts);
         
     | 
| 
       47 
     | 
    
         
            -
            VALUE rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl);
         
     | 
| 
       48 
     | 
    
         
            -
            VALUE rb_str_escape(VALUE str);
         
     | 
| 
       49 
     | 
    
         
            -
            size_t rb_str_memsize(VALUE);
         
     | 
| 
       50 
     | 
    
         
            -
            char *rb_str_to_cstr(VALUE str);
         
     | 
| 
       51 
     | 
    
         
            -
            const char *ruby_escaped_char(int c);
         
     | 
| 
       52 
     | 
    
         
            -
            void rb_str_make_independent(VALUE str);
         
     | 
| 
       53 
     | 
    
         
            -
            int rb_enc_str_coderange_scan(VALUE str, rb_encoding *enc);
         
     | 
| 
       54 
     | 
    
         
            -
            int rb_ascii8bit_appendable_encoding_index(rb_encoding *enc, unsigned int code);
         
     | 
| 
       55 
     | 
    
         
            -
            VALUE rb_str_include(VALUE str, VALUE arg);
         
     | 
| 
       56 
     | 
    
         
            -
            VALUE rb_str_byte_substr(VALUE str, VALUE beg, VALUE len);
         
     | 
| 
       57 
     | 
    
         
            -
            VALUE rb_str_substr_two_fixnums(VALUE str, VALUE beg, VALUE len, int empty);
         
     | 
| 
       58 
     | 
    
         
            -
            VALUE rb_str_tmp_frozen_no_embed_acquire(VALUE str);
         
     | 
| 
       59 
     | 
    
         
            -
            void rb_str_make_embedded(VALUE);
         
     | 
| 
       60 
     | 
    
         
            -
            VALUE rb_str_upto_each(VALUE, VALUE, int, int (*each)(VALUE, VALUE), VALUE);
         
     | 
| 
       61 
     | 
    
         
            -
            size_t rb_str_size_as_embedded(VALUE);
         
     | 
| 
       62 
     | 
    
         
            -
            bool rb_str_reembeddable_p(VALUE);
         
     | 
| 
       63 
     | 
    
         
            -
            VALUE rb_str_upto_endless_each(VALUE, int (*each)(VALUE, VALUE), VALUE);
         
     | 
| 
       64 
     | 
    
         
            -
            VALUE rb_str_with_debug_created_info(VALUE, VALUE, int);
         
     | 
| 
       65 
     | 
    
         
            -
            VALUE rb_str_frozen_bare_string(VALUE);
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
            /* error.c */
         
     | 
| 
       68 
     | 
    
         
            -
            void rb_warn_unchilled_literal(VALUE str);
         
     | 
| 
       69 
     | 
    
         
            -
            void rb_warn_unchilled_symbol_to_s(VALUE str);
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
            static inline bool STR_EMBED_P(VALUE str);
         
     | 
| 
       72 
     | 
    
         
            -
            static inline bool STR_SHARED_P(VALUE str);
         
     | 
| 
       73 
     | 
    
         
            -
            static inline VALUE QUOTE(VALUE v);
         
     | 
| 
       74 
     | 
    
         
            -
            static inline VALUE QUOTE_ID(ID v);
         
     | 
| 
       75 
     | 
    
         
            -
            static inline bool is_ascii_string(VALUE str);
         
     | 
| 
       76 
     | 
    
         
            -
            static inline bool is_broken_string(VALUE str);
         
     | 
| 
       77 
     | 
    
         
            -
            static inline VALUE rb_str_eql_internal(const VALUE str1, const VALUE str2);
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
            RUBY_SYMBOL_EXPORT_BEGIN
         
     | 
| 
       80 
     | 
    
         
            -
            /* string.c (export) */
         
     | 
| 
       81 
     | 
    
         
            -
            VALUE rb_str_tmp_frozen_acquire(VALUE str);
         
     | 
| 
       82 
     | 
    
         
            -
            void rb_str_tmp_frozen_release(VALUE str, VALUE tmp);
         
     | 
| 
       83 
     | 
    
         
            -
            VALUE rb_setup_fake_str(struct RString *fake_str, const char *name, long len, rb_encoding *enc);
         
     | 
| 
       84 
     | 
    
         
            -
            RUBY_SYMBOL_EXPORT_END
         
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
            VALUE rb_fstring_new(const char *ptr, long len);
         
     | 
| 
       87 
     | 
    
         
            -
            void rb_gc_free_fstring(VALUE obj);
         
     | 
| 
       88 
     | 
    
         
            -
            bool rb_obj_is_fstring_table(VALUE obj);
         
     | 
| 
       89 
     | 
    
         
            -
            void Init_fstring_table();
         
     | 
| 
       90 
     | 
    
         
            -
            VALUE rb_obj_as_string_result(VALUE str, VALUE obj);
         
     | 
| 
       91 
     | 
    
         
            -
            VALUE rb_str_opt_plus(VALUE x, VALUE y);
         
     | 
| 
       92 
     | 
    
         
            -
            VALUE rb_str_concat_literals(size_t num, const VALUE *strary);
         
     | 
| 
       93 
     | 
    
         
            -
            VALUE rb_str_eql(VALUE str1, VALUE str2);
         
     | 
| 
       94 
     | 
    
         
            -
            VALUE rb_id_quote_unprintable(ID);
         
     | 
| 
       95 
     | 
    
         
            -
            VALUE rb_sym_proc_call(ID mid, int argc, const VALUE *argv, int kw_splat, VALUE passed_proc);
         
     | 
| 
       96 
     | 
    
         
            -
            VALUE rb_enc_literal_str(const char *ptr, long len, rb_encoding *enc);
         
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
            struct rb_execution_context_struct;
         
     | 
| 
       99 
     | 
    
         
            -
            VALUE rb_ec_str_resurrect(struct rb_execution_context_struct *ec, VALUE str, bool chilled);
         
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
            #define rb_fstring_lit(str) rb_fstring_new((str), rb_strlen_lit(str))
         
     | 
| 
       102 
     | 
    
         
            -
            #define rb_fstring_literal(str) rb_fstring_lit(str)
         
     | 
| 
       103 
     | 
    
         
            -
            #define rb_fstring_enc_lit(str, enc) rb_fstring_enc_new((str), rb_strlen_lit(str), (enc))
         
     | 
| 
       104 
     | 
    
         
            -
            #define rb_fstring_enc_literal(str, enc) rb_fstring_enc_lit(str, enc)
         
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
            static inline VALUE
         
     | 
| 
       107 
     | 
    
         
            -
            QUOTE(VALUE v)
         
     | 
| 
       108 
     | 
    
         
            -
            {
         
     | 
| 
       109 
     | 
    
         
            -
                return rb_str_quote_unprintable(v);
         
     | 
| 
       110 
     | 
    
         
            -
            }
         
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
            static inline VALUE
         
     | 
| 
       113 
     | 
    
         
            -
            QUOTE_ID(ID i)
         
     | 
| 
       114 
     | 
    
         
            -
            {
         
     | 
| 
       115 
     | 
    
         
            -
                return rb_id_quote_unprintable(i);
         
     | 
| 
       116 
     | 
    
         
            -
            }
         
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
            static inline bool
         
     | 
| 
       119 
     | 
    
         
            -
            STR_EMBED_P(VALUE str)
         
     | 
| 
       120 
     | 
    
         
            -
            {
         
     | 
| 
       121 
     | 
    
         
            -
                return ! FL_TEST_RAW(str, STR_NOEMBED);
         
     | 
| 
       122 
     | 
    
         
            -
            }
         
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
            static inline bool
         
     | 
| 
       125 
     | 
    
         
            -
            STR_SHARED_P(VALUE str)
         
     | 
| 
       126 
     | 
    
         
            -
            {
         
     | 
| 
       127 
     | 
    
         
            -
                return FL_ALL_RAW(str, STR_NOEMBED | STR_SHARED);
         
     | 
| 
       128 
     | 
    
         
            -
            }
         
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
            static inline bool
         
     | 
| 
       131 
     | 
    
         
            -
            CHILLED_STRING_P(VALUE obj)
         
     | 
| 
       132 
     | 
    
         
            -
            {
         
     | 
| 
       133 
     | 
    
         
            -
                return RB_TYPE_P(obj, T_STRING) && FL_TEST_RAW(obj, STR_CHILLED);
         
     | 
| 
       134 
     | 
    
         
            -
            }
         
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
            static inline void
         
     | 
| 
       137 
     | 
    
         
            -
            CHILLED_STRING_MUTATED(VALUE str)
         
     | 
| 
       138 
     | 
    
         
            -
            {
         
     | 
| 
       139 
     | 
    
         
            -
                VALUE chilled_reason = RB_FL_TEST_RAW(str, STR_CHILLED);
         
     | 
| 
       140 
     | 
    
         
            -
                FL_UNSET_RAW(str, STR_CHILLED);
         
     | 
| 
       141 
     | 
    
         
            -
                switch (chilled_reason) {
         
     | 
| 
       142 
     | 
    
         
            -
                  case STR_CHILLED_SYMBOL_TO_S:
         
     | 
| 
       143 
     | 
    
         
            -
                    rb_warn_unchilled_symbol_to_s(str);
         
     | 
| 
       144 
     | 
    
         
            -
                    break;
         
     | 
| 
       145 
     | 
    
         
            -
                  case STR_CHILLED_LITERAL:
         
     | 
| 
       146 
     | 
    
         
            -
                    rb_warn_unchilled_literal(str);
         
     | 
| 
       147 
     | 
    
         
            -
                    break;
         
     | 
| 
       148 
     | 
    
         
            -
                  default:
         
     | 
| 
       149 
     | 
    
         
            -
                    rb_bug("RString was chilled for multiple reasons");
         
     | 
| 
       150 
     | 
    
         
            -
                }
         
     | 
| 
       151 
     | 
    
         
            -
            }
         
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
            static inline bool
         
     | 
| 
       154 
     | 
    
         
            -
            is_ascii_string(VALUE str)
         
     | 
| 
       155 
     | 
    
         
            -
            {
         
     | 
| 
       156 
     | 
    
         
            -
                return rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT;
         
     | 
| 
       157 
     | 
    
         
            -
            }
         
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
            static inline bool
         
     | 
| 
       160 
     | 
    
         
            -
            is_broken_string(VALUE str)
         
     | 
| 
       161 
     | 
    
         
            -
            {
         
     | 
| 
       162 
     | 
    
         
            -
                return rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN;
         
     | 
| 
       163 
     | 
    
         
            -
            }
         
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
       165 
     | 
    
         
            -
            static inline bool
         
     | 
| 
       166 
     | 
    
         
            -
            at_char_boundary(const char *s, const char *p, const char *e, rb_encoding *enc)
         
     | 
| 
       167 
     | 
    
         
            -
            {
         
     | 
| 
       168 
     | 
    
         
            -
                return rb_enc_left_char_head(s, p, e, enc) == p;
         
     | 
| 
       169 
     | 
    
         
            -
            }
         
     | 
| 
       170 
     | 
    
         
            -
             
     | 
| 
       171 
     | 
    
         
            -
            static inline bool
         
     | 
| 
       172 
     | 
    
         
            -
            at_char_right_boundary(const char *s, const char *p, const char *e, rb_encoding *enc)
         
     | 
| 
       173 
     | 
    
         
            -
            {
         
     | 
| 
       174 
     | 
    
         
            -
                RUBY_ASSERT(s <= p);
         
     | 
| 
       175 
     | 
    
         
            -
                RUBY_ASSERT(p <= e);
         
     | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
       177 
     | 
    
         
            -
                return rb_enc_right_char_head(s, p, e, enc) == p;
         
     | 
| 
       178 
     | 
    
         
            -
            }
         
     | 
| 
       179 
     | 
    
         
            -
             
     | 
| 
       180 
     | 
    
         
            -
            /* expect tail call optimization */
         
     | 
| 
       181 
     | 
    
         
            -
            // YJIT needs this function to never allocate and never raise
         
     | 
| 
       182 
     | 
    
         
            -
            static inline VALUE
         
     | 
| 
       183 
     | 
    
         
            -
            rb_str_eql_internal(const VALUE str1, const VALUE str2)
         
     | 
| 
       184 
     | 
    
         
            -
            {
         
     | 
| 
       185 
     | 
    
         
            -
                const long len = RSTRING_LEN(str1);
         
     | 
| 
       186 
     | 
    
         
            -
                const char *ptr1, *ptr2;
         
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
       188 
     | 
    
         
            -
                if (len != RSTRING_LEN(str2)) return Qfalse;
         
     | 
| 
       189 
     | 
    
         
            -
                if (!rb_str_comparable(str1, str2)) return Qfalse;
         
     | 
| 
       190 
     | 
    
         
            -
                if ((ptr1 = RSTRING_PTR(str1)) == (ptr2 = RSTRING_PTR(str2)))
         
     | 
| 
       191 
     | 
    
         
            -
                    return Qtrue;
         
     | 
| 
       192 
     | 
    
         
            -
                if (memcmp(ptr1, ptr2, len) == 0)
         
     | 
| 
       193 
     | 
    
         
            -
                    return Qtrue;
         
     | 
| 
       194 
     | 
    
         
            -
                return Qfalse;
         
     | 
| 
       195 
     | 
    
         
            -
            }
         
     | 
| 
       196 
     | 
    
         
            -
             
     | 
| 
       197 
     | 
    
         
            -
            #if __has_builtin(__builtin_constant_p)
         
     | 
| 
       198 
     | 
    
         
            -
            # define rb_fstring_cstr(str) \
         
     | 
| 
       199 
     | 
    
         
            -
                (__builtin_constant_p(str) ? \
         
     | 
| 
       200 
     | 
    
         
            -
                    rb_fstring_new((str), (long)strlen(str)) : \
         
     | 
| 
       201 
     | 
    
         
            -
                    (rb_fstring_cstr)(str))
         
     | 
| 
       202 
     | 
    
         
            -
            #endif
         
     | 
| 
       203 
     | 
    
         
            -
            #endif /* INTERNAL_STRING_H */
         
     |