looksee 4.2.0 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,108 @@
1
+ #ifndef INTERNAL_COMPILERS_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_COMPILERS_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 absorbing C compipler differences.
11
+ */
12
+ #include "ruby/internal/compiler_since.h"
13
+ #include "ruby/internal/has/attribute.h"
14
+ #include "ruby/internal/has/builtin.h"
15
+ #include "ruby/internal/has/c_attribute.h"
16
+ #include "ruby/internal/has/declspec_attribute.h"
17
+ #include "ruby/internal/has/extension.h"
18
+ #include "ruby/internal/has/feature.h"
19
+ #include "ruby/internal/has/warning.h"
20
+ #include "ruby/backward/2/gcc_version_since.h"
21
+
22
+ #define MSC_VERSION_SINCE(_) RBIMPL_COMPILER_SINCE(MSVC, (_) / 100, (_) % 100, 0)
23
+ #define MSC_VERSION_BEFORE(_) RBIMPL_COMPILER_BEFORE(MSVC, (_) / 100, (_) % 100, 0)
24
+
25
+ #ifndef __has_attribute
26
+ # define __has_attribute(...) RBIMPL_HAS_ATTRIBUTE(__VA_ARGS__)
27
+ #endif
28
+
29
+ #ifndef __has_c_attribute
30
+ # /* As of writing everything that lacks __has_c_attribute also completely
31
+ # * lacks C2x attributes as well. Might change in future? */
32
+ # define __has_c_attribute(...) 0
33
+ #endif
34
+
35
+ #ifndef __has_declspec_attribute
36
+ # define __has_declspec_attribute(...) RBIMPL_HAS_DECLSPEC_ATTRIBUTE(__VA_ARGS__)
37
+ #endif
38
+
39
+ #ifndef __has_builtin
40
+ # define __has_builtin(...) RBIMPL_HAS_BUILTIN(__VA_ARGS__)
41
+ #endif
42
+
43
+ #ifndef __has_feature
44
+ # define __has_feature(...) RBIMPL_HAS_FEATURE(__VA_ARGS__)
45
+ #endif
46
+
47
+ #ifndef __has_extension
48
+ # define __has_extension(...) RBIMPL_HAS_EXTENSION(__VA_ARGS__)
49
+ #endif
50
+
51
+ #ifndef __has_warning
52
+ # define __has_warning(...) RBIMPL_HAS_WARNING(__VA_ARGS__)
53
+ #endif
54
+
55
+ #ifndef __GNUC__
56
+ # define __extension__ /* void */
57
+ #endif
58
+
59
+ #ifndef MAYBE_UNUSED
60
+ # define MAYBE_UNUSED(x) x
61
+ #endif
62
+
63
+ #ifndef WARN_UNUSED_RESULT
64
+ # define WARN_UNUSED_RESULT(x) x
65
+ #endif
66
+
67
+ #define RB_OBJ_BUILTIN_TYPE(obj) rb_obj_builtin_type(obj)
68
+ #define OBJ_BUILTIN_TYPE(obj) RB_OBJ_BUILTIN_TYPE(obj)
69
+ #ifdef __GNUC__
70
+ #define rb_obj_builtin_type(obj) \
71
+ __extension__({ \
72
+ VALUE arg_obj = (obj); \
73
+ RB_SPECIAL_CONST_P(arg_obj) ? -1 : \
74
+ (int)RB_BUILTIN_TYPE(arg_obj); \
75
+ })
76
+ #else
77
+ # include "ruby/ruby.h"
78
+ static inline int
79
+ rb_obj_builtin_type(VALUE obj)
80
+ {
81
+ return RB_SPECIAL_CONST_P(obj) ? -1 :
82
+ (int)RB_BUILTIN_TYPE(obj);
83
+ }
84
+ #endif
85
+
86
+ /* A macro for defining a flexible array, like: VALUE ary[FLEX_ARY_LEN]; */
87
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
88
+ # define FLEX_ARY_LEN /* VALUE ary[]; */
89
+ #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
90
+ # define FLEX_ARY_LEN 0 /* VALUE ary[0]; */
91
+ #else
92
+ # define FLEX_ARY_LEN 1 /* VALUE ary[1]; */
93
+ #endif
94
+
95
+ /*
96
+ * For declaring bitfields out of non-unsigned int types:
97
+ * struct date {
98
+ * BITFIELD(enum months, month, 4);
99
+ * ...
100
+ * };
101
+ */
102
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
103
+ # define BITFIELD(type, name, size) type name : size
104
+ #else
105
+ # define BITFIELD(type, name, size) unsigned int name : size
106
+ #endif
107
+
108
+ #endif /* INTERNAL_COMPILERS_H */
@@ -0,0 +1,161 @@
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
+
34
+ #define RB_EC_NEWOBJ_OF(ec, var, T, c, f) \
35
+ T *(var) = (T *)(((f) & FL_WB_PROTECTED) ? \
36
+ rb_ec_wb_protected_newobj_of((ec), (c), (f) & ~FL_WB_PROTECTED) : \
37
+ rb_wb_unprotected_newobj_of((c), (f)))
38
+
39
+ #define NEWOBJ_OF(var, T, c, f) RB_NEWOBJ_OF((var), T, (c), (f))
40
+ #define RB_OBJ_GC_FLAGS_MAX 6 /* used in ext/objspace */
41
+
42
+ #ifndef USE_UNALIGNED_MEMBER_ACCESS
43
+ # define UNALIGNED_MEMBER_ACCESS(expr) (expr)
44
+ #elif ! USE_UNALIGNED_MEMBER_ACCESS
45
+ # define UNALIGNED_MEMBER_ACCESS(expr) (expr)
46
+ #elif ! (__has_warning("-Waddress-of-packed-member") || GCC_VERSION_SINCE(9, 0, 0))
47
+ # define UNALIGNED_MEMBER_ACCESS(expr) (expr)
48
+ #else
49
+ # include "internal/warnings.h"
50
+ # define UNALIGNED_MEMBER_ACCESS(expr) __extension__({ \
51
+ COMPILER_WARNING_PUSH; \
52
+ COMPILER_WARNING_IGNORED(-Waddress-of-packed-member); \
53
+ __typeof__(expr) unaligned_member_access_result = (expr); \
54
+ COMPILER_WARNING_POP; \
55
+ unaligned_member_access_result; \
56
+ })
57
+ #endif
58
+
59
+ #define UNALIGNED_MEMBER_PTR(ptr, mem) UNALIGNED_MEMBER_ACCESS(&(ptr)->mem)
60
+ #define RB_OBJ_WRITE(a, slot, b) \
61
+ rb_obj_write((VALUE)(a), UNALIGNED_MEMBER_ACCESS((VALUE *)(slot)), \
62
+ (VALUE)(b), __FILE__, __LINE__)
63
+
64
+ /* gc.c */
65
+ extern VALUE *ruby_initial_gc_stress_ptr;
66
+ extern int ruby_disable_gc;
67
+ RUBY_ATTR_MALLOC void *ruby_mimmalloc(size_t size);
68
+ void ruby_mimfree(void *ptr);
69
+ void rb_objspace_set_event_hook(const rb_event_flag_t event);
70
+ VALUE rb_objspace_gc_enable(struct rb_objspace *);
71
+ VALUE rb_objspace_gc_disable(struct rb_objspace *);
72
+ void ruby_gc_set_params(void);
73
+ void rb_copy_wb_protected_attribute(VALUE dest, VALUE obj);
74
+ #if __has_attribute(alloc_align)
75
+ __attribute__((__alloc_align__(1)))
76
+ #endif
77
+ RUBY_ATTR_MALLOC void *rb_aligned_malloc(size_t, size_t) RUBY_ATTR_ALLOC_SIZE((2));
78
+ size_t rb_size_mul_or_raise(size_t, size_t, VALUE); /* used in compile.c */
79
+ size_t rb_size_mul_add_or_raise(size_t, size_t, size_t, VALUE); /* used in iseq.h */
80
+ RUBY_ATTR_MALLOC void *rb_xmalloc_mul_add(size_t, size_t, size_t);
81
+ void *rb_xrealloc_mul_add(const void *, size_t, size_t, size_t);
82
+ RUBY_ATTR_MALLOC void *rb_xmalloc_mul_add_mul(size_t, size_t, size_t, size_t);
83
+ RUBY_ATTR_MALLOC void *rb_xcalloc_mul_add_mul(size_t, size_t, size_t, size_t);
84
+ 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));
85
+ 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));
86
+ static inline void ruby_sized_xfree_inlined(void *ptr, size_t size);
87
+ VALUE rb_class_allocate_instance(VALUE klass);
88
+
89
+ RUBY_SYMBOL_EXPORT_BEGIN
90
+ /* gc.c (export) */
91
+ const char *rb_objspace_data_type_name(VALUE obj);
92
+ VALUE rb_wb_protected_newobj_of(VALUE, VALUE);
93
+ VALUE rb_wb_unprotected_newobj_of(VALUE, VALUE);
94
+ VALUE rb_ec_wb_protected_newobj_of(struct rb_execution_context_struct *ec, VALUE klass, VALUE flags);
95
+ size_t rb_obj_memsize_of(VALUE);
96
+ void rb_gc_verify_internal_consistency(void);
97
+ size_t rb_obj_gc_flags(VALUE, ID[], size_t);
98
+ void rb_gc_mark_values(long n, const VALUE *values);
99
+ void rb_gc_mark_vm_stack_values(long n, const VALUE *values);
100
+ void *ruby_sized_xrealloc(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2));
101
+ 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));
102
+ void ruby_sized_xfree(void *x, size_t size);
103
+ RUBY_SYMBOL_EXPORT_END
104
+
105
+ MJIT_SYMBOL_EXPORT_BEGIN
106
+ int rb_ec_stack_check(struct rb_execution_context_struct *ec);
107
+ void rb_gc_writebarrier_remember(VALUE obj);
108
+ const char *rb_obj_info(VALUE obj);
109
+ MJIT_SYMBOL_EXPORT_END
110
+
111
+ #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE) || defined(_WIN32)
112
+
113
+ static inline void *
114
+ ruby_sized_xrealloc_inlined(void *ptr, size_t new_size, size_t old_size)
115
+ {
116
+ return ruby_xrealloc(ptr, new_size);
117
+ }
118
+
119
+ static inline void *
120
+ ruby_sized_xrealloc2_inlined(void *ptr, size_t new_count, size_t elemsiz, size_t old_count)
121
+ {
122
+ return ruby_xrealloc2(ptr, new_count, elemsiz);
123
+ }
124
+
125
+ static inline void
126
+ ruby_sized_xfree_inlined(void *ptr, size_t size)
127
+ {
128
+ ruby_xfree(ptr);
129
+ }
130
+
131
+ # define SIZED_REALLOC_N(x, y, z, w) REALLOC_N(x, y, z)
132
+
133
+ #else
134
+
135
+ static inline void *
136
+ ruby_sized_xrealloc_inlined(void *ptr, size_t new_size, size_t old_size)
137
+ {
138
+ return ruby_sized_xrealloc(ptr, new_size, old_size);
139
+ }
140
+
141
+ static inline void *
142
+ ruby_sized_xrealloc2_inlined(void *ptr, size_t new_count, size_t elemsiz, size_t old_count)
143
+ {
144
+ return ruby_sized_xrealloc2(ptr, new_count, elemsiz, old_count);
145
+ }
146
+
147
+ static inline void
148
+ ruby_sized_xfree_inlined(void *ptr, size_t size)
149
+ {
150
+ ruby_sized_xfree(ptr, size);
151
+ }
152
+
153
+ # define SIZED_REALLOC_N(v, T, m, n) \
154
+ ((v) = (T *)ruby_sized_xrealloc2((void *)(v), (m), sizeof(T), (n)))
155
+
156
+ #endif /* HAVE_MALLOC_USABLE_SIZE */
157
+
158
+ #define ruby_sized_xrealloc ruby_sized_xrealloc_inlined
159
+ #define ruby_sized_xrealloc2 ruby_sized_xrealloc2_inlined
160
+ #define ruby_sized_xfree ruby_sized_xfree_inlined
161
+ #endif /* INTERNAL_GC_H */
@@ -0,0 +1,243 @@
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) ((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_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
+ const char *rb_imemo_name(enum imemo_type type);
154
+ RUBY_SYMBOL_EXPORT_END
155
+
156
+ static inline enum imemo_type
157
+ imemo_type(VALUE imemo)
158
+ {
159
+ return (RBASIC(imemo)->flags >> FL_USHIFT) & IMEMO_MASK;
160
+ }
161
+
162
+ static inline int
163
+ imemo_type_p(VALUE imemo, enum imemo_type imemo_type)
164
+ {
165
+ if (LIKELY(!RB_SPECIAL_CONST_P(imemo))) {
166
+ /* fixed at compile time if imemo_type is given. */
167
+ const VALUE mask = (IMEMO_MASK << FL_USHIFT) | RUBY_T_MASK;
168
+ const VALUE expected_type = (imemo_type << FL_USHIFT) | T_IMEMO;
169
+ /* fixed at runtime. */
170
+ return expected_type == (RBASIC(imemo)->flags & mask);
171
+ }
172
+ else {
173
+ return 0;
174
+ }
175
+ }
176
+
177
+ #define IMEMO_TYPE_P(v, t) imemo_type_p((VALUE)v, t)
178
+
179
+ static inline bool
180
+ imemo_throw_data_p(VALUE imemo)
181
+ {
182
+ return RB_TYPE_P(imemo, T_IMEMO);
183
+ }
184
+
185
+ static inline struct vm_ifunc *
186
+ rb_vm_ifunc_proc_new(rb_block_call_func_t func, const void *data)
187
+ {
188
+ return rb_vm_ifunc_new(func, data, 0, UNLIMITED_ARGUMENTS);
189
+ }
190
+
191
+ static inline VALUE
192
+ rb_imemo_tmpbuf_auto_free_pointer(void)
193
+ {
194
+ return rb_imemo_new(imemo_tmpbuf, 0, 0, 0, 0);
195
+ }
196
+
197
+ static inline void *
198
+ RB_IMEMO_TMPBUF_PTR(VALUE v)
199
+ {
200
+ const struct rb_imemo_tmpbuf_struct *p = (const void *)v;
201
+ return p->ptr;
202
+ }
203
+
204
+ static inline void *
205
+ rb_imemo_tmpbuf_set_ptr(VALUE v, void *ptr)
206
+ {
207
+ return ((rb_imemo_tmpbuf_t *)v)->ptr = ptr;
208
+ }
209
+
210
+ static inline VALUE
211
+ rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str)
212
+ {
213
+ const void *src;
214
+ VALUE imemo;
215
+ rb_imemo_tmpbuf_t *tmpbuf;
216
+ void *dst;
217
+ size_t len;
218
+
219
+ SafeStringValue(str);
220
+ /* create tmpbuf to keep the pointer before xmalloc */
221
+ imemo = rb_imemo_tmpbuf_auto_free_pointer();
222
+ tmpbuf = (rb_imemo_tmpbuf_t *)imemo;
223
+ len = RSTRING_LEN(str);
224
+ src = RSTRING_PTR(str);
225
+ dst = ruby_xmalloc(len);
226
+ memcpy(dst, src, len);
227
+ tmpbuf->ptr = dst;
228
+ return imemo;
229
+ }
230
+
231
+ static inline void
232
+ MEMO_V1_SET(struct MEMO *m, VALUE v)
233
+ {
234
+ RB_OBJ_WRITE(m, &m->v1, v);
235
+ }
236
+
237
+ static inline void
238
+ MEMO_V2_SET(struct MEMO *m, VALUE v)
239
+ {
240
+ RB_OBJ_WRITE(m, &m->v2, v);
241
+ }
242
+
243
+ #endif /* INTERNAL_IMEMO_H */