Commit 7103e032 authored by Tomoyuki Sahara's avatar Tomoyuki Sahara

mrb_sys_fail raises SystemCallError if we have it.

parent 46d8c517
......@@ -156,6 +156,7 @@ void mrb_undef_class_method(mrb_state*, struct RClass*, const char*);
mrb_value mrb_instance_new(mrb_state *mrb, mrb_value cv);
struct RClass * mrb_class_new(mrb_state *mrb, struct RClass *super);
struct RClass * mrb_module_new(mrb_state *mrb);
int mrb_class_defined(mrb_state *mrb, const char *name);
struct RClass * mrb_class_get(mrb_state *mrb, const char *name);
struct RClass * mrb_class_obj_get(mrb_state *mrb, const char *name);
......
......@@ -203,6 +203,12 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id
return c;
}
int
mrb_class_defined(mrb_state *mrb, const char *name)
{
return mrb_const_defined(mrb, mrb_obj_value(mrb->object_class), mrb_intern(mrb, name));
}
static struct RClass *
class_from_sym(mrb_state *mrb, struct RClass *klass, mrb_sym id)
{
......
......@@ -5,6 +5,7 @@
*/
#include "mruby.h"
#include <errno.h>
#include <stdarg.h>
#include <setjmp.h>
#include <string.h>
......@@ -401,7 +402,20 @@ mrb_make_exception(mrb_state *mrb, int argc, mrb_value *argv)
void
mrb_sys_fail(mrb_state *mrb, const char *mesg)
{
mrb_raise(mrb, E_RUNTIME_ERROR, mesg);
struct RClass *sce;
mrb_int no;
no = (mrb_int)errno;
if (mrb_class_defined(mrb, "SystemCallError")) {
sce = mrb_class_get(mrb, "SystemCallError");
if (mesg != NULL) {
mrb_funcall(mrb, mrb_obj_value(sce), "_sys_fail", 2, mrb_fixnum_value(no), mrb_str_new2(mrb, mesg));
} else {
mrb_funcall(mrb, mrb_obj_value(sce), "_sys_fail", 1, mrb_fixnum_value(no));
}
} else {
mrb_raise(mrb, E_RUNTIME_ERROR, mesg);
}
}
void
......
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