Skip to content

Conversation

@tompng
Copy link
Member

@tompng tompng commented Jul 28, 2025

Reduce usage of GUARD_OBJ and replace to RB_GC_GUARD.
BigDecimal couldn't use RB_GC_GUARD due to the structure before #344. Now we can reduce it.

GUARD_OBJ to retval is not needed

 {
   ...
-  GUARD_OBJ(retval, foo());
+  retval = foo();
   ....
   return CheckGetValue(retval);
 }

Remove GUARD_OBJ of self and arg, add RB_GC_GUARD before return.
In most case, self is stored in stack, but some function (example: BigDecimal_to_i) calls self with non-self ruby object that needs RB_GC_GUARD.

 static VALUE
 BigDecimal_foobar(VALUE self, VALUE arg)
 {
-  GUARD_OBJ(a, foo(self));
-  GUARD_OBJ(b, bar(arg));
+  a = foo(self);
+  b = bar(arg);
   ...
+  RB_GC_GUARD(a.bigdecimal)
+  RB_GC_GUARD(b.bigdecimal)
   return z;
 }

Remaining GUARD_OBJ and ENTER macro is in BigDecimal_div2 and in BigDecimal_DoDivmod.

tompng added 3 commits July 28, 2025 20:41
Remove GUARD_OBJ of self and add RB_GC_GUARD.
Some BigDecimal_ func are called from another func with non-self object that needs RB_GC_GUARD.
Remove GUARD_OBJ and use GUARD_OBJ(self) and GUARD_OBJ(rhs_value)
@tompng tompng merged commit 81de140 into ruby:master Jul 28, 2025
79 checks passed
@tompng tompng deleted the reduce_guard_obj branch July 28, 2025 12:15
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.

1 participant