From a099ca44f4d165cf89575c21d78abff062d6767e Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 14 Nov 2022 15:47:26 +0900 Subject: [PATCH] error.c (mrb_sys_fail): `errno` argument removed from `_sys_fail`. As a side effect, `errno.h` dependency removed from `error.c`. --- mrbgems/mruby-errno/src/errno.c | 8 ++++---- src/error.c | 7 ++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/mrbgems/mruby-errno/src/errno.c b/mrbgems/mruby-errno/src/errno.c index 97132b4b5..11b050059 100644 --- a/mrbgems/mruby-errno/src/errno.c +++ b/mrbgems/mruby-errno/src/errno.c @@ -275,12 +275,12 @@ static mrb_value mrb_sce_sys_fail(mrb_state *mrb, mrb_value cls) { struct RClass *sce; - mrb_value msg, no; + mrb_value msg; mrb_int argc; mrb->c->ci->mid = 0; sce = mrb_class_ptr(cls); - argc = mrb_get_args(mrb, "o|S", &no, &msg); + argc = mrb_get_args(mrb, "|S", &msg); struct RBasic* e = mrb_obj_alloc(mrb, MRB_TT_EXCEPTION, sce); mrb_value exc = mrb_obj_value(e); @@ -288,7 +288,7 @@ mrb_sce_sys_fail(mrb_state *mrb, mrb_value cls) msg = mrb_nil_value(); } exc = mrb_obj_value(e); - mrb_sce_init(mrb, exc, msg, no); + mrb_sce_init(mrb, exc, msg, mrb_fixnum_value(errno)); mrb_exc_raise(mrb, exc); return mrb_nil_value(); /* NOTREACHED */ } @@ -301,7 +301,7 @@ mrb_mruby_errno_gem_init(mrb_state *mrb) ste = mrb->eStandardError_class; sce = mrb_define_class(mrb, "SystemCallError", ste); - mrb_define_class_method(mrb, sce, "_sys_fail", mrb_sce_sys_fail, MRB_ARGS_REQ(1)); + mrb_define_class_method(mrb, sce, "_sys_fail", mrb_sce_sys_fail, MRB_ARGS_OPT(1)); mrb_define_method(mrb, sce, "errno", mrb_sce_errno, MRB_ARGS_NONE()); mrb_define_method(mrb, sce, "initialize", mrb_sce_init_m, MRB_ARGS_ARG(1, 1)); diff --git a/src/error.c b/src/error.c index 8773f1347..0bea762eb 100644 --- a/src/error.c +++ b/src/error.c @@ -4,7 +4,6 @@ ** See Copyright Notice in mruby.h */ -#include #include #include #include @@ -512,16 +511,14 @@ MRB_API mrb_noreturn void mrb_sys_fail(mrb_state *mrb, const char *mesg) { struct RClass *sce; - mrb_int no; - no = (mrb_int)errno; if (mrb_class_defined_id(mrb, MRB_SYM(SystemCallError))) { sce = mrb_class_get_id(mrb, MRB_SYM(SystemCallError)); if (mesg != NULL) { - mrb_funcall_id(mrb, mrb_obj_value(sce), MRB_SYM(_sys_fail), 2, mrb_fixnum_value(no), mrb_str_new_cstr(mrb, mesg)); + mrb_funcall_id(mrb, mrb_obj_value(sce), MRB_SYM(_sys_fail), 1, mrb_str_new_cstr(mrb, mesg)); } else { - mrb_funcall_id(mrb, mrb_obj_value(sce), MRB_SYM(_sys_fail), 1, mrb_fixnum_value(no)); + mrb_funcall_id(mrb, mrb_obj_value(sce), MRB_SYM(_sys_fail), 0); } }