Unverified Commit cc636f33 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4715 from dearblue/need-block

Entrust "no block given" error to `mrb_get_args()`
parents d45c94fe 099a4f39
......@@ -40,11 +40,7 @@ mrb_mod_module_exec(mrb_state *mrb, mrb_value self)
mrb_int argc;
mrb_value blk;
mrb_get_args(mrb, "*&", &argv, &argc, &blk);
if (mrb_nil_p(blk)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
}
mrb_get_args(mrb, "*&!", &argv, &argc, &blk);
mrb->c->ci->target_class = mrb_class_ptr(self);
return mrb_yield_cont(mrb, blk, self, argc, argv);
......
......@@ -72,14 +72,11 @@ fiber_init(mrb_state *mrb, mrb_value self)
mrb_value blk;
size_t slen;
mrb_get_args(mrb, "&", &blk);
mrb_get_args(mrb, "&!", &blk);
if (f->cxt) {
mrb_raise(mrb, E_RUNTIME_ERROR, "cannot initialize twice");
}
if (mrb_nil_p(blk)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "tried to create Fiber object without a block");
}
p = mrb_proc_ptr(blk);
if (MRB_PROC_CFUNC_P(p)) {
mrb_raise(mrb, E_FIBER_ERROR, "tried to create Fiber from C defined method");
......
......@@ -389,10 +389,7 @@ mod_define_singleton_method(mrb_state *mrb, mrb_value self)
mrb_sym mid;
mrb_value blk = mrb_nil_value();
mrb_get_args(mrb, "n&", &mid, &blk);
if (mrb_nil_p(blk)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
}
mrb_get_args(mrb, "n&!", &mid, &blk);
p = (struct RProc*)mrb_obj_alloc(mrb, MRB_TT_PROC, mrb->proc_class);
mrb_proc_copy(p, mrb_proc_ptr(blk));
p->flags |= MRB_PROC_STRICT;
......
......@@ -100,11 +100,7 @@ mrb_obj_instance_exec(mrb_state *mrb, mrb_value self)
mrb_value blk;
struct RClass *c;
mrb_get_args(mrb, "*&", &argv, &argc, &blk);
if (mrb_nil_p(blk)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
}
mrb_get_args(mrb, "*&!", &argv, &argc, &blk);
switch (mrb_type(self)) {
case MRB_TT_SYMBOL:
......
......@@ -161,11 +161,7 @@ os_each_object(mrb_state *mrb, mrb_value self)
{
mrb_value cls = mrb_nil_value();
struct os_each_object_data d;
mrb_get_args(mrb, "&|C", &d.block, &cls);
if (mrb_nil_p(d.block)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "Expected block in ObjectSpace.each_object.");
}
mrb_get_args(mrb, "&!|C", &d.block, &cls);
d.target_module = mrb_nil_p(cls) ? NULL : mrb_class_ptr(cls);
d.count = 0;
......
......@@ -72,10 +72,7 @@ mrb_kernel_proc(mrb_state *mrb, mrb_value self)
{
mrb_value blk;
mrb_get_args(mrb, "&", &blk);
if (mrb_nil_p(blk)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "tried to create Proc object without a block");
}
mrb_get_args(mrb, "&!", &blk);
return blk;
}
......
......@@ -184,11 +184,8 @@ mrb_proc_s_new(mrb_state *mrb, mrb_value proc_class)
mrb_value proc;
struct RProc *p;
mrb_get_args(mrb, "&", &blk);
if (mrb_nil_p(blk)) {
/* Calling Proc.new without a block is not implemented yet */
mrb_raise(mrb, E_ARGUMENT_ERROR, "tried to create Proc object without a block");
}
/* Calling Proc.new without a block is not implemented yet */
mrb_get_args(mrb, "&!", &blk);
p = (struct RProc *)mrb_obj_alloc(mrb, MRB_TT_PROC, mrb_class_ptr(proc_class));
mrb_proc_copy(p, mrb_proc_ptr(blk));
proc = mrb_obj_value(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