Restore the GC arena with tests.

This was the unintentional catalyst for finding the problem in #6329, but it is preferable to add a test if necessary.
This commit is contained in:
dearblue
2024-08-25 11:08:40 +09:00
parent a2db222422
commit 79d7ac5f7e
2 changed files with 15 additions and 0 deletions
+7
View File
@@ -54,9 +54,11 @@ t_print(mrb_state *mrb, mrb_value self)
mrb_int argc;
mrb_get_args(mrb, "*!", &argv, &argc);
int ai = mrb_gc_arena_save(mrb);
for (mrb_int i = 0; i < argc; i++) {
mrb_value s = mrb_obj_as_string(mrb, argv[i]);
fwrite(RSTRING_PTR(s), RSTRING_LEN(s), 1, stdout);
mrb_gc_arena_restore(mrb, ai);
}
fflush(stdout);
@@ -266,10 +268,12 @@ mrb_t_pass_result(mrb_state *mrb_dst, mrb_state *mrb_src)
if (mrb_array_p(res_src)) {
mrb_int i;
mrb_value res_dst = mrb_gv_get(mrb_dst, mrb_intern_lit(mrb_dst, "$asserts"));
int ai = mrb_gc_arena_save(mrb_dst);
for (i = 0; i < RARRAY_LEN(res_src); i++) {
mrb_value val_src = RARRAY_PTR(res_src)[i];
mrb_ensure_string_type(mrb_dst, val_src);
mrb_ary_push(mrb_dst, res_dst, mrb_str_new(mrb_dst, RSTRING_PTR(val_src), RSTRING_LEN(val_src)));
mrb_gc_arena_restore(mrb_dst, ai);
}
}
}
@@ -294,8 +298,11 @@ main(int argc, char **argv)
verbose = TRUE;
}
int ai = mrb_gc_arena_save(mrb);
mrb_init_test_driver(mrb, verbose);
mrb_gc_arena_restore(mrb, ai);
mrb_load_irep(mrb, mrbtest_assert_irep);
mrb_gc_arena_restore(mrb, ai);
mrbgemtest_init(mrb);
int ret = eval_test(mrb);
+8
View File
@@ -74,7 +74,9 @@ MRuby::Gem::Specification.new('mruby-test') do |spec|
f.puts %Q[ fprintf(stderr, "Invalid mrb_state, exiting \%s", __func__);]
f.puts %Q[ exit(EXIT_FAILURE);]
f.puts %Q[ }]
f.puts %Q[ int ai = mrb_gc_arena_save(mrb2);]
f.puts %Q[ mrb_const_set(mrb2, mrb_obj_value(mrb2->object_class), mrb_intern_lit(mrb2, "GEMNAME"), mrb_str_new(mrb2, "#{g.name}", #{g.name.length}));]
f.puts %Q[ mrb_gc_arena_restore(mrb2, ai);]
if test_preload.nil?
f.puts %Q[ mrb_load_irep(mrb2, mrbtest_assert_irep);]
else
@@ -83,8 +85,10 @@ MRuby::Gem::Specification.new('mruby-test') do |spec|
dep_list.each do |d|
f.puts %Q[ GENERATED_TMP_mrb_#{d.funcname}_gem_init(mrb2);]
f.puts %Q[ mrb_state_atexit(mrb2, GENERATED_TMP_mrb_#{d.funcname}_gem_final);]
f.puts %Q[ mrb_gc_arena_restore(mrb2, ai);]
end
f.puts %Q[ mrb_init_test_driver(mrb2, mrb_test(mrb_gv_get(mrb, mrb_intern_lit(mrb, "$mrbtest_verbose"))));]
f.puts %Q[ mrb_gc_arena_restore(mrb2, ai);]
f.puts %Q[ ]
g.test_rbfiles.count.times do |i|
unless g.test_args.empty?
@@ -96,8 +100,10 @@ MRuby::Gem::Specification.new('mruby-test') do |spec|
end
f.puts %Q[ mrb_const_set(mrb2, mrb_obj_value(mrb2->object_class), mrb_intern_lit(mrb2, "TEST_ARGS"), test_args_hash); ]
end
f.puts %Q[ mrb_gc_arena_restore(mrb2, ai);]
f.puts %Q[ mrb_#{g.funcname}_gem_test(mrb2);] if g.custom_test_init?
f.puts %Q[ mrb_gc_arena_restore(mrb2, ai);]
f.puts %Q[ mrb_load_irep(mrb2, gem_test_irep_#{g.funcname}_#{i});]
f.puts %Q[ if (mrb2->exc) {]
f.puts %Q[ mrb_print_error(mrb2);]
@@ -146,6 +152,7 @@ MRuby::Gem::Specification.new('mruby-test') do |spec|
f.puts %Q[void GENERATED_TMP_mrb_#{g.funcname}_gem_test(mrb_state *mrb);]
end
f.puts %Q[void mrbgemtest_init(mrb_state* mrb) {]
f.puts %Q[ int ai = mrb_gc_arena_save(mrb);]
build.gems.each do |g|
if g.skip_test?
f.puts %Q[ do {]
@@ -158,6 +165,7 @@ MRuby::Gem::Specification.new('mruby-test') do |spec|
else
f.puts %Q[ GENERATED_TMP_mrb_#{g.funcname}_gem_test(mrb);]
end
f.puts %Q[ mrb_gc_arena_restore(mrb, ai);]
end
f.puts %Q[}]
end