looksee 4.4.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,188 @@
1
+ #ifndef INTERNAL_GC_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_GC_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 GC.
10
+ */
11
+ #include "ruby/internal/config.h"
12
+
13
+ #include <stddef.h> /* for size_t */
14
+
15
+ #include "internal/compilers.h" /* for __has_attribute */
16
+ #include "ruby/ruby.h" /* for rb_event_flag_t */
17
+
18
+ struct rb_execution_context_struct; /* in vm_core.h */
19
+ struct rb_objspace; /* in vm_core.h */
20
+
21
+ #ifdef NEWOBJ_OF
22
+ # undef NEWOBJ_OF
23
+ # undef RB_NEWOBJ_OF
24
+ # undef RB_OBJ_WRITE
25
+ #endif
26
+
27
+ #define RVALUE_SIZE (sizeof(struct RBasic) + sizeof(VALUE[RBIMPL_RVALUE_EMBED_LEN_MAX]))
28
+
29
+ #define RB_RVARGC_NEWOBJ_OF(var, T, c, f, s) \
30
+ T *(var) = (T *)(((f) & FL_WB_PROTECTED) ? \
31
+ rb_wb_protected_newobj_of((c), (f) & ~FL_WB_PROTECTED, s) : \
32
+ rb_wb_unprotected_newobj_of((c), (f), s))
33
+
34
+ #define RB_RVARGC_EC_NEWOBJ_OF(ec, var, T, c, f, s) \
35
+ T *(var) = (T *)(((f) & FL_WB_PROTECTED) ? \
36
+ rb_ec_wb_protected_newobj_of((ec), (c), (f) & ~FL_WB_PROTECTED, s) : \
37
+ rb_wb_unprotected_newobj_of((c), (f), s))
38
+
39
+ /* optimized version of NEWOBJ() */
40
+ #define RB_NEWOBJ_OF(var, T, c, f) RB_RVARGC_NEWOBJ_OF(var, T, c, f, RVALUE_SIZE)
41
+
42
+ #define RB_EC_NEWOBJ_OF(ec, var, T, c, f) RB_RVARGC_EC_NEWOBJ_OF(ec, var, T, c, f, RVALUE_SIZE)
43
+
44
+ #define NEWOBJ_OF(var, T, c, f) RB_NEWOBJ_OF((var), T, (c), (f))
45
+ #define RVARGC_NEWOBJ_OF(var, T, c, f, s) RB_RVARGC_NEWOBJ_OF((var), T, (c), (f), (s))
46
+ #define RB_OBJ_GC_FLAGS_MAX 6 /* used in ext/objspace */
47
+
48
+ #ifndef USE_UNALIGNED_MEMBER_ACCESS
49
+ # define UNALIGNED_MEMBER_ACCESS(expr) (expr)
50
+ #elif ! USE_UNALIGNED_MEMBER_ACCESS
51
+ # define UNALIGNED_MEMBER_ACCESS(expr) (expr)
52
+ #elif ! (__has_warning("-Waddress-of-packed-member") || GCC_VERSION_SINCE(9, 0, 0))
53
+ # define UNALIGNED_MEMBER_ACCESS(expr) (expr)
54
+ #else
55
+ # include "internal/warnings.h"
56
+ # define UNALIGNED_MEMBER_ACCESS(expr) __extension__({ \
57
+ COMPILER_WARNING_PUSH; \
58
+ COMPILER_WARNING_IGNORED(-Waddress-of-packed-member); \
59
+ __typeof__(expr) unaligned_member_access_result = (expr); \
60
+ COMPILER_WARNING_POP; \
61
+ unaligned_member_access_result; \
62
+ })
63
+ #endif
64
+
65
+ #define UNALIGNED_MEMBER_PTR(ptr, mem) UNALIGNED_MEMBER_ACCESS(&(ptr)->mem)
66
+ #define RB_OBJ_WRITE(a, slot, b) \
67
+ rb_obj_write((VALUE)(a), UNALIGNED_MEMBER_ACCESS((VALUE *)(slot)), \
68
+ (VALUE)(b), __FILE__, __LINE__)
69
+
70
+ #if USE_RVARGC
71
+ # define SIZE_POOL_COUNT 5
72
+ #else
73
+ # define SIZE_POOL_COUNT 1
74
+ #endif
75
+
76
+ typedef struct ractor_newobj_size_pool_cache {
77
+ struct RVALUE *freelist;
78
+ struct heap_page *using_page;
79
+ } rb_ractor_newobj_size_pool_cache_t;
80
+
81
+ typedef struct ractor_newobj_cache {
82
+ size_t incremental_mark_step_allocated_slots;
83
+ rb_ractor_newobj_size_pool_cache_t size_pool_caches[SIZE_POOL_COUNT];
84
+ } rb_ractor_newobj_cache_t;
85
+
86
+ /* gc.c */
87
+ extern VALUE *ruby_initial_gc_stress_ptr;
88
+ extern int ruby_disable_gc;
89
+ RUBY_ATTR_MALLOC void *ruby_mimmalloc(size_t size);
90
+ void ruby_mimfree(void *ptr);
91
+ void rb_objspace_set_event_hook(const rb_event_flag_t event);
92
+ VALUE rb_objspace_gc_enable(struct rb_objspace *);
93
+ VALUE rb_objspace_gc_disable(struct rb_objspace *);
94
+ void ruby_gc_set_params(void);
95
+ void rb_copy_wb_protected_attribute(VALUE dest, VALUE obj);
96
+ #if __has_attribute(alloc_align)
97
+ __attribute__((__alloc_align__(1)))
98
+ #endif
99
+ RUBY_ATTR_MALLOC void *rb_aligned_malloc(size_t, size_t) RUBY_ATTR_ALLOC_SIZE((2));
100
+ size_t rb_size_mul_or_raise(size_t, size_t, VALUE); /* used in compile.c */
101
+ size_t rb_size_mul_add_or_raise(size_t, size_t, size_t, VALUE); /* used in iseq.h */
102
+ RUBY_ATTR_MALLOC void *rb_xmalloc_mul_add(size_t, size_t, size_t);
103
+ RUBY_ATTR_MALLOC void *rb_xcalloc_mul_add(size_t, size_t, size_t);
104
+ void *rb_xrealloc_mul_add(const void *, size_t, size_t, size_t);
105
+ RUBY_ATTR_MALLOC void *rb_xmalloc_mul_add_mul(size_t, size_t, size_t, size_t);
106
+ RUBY_ATTR_MALLOC void *rb_xcalloc_mul_add_mul(size_t, size_t, size_t, size_t);
107
+ 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));
108
+ 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));
109
+ static inline void ruby_sized_xfree_inlined(void *ptr, size_t size);
110
+ VALUE rb_class_allocate_instance(VALUE klass);
111
+ void rb_gc_ractor_newobj_cache_clear(rb_ractor_newobj_cache_t *newobj_cache);
112
+ size_t rb_gc_obj_slot_size(VALUE obj);
113
+ bool rb_gc_size_allocatable_p(size_t size);
114
+ int rb_objspace_garbage_object_p(VALUE obj);
115
+
116
+ RUBY_SYMBOL_EXPORT_BEGIN
117
+ /* gc.c (export) */
118
+ const char *rb_objspace_data_type_name(VALUE obj);
119
+ VALUE rb_wb_protected_newobj_of(VALUE, VALUE, size_t);
120
+ VALUE rb_wb_unprotected_newobj_of(VALUE, VALUE, size_t);
121
+ VALUE rb_ec_wb_protected_newobj_of(struct rb_execution_context_struct *ec, VALUE klass, VALUE flags, size_t);
122
+ size_t rb_obj_memsize_of(VALUE);
123
+ void rb_gc_verify_internal_consistency(void);
124
+ size_t rb_obj_gc_flags(VALUE, ID[], size_t);
125
+ void rb_gc_mark_values(long n, const VALUE *values);
126
+ void rb_gc_mark_vm_stack_values(long n, const VALUE *values);
127
+ void *ruby_sized_xrealloc(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2));
128
+ 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));
129
+ void ruby_sized_xfree(void *x, size_t size);
130
+ RUBY_SYMBOL_EXPORT_END
131
+
132
+ MJIT_SYMBOL_EXPORT_BEGIN
133
+ int rb_ec_stack_check(struct rb_execution_context_struct *ec);
134
+ void rb_gc_writebarrier_remember(VALUE obj);
135
+ const char *rb_obj_info(VALUE obj);
136
+ MJIT_SYMBOL_EXPORT_END
137
+
138
+ #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE) || defined(_WIN32)
139
+
140
+ static inline void *
141
+ ruby_sized_xrealloc_inlined(void *ptr, size_t new_size, size_t old_size)
142
+ {
143
+ return ruby_xrealloc(ptr, new_size);
144
+ }
145
+
146
+ static inline void *
147
+ ruby_sized_xrealloc2_inlined(void *ptr, size_t new_count, size_t elemsiz, size_t old_count)
148
+ {
149
+ return ruby_xrealloc2(ptr, new_count, elemsiz);
150
+ }
151
+
152
+ static inline void
153
+ ruby_sized_xfree_inlined(void *ptr, size_t size)
154
+ {
155
+ ruby_xfree(ptr);
156
+ }
157
+
158
+ # define SIZED_REALLOC_N(x, y, z, w) REALLOC_N(x, y, z)
159
+
160
+ #else
161
+
162
+ static inline void *
163
+ ruby_sized_xrealloc_inlined(void *ptr, size_t new_size, size_t old_size)
164
+ {
165
+ return ruby_sized_xrealloc(ptr, new_size, old_size);
166
+ }
167
+
168
+ static inline void *
169
+ ruby_sized_xrealloc2_inlined(void *ptr, size_t new_count, size_t elemsiz, size_t old_count)
170
+ {
171
+ return ruby_sized_xrealloc2(ptr, new_count, elemsiz, old_count);
172
+ }
173
+
174
+ static inline void
175
+ ruby_sized_xfree_inlined(void *ptr, size_t size)
176
+ {
177
+ ruby_sized_xfree(ptr, size);
178
+ }
179
+
180
+ # define SIZED_REALLOC_N(v, T, m, n) \
181
+ ((v) = (T *)ruby_sized_xrealloc2((void *)(v), (m), sizeof(T), (n)))
182
+
183
+ #endif /* HAVE_MALLOC_USABLE_SIZE */
184
+
185
+ #define ruby_sized_xrealloc ruby_sized_xrealloc_inlined
186
+ #define ruby_sized_xrealloc2 ruby_sized_xrealloc2_inlined
187
+ #define ruby_sized_xfree ruby_sized_xfree_inlined
188
+ #endif /* INTERNAL_GC_H */
@@ -0,0 +1,242 @@
1
+ #ifndef INTERNAL_IMEMO_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_IMEMO_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 IMEMO: Internal memo object.
10
+ */
11
+ #include "ruby/internal/config.h"
12
+ #include <stddef.h> /* for size_t */
13
+ #include "internal/array.h" /* for rb_ary_hidden_new_fill */
14
+ #include "internal/gc.h" /* for RB_OBJ_WRITE */
15
+ #include "ruby/internal/stdbool.h" /* for bool */
16
+ #include "ruby/ruby.h" /* for rb_block_call_func_t */
17
+
18
+ #ifndef IMEMO_DEBUG
19
+ # define IMEMO_DEBUG 0
20
+ #endif
21
+
22
+ #define IMEMO_MASK 0x0f
23
+
24
+ /* FL_USER0 to FL_USER3 is for type */
25
+ #define IMEMO_FL_USHIFT (FL_USHIFT + 4)
26
+ #define IMEMO_FL_USER0 FL_USER4
27
+ #define IMEMO_FL_USER1 FL_USER5
28
+ #define IMEMO_FL_USER2 FL_USER6
29
+ #define IMEMO_FL_USER3 FL_USER7
30
+ #define IMEMO_FL_USER4 FL_USER8
31
+ #define IMEMO_FL_USER5 FL_USER9
32
+
33
+ enum imemo_type {
34
+ imemo_env = 0,
35
+ imemo_cref = 1, /*!< class reference */
36
+ imemo_svar = 2, /*!< special variable */
37
+ imemo_throw_data = 3,
38
+ imemo_ifunc = 4, /*!< iterator function */
39
+ imemo_memo = 5,
40
+ imemo_ment = 6,
41
+ imemo_iseq = 7,
42
+ imemo_tmpbuf = 8,
43
+ imemo_ast = 9,
44
+ imemo_parser_strterm = 10,
45
+ imemo_callinfo = 11,
46
+ imemo_callcache = 12,
47
+ imemo_constcache = 13,
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) ((struct 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_hidden_new_fill(type_roomof(type, VALUE)), MEMO_FOR(type, value))
125
+ #define NEW_PARTIAL_MEMO_FOR(type, value, member) \
126
+ ((value) = rb_ary_hidden_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
+ rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
132
+ struct vm_ifunc *rb_vm_ifunc_new(rb_block_call_func_t func, const void *data, int min_argc, int max_argc);
133
+ void rb_strterm_mark(VALUE obj);
134
+ static inline enum imemo_type imemo_type(VALUE imemo);
135
+ static inline int imemo_type_p(VALUE imemo, enum imemo_type imemo_type);
136
+ static inline bool imemo_throw_data_p(VALUE imemo);
137
+ static inline struct vm_ifunc *rb_vm_ifunc_proc_new(rb_block_call_func_t func, const void *data);
138
+ static inline VALUE rb_imemo_tmpbuf_auto_free_pointer(void);
139
+ static inline void *RB_IMEMO_TMPBUF_PTR(VALUE v);
140
+ static inline void *rb_imemo_tmpbuf_set_ptr(VALUE v, void *ptr);
141
+ static inline VALUE rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str);
142
+ static inline void MEMO_V1_SET(struct MEMO *m, VALUE v);
143
+ static inline void MEMO_V2_SET(struct MEMO *m, VALUE v);
144
+
145
+ RUBY_SYMBOL_EXPORT_BEGIN
146
+ #if IMEMO_DEBUG
147
+ VALUE rb_imemo_new_debug(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0, const char *file, int line);
148
+ #define rb_imemo_new(type, v1, v2, v3, v0) rb_imemo_new_debug(type, v1, v2, v3, v0, __FILE__, __LINE__)
149
+ #else
150
+ VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0);
151
+ #endif
152
+ const char *rb_imemo_name(enum imemo_type type);
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 */
@@ -0,0 +1,23 @@
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 */
@@ -0,0 +1,16 @@
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 */
@@ -0,0 +1,16 @@
1
+ #ifndef INTERNAL_WARNINGS_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_WARNINGS_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 to suppress / mandate warnings.
10
+ */
11
+ #include "ruby/internal/warning_push.h"
12
+ #define COMPILER_WARNING_PUSH RBIMPL_WARNING_PUSH()
13
+ #define COMPILER_WARNING_POP RBIMPL_WARNING_POP()
14
+ #define COMPILER_WARNING_ERROR(flag) RBIMPL_WARNING_ERROR(flag)
15
+ #define COMPILER_WARNING_IGNORED(flag) RBIMPL_WARNING_IGNORED(flag)
16
+ #endif /* INTERNAL_WARNINGS_H */
@@ -0,0 +1,113 @@
1
+ #ifndef RUBY_INTERNAL_H /*-*-C-*-vi:se ft=c:*/
2
+ #define RUBY_INTERNAL_H 1
3
+ /**
4
+ * @author $Author$
5
+ * @date Tue May 17 11:42:20 JST 2011
6
+ * @copyright Copyright (C) 2011 Yukihiro Matsumoto
7
+ * @copyright This file is a part of the programming language Ruby.
8
+ * Permission is hereby granted, to either redistribute and/or
9
+ * modify this file, provided that the conditions mentioned in the
10
+ * file COPYING are met. Consult the file for details.
11
+ */
12
+ #include "ruby/internal/config.h"
13
+
14
+ #ifdef __cplusplus
15
+ # error not for C++
16
+ #endif
17
+
18
+ #define LIKELY(x) RB_LIKELY(x)
19
+ #define UNLIKELY(x) RB_UNLIKELY(x)
20
+
21
+ #define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
22
+ #define roomof(x, y) (((x) + (y) - 1) / (y))
23
+ #define type_roomof(x, y) roomof(sizeof(x), sizeof(y))
24
+
25
+ /* Prevent compiler from reordering access */
26
+ #define ACCESS_ONCE(type,x) (*((volatile type *)&(x)))
27
+
28
+ #include "ruby/ruby.h"
29
+
30
+ /* Following macros were formerly defined in this header but moved to somewhere
31
+ * else. In order to detect them we undef here. */
32
+
33
+ /* internal/array.h */
34
+ #undef RARRAY_AREF
35
+
36
+ /* internal/class.h */
37
+ #undef RClass
38
+ #undef RCLASS_SUPER
39
+
40
+ /* internal/gc.h */
41
+ #undef NEWOBJ_OF
42
+ #undef RB_NEWOBJ_OF
43
+ #undef RB_OBJ_WRITE
44
+
45
+ /* internal/hash.h */
46
+ #undef RHASH_IFNONE
47
+ #undef RHASH_SIZE
48
+ #undef RHASH_TBL
49
+ #undef RHASH_EMPTY_P
50
+
51
+ /* internal/object.h */
52
+ #undef ROBJECT_IV_INDEX_TBL
53
+
54
+ /* internal/struct.h */
55
+ #undef RSTRUCT_LEN
56
+ #undef RSTRUCT_PTR
57
+ #undef RSTRUCT_SET
58
+ #undef RSTRUCT_GET
59
+
60
+ /* Also, we keep the following macros here. They are expected to be
61
+ * overridden in each headers. */
62
+
63
+ /* internal/array.h */
64
+ #define rb_ary_new_from_args(...) rb_nonexistent_symbol(__VA_ARGS__)
65
+
66
+ /* internal/io.h */
67
+ #define rb_io_fptr_finalize(...) rb_nonexistent_symbol(__VA_ARGS__)
68
+
69
+ /* internal/string.h */
70
+ #define rb_fstring_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
71
+
72
+ /* internal/symbol.h */
73
+ #define rb_sym_intern_ascii_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
74
+
75
+ /* internal/vm.h */
76
+ #define rb_funcallv(...) rb_nonexistent_symbol(__VA_ARGS__)
77
+ #define rb_method_basic_definition_p(...) rb_nonexistent_symbol(__VA_ARGS__)
78
+
79
+
80
+ /* MRI debug support */
81
+
82
+ /* gc.c */
83
+ void rb_obj_info_dump(VALUE obj);
84
+ void rb_obj_info_dump_loc(VALUE obj, const char *file, int line, const char *func);
85
+
86
+ /* debug.c */
87
+
88
+ RUBY_SYMBOL_EXPORT_BEGIN
89
+ void ruby_debug_breakpoint(void);
90
+ PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
91
+ RUBY_SYMBOL_EXPORT_END
92
+
93
+ // show obj data structure without any side-effect
94
+ #define rp(obj) rb_obj_info_dump_loc((VALUE)(obj), __FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING)
95
+
96
+ // same as rp, but add message header
97
+ #define rp_m(msg, obj) do { \
98
+ fputs((msg), stderr); \
99
+ rb_obj_info_dump((VALUE)(obj)); \
100
+ } while (0)
101
+
102
+ // `ruby_debug_breakpoint()` does nothing,
103
+ // but breakpoint is set in run.gdb, so `make gdb` can stop here.
104
+ #define bp() ruby_debug_breakpoint()
105
+
106
+ #define RBOOL(v) ((v) ? Qtrue : Qfalse)
107
+ #define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
108
+
109
+ #ifndef __MINGW32__
110
+ #undef memcpy
111
+ #define memcpy ruby_nonempty_memcpy
112
+ #endif
113
+ #endif /* RUBY_INTERNAL_H */