From 35490c2c326a54265999b8194788f6288614b711 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 25 Dec 2022 21:25:21 +0900 Subject: [PATCH] Define also the exception class `IOError` in `mruby-dir` Since `IOError` is a standard exception class in Ruby, there is no need to assume different superclasses. The Ruby specification allows repeated class definitions as long as the superclass is the same. This also avoids using the `mruby/ext/io.h` file to reference `E_IO_ERROR`. --- mrbgems/mruby-dir/src/dir.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mrbgems/mruby-dir/src/dir.c b/mrbgems/mruby-dir/src/dir.c index fcf80d71f..174bdcf7a 100644 --- a/mrbgems/mruby-dir/src/dir.c +++ b/mrbgems/mruby-dir/src/dir.c @@ -9,6 +9,7 @@ #include "mruby/data.h" #include "mruby/error.h" #include "mruby/string.h" +#include "mruby/presym.h" #include #if defined(_WIN32) || defined(_WIN64) #define MAXPATHLEN 1024 @@ -34,12 +35,7 @@ #include #include -/* with/without IO module */ -#ifdef ENABLE_IO -#include "mruby/ext/io.h" -#else -#define E_IO_ERROR E_RUNTIME_ERROR -#endif +#define E_IO_ERROR mrb_exc_get_id(mrb, MRB_SYM(IOError)) struct mrb_dir { DIR *dir; @@ -329,6 +325,8 @@ mrb_mruby_dir_gem_init(mrb_state *mrb) mrb_define_method(mrb, d, "rewind", mrb_dir_rewind, MRB_ARGS_NONE()); mrb_define_method(mrb, d, "seek", mrb_dir_seek, MRB_ARGS_REQ(1)); mrb_define_method(mrb, d, "tell", mrb_dir_tell, MRB_ARGS_NONE()); + + mrb_define_class(mrb, "IOError", mrb->eStandardError_class); } void