Skip to content

Reduce GUARD_OBJ#361

Closed
tompng wants to merge 1 commit intoruby:masterfrom
tompng:reduce_guard_obj
Closed

Reduce GUARD_OBJ#361
tompng wants to merge 1 commit intoruby:masterfrom
tompng:reduce_guard_obj

Conversation

@tompng
Copy link
Copy Markdown
Member

@tompng tompng commented Jul 6, 2025

Remove GUARD_OBJ for returned value.
Return value will remain on stack as long as the returned value is used.

GUARD_OBJ(retval, NewZeroWrapLimited(1, mx));
do_something(retval.real);
return retval.bigdecimal;

// ↓

retval = NewZeroWrapLimited(1, mx);
do_something(retval.real);
return retval.bigdecimal;

On the other hand, self is not always on the stack.

GUARD_OBJ(x, GetBDValueMust(self));

// ↓ this conversion is not GC safe

x = GetBDValueMust(self);
static VALUE BigDecimal_to_r(VALUE self){
  self is always on the stack
}

static VALUE BigDecimal_to_i(VALUE self) {
  self is NOT always on the stack
  because this function is used as `BigDecimal_to_i(CheckGetValue(c))`
}

Returned value will be on the stack as long as the returned value is used.
@tompng tompng marked this pull request as draft July 6, 2025 10:43
@tompng tompng force-pushed the reduce_guard_obj branch from 372a98e to a7eb57c Compare July 6, 2025 10:50
@tompng
Copy link
Copy Markdown
Member Author

tompng commented Jul 14, 2025

I'll revisit after some C function (VpSqrt, BigDecimal_power, BigMath_s_exp, BigMath_s_log) are removed.
These functions calls BigDecimal_ function with non-self object which is not on the stack.
It means that BigDecimal_xxx(VALUE self) needs RB_GC_GUARD(self).

@tompng tompng closed this Jul 14, 2025
@tompng tompng deleted the reduce_guard_obj branch July 14, 2025 19:30
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