Commit feaf80d8 authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

Use type predicate macros instead of `mrb_type` if possible

For efficiency with `MRB_WORD_BOXING` (implement type predicate macros for
all `enum mrb_vtype`).
parent 60cc46a9
......@@ -133,6 +133,20 @@ MRB_API mrb_value mrb_word_boxing_float_pool(struct mrb_state*, mrb_float);
#define mrb_hash_p(o) BOXWORD_OBJ_TYPE_P(o, HASH)
#define mrb_cptr_p(o) BOXWORD_OBJ_TYPE_P(o, CPTR)
#define mrb_exception_p(o) BOXWORD_OBJ_TYPE_P(o, EXCEPTION)
#define mrb_free_p(o) BOXWORD_OBJ_TYPE_P(o, FREE)
#define mrb_object_p(o) BOXWORD_OBJ_TYPE_P(o, OBJECT)
#define mrb_class_p(o) BOXWORD_OBJ_TYPE_P(o, CLASS)
#define mrb_module_p(o) BOXWORD_OBJ_TYPE_P(o, MODULE)
#define mrb_iclass_p(o) BOXWORD_OBJ_TYPE_P(o, ICLASS)
#define mrb_sclass_p(o) BOXWORD_OBJ_TYPE_P(o, SCLASS)
#define mrb_proc_p(o) BOXWORD_OBJ_TYPE_P(o, PROC)
#define mrb_range_p(o) BOXWORD_OBJ_TYPE_P(o, RANGE)
#define mrb_file_p(o) BOXWORD_OBJ_TYPE_P(o, FILE)
#define mrb_env_p(o) BOXWORD_OBJ_TYPE_P(o, ENV)
#define mrb_data_p(o) BOXWORD_OBJ_TYPE_P(o, DATA)
#define mrb_fiber_p(o) BOXWORD_OBJ_TYPE_P(o, FIBER)
#define mrb_istruct_p(o) BOXWORD_OBJ_TYPE_P(o, ISTRUCT)
#define mrb_break_p(o) BOXWORD_OBJ_TYPE_P(o, BREAK)
#ifndef MRB_WITHOUT_FLOAT
#define SET_FLOAT_VALUE(mrb,r,v) ((r) = mrb_word_boxing_float_value(mrb, v))
......
......@@ -66,7 +66,7 @@ MRB_API void *mrb_data_check_get_ptr(mrb_state *mrb, mrb_value, const mrb_data_t
MRB_INLINE void
mrb_data_init(mrb_value v, void *ptr, const mrb_data_type *type)
{
mrb_assert(mrb_type(v) == MRB_TT_DATA);
mrb_assert(mrb_data_p(v));
DATA_PTR(v) = ptr;
DATA_TYPE(v) = type;
}
......
......@@ -169,6 +169,11 @@ typedef void mrb_value;
#include "boxing_no.h"
#endif
#if !defined(MRB_SYMBOL_BITSIZE)
#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT)
#define MRB_SYMBOL_MAX UINT32_MAX
#endif
#ifndef mrb_immediate_p
#define mrb_immediate_p(o) (mrb_type(o) < MRB_TT_FREE)
#endif
......@@ -190,13 +195,6 @@ typedef void mrb_value;
#ifndef mrb_true_p
#define mrb_true_p(o) (mrb_type(o) == MRB_TT_TRUE)
#endif
#ifndef mrb_bool
#define mrb_bool(o) (mrb_type(o) != MRB_TT_FALSE)
#endif
#if !defined(MRB_SYMBOL_BITSIZE)
#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT)
#define MRB_SYMBOL_MAX UINT32_MAX
#endif
#ifndef MRB_WITHOUT_FLOAT
#ifndef mrb_float_p
#define mrb_float_p(o) (mrb_type(o) == MRB_TT_FLOAT)
......@@ -217,6 +215,51 @@ typedef void mrb_value;
#ifndef mrb_exception_p
#define mrb_exception_p(o) (mrb_type(o) == MRB_TT_EXCEPTION)
#endif
#ifndef mrb_free_p
#define mrb_free_p(o) (mrb_type(o) == MRB_TT_FREE)
#endif
#ifndef mrb_object_p
#define mrb_object_p(o) (mrb_type(o) == MRB_TT_OBJECT)
#endif
#ifndef mrb_class_p
#define mrb_class_p(o) (mrb_type(o) == MRB_TT_CLASS)
#endif
#ifndef mrb_module_p
#define mrb_module_p(o) (mrb_type(o) == MRB_TT_MODULE)
#endif
#ifndef mrb_iclass_p
#define mrb_iclass_p(o) (mrb_type(o) == MRB_TT_ICLASS)
#endif
#ifndef mrb_sclass_p
#define mrb_sclass_p(o) (mrb_type(o) == MRB_TT_SCLASS)
#endif
#ifndef mrb_proc_p
#define mrb_proc_p(o) (mrb_type(o) == MRB_TT_PROC)
#endif
#ifndef mrb_range_p
#define mrb_range_p(o) (mrb_type(o) == MRB_TT_RANGE)
#endif
#ifndef mrb_file_p
#define mrb_file_p(o) (mrb_type(o) == MRB_TT_FILE)
#endif
#ifndef mrb_env_p
#define mrb_env_p(o) (mrb_type(o) == MRB_TT_ENV)
#endif
#ifndef mrb_data_p
#define mrb_data_p(o) (mrb_type(o) == MRB_TT_DATA)
#endif
#ifndef mrb_fiber_p
#define mrb_fiber_p(o) (mrb_type(o) == MRB_TT_FIBER)
#endif
#ifndef mrb_istruct_p
#define mrb_istruct_p(o) (mrb_type(o) == MRB_TT_ISTRUCT)
#endif
#ifndef mrb_break_p
#define mrb_break_p(o) (mrb_type(o) == MRB_TT_BREAK)
#endif
#ifndef mrb_bool
#define mrb_bool(o) (mrb_type(o) != MRB_TT_FALSE)
#endif
#define mrb_test(o) mrb_bool(o)
/**
......
......@@ -65,7 +65,7 @@ mrb_ary_rassoc(mrb_state *mrb, mrb_value ary)
for (i = 0; i < RARRAY_LEN(ary); ++i) {
v = RARRAY_PTR(ary)[i];
if (mrb_type(v) == MRB_TT_ARRAY &&
if (mrb_array_p(v) &&
RARRAY_LEN(v) > 1 &&
mrb_equal(mrb, RARRAY_PTR(v)[1], value))
return v;
......
......@@ -11,7 +11,7 @@ mrb_mod_name(mrb_state *mrb, mrb_value self)
static mrb_value
mrb_mod_singleton_class_p(mrb_state *mrb, mrb_value self)
{
return mrb_bool_value(mrb_type(self) == MRB_TT_SCLASS);
return mrb_bool_value(mrb_sclass_p(self));
}
/*
......
......@@ -559,7 +559,7 @@ new_lit(codegen_scope *s, mrb_value val)
mrb_int len;
pv = &s->irep->pool[i];
if (mrb_type(*pv) != MRB_TT_STRING) continue;
if (!mrb_string_p(*pv)) continue;
if ((len = RSTRING_LEN(*pv)) != RSTRING_LEN(val)) continue;
if (memcmp(RSTRING_PTR(*pv), RSTRING_PTR(val), len) == 0)
return i;
......@@ -570,7 +570,7 @@ new_lit(codegen_scope *s, mrb_value val)
for (i=0; i<s->irep->plen; i++) {
mrb_float f1, f2;
pv = &s->irep->pool[i];
if (mrb_type(*pv) != MRB_TT_FLOAT) continue;
if (!mrb_float_p(*pv)) continue;
f1 = mrb_float(*pv);
f2 = mrb_float(val);
if (f1 == f2 && !signbit(f1) == !signbit(f2)) return i;
......
......@@ -294,7 +294,7 @@ fiber_eq(mrb_state *mrb, mrb_value self)
mrb_value other;
mrb_get_args(mrb, "o", &other);
if (mrb_type(other) != MRB_TT_FIBER) {
if (!mrb_fiber_p(other)) {
return mrb_false_value();
}
return mrb_bool_value(fiber_ptr(self) == fiber_ptr(other));
......
......@@ -907,7 +907,7 @@ mrb_io_syswrite(mrb_state *mrb, mrb_value io)
}
mrb_get_args(mrb, "S", &str);
if (mrb_type(str) != MRB_TT_STRING) {
if (!mrb_string_p(str)) {
buf = mrb_funcall(mrb, str, "to_s", 0);
} else {
buf = str;
......@@ -1000,7 +1000,7 @@ static int
mrb_io_read_data_pending(mrb_state *mrb, mrb_value io)
{
mrb_value buf = mrb_iv_get(mrb, io, mrb_intern_cstr(mrb, "@buf"));
if (mrb_type(buf) == MRB_TT_STRING && RSTRING_LEN(buf) > 0) {
if (mrb_string_p(buf) && RSTRING_LEN(buf) > 0) {
return 1;
}
return 0;
......
......@@ -154,16 +154,16 @@ mrb_io_test_io_cleanup(mrb_state *mrb, mrb_value self)
mrb_value symlinkname = mrb_gv_get(mrb, mrb_intern_cstr(mrb, "$mrbtest_io_symlinkname"));
mrb_value socketname = mrb_gv_get(mrb, mrb_intern_cstr(mrb, "$mrbtest_io_socketname"));
if (mrb_type(rfname) == MRB_TT_STRING) {
if (mrb_string_p(rfname)) {
remove(RSTRING_PTR(rfname));
}
if (mrb_type(wfname) == MRB_TT_STRING) {
if (mrb_string_p(wfname)) {
remove(RSTRING_PTR(wfname));
}
if (mrb_type(symlinkname) == MRB_TT_STRING) {
if (mrb_string_p(symlinkname)) {
remove(RSTRING_PTR(symlinkname));
}
if (mrb_type(socketname) == MRB_TT_STRING) {
if (mrb_string_p(socketname)) {
remove(RSTRING_PTR(socketname));
}
......
......@@ -20,7 +20,7 @@ mrb_f_caller(mrb_state *mrb, mrb_value self)
n = bt_len - lev;
break;
case 1:
if (mrb_type(v) == MRB_TT_RANGE) {
if (mrb_range_p(v)) {
mrb_int beg, len;
if (mrb_range_beg_len(mrb, v, &beg, &len, bt_len, TRUE) == MRB_RANGE_OK) {
lev = beg;
......
......@@ -14,10 +14,10 @@ method_object_alloc(mrb_state *mrb, struct RClass *mclass)
static void
bind_check(mrb_state *mrb, mrb_value recv, mrb_value owner)
{
if (mrb_type(owner) != MRB_TT_MODULE &&
if (!mrb_module_p(owner) &&
mrb_class_ptr(owner) != mrb_obj_class(mrb, recv) &&
!mrb_obj_is_kind_of(mrb, recv, mrb_class_ptr(owner))) {
if (mrb_type(owner) == MRB_TT_SCLASS) {
if (mrb_sclass_p(owner)) {
mrb_raise(mrb, E_TYPE_ERROR, "singleton method called for a different object");
} else {
mrb_raisef(mrb, E_TYPE_ERROR, "bind argument must be an instance of %v", owner);
......
......@@ -136,7 +136,7 @@ get_opt(mrb_state* mrb)
static void
random_check(mrb_state *mrb, mrb_value random) {
struct RClass *c = mrb_class_get(mrb, "Random");
if (!mrb_obj_is_kind_of(mrb, random, c) || mrb_type(random) != MRB_TT_ISTRUCT) {
if (!mrb_obj_is_kind_of(mrb, random, c) || !mrb_istruct_p(random)) {
mrb_raise(mrb, E_TYPE_ERROR, "Random instance required");
}
}
......
......@@ -455,7 +455,7 @@ mrb_basicsocket_setsockopt(mrb_state *mrb, mrb_value self)
level = mrb_fixnum(so);
if (mrb_string_p(optval)) {
/* that's good */
} else if (mrb_type(optval) == MRB_TT_TRUE || mrb_type(optval) == MRB_TT_FALSE) {
} else if (mrb_true_p(optval) || mrb_false_p(optval)) {
mrb_int i = mrb_test(optval) ? 1 : 0;
optval = mrb_str_new(mrb, (char*)&i, sizeof(i));
} else if (mrb_fixnum_p(optval)) {
......
......@@ -215,7 +215,7 @@ mrb_vm_define_module(mrb_state *mrb, mrb_value outer, mrb_sym id)
if (mrb_const_defined_at(mrb, outer, id)) {
mrb_value old = mrb_const_get(mrb, outer, id);
if (mrb_type(old) != MRB_TT_MODULE) {
if (!mrb_module_p(old)) {
mrb_raisef(mrb, E_TYPE_ERROR, "%!v is not a module", old);
}
return mrb_class_ptr(old);
......@@ -312,7 +312,7 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id
struct RClass *c;
if (!mrb_nil_p(super)) {
if (mrb_type(super) != MRB_TT_CLASS) {
if (!mrb_class_p(super)) {
mrb_raisef(mrb, E_TYPE_ERROR, "superclass must be a Class (%!v given)", super);
}
s = mrb_class_ptr(super);
......@@ -324,7 +324,7 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id
if (mrb_const_defined_at(mrb, outer, id)) {
mrb_value old = mrb_const_get(mrb, outer, id);
if (mrb_type(old) != MRB_TT_CLASS) {
if (!mrb_class_p(old)) {
mrb_raisef(mrb, E_TYPE_ERROR, "%!v is not a class", old);
}
c = mrb_class_ptr(old);
......@@ -381,7 +381,7 @@ mrb_exc_get(mrb_state *mrb, const char *name)
mrb_value c = mrb_const_get(mrb, mrb_obj_value(mrb->object_class),
mrb_intern_cstr(mrb, name));
if (mrb_type(c) != MRB_TT_CLASS) {
if (!mrb_class_p(c)) {
mrb_raise(mrb, mrb->eException_class, "exception corrupted");
}
exc = e = mrb_class_ptr(c);
......@@ -791,7 +791,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, void**);
if (i < argc) {
ss = argv[arg_i];
if (mrb_type(ss) != MRB_TT_ISTRUCT)
if (!mrb_istruct_p(ss))
{
mrb_raisef(mrb, E_TYPE_ERROR, "%v is not inline struct", ss);
}
......@@ -1789,7 +1789,7 @@ mrb_value
mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
{
if (mrb_type(klass) == MRB_TT_SCLASS) {
if (mrb_sclass_p(klass)) {
mrb_value v = mrb_iv_get(mrb, klass, mrb_intern_lit(mrb, "__attached__"));
mrb_value str = mrb_str_new_lit(mrb, "#<Class:");
......
......@@ -24,7 +24,7 @@ mrb_data_object_alloc(mrb_state *mrb, struct RClass *klass, void *ptr, const mrb
MRB_API void
mrb_data_check_type(mrb_state *mrb, mrb_value obj, const mrb_data_type *type)
{
if (mrb_type(obj) != MRB_TT_DATA) {
if (!mrb_data_p(obj)) {
mrb_check_type(mrb, obj, MRB_TT_DATA);
}
if (DATA_TYPE(obj) != type) {
......@@ -44,7 +44,7 @@ mrb_data_check_type(mrb_state *mrb, mrb_value obj, const mrb_data_type *type)
MRB_API void*
mrb_data_check_get_ptr(mrb_state *mrb, mrb_value obj, const mrb_data_type *type)
{
if (mrb_type(obj) != MRB_TT_DATA) {
if (!mrb_data_p(obj)) {
return NULL;
}
if (DATA_TYPE(obj) != type) {
......
......@@ -479,7 +479,7 @@ mrb_gc_register(mrb_state *mrb, mrb_value obj)
if (mrb_immediate_p(obj)) return;
root = mrb_intern_lit(mrb, GC_ROOT_NAME);
table = mrb_gv_get(mrb, root);
if (mrb_nil_p(table) || mrb_type(table) != MRB_TT_ARRAY) {
if (mrb_nil_p(table) || !mrb_array_p(table)) {
table = mrb_ary_new(mrb);
mrb_gv_set(mrb, root, table);
}
......@@ -499,7 +499,7 @@ mrb_gc_unregister(mrb_state *mrb, mrb_value obj)
root = mrb_intern_lit(mrb, GC_ROOT_NAME);
table = mrb_gv_get(mrb, root);
if (mrb_nil_p(table)) return;
if (mrb_type(table) != MRB_TT_ARRAY) {
if (!mrb_array_p(table)) {
mrb_gv_set(mrb, root, mrb_nil_value());
return;
}
......
......@@ -92,7 +92,7 @@ ht_hash_equal(mrb_state *mrb, htable *t, mrb_value a, mrb_value b)
return mrb_str_equal(mrb, a, b);
case MRB_TT_SYMBOL:
if (mrb_type(b) != MRB_TT_SYMBOL) return FALSE;
if (!mrb_symbol_p(b)) return FALSE;
return mrb_symbol(a) == mrb_symbol(b);
case MRB_TT_FIXNUM:
......
......@@ -53,7 +53,7 @@ mrb_obj_basic_to_s_p(mrb_state *mrb, mrb_value obj)
MRB_API mrb_value
mrb_obj_inspect(mrb_state *mrb, mrb_value obj)
{
if ((mrb_type(obj) == MRB_TT_OBJECT) && mrb_obj_basic_to_s_p(mrb, obj)) {
if (mrb_object_p(obj) && mrb_obj_basic_to_s_p(mrb, obj)) {
return mrb_obj_iv_inspect(mrb, mrb_obj_ptr(obj));
}
return mrb_any_to_s(mrb, obj);
......@@ -327,7 +327,7 @@ mrb_obj_clone(mrb_state *mrb, mrb_value self)
if (mrb_immediate_p(self)) {
mrb_raisef(mrb, E_TYPE_ERROR, "can't clone %v", self);
}
if (mrb_type(self) == MRB_TT_SCLASS) {
if (mrb_sclass_p(self)) {
mrb_raise(mrb, E_TYPE_ERROR, "can't clone singleton class");
}
p = (struct RObject*)mrb_obj_alloc(mrb, mrb_type(self), mrb_obj_class(mrb, self));
......@@ -368,7 +368,7 @@ mrb_obj_dup(mrb_state *mrb, mrb_value obj)
if (mrb_immediate_p(obj)) {
mrb_raisef(mrb, E_TYPE_ERROR, "can't dup %v", obj);
}
if (mrb_type(obj) == MRB_TT_SCLASS) {
if (mrb_sclass_p(obj)) {
mrb_raise(mrb, E_TYPE_ERROR, "can't dup singleton class");
}
p = mrb_obj_alloc(mrb, mrb_type(obj), mrb_obj_class(mrb, obj));
......
......@@ -1562,7 +1562,7 @@ mrb_cmp(mrb_state *mrb, mrb_value obj1, mrb_value obj2)
case MRB_TT_FLOAT:
return cmpnum(mrb, obj1, obj2);
case MRB_TT_STRING:
if (mrb_type(obj2) != MRB_TT_STRING)
if (!mrb_string_p(obj2))
return -2;
return mrb_str_cmp(mrb, obj1, obj2);
default:
......
......@@ -384,7 +384,7 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t)
else if (mrb_fixnum_p(x)) {
etype = "Fixnum";
}
else if (mrb_type(x) == MRB_TT_SYMBOL) {
else if (mrb_symbol_p(x)) {
etype = "Symbol";
}
else if (mrb_immediate_p(x)) {
......
......@@ -206,7 +206,7 @@ mrb_proc_init_copy(mrb_state *mrb, mrb_value self)
mrb_value proc;
mrb_get_args(mrb, "o", &proc);
if (mrb_type(proc) != MRB_TT_PROC) {
if (!mrb_proc_p(proc)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "not a proc");
}
mrb_proc_copy(mrb_proc_ptr(self), mrb_proc_ptr(proc));
......@@ -239,7 +239,7 @@ proc_lambda(mrb_state *mrb, mrb_value self)
if (mrb_nil_p(blk)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "tried to create Proc object without a block");
}
if (mrb_type(blk) != MRB_TT_PROC) {
if (!mrb_proc_p(blk)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "not a proc");
}
p = mrb_proc_ptr(blk);
......
......@@ -296,7 +296,7 @@ range_eql(mrb_state *mrb, mrb_value range)
if (mrb_obj_equal(mrb, range, obj)) return mrb_true_value();
if (!mrb_obj_is_kind_of(mrb, obj, mrb->range_class)) return mrb_false_value();
if (mrb_type(obj) != MRB_TT_RANGE) return mrb_false_value();
if (!mrb_range_p(obj)) return mrb_false_value();
r = mrb_range_ptr(mrb, range);
o = mrb_range_ptr(mrb, obj);
......@@ -391,7 +391,7 @@ mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp,
mrb_int beg, end;
struct RRange *r;
if (mrb_type(range) != MRB_TT_RANGE) return MRB_RANGE_TYPE_MISMATCH;
if (!mrb_range_p(range)) return MRB_RANGE_TYPE_MISMATCH;
r = mrb_range_ptr(mrb, range);
beg = mrb_int(mrb, RANGE_BEG(r));
......
......@@ -119,12 +119,12 @@ mrb_irep_free(mrb_state *mrb, mrb_irep *irep)
if (!(irep->flags & MRB_ISEQ_NO_FREE))
mrb_free(mrb, (void*)irep->iseq);
if (irep->pool) for (i=0; i<irep->plen; i++) {
if (mrb_type(irep->pool[i]) == MRB_TT_STRING) {
if (mrb_string_p(irep->pool[i])) {
mrb_gc_free_str(mrb, RSTRING(irep->pool[i]));
mrb_free(mrb, mrb_obj_ptr(irep->pool[i]));
}
#if defined(MRB_WORD_BOXING) && !defined(MRB_WITHOUT_FLOAT)
else if (mrb_type(irep->pool[i]) == MRB_TT_FLOAT) {
else if (mrb_float_p(irep->pool[i])) {
mrb_free(mrb, mrb_obj_ptr(irep->pool[i]));
}
#endif
......
......@@ -1688,7 +1688,7 @@ mrb_str_eql(mrb_state *mrb, mrb_value self)
mrb_bool eql_p;
mrb_get_args(mrb, "o", &str2);
eql_p = (mrb_type(str2) == MRB_TT_STRING) && str_eql(mrb, self, str2);
eql_p = (mrb_string_p(str2)) && str_eql(mrb, self, str2);
return mrb_bool_value(eql_p);
}
......@@ -2977,7 +2977,7 @@ mrb_str_byteslice(mrb_state *mrb, mrb_value str)
beg = mrb_fixnum(mrb_to_int(mrb, a1));
len = mrb_fixnum(mrb_to_int(mrb, a2));
}
else if (mrb_type(a1) == MRB_TT_RANGE) {
else if (mrb_range_p(a1)) {
if (mrb_range_beg_len(mrb, a1, &beg, &len, str_len, TRUE) != MRB_RANGE_OK) {
return mrb_nil_value();
}
......
......@@ -551,7 +551,7 @@ sym_cmp(mrb_state *mrb, mrb_value s1)
mrb_sym sym1, sym2;
mrb_get_args(mrb, "o", &s2);
if (mrb_type(s2) != MRB_TT_SYMBOL) return mrb_nil_value();
if (!mrb_symbol_p(s2)) return mrb_nil_value();
sym1 = mrb_symbol(s1);
sym2 = mrb_symbol(s2);
if (sym1 == sym2) return mrb_fixnum_value(0);
......
......@@ -486,7 +486,7 @@ inspect_i(mrb_state *mrb, mrb_sym sym, mrb_value v, void *p)
s = mrb_sym_name_len(mrb, sym, &len);
mrb_str_cat(mrb, str, s, len);
mrb_str_cat_lit(mrb, str, "=");
if (mrb_type(v) == MRB_TT_OBJECT) {
if (mrb_object_p(v)) {
ins = mrb_any_to_s(mrb, v);
}
else {
......
......@@ -816,7 +816,7 @@ mrb_yield_cont(mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const
if (mrb_nil_p(b)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
}
if (mrb_type(b) != MRB_TT_PROC) {
if (!mrb_proc_p(b)) {
mrb_raise(mrb, E_TYPE_ERROR, "not a block");
}
......@@ -1387,7 +1387,7 @@ RETRY_TRY_BLOCK:
recv = regs[a];
blk = regs[bidx];
if (!mrb_nil_p(blk) && mrb_type(blk) != MRB_TT_PROC) {
if (!mrb_nil_p(blk) && !mrb_proc_p(blk)) {
blk = mrb_convert_type(mrb, blk, MRB_TT_PROC, "Proc", "to_proc");
/* The stack might have been reallocated during mrb_convert_type(),
see #3622 */
......@@ -1447,7 +1447,7 @@ RETRY_TRY_BLOCK:
mrb_gc_arena_shrink(mrb, ai);
if (mrb->exc) goto L_RAISE;
ci = mrb->c->ci;
if (mrb_type(blk) == MRB_TT_PROC) {
if (mrb_proc_p(blk)) {
struct RProc *p = mrb_proc_ptr(blk);
if (p && !MRB_PROC_STRICT_P(p) && MRB_PROC_ENV(p) == ci[-1].env) {
p->flags |= MRB_PROC_ORPHAN;
......@@ -1588,7 +1588,7 @@ RETRY_TRY_BLOCK:
goto L_RAISE;
}
blk = regs[bidx];
if (!mrb_nil_p(blk) && mrb_type(blk) != MRB_TT_PROC) {
if (!mrb_nil_p(blk) && !mrb_proc_p(blk)) {
blk = mrb_convert_type(mrb, blk, MRB_TT_PROC, "Proc", "to_proc");
/* The stack or ci stack might have been reallocated during
mrb_convert_type(), see #3622 and #3784 */
......@@ -1939,7 +1939,7 @@ RETRY_TRY_BLOCK:
else {
blk = regs[ci->argc+1];
}
if (mrb_type(blk) == MRB_TT_PROC) {
if (mrb_proc_p(blk)) {
struct RProc *p = mrb_proc_ptr(blk);
if (!MRB_PROC_STRICT_P(p) &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment