introduce imemo_type_p(v, imemo_type)

* internal.h: introduce imemo_type_p() which checks the given value is
  T_IMEMO and imemo_type() == given imemo_type.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2017-04-07 06:41:32 +00:00
Родитель 5c79f6dbb7
Коммит 7519688ed8
6 изменённых файлов: 27 добавлений и 17 удалений

Просмотреть файл

@ -615,7 +615,7 @@ rb_iseq_compile_node(rb_iseq_t *iseq, NODE *node)
}
}
}
else if (RB_TYPE_P((VALUE)node, T_IMEMO)) {
else if (imemo_type_p((VALUE)node, imemo_ifunc)) {
const struct vm_ifunc *ifunc = (struct vm_ifunc *)node;
/* user callback */
(*ifunc->func)(iseq, ret, ifunc->data);

Просмотреть файл

@ -855,6 +855,21 @@ imemo_type(VALUE imemo)
return (RBASIC(imemo)->flags >> FL_USHIFT) & imemo_mask;
}
static inline int
imemo_type_p(VALUE imemo, enum imemo_type imemo_type)
{
if (LIKELY(!RB_SPECIAL_CONST_P(imemo))) {
/* fixed at compile time if imemo_type is given. */
const VALUE mask = (imemo_mask << FL_USHIFT) | RUBY_T_MASK;
const VALUE expected_type = (imemo_type << FL_USHIFT) | T_IMEMO;
/* fixed at runtime. */
return expected_type == (RBASIC(imemo)->flags & mask);
}
else {
return 0;
}
}
/* FL_USER0 to FL_USER2 is for type */
#define IMEMO_FL_USHIFT (FL_USHIFT + 3)
#define IMEMO_FL_USER0 FL_USER3

2
load.c
Просмотреть файл

@ -732,7 +732,7 @@ load_lock(const char *ftptr)
st_insert(loading_tbl, (st_data_t)ftptr, data);
return (char *)ftptr;
}
else if (RB_TYPE_P((VALUE)data, T_IMEMO) && imemo_type((VALUE)data) == imemo_memo) {
else if (imemo_type_p(data, imemo_memo)) {
struct MEMO *memo = MEMO_CAST(data);
void (*init)(void) = (void (*)(void))memo->u3.func;
data = (st_data_t)rb_thread_shield_new();

3
vm.c
Просмотреть файл

@ -864,7 +864,8 @@ rb_vm_make_proc_lambda(rb_thread_t *th, const struct rb_captured_block *captured
vm_make_env_object(th, cfp);
}
VM_ASSERT(VM_EP_IN_HEAP_P(th, captured->ep));
VM_ASSERT(RB_TYPE_P(captured->code.val, T_IMEMO));
VM_ASSERT(imemo_type_p(captured->code.val, imemo_iseq) ||
imemo_type_p(captured->code.val, imemo_ifunc));
procval = rb_proc_create_from_captured(klass, captured,
imemo_type(captured->code.val) == imemo_iseq ? block_type_iseq : block_type_ifunc,

Просмотреть файл

@ -45,8 +45,7 @@
#include "ruby_assert.h"
#if VM_CHECK_MODE > 0
#define VM_ASSERT(expr) ( \
RUBY_ASSERT_MESG_WHEN(VM_CHECK_MODE > 0, expr, #expr))
#define VM_ASSERT(expr) RUBY_ASSERT_MESG_WHEN(VM_CHECK_MODE > 0, expr, #expr)
#define VM_UNREACHABLE(func) rb_bug(#func ": unreachable")
@ -1044,7 +1043,7 @@ VM_FRAME_BMETHOD_P(const rb_control_frame_t *cfp)
static inline int
rb_obj_is_iseq(VALUE iseq)
{
return RB_TYPE_P(iseq, T_IMEMO) && imemo_type(iseq) == imemo_iseq;
return imemo_type_p(iseq, imemo_iseq);
}
#if VM_CHECK_MODE > 0
@ -1106,8 +1105,7 @@ VM_ENV_ESCAPED_P(const VALUE *ep)
static inline int
vm_assert_env(VALUE obj)
{
VM_ASSERT(RB_TYPE_P(obj, T_IMEMO));
VM_ASSERT(imemo_type(obj) == imemo_env);
VM_ASSERT(imemo_type_p(obj, imemo_env));
return 1;
}
#endif
@ -1186,8 +1184,7 @@ VM_BH_ISEQ_BLOCK_P(VALUE block_handler)
if ((block_handler & 0x03) == 0x01) {
#if VM_CHECK_MODE > 0
struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
VM_ASSERT(RB_TYPE_P(captured->code.val, T_IMEMO));
VM_ASSERT(imemo_type(captured->code.val) == imemo_iseq);
VM_ASSERT(imemo_type_p(captured->code.val, imemo_iseq));
#endif
return 1;
}
@ -1218,8 +1215,7 @@ VM_BH_IFUNC_P(VALUE block_handler)
if ((block_handler & 0x03) == 0x03) {
#if VM_CHECK_MODE > 0
struct rb_captured_block *captured = (void *)(block_handler & ~0x03);
VM_ASSERT(RB_TYPE_P(captured->code.val, T_IMEMO));
VM_ASSERT(imemo_type(captured->code.val) == imemo_ifunc);
VM_ASSERT(imemo_type_p(captured->code.val, imemo_ifunc));
#endif
return 1;
}
@ -1284,12 +1280,10 @@ vm_block_type(const struct rb_block *block)
#if VM_CHECK_MODE > 0
switch (block->type) {
case block_type_iseq:
VM_ASSERT(RB_TYPE_P(block->as.captured.code.val, T_IMEMO));
VM_ASSERT(imemo_type(block->as.captured.code.val) == imemo_iseq);
VM_ASSERT(imemo_type_p(block->as.captured.code.val, imemo_iseq));
break;
case block_type_ifunc:
VM_ASSERT(RB_TYPE_P(block->as.captured.code.val, T_IMEMO));
VM_ASSERT(imemo_type(block->as.captured.code.val) == imemo_ifunc);
VM_ASSERT(imemo_type_p(block->as.captured.code.val, imemo_ifunc));
break;
case block_type_symbol:
VM_ASSERT(SYMBOL_P(block->as.symbol));

Просмотреть файл

@ -91,7 +91,7 @@ control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp)
}
if (cfp->iseq != 0) {
#define RUBY_VM_IFUNC_P(ptr) (RB_TYPE_P((VALUE)(ptr), T_IMEMO) && imemo_type((VALUE)ptr) == imemo_ifunc)
#define RUBY_VM_IFUNC_P(ptr) imemo_type_p((VALUE)ptr, imemo_ifunc)
if (RUBY_VM_IFUNC_P(cfp->iseq)) {
iseq_name = "<ifunc>";
}