Merge pull request #2582 from iij/pr-attr-accessor-save-arena

save and restore arena index to prevent arena overflow.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-09-03 11:02:52 +09:00
+6
View File
@@ -1069,8 +1069,10 @@ mrb_mod_attr_reader(mrb_state *mrb, mrb_value mod)
struct RClass *c = mrb_class_ptr(mod);
mrb_value *argv;
mrb_int argc, i;
int ai;
mrb_get_args(mrb, "*", &argv, &argc);
ai = mrb_gc_arena_save(mrb);
for (i=0; i<argc; i++) {
mrb_value name, str;
mrb_sym method, sym;
@@ -1085,6 +1087,7 @@ mrb_mod_attr_reader(mrb_state *mrb, mrb_value mod)
name = mrb_symbol_value(sym);
mrb_define_method_raw(mrb, c, method,
mrb_proc_new_cfunc_with_env(mrb, attr_reader, 1, &name));
mrb_gc_arena_restore(mrb, ai);
}
return mrb_nil_value();
}
@@ -1106,8 +1109,10 @@ mrb_mod_attr_writer(mrb_state *mrb, mrb_value mod)
struct RClass *c = mrb_class_ptr(mod);
mrb_value *argv;
mrb_int argc, i;
int ai;
mrb_get_args(mrb, "*", &argv, &argc);
ai = mrb_gc_arena_save(mrb);
for (i=0; i<argc; i++) {
mrb_value name, str, attr;
mrb_sym method, sym;
@@ -1131,6 +1136,7 @@ mrb_mod_attr_writer(mrb_state *mrb, mrb_value mod)
mrb_define_method_raw(mrb, c, method,
mrb_proc_new_cfunc_with_env(mrb, attr_writer, 1, &attr));
mrb_gc_arena_restore(mrb, ai);
}
return mrb_nil_value();
}