diff options
author | Peter Zhu <peter@peterzhu.ca> | 2024-02-20 15:58:10 -0500 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2024-02-21 11:33:05 -0500 |
commit | 330830dd1a44b6e497250a14d93efae6fa363f82 (patch) | |
tree | 864fc9a6ba29c91fcbeb0c9c439e99b7d7fb0a04 /internal | |
parent | 2e6f8554f8c4ec12f620f31d4a110066ee76bfbe (diff) | |
download | ruby-330830dd1a44b6e497250a14d93efae6fa363f82.tar.gz |
Add IMEMO_NEW
Rather than exposing that an imemo has a flag and four fields, this
changes the implementation to only expose one field (the klass) and
fills the rest with 0. The type will have to fill in the values themselves.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/imemo.h | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/internal/imemo.h b/internal/imemo.h index f52b60e016..5b54629c99 100644 --- a/internal/imemo.h +++ b/internal/imemo.h @@ -113,11 +113,12 @@ struct MEMO { } u3; }; +#define IMEMO_NEW(T, type, v0) ((T *)rb_imemo_new((type), (v0))) + /* ment is in method.h */ #define THROW_DATA_P(err) imemo_throw_data_p((VALUE)err) #define MEMO_CAST(m) ((struct MEMO *)(m)) -#define MEMO_NEW(a, b, c) ((struct MEMO *)rb_imemo_new(imemo_memo, (VALUE)(a), (VALUE)(b), (VALUE)(c), 0)) #define MEMO_FOR(type, value) ((type *)RARRAY_PTR(value)) #define NEW_MEMO_FOR(type, value) \ ((value) = rb_ary_hidden_new_fill(type_roomof(type, VALUE)), MEMO_FOR(type, value)) @@ -144,14 +145,25 @@ static inline void MEMO_V2_SET(struct MEMO *m, VALUE v); RUBY_SYMBOL_EXPORT_BEGIN #if IMEMO_DEBUG -VALUE rb_imemo_new_debug(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0, const char *file, int line); +VALUE rb_imemo_new_debug(enum imemo_type type, VALUE v0, const char *file, int line); #define rb_imemo_new(type, v1, v2, v3, v0) rb_imemo_new_debug(type, v1, v2, v3, v0, __FILE__, __LINE__) #else -VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0); +VALUE rb_imemo_new(enum imemo_type type, VALUE v0); #endif const char *rb_imemo_name(enum imemo_type type); RUBY_SYMBOL_EXPORT_END +static inline struct MEMO * +MEMO_NEW(VALUE a, VALUE b, VALUE c) +{ + struct MEMO *memo = IMEMO_NEW(struct MEMO, imemo_memo, 0); + *((VALUE *)&memo->v1) = a; + *((VALUE *)&memo->v2) = b; + *((VALUE *)&memo->u3.value) = c; + + return memo; +} + static inline enum imemo_type imemo_type(VALUE imemo) { @@ -190,7 +202,7 @@ rb_vm_ifunc_proc_new(rb_block_call_func_t func, const void *data) static inline VALUE rb_imemo_tmpbuf_auto_free_pointer(void) { - return rb_imemo_new(imemo_tmpbuf, 0, 0, 0, 0); + return rb_imemo_new(imemo_tmpbuf, 0); } static inline void * |