zscan 2.0.6 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/ext/extconf.rb +9 -1
  3. data/ext/pack/builtin-27.h +79 -0
  4. data/ext/pack/builtin.h +79 -0
  5. data/ext/pack/internal-27.h +96 -0
  6. data/ext/pack/internal-27/array.h +103 -0
  7. data/ext/pack/internal-27/bignum.h +246 -0
  8. data/ext/pack/internal-27/bits.h +566 -0
  9. data/ext/pack/internal-27/class.h +162 -0
  10. data/ext/pack/internal-27/compar.h +50 -0
  11. data/ext/pack/internal-27/compile.h +32 -0
  12. data/ext/pack/internal-27/compilers.h +108 -0
  13. data/ext/pack/internal-27/complex.h +29 -0
  14. data/ext/pack/internal-27/cont.h +23 -0
  15. data/ext/pack/internal-27/dir.h +17 -0
  16. data/ext/pack/internal-27/enc.h +20 -0
  17. data/ext/pack/internal-27/encoding.h +28 -0
  18. data/ext/pack/internal-27/enum.h +19 -0
  19. data/ext/pack/internal-27/enumerator.h +22 -0
  20. data/ext/pack/internal-27/error.h +129 -0
  21. data/ext/pack/internal-27/eval.h +33 -0
  22. data/ext/pack/internal-27/file.h +39 -0
  23. data/ext/pack/internal-27/fixnum.h +185 -0
  24. data/ext/pack/internal-27/gc.h +153 -0
  25. data/ext/pack/internal-27/hash.h +234 -0
  26. data/ext/pack/internal-27/imemo.h +242 -0
  27. data/ext/pack/internal-27/inits.h +51 -0
  28. data/ext/pack/internal-27/io.h +35 -0
  29. data/ext/pack/internal-27/load.h +19 -0
  30. data/ext/pack/internal-27/loadpath.h +17 -0
  31. data/ext/pack/internal-27/math.h +24 -0
  32. data/ext/pack/internal-27/missing.h +19 -0
  33. data/ext/pack/internal-27/mjit.h +29 -0
  34. data/ext/pack/internal-27/numeric.h +249 -0
  35. data/ext/pack/internal-27/object.h +60 -0
  36. data/ext/pack/internal-27/parse.h +23 -0
  37. data/ext/pack/internal-27/proc.h +32 -0
  38. data/ext/pack/internal-27/process.h +130 -0
  39. data/ext/pack/internal-27/random.h +17 -0
  40. data/ext/pack/internal-27/range.h +37 -0
  41. data/ext/pack/internal-27/rational.h +68 -0
  42. data/ext/pack/internal-27/re.h +29 -0
  43. data/ext/pack/internal-27/sanitizers.h +191 -0
  44. data/ext/pack/internal-27/serial.h +24 -0
  45. data/ext/pack/internal-27/signal.h +22 -0
  46. data/ext/pack/internal-27/static_assert.h +17 -0
  47. data/ext/pack/internal-27/string.h +135 -0
  48. data/ext/pack/internal-27/struct.h +154 -0
  49. data/ext/pack/internal-27/symbol.h +41 -0
  50. data/ext/pack/internal-27/thread.h +52 -0
  51. data/ext/pack/internal-27/time.h +35 -0
  52. data/ext/pack/internal-27/transcode.h +21 -0
  53. data/ext/pack/internal-27/util.h +31 -0
  54. data/ext/pack/internal-27/variable.h +92 -0
  55. data/ext/pack/internal-27/vm.h +127 -0
  56. data/ext/pack/internal-27/warnings.h +17 -0
  57. data/ext/pack/internal.h +57 -2102
  58. data/ext/pack/internal/array.h +103 -0
  59. data/ext/pack/internal/bignum.h +246 -0
  60. data/ext/pack/internal/bits.h +566 -0
  61. data/ext/pack/internal/class.h +162 -0
  62. data/ext/pack/internal/compar.h +50 -0
  63. data/ext/pack/internal/compile.h +32 -0
  64. data/ext/pack/internal/compilers.h +108 -0
  65. data/ext/pack/internal/complex.h +29 -0
  66. data/ext/pack/internal/cont.h +23 -0
  67. data/ext/pack/internal/dir.h +17 -0
  68. data/ext/pack/internal/enc.h +20 -0
  69. data/ext/pack/internal/encoding.h +28 -0
  70. data/ext/pack/internal/enum.h +19 -0
  71. data/ext/pack/internal/enumerator.h +22 -0
  72. data/ext/pack/internal/error.h +129 -0
  73. data/ext/pack/internal/eval.h +33 -0
  74. data/ext/pack/internal/file.h +39 -0
  75. data/ext/pack/internal/fixnum.h +185 -0
  76. data/ext/pack/internal/gc.h +153 -0
  77. data/ext/pack/internal/hash.h +234 -0
  78. data/ext/pack/internal/imemo.h +242 -0
  79. data/ext/pack/internal/inits.h +51 -0
  80. data/ext/pack/internal/io.h +35 -0
  81. data/ext/pack/internal/load.h +19 -0
  82. data/ext/pack/internal/loadpath.h +17 -0
  83. data/ext/pack/internal/math.h +24 -0
  84. data/ext/pack/internal/missing.h +19 -0
  85. data/ext/pack/internal/mjit.h +29 -0
  86. data/ext/pack/internal/numeric.h +249 -0
  87. data/ext/pack/internal/object.h +60 -0
  88. data/ext/pack/internal/parse.h +23 -0
  89. data/ext/pack/internal/proc.h +32 -0
  90. data/ext/pack/internal/process.h +130 -0
  91. data/ext/pack/internal/random.h +17 -0
  92. data/ext/pack/internal/range.h +37 -0
  93. data/ext/pack/internal/rational.h +68 -0
  94. data/ext/pack/internal/re.h +29 -0
  95. data/ext/pack/internal/sanitizers.h +191 -0
  96. data/ext/pack/internal/serial.h +24 -0
  97. data/ext/pack/internal/signal.h +22 -0
  98. data/ext/pack/internal/static_assert.h +17 -0
  99. data/ext/pack/internal/string.h +135 -0
  100. data/ext/pack/internal/struct.h +154 -0
  101. data/ext/pack/internal/symbol.h +41 -0
  102. data/ext/pack/internal/thread.h +52 -0
  103. data/ext/pack/internal/time.h +35 -0
  104. data/ext/pack/internal/transcode.h +21 -0
  105. data/ext/pack/internal/util.h +31 -0
  106. data/ext/pack/internal/variable.h +92 -0
  107. data/ext/pack/internal/vm.h +127 -0
  108. data/ext/pack/internal/warnings.h +17 -0
  109. data/ext/pack/pack-26.c +2 -109
  110. data/ext/pack/pack-27.c +1022 -0
  111. data/ext/pack/pack.c +57 -1047
  112. data/lib/zscan.rb +1 -1
  113. data/zscan.gemspec +1 -1
  114. metadata +109 -3
