1#ifndef INTERNAL_IMEMO_H
2#define INTERNAL_IMEMO_H
11#include "ruby/internal/config.h"
13#include "internal/array.h"
21#define IMEMO_MASK 0x0f
24#define IMEMO_FL_USHIFT (FL_USHIFT + 4)
25#define IMEMO_FL_USER0 FL_USER4
26#define IMEMO_FL_USER1 FL_USER5
27#define IMEMO_FL_USER2 FL_USER6
28#define IMEMO_FL_USER3 FL_USER7
29#define IMEMO_FL_USER4 FL_USER8
30#define IMEMO_FL_USER5 FL_USER9
43 imemo_parser_strterm = 10,
46 imemo_constcache = 13,
64 const VALUE throw_obj;
69#define THROW_DATA_CONSUMED IMEMO_FL_USER0
74#if SIZEOF_INT * 2 > SIZEOF_VALUE
118#define THROW_DATA_P(err) imemo_throw_data_p((VALUE)err)
119#define MEMO_CAST(m) ((struct MEMO *)(m))
120#define MEMO_NEW(a, b, c) ((struct MEMO *)rb_imemo_new(imemo_memo, (VALUE)(a), (VALUE)(b), (VALUE)(c), 0))
121#define MEMO_FOR(type, value) ((type *)RARRAY_PTR(value))
122#define NEW_MEMO_FOR(type, value) \
123 ((value) = rb_ary_hidden_new_fill(type_roomof(type, VALUE)), MEMO_FOR(type, value))
124#define NEW_PARTIAL_MEMO_FOR(type, value, member) \
125 ((value) = rb_ary_hidden_new_fill(type_roomof(type, VALUE)), \
126 rb_ary_set_len((value), offsetof(type, member) / sizeof(VALUE)), \
127 MEMO_FOR(type, value))
130rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(
void *buf, rb_imemo_tmpbuf_t *old_heap,
size_t cnt);
132static inline enum imemo_type imemo_type(
VALUE imemo);
133static inline int imemo_type_p(
VALUE imemo,
enum imemo_type imemo_type);
134static inline bool imemo_throw_data_p(
VALUE imemo);
136static inline VALUE rb_imemo_tmpbuf_auto_free_pointer(
void);
137static inline void *RB_IMEMO_TMPBUF_PTR(
VALUE v);
138static inline void *rb_imemo_tmpbuf_set_ptr(
VALUE v,
void *ptr);
139static inline VALUE rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(
VALUE str);
140static inline void MEMO_V1_SET(
struct MEMO *m,
VALUE v);
141static inline void MEMO_V2_SET(
struct MEMO *m,
VALUE v);
143RUBY_SYMBOL_EXPORT_BEGIN
146#define rb_imemo_new(type, v1, v2, v3, v0) rb_imemo_new_debug(type, v1, v2, v3, v0, __FILE__, __LINE__)
150const char *rb_imemo_name(
enum imemo_type
type);
151RUBY_SYMBOL_EXPORT_END
153static inline enum imemo_type
154imemo_type(
VALUE imemo)
160imemo_type_p(
VALUE imemo,
enum imemo_type imemo_type)
167 return expected_type == (
RBASIC(imemo)->flags & mask);
174#define IMEMO_TYPE_P(v, t) imemo_type_p((VALUE)v, t)
177imemo_throw_data_p(
VALUE imemo)
179 return RB_TYPE_P(imemo,
T_IMEMO);
189rb_imemo_tmpbuf_auto_free_pointer(
void)
191 return rb_imemo_new(imemo_tmpbuf, 0, 0, 0, 0);
195RB_IMEMO_TMPBUF_PTR(
VALUE v)
202rb_imemo_tmpbuf_set_ptr(
VALUE v,
void *ptr)
204 return ((rb_imemo_tmpbuf_t *)v)->ptr = ptr;
208rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(
VALUE str)
212 rb_imemo_tmpbuf_t *tmpbuf;
218 imemo = rb_imemo_tmpbuf_auto_free_pointer();
219 tmpbuf = (rb_imemo_tmpbuf_t *)imemo;
220 len = RSTRING_LEN(str);
221 src = RSTRING_PTR(str);
222 dst = ruby_xmalloc(
len);
223 memcpy(dst, src,
len);
#define T_IMEMO
Old name of RUBY_T_IMEMO.
#define FL_USHIFT
Old name of RUBY_FL_USHIFT.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
int len
Length of the buffer.
rb_block_call_func * rb_block_call_func_t
Shorthand type that represents an iterator-written-in-C function pointer.
VALUE type(ANYARGS)
ANYARGS-ed function type.
#define RBASIC(obj)
Convenient casting macro.
#define SafeStringValue(v)
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
IFUNC (Internal FUNCtion)
const VALUE cref_or_me
class reference or rb_method_entry_t
#define SIZEOF_VALUE
Identical to sizeof(VALUE), except it is a macro that can also be used inside of preprocessor directi...
uintptr_t VALUE
Type that represents a Ruby object.
@ RUBY_T_MASK
Bitmask of ruby_value_type.