Skip to content

Protect strings from GC in JSON.generate #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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