Bug #7721 ยป 0001-error.c-defer-error-message.patch
error.c | ||
---|---|---|
return error;
|
||
}
|
||
static VALUE
|
||
syserr_alloc(VALUE klass)
|
||
{
|
||
NEWOBJ_OF(obj, struct RObject, klass, T_OBJECT);
|
||
return (VALUE)obj;
|
||
}
|
||
/*
|
||
* call-seq:
|
||
* SystemCallError.new(msg, errno) -> system_call_error_subclass
|
||
... | ... | |
#if !defined(_WIN32)
|
||
char *strerror();
|
||
#endif
|
||
const char *err;
|
||
VALUE mesg, error;
|
||
VALUE klass = rb_obj_class(self);
|
||
... | ... | |
rb_scan_args(argc, argv, "01", &mesg);
|
||
error = rb_const_get(klass, rb_intern("Errno"));
|
||
}
|
||
if (!NIL_P(error)) err = strerror(NUM2INT(error));
|
||
else err = "unknown error";
|
||
if (!NIL_P(mesg)) {
|
||
rb_encoding *le = rb_locale_encoding();
|
||
VALUE str = StringValue(mesg);
|
||
rb_encoding *me = rb_enc_get(mesg);
|
||
mesg = rb_sprintf("%s - %"PRIsVALUE, err, mesg);
|
||
if (le != me && rb_enc_asciicompat(me)) {
|
||
le = me;
|
||
}/* else assume err is non ASCII string. */
|
||
OBJ_INFECT(mesg, str);
|
||
rb_enc_associate(mesg, le);
|
||
}
|
||
else {
|
||
mesg = rb_str_new2(err);
|
||
rb_enc_associate(mesg, rb_locale_encoding());
|
||
}
|
||
rb_call_super(1, &mesg);
|
||
rb_call_super(0, 0);
|
||
rb_iv_set(self, "_mesg", rb_str_new_frozen(mesg));
|
||
rb_iv_set(self, "errno", error);
|
||
return self;
|
||
}
|
||
... | ... | |
/*
|
||
* call-seq:
|
||
* system_call_error.to_s -> string
|
||
*
|
||
* Return this SystemCallError's message.
|
||
*/
|
||
static VALUE
|
||
syserr_to_s(VALUE self)
|
||
{
|
||
VALUE mesg = rb_attr_get(self, rb_intern("mesg"));
|
||
if (NIL_P(mesg)) {
|
||
const char *err;
|
||
VALUE error = rb_attr_get(self, rb_intern("errno"));
|
||
mesg = rb_ivar_remove(self, rb_intern("_mesg"));
|
||
if (!NIL_P(error)) err = strerror(NUM2INT(error));
|
||
else err = "unknown error";
|
||
if (!NIL_P(mesg)) {
|
||
rb_encoding *le = rb_locale_encoding();
|
||
VALUE str = StringValue(mesg);
|
||
rb_encoding *me = rb_enc_get(mesg);
|
||
mesg = rb_sprintf("%s - %"PRIsVALUE, err, mesg);
|
||
if (le != me && rb_enc_asciicompat(me)) {
|
||
le = me;
|
||
}/* else assume err is non ASCII string. */
|
||
OBJ_INFECT(mesg, str);
|
||
rb_enc_associate(mesg, le);
|
||
}
|
||
else {
|
||
mesg = rb_str_new2(err);
|
||
rb_enc_associate(mesg, rb_locale_encoding());
|
||
}
|
||
rb_ivar_set(self, rb_intern("mesg"), mesg);
|
||
}
|
||
return mesg;
|
||
}
|
||
static VALUE
|
||
syserr_dump(VALUE self)
|
||
{
|
||
if (FL_TEST(self, FL_FREEZE)) self = rb_obj_dup(self);
|
||
syserr_to_s(self);
|
||
return self;
|
||
}
|
||
static VALUE
|
||
syserr_load(VALUE real_obj, VALUE load_data)
|
||
{
|
||
return real_obj;
|
||
}
|
||
/*
|
||
* call-seq:
|
||
* system_call_error === other -> true or false
|
||
*
|
||
* Return +true+ if the receiver is a generic +SystemCallError+, or
|
||
... | ... | |
syserr_tbl = st_init_numtable();
|
||
rb_eSystemCallError = rb_define_class("SystemCallError", rb_eStandardError);
|
||
rb_define_alloc_func(rb_eSystemCallError, syserr_alloc);
|
||
rb_define_method(rb_eSystemCallError, "initialize", syserr_initialize, -1);
|
||
rb_define_method(rb_eSystemCallError, "errno", syserr_errno, 0);
|
||
rb_define_method(rb_eSystemCallError, "to_s", syserr_to_s, 0);
|
||
rb_define_singleton_method(rb_eSystemCallError, "===", syserr_eqq, 1);
|
||
rb_marshal_define_compat(rb_eSystemCallError, rb_eSystemCallError, syserr_dump, syserr_load);
|
||
rb_mErrno = rb_define_module("Errno");
|
||
inits.c | ||
---|---|---|
CALL(Comparable);
|
||
CALL(Enumerable);
|
||
CALL(String);
|
||
CALL(marshal_compat);
|
||
CALL(Exception);
|
||
CALL(eval);
|
||
CALL(safe);
|
internal.h | ||
---|---|---|
void rb_gc_mark_global_tbl(void);
|
||
void rb_mark_generic_ivar(VALUE);
|
||
void rb_mark_generic_ivar_tbl(void);
|
||
VALUE rb_ivar_remove(VALUE obj, ID id);
|
||
#if defined __GNUC__ && __GNUC__ >= 4
|
||
#pragma GCC visibility pop
|
marshal.c | ||
---|---|---|
rb_define_const(rb_mMarshal, "MAJOR_VERSION", INT2FIX(MARSHAL_MAJOR));
|
||
rb_define_const(rb_mMarshal, "MINOR_VERSION", INT2FIX(MARSHAL_MINOR));
|
||
}
|
||
void
|
||
Init_marshal_compat(void)
|
||
{
|
||
compat_allocator_tbl = st_init_numtable();
|
||
compat_allocator_tbl_wrapper =
|
||
Data_Wrap_Struct(rb_cData, mark_marshal_compat_t, 0, compat_allocator_tbl);
|
variable.c | ||
---|---|---|
{
|
||
VALUE val = Qnil;
|
||
const ID id = rb_check_id(&name);
|
||
st_data_t n, v;
|
||
struct st_table *iv_index_tbl;
|
||
st_data_t index;
|
||
if (!OBJ_UNTRUSTED(obj) && rb_safe_level() >= 4)
|
||
rb_raise(rb_eSecurityError, "Insecure: can't modify instance variable");
|
||
... | ... | |
QUOTE_ID(id));
|
||
}
|
||
val = rb_ivar_remove(obj, id);
|
||
if (val == Qundef)
|
||
rb_name_error(id, "instance variable %"PRIsVALUE" not defined", QUOTE_ID(id));
|
||
return val;
|
||
}
|
||
VALUE
|
||
rb_ivar_remove(VALUE obj, ID id)
|
||
{
|
||
VALUE val = Qnil;
|
||
st_data_t n, v;
|
||
struct st_table *iv_index_tbl;
|
||
st_data_t index;
|
||
if (SPECIAL_CONST_P(obj)) goto generic;
|
||
switch (BUILTIN_TYPE(obj)) {
|
||
case T_OBJECT:
|
||
... | ... | |
}
|
||
break;
|
||
}
|
||
rb_name_error(id, "instance variable %"PRIsVALUE" not defined", QUOTE_ID(id));
|
||
UNREACHABLE;
|
||
return Qundef;
|
||
}
|
||
NORETURN(static void uninitialized_constant(VALUE, ID));
|