@@ -0,0 +1,153 @@
1
+ #ifndef INTERNAL_GC_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_GC_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @brief Internal header for GC.
11
+ */
12
+ #include "ruby/internal/config.h"
13
+
14
+ #include <stddef.h> /* for size_t */
15
+
16
+ #include "internal/compilers.h" /* for __has_attribute */
17
+ #include "ruby/ruby.h" /* for rb_event_flag_t */
18
+
19
+ struct rb_execution_context_struct; /* in vm_core.h */
20
+ struct rb_objspace; /* in vm_core.h */
21
+
22
+ #ifdef NEWOBJ_OF
23
+ # undef NEWOBJ_OF
24
+ # undef RB_NEWOBJ_OF
25
+ # undef RB_OBJ_WRITE
26
+ #endif
27
+
28
+ /* optimized version of NEWOBJ() */
29
+ #define RB_NEWOBJ_OF(var, T, c, f) \
30
+ T *(var) = (T *)(((f) & FL_WB_PROTECTED) ? \
31
+ rb_wb_protected_newobj_of((c), (f) & ~FL_WB_PROTECTED) : \
32
+ rb_wb_unprotected_newobj_of((c), (f)))
33
+ #define NEWOBJ_OF(var, T, c, f) RB_NEWOBJ_OF((var), T, (c), (f))
34
+ #define RB_OBJ_GC_FLAGS_MAX 6 /* used in ext/objspace */
35
+
36
+ #ifndef USE_UNALIGNED_MEMBER_ACCESS
37
+ # define UNALIGNED_MEMBER_ACCESS(expr) (expr)
38
+ #elif ! USE_UNALIGNED_MEMBER_ACCESS
39
+ # define UNALIGNED_MEMBER_ACCESS(expr) (expr)
40
+ #elif ! (__has_warning("-Waddress-of-packed-member") || GCC_VERSION_SINCE(9, 0, 0))
41
+ # define UNALIGNED_MEMBER_ACCESS(expr) (expr)
42
+ #else
43
+ # include "internal/warnings.h"
44
+ # define UNALIGNED_MEMBER_ACCESS(expr) __extension__({ \
45
+ COMPILER_WARNING_PUSH; \
46
+ COMPILER_WARNING_IGNORED(-Waddress-of-packed-member); \
47
+ __typeof__(expr) unaligned_member_access_result = (expr); \
48
+ COMPILER_WARNING_POP; \
49
+ unaligned_member_access_result; \
50
+ })
51
+ #endif
52
+
53
+ #define UNALIGNED_MEMBER_PTR(ptr, mem) UNALIGNED_MEMBER_ACCESS(&(ptr)->mem)
54
+ #define RB_OBJ_WRITE(a, slot, b) \
55
+ UNALIGNED_MEMBER_ACCESS(\
56
+ rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__))
57
+
58
+ /* gc.c */
59
+ extern VALUE *ruby_initial_gc_stress_ptr;
60
+ extern int ruby_disable_gc;
61
+ RUBY_ATTR_MALLOC void *ruby_mimmalloc(size_t size);
62
+ void ruby_mimfree(void *ptr);
63
+ void rb_objspace_set_event_hook(const rb_event_flag_t event);
64
+ VALUE rb_objspace_gc_enable(struct rb_objspace *);
65
+ VALUE rb_objspace_gc_disable(struct rb_objspace *);
66
+ void ruby_gc_set_params(void);
67
+ void rb_copy_wb_protected_attribute(VALUE dest, VALUE obj);
68
+ #if __has_attribute(alloc_align)
69
+ __attribute__((__alloc_align__(1)))
70
+ #endif
71
+ RUBY_ATTR_MALLOC void *rb_aligned_malloc(size_t, size_t) RUBY_ATTR_ALLOC_SIZE((2));
72
+ size_t rb_size_mul_or_raise(size_t, size_t, VALUE); /* used in compile.c */
73
+ size_t rb_size_mul_add_or_raise(size_t, size_t, size_t, VALUE); /* used in iseq.h */
74
+ RUBY_ATTR_MALLOC void *rb_xmalloc_mul_add(size_t, size_t, size_t);
75
+ void *rb_xrealloc_mul_add(const void *, size_t, size_t, size_t);
76
+ RUBY_ATTR_MALLOC void *rb_xmalloc_mul_add_mul(size_t, size_t, size_t, size_t);
77
+ RUBY_ATTR_MALLOC void *rb_xcalloc_mul_add_mul(size_t, size_t, size_t, size_t);
78
+ static inline void *ruby_sized_xrealloc_inlined(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2));
79
+ static inline void *ruby_sized_xrealloc2_inlined(void *ptr, size_t new_count, size_t elemsiz, size_t old_count) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2, 3));
80
+ static inline void ruby_sized_xfree_inlined(void *ptr, size_t size);
81
+
82
+ RUBY_SYMBOL_EXPORT_BEGIN
83
+ /* gc.c (export) */
84
+ const char *rb_objspace_data_type_name(VALUE obj);
85
+ VALUE rb_wb_protected_newobj_of(VALUE, VALUE);
86
+ VALUE rb_wb_unprotected_newobj_of(VALUE, VALUE);
87
+ size_t rb_obj_memsize_of(VALUE);
88
+ void rb_gc_verify_internal_consistency(void);
89
+ size_t rb_obj_gc_flags(VALUE, ID[], size_t);
90
+ void rb_gc_mark_values(long n, const VALUE *values);
91
+ void rb_gc_mark_vm_stack_values(long n, const VALUE *values);
92
+ void *ruby_sized_xrealloc(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2));
93
+ void *ruby_sized_xrealloc2(void *ptr, size_t new_count, size_t element_size, size_t old_count) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2, 3));
94
+ void ruby_sized_xfree(void *x, size_t size);
95
+ RUBY_SYMBOL_EXPORT_END
96
+
97
+ MJIT_SYMBOL_EXPORT_BEGIN
98
+ int rb_ec_stack_check(struct rb_execution_context_struct *ec);
99
+ void rb_gc_writebarrier_remember(VALUE obj);
100
+ const char *rb_obj_info(VALUE obj);
101
+ MJIT_SYMBOL_EXPORT_END
102
+
103
+ #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE) || defined(_WIN32)
104
+
105
+ static inline void *
106
+ ruby_sized_xrealloc_inlined(void *ptr, size_t new_size, size_t old_size)
107
+ {
108
+ return ruby_xrealloc(ptr, new_size);
109
+ }
110
+
111
+ static inline void *
112
+ ruby_sized_xrealloc2_inlined(void *ptr, size_t new_count, size_t elemsiz, size_t old_count)
113
+ {
114
+ return ruby_xrealloc2(ptr, new_count, elemsiz);
115
+ }
116
+
117
+ static inline void
118
+ ruby_sized_xfree_inlined(void *ptr, size_t size)
119
+ {
120
+ ruby_xfree(ptr);
121
+ }
122
+
123
+ # define SIZED_REALLOC_N(x, y, z, w) REALLOC_N(x, y, z)
124
+
125
+ #else
126
+
127
+ static inline void *
128
+ ruby_sized_xrealloc_inlined(void *ptr, size_t new_size, size_t old_size)
129
+ {
130
+ return ruby_sized_xrealloc(ptr, new_size, old_size);
131
+ }
132
+
133
+ static inline void *
134
+ ruby_sized_xrealloc2_inlined(void *ptr, size_t new_count, size_t elemsiz, size_t old_count)
135
+ {
136
+ return ruby_sized_xrealloc2(ptr, new_count, elemsiz, old_count);
137
+ }
138
+
139
+ static inline void
140
+ ruby_sized_xfree_inlined(void *ptr, size_t size)
141
+ {
142
+ ruby_sized_xfree(ptr, size);
143
+ }
144
+
145
+ # define SIZED_REALLOC_N(v, T, m, n) \
146
+ ((v) = (T *)ruby_sized_xrealloc2((void *)(v), (m), sizeof(T), (n)))
147
+
148
+ #endif /* HAVE_MALLOC_USABLE_SIZE */
149
+
150
+ #define ruby_sized_xrealloc ruby_sized_xrealloc_inlined
151
+ #define ruby_sized_xrealloc2 ruby_sized_xrealloc2_inlined
152
+ #define ruby_sized_xfree ruby_sized_xfree_inlined
153
+ #endif /* INTERNAL_GC_H */
@@ -0,0 +1,234 @@
1
+ #ifndef INTERNAL_HASH_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_HASH_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @brief Internal header for Hash.
11
+ */
12
+ #include "ruby/internal/config.h"
13
+ #include <stddef.h> /* for size_t */
14
+ #include "ruby/internal/stdbool.h" /* for bool */
15
+ #include "ruby/ruby.h" /* for struct RBasic */
16
+ #include "ruby/st.h" /* for struct st_table */
17
+
18
+ #define RHASH_AR_TABLE_MAX_SIZE SIZEOF_VALUE
19
+
20
+ struct ar_table_struct;
21
+ typedef unsigned char ar_hint_t;
22
+
23
+ enum ruby_rhash_flags {
24
+ RHASH_PASS_AS_KEYWORDS = FL_USER1, /* FL 1 */
25
+ RHASH_PROC_DEFAULT = FL_USER2, /* FL 2 */
26
+ RHASH_ST_TABLE_FLAG = FL_USER3, /* FL 3 */
27
+ RHASH_AR_TABLE_SIZE_MASK = (FL_USER4|FL_USER5|FL_USER6|FL_USER7), /* FL 4..7 */
28
+ RHASH_AR_TABLE_SIZE_SHIFT = (FL_USHIFT+4),
29
+ RHASH_AR_TABLE_BOUND_MASK = (FL_USER8|FL_USER9|FL_USER10|FL_USER11), /* FL 8..11 */
30
+ RHASH_AR_TABLE_BOUND_SHIFT = (FL_USHIFT+8),
31
+
32
+ #if USE_TRANSIENT_HEAP
33
+ RHASH_TRANSIENT_FLAG = FL_USER12, /* FL 12 */
34
+ #endif
35
+
36
+ // we can not put it in "enum" because it can exceed "int" range.
37
+ #define RHASH_LEV_MASK (FL_USER13 | FL_USER14 | FL_USER15 | /* FL 13..19 */ \
38
+ FL_USER16 | FL_USER17 | FL_USER18 | FL_USER19)
39
+
40
+ RHASH_LEV_SHIFT = (FL_USHIFT + 13),
41
+ RHASH_LEV_MAX = 127, /* 7 bits */
42
+ };
43
+
44
+ struct RHash {
45
+ struct RBasic basic;
46
+ union {
47
+ st_table *st;
48
+ struct ar_table_struct *ar; /* possibly 0 */
49
+ } as;
50
+ const VALUE ifnone;
51
+ union {
52
+ ar_hint_t ary[RHASH_AR_TABLE_MAX_SIZE];
53
+ VALUE word;
54
+ } ar_hint;
55
+ };
56
+
57
+ #define RHASH(obj) (R_CAST(RHash)(obj))
58
+
59
+ #ifdef RHASH_IFNONE
60
+ # undef RHASH_IFNONE
61
+ #endif
62
+
63
+ #ifdef RHASH_SIZE
64
+ # undef RHASH_SIZE
65
+ #endif
66
+
67
+ /* hash.c */
68
+ void rb_hash_st_table_set(VALUE hash, st_table *st);
69
+ VALUE rb_hash_default_value(VALUE hash, VALUE key);
70
+ VALUE rb_hash_set_default_proc(VALUE hash, VALUE proc);
71
+ long rb_dbl_long_hash(double d);
72
+ st_table *rb_init_identtable(void);
73
+ VALUE rb_to_hash_type(VALUE obj);
74
+ VALUE rb_hash_key_str(VALUE);
75
+ VALUE rb_hash_values(VALUE hash);
76
+ VALUE rb_hash_rehash(VALUE hash);
77
+ int rb_hash_add_new_element(VALUE hash, VALUE key, VALUE val);
78
+ VALUE rb_hash_set_pair(VALUE hash, VALUE pair);
79
+ int rb_hash_stlike_delete(VALUE hash, st_data_t *pkey, st_data_t *pval);
80
+ int rb_hash_stlike_foreach_with_replace(VALUE hash, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg);
81
+ int rb_hash_stlike_update(VALUE hash, st_data_t key, st_update_callback_func *func, st_data_t arg);
82
+ static inline unsigned RHASH_AR_TABLE_SIZE_RAW(VALUE h);
83
+ static inline VALUE RHASH_IFNONE(VALUE h);
84
+ static inline size_t RHASH_SIZE(VALUE h);
85
+ static inline bool RHASH_AR_TABLE_P(VALUE h);
86
+ static inline bool RHASH_ST_TABLE_P(VALUE h);
87
+ static inline struct ar_table_struct *RHASH_AR_TABLE(VALUE h);
88
+ static inline st_table *RHASH_ST_TABLE(VALUE h);
89
+ static inline size_t RHASH_ST_SIZE(VALUE h);
90
+ static inline void RHASH_ST_CLEAR(VALUE h);
91
+ static inline bool RHASH_TRANSIENT_P(VALUE h);
92
+ static inline void RHASH_SET_TRANSIENT_FLAG(VALUE h);
93
+ static inline void RHASH_UNSET_TRANSIENT_FLAG(VALUE h);
94
+
95
+ RUBY_SYMBOL_EXPORT_BEGIN
96
+ /* hash.c (export) */
97
+ VALUE rb_hash_delete_entry(VALUE hash, VALUE key);
98
+ VALUE rb_ident_hash_new(void);
99
+ int rb_hash_stlike_foreach(VALUE hash, st_foreach_callback_func *func, st_data_t arg);
100
+ RUBY_SYMBOL_EXPORT_END
101
+
102
+ MJIT_SYMBOL_EXPORT_BEGIN
103
+ VALUE rb_hash_new_with_size(st_index_t size);
104
+ VALUE rb_hash_resurrect(VALUE hash);
105
+ int rb_hash_stlike_lookup(VALUE hash, st_data_t key, st_data_t *pval);
106
+ VALUE rb_hash_keys(VALUE hash);
107
+ VALUE rb_hash_has_key(VALUE hash, VALUE key);
108
+ VALUE rb_hash_compare_by_id_p(VALUE hash);
109
+
110
+ #if RHASH_CONVERT_TABLE_DEBUG
111
+ st_table *rb_hash_tbl_raw(VALUE hash, const char *file, int line);
112
+ #define RHASH_TBL_RAW(h) rb_hash_tbl_raw(h, __FILE__, __LINE__)
113
+ #else
114
+ st_table *rb_hash_tbl_raw(VALUE hash);
115
+ #define RHASH_TBL_RAW(h) rb_hash_tbl_raw(h)
116
+ #endif
117
+ MJIT_SYMBOL_EXPORT_END
118
+
119
+ #if 0 /* for debug */
120
+
121
+ static inline bool
122
+ RHASH_AR_TABLE_P(VALUE h)
123
+ {
124
+ extern int rb_hash_ar_table_p(VALUE hash);
125
+ return rb_hash_ar_table_p(h)
126
+ }
127
+
128
+ static inline struct ar_table_struct *
129
+ RHASH_AR_TABLE(VALUE h)
130
+ {
131
+ extern struct ar_table_struct *rb_hash_ar_table(VALUE hash);
132
+ return rb_hash_ar_table(h)
133
+ }
134
+
135
+ static inline st_table *
136
+ RHASH_ST_TABLE(VALUE h)
137
+ {
138
+ extern st_table *rb_hash_st_table(VALUE hash);
139
+ return rb_hash_st_table(h)
140
+ }
141
+
142
+ #else
143
+
144
+ static inline bool
145
+ RHASH_AR_TABLE_P(VALUE h)
146
+ {
147
+ return ! FL_TEST_RAW(h, RHASH_ST_TABLE_FLAG);
148
+ }
149
+
150
+ static inline struct ar_table_struct *
151
+ RHASH_AR_TABLE(VALUE h)
152
+ {
153
+ return RHASH(h)->as.ar;
154
+ }
155
+
156
+ static inline st_table *
157
+ RHASH_ST_TABLE(VALUE h)
158
+ {
159
+ return RHASH(h)->as.st;
160
+ }
161
+
162
+ #endif
163
+
164
+ static inline VALUE
165
+ RHASH_IFNONE(VALUE h)
166
+ {
167
+ return RHASH(h)->ifnone;
168
+ }
169
+
170
+ static inline size_t
171
+ RHASH_SIZE(VALUE h)
172
+ {
173
+ if (RHASH_AR_TABLE_P(h)) {
174
+ return RHASH_AR_TABLE_SIZE_RAW(h);
175
+ }
176
+ else {
177
+ return RHASH_ST_SIZE(h);
178
+ }
179
+ }
180
+
181
+ static inline bool
182
+ RHASH_ST_TABLE_P(VALUE h)
183
+ {
184
+ return ! RHASH_AR_TABLE_P(h);
185
+ }
186
+
187
+ static inline size_t
188
+ RHASH_ST_SIZE(VALUE h)
189
+ {
190
+ return RHASH_ST_TABLE(h)->num_entries;
191
+ }
192
+
193
+ static inline void
194
+ RHASH_ST_CLEAR(VALUE h)
195
+ {
196
+ FL_UNSET_RAW(h, RHASH_ST_TABLE_FLAG);
197
+ RHASH(h)->as.ar = NULL;
198
+ }
199
+
200
+ static inline unsigned
201
+ RHASH_AR_TABLE_SIZE_RAW(VALUE h)
202
+ {
203
+ VALUE ret = FL_TEST_RAW(h, RHASH_AR_TABLE_SIZE_MASK);
204
+ ret >>= RHASH_AR_TABLE_SIZE_SHIFT;
205
+ return (unsigned)ret;
206
+ }
207
+
208
+ static inline bool
209
+ RHASH_TRANSIENT_P(VALUE h)
210
+ {
211
+ #if USE_TRANSIENT_HEAP
212
+ return FL_TEST_RAW(h, RHASH_TRANSIENT_FLAG);
213
+ #else
214
+ return false;
215
+ #endif
216
+ }
217
+
218
+ static inline void
219
+ RHASH_SET_TRANSIENT_FLAG(VALUE h)
220
+ {
221
+ #if USE_TRANSIENT_HEAP
222
+ FL_SET_RAW(h, RHASH_TRANSIENT_FLAG);
223
+ #endif
224
+ }
225
+
226
+ static inline void
227
+ RHASH_UNSET_TRANSIENT_FLAG(VALUE h)
228
+ {
229
+ #if USE_TRANSIENT_HEAP
230
+ FL_UNSET_RAW(h, RHASH_TRANSIENT_FLAG);
231
+ #endif
232
+ }
233
+
234
+ #endif /* INTERNAL_HASH_H */
@@ -0,0 +1,242 @@
1
+ #ifndef INTERNAL_IMEMO_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_IMEMO_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @brief IMEMO: Internal memo object.
11
+ */
12
+ #include "ruby/internal/config.h"
13
+ #include <stddef.h> /* for size_t */
14
+ #include "internal/array.h" /* for rb_ary_tmp_new_fill */
15
+ #include "internal/gc.h" /* for RB_OBJ_WRITE */
16
+ #include "ruby/internal/stdbool.h" /* for bool */
17
+ #include "ruby/ruby.h" /* for rb_block_call_func_t */
18
+
19
+ #ifndef IMEMO_DEBUG
20
+ # define IMEMO_DEBUG 0
21
+ #endif
22
+
23
+ #define IMEMO_MASK 0x0f
24
+
25
+ /* FL_USER0 to FL_USER3 is for type */
26
+ #define IMEMO_FL_USHIFT (FL_USHIFT + 4)
27
+ #define IMEMO_FL_USER0 FL_USER4
28
+ #define IMEMO_FL_USER1 FL_USER5
29
+ #define IMEMO_FL_USER2 FL_USER6
30
+ #define IMEMO_FL_USER3 FL_USER7
31
+ #define IMEMO_FL_USER4 FL_USER8
32
+ #define IMEMO_FL_USER5 FL_USER9
33
+
34
+ enum imemo_type {
35
+ imemo_env = 0,
36
+ imemo_cref = 1, /*!< class reference */
37
+ imemo_svar = 2, /*!< special variable */
38
+ imemo_throw_data = 3,
39
+ imemo_ifunc = 4, /*!< iterator function */
40
+ imemo_memo = 5,
41
+ imemo_ment = 6,
42
+ imemo_iseq = 7,
43
+ imemo_tmpbuf = 8,
44
+ imemo_ast = 9,
45
+ imemo_parser_strterm = 10,
46
+ imemo_callinfo = 11,
47
+ imemo_callcache = 12,
48
+ };
49
+
50
+ /* CREF (Class REFerence) is defined in method.h */
51
+
52
+ /*! SVAR (Special VARiable) */
53
+ struct vm_svar {
54
+ VALUE flags;
55
+ const VALUE cref_or_me; /*!< class reference or rb_method_entry_t */
56
+ const VALUE lastline;
57
+ const VALUE backref;
58
+ const VALUE others;
59
+ };
60
+
61
+ /*! THROW_DATA */
62
+ struct vm_throw_data {
63
+ VALUE flags;
64
+ VALUE reserved;
65
+ const VALUE throw_obj;
66
+ const struct rb_control_frame_struct *catch_frame;
67
+ int throw_state;
68
+ };
69
+
70
+ #define THROW_DATA_CONSUMED IMEMO_FL_USER0
71
+
72
+ /* IFUNC (Internal FUNCtion) */
73
+
74
+ struct vm_ifunc_argc {
75
+ #if SIZEOF_INT * 2 > SIZEOF_VALUE
76
+ signed int min: (SIZEOF_VALUE * CHAR_BIT) / 2;
77
+ signed int max: (SIZEOF_VALUE * CHAR_BIT) / 2;
78
+ #else
79
+ int min, max;
80
+ #endif
81
+ };
82
+
83
+ /*! IFUNC (Internal FUNCtion) */
84
+ struct vm_ifunc {
85
+ VALUE flags;
86
+ VALUE reserved;
87
+ rb_block_call_func_t func;
88
+ const void *data;
89
+ struct vm_ifunc_argc argc;
90
+ };
91
+
92
+ struct rb_imemo_tmpbuf_struct {
93
+ VALUE flags;
94
+ VALUE reserved;
95
+ VALUE *ptr; /* malloc'ed buffer */
96
+ struct rb_imemo_tmpbuf_struct *next; /* next imemo */
97
+ size_t cnt; /* buffer size in VALUE */
98
+ };
99
+
100
+ /*! MEMO
101
+ *
102
+ * @see imemo_type
103
+ * */
104
+ struct MEMO {
105
+ VALUE flags;
106
+ VALUE reserved;
107
+ const VALUE v1;
108
+ const VALUE v2;
109
+ union {
110
+ long cnt;
111
+ long state;
112
+ const VALUE value;
113
+ void (*func)(void);
114
+ } u3;
115
+ };
116
+
117
+ /* ment is in method.h */
118
+
119
+ #define THROW_DATA_P(err) imemo_throw_data_p((VALUE)err)
120
+ #define MEMO_CAST(m) (R_CAST(MEMO)(m))
121
+ #define MEMO_NEW(a, b, c) ((struct MEMO *)rb_imemo_new(imemo_memo, (VALUE)(a), (VALUE)(b), (VALUE)(c), 0))
122
+ #define MEMO_FOR(type, value) ((type *)RARRAY_PTR(value))
123
+ #define NEW_MEMO_FOR(type, value) \
124
+ ((value) = rb_ary_tmp_new_fill(type_roomof(type, VALUE)), MEMO_FOR(type, value))
125
+ #define NEW_PARTIAL_MEMO_FOR(type, value, member) \
126
+ ((value) = rb_ary_tmp_new_fill(type_roomof(type, VALUE)), \
127
+ rb_ary_set_len((value), offsetof(type, member) / sizeof(VALUE)), \
128
+ MEMO_FOR(type, value))
129
+
130
+ typedef struct rb_imemo_tmpbuf_struct rb_imemo_tmpbuf_t;
131
+ VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0);
132
+ rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
133
+ struct vm_ifunc *rb_vm_ifunc_new(rb_block_call_func_t func, const void *data, int min_argc, int max_argc);
134
+ void rb_strterm_mark(VALUE obj);
135
+ static inline enum imemo_type imemo_type(VALUE imemo);
136
+ static inline int imemo_type_p(VALUE imemo, enum imemo_type imemo_type);
137
+ static inline bool imemo_throw_data_p(VALUE imemo);
138
+ static inline struct vm_ifunc *rb_vm_ifunc_proc_new(rb_block_call_func_t func, const void *data);
139
+ static inline VALUE rb_imemo_tmpbuf_auto_free_pointer(void);
140
+ static inline void *RB_IMEMO_TMPBUF_PTR(VALUE v);
141
+ static inline void *rb_imemo_tmpbuf_set_ptr(VALUE v, void *ptr);
142
+ static inline VALUE rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str);
143
+ static inline void MEMO_V1_SET(struct MEMO *m, VALUE v);
144
+ static inline void MEMO_V2_SET(struct MEMO *m, VALUE v);
145
+
146
+ RUBY_SYMBOL_EXPORT_BEGIN
147
+ #if IMEMO_DEBUG
148
+ VALUE rb_imemo_new_debug(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0, const char *file, int line);
149
+ #define rb_imemo_new(type, v1, v2, v3, v0) rb_imemo_new_debug(type, v1, v2, v3, v0, __FILE__, __LINE__)
150
+ #else
151
+ VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0);
152
+ #endif
153
+ RUBY_SYMBOL_EXPORT_END
154
+
155
+ static inline enum imemo_type
156
+ imemo_type(VALUE imemo)
157
+ {
158
+ return (RBASIC(imemo)->flags >> FL_USHIFT) & IMEMO_MASK;
159
+ }
160
+
161
+ static inline int
162
+ imemo_type_p(VALUE imemo, enum imemo_type imemo_type)
163
+ {
164
+ if (LIKELY(!RB_SPECIAL_CONST_P(imemo))) {
165
+ /* fixed at compile time if imemo_type is given. */
166
+ const VALUE mask = (IMEMO_MASK << FL_USHIFT) | RUBY_T_MASK;
167
+ const VALUE expected_type = (imemo_type << FL_USHIFT) | T_IMEMO;
168
+ /* fixed at runtime. */
169
+ return expected_type == (RBASIC(imemo)->flags & mask);
170
+ }
171
+ else {
172
+ return 0;
173
+ }
174
+ }
175
+
176
+ #define IMEMO_TYPE_P(v, t) imemo_type_p((VALUE)v, t)
177
+
178
+ static inline bool
179
+ imemo_throw_data_p(VALUE imemo)
180
+ {
181
+ return RB_TYPE_P(imemo, T_IMEMO);
182
+ }
183
+
184
+ static inline struct vm_ifunc *
185
+ rb_vm_ifunc_proc_new(rb_block_call_func_t func, const void *data)
186
+ {
187
+ return rb_vm_ifunc_new(func, data, 0, UNLIMITED_ARGUMENTS);
188
+ }
189
+
190
+ static inline VALUE
191
+ rb_imemo_tmpbuf_auto_free_pointer(void)
192
+ {
193
+ return rb_imemo_new(imemo_tmpbuf, 0, 0, 0, 0);
194
+ }
195
+
196
+ static inline void *
197
+ RB_IMEMO_TMPBUF_PTR(VALUE v)
198
+ {
199
+ const struct rb_imemo_tmpbuf_struct *p = (const void *)v;
200
+ return p->ptr;
201
+ }
202
+
203
+ static inline void *
204
+ rb_imemo_tmpbuf_set_ptr(VALUE v, void *ptr)
205
+ {
206
+ return ((rb_imemo_tmpbuf_t *)v)->ptr = ptr;
207
+ }
208
+
209
+ static inline VALUE
210
+ rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str)
211
+ {
212
+ const void *src;
213
+ VALUE imemo;
214
+ rb_imemo_tmpbuf_t *tmpbuf;
215
+ void *dst;
216
+ size_t len;
217
+
218
+ SafeStringValue(str);
219
+ /* create tmpbuf to keep the pointer before xmalloc */
220
+ imemo = rb_imemo_tmpbuf_auto_free_pointer();
221
+ tmpbuf = (rb_imemo_tmpbuf_t *)imemo;
222
+ len = RSTRING_LEN(str);
223
+ src = RSTRING_PTR(str);
224
+ dst = ruby_xmalloc(len);
225
+ memcpy(dst, src, len);
226
+ tmpbuf->ptr = dst;
227
+ return imemo;
228
+ }
229
+
230
+ static inline void
231
+ MEMO_V1_SET(struct MEMO *m, VALUE v)
232
+ {
233
+ RB_OBJ_WRITE(m, &m->v1, v);
234
+ }
235
+
236
+ static inline void
237
+ MEMO_V2_SET(struct MEMO *m, VALUE v)
238
+ {
239
+ RB_OBJ_WRITE(m, &m->v2, v);
240
+ }
241
+
242
+ #endif /* INTERNAL_IMEMO_H */