Skip to content

Conversation

@dearblue
Copy link

String objects could be GC'd if mrb_value_to_string() was recursively called by an array or hash object.
This patch no longer handles GC arena indices, since no other objects are created when strings are dumped.

String objects could be GC'd if `mrb_value_to_string()` was recursively called by an array or hash object.
This patch no longer handles GC arena indices, since no other objects are created when strings are dumped.
@mattn
Copy link
Owner

mattn commented Oct 30, 2023

Thank you.

How about to move memory allocation of str outside mrb_gc_arena_save and mrb_gc_arena_restore blocks?

      str = mrb_str_new_cstr(mrb, "\""); 
      int ai = mrb_gc_arena_save(mrb);
      ...
      mrb_gc_arena_restore(mrb, ai);

@dearblue
Copy link
Author

レビューありがとうございます。

僕は問題の箇所における GC アリーナの復帰は不要だと考えています。

case MRB_TT_STRING ブロック内では、返り値となる文字列オブジェクトが生成される以外はオブジェクトの生成が行われません。
mrb_str_cat()mrb_str_cat_cstr() が呼び出されますが、これらの関数がオブジェクトの生成を行うのは例外が発生する時に限定されます。
念の為に過去のバージョンも含めて mruby の実装を確認しました。

それとも僕は何か見落としているのでしょうか?

@dearblue dearblue mentioned this pull request Nov 23, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants