aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-07 06:41:32 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-07 06:41:32 +0000
commit030ff85a1f03f41aec164c3c3d4bdbbabe220a43 (patch)
tree4da19d177860b3f3e90d8cf575c69a0397c1c9b3
parent655e354e1acb81179239a637bba053733483fbe0 (diff)
downloadruby-030ff85a1f03f41aec164c3c3d4bdbbabe220a43.tar.gz
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
-rw-r--r--compile.c2
-rw-r--r--internal.h15
-rw-r--r--load.c2
-rw-r--r--vm.c3
-rw-r--r--vm_core.h20
-rw-r--r--vm_dump.c2
6 files changed, 27 insertions, 17 deletions
diff --git a/compile.c b/compile.c
index 906e89a650..7b947d7d0a 100644
--- a/compile.c
+++ b/compile.c
@@ -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);
diff --git a/internal.h b/internal.h
index 993b0266ed..c87d087d0d 100644
--- a/internal.h
+++ b/internal.h
@@ -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
diff --git a/load.c b/load.c
index 284ebf2e48..5adef7cdd0 100644
--- a/load.c
+++ b/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();
diff --git a/vm.c b/vm.c
index b1ab93073d..6182240526 100644
--- a/vm.c
+++ b/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,
diff --git a/vm_core.h b/vm_core.h
index 437c4d9c2d..984ca89f16 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -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));
diff --git a/vm_dump.c b/vm_dump.c
index 01c6db9858..40d3b20959 100644
--- a/vm_dump.c
+++ b/vm_dump.c
@@ -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>";
}