mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #996 from iij/pr-systemcallerror
mrb_sys_fail raises an instance of (subclass of) SystemCallError if we have it
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
+15
-1
@@ -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_new_cstr(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
|
||||
|
||||
Reference in New Issue
Block a user