Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion include/rice/rice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1667,14 +1667,20 @@ namespace Rice
{
namespace detail
{
inline Anchor::Anchor(VALUE value) : value_(value)
inline Anchor::Anchor(VALUE value)
{
// rb_gc_register_address() can trigger GC, so we must register the
// empty this->value_ slot before storing a heap VALUE in it.
// RB_GC_GUARD(value) keeps the ctor argument alive through the end of
// this method until the registered slot has been updated.
if (!RB_SPECIAL_CONST_P(value))
{
Anchor::registerExitHandler();
detail::protect(rb_gc_register_address, &this->value_);
this->registered_ = true;
}
this->value_ = value;
RB_GC_GUARD(value);
}

inline Anchor::~Anchor()
Expand Down
8 changes: 7 additions & 1 deletion rice/detail/Anchor.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ namespace Rice
{
namespace detail
{
inline Anchor::Anchor(VALUE value) : value_(value)
inline Anchor::Anchor(VALUE value)
{
// rb_gc_register_address() can trigger GC, so we must register the
// empty this->value_ slot before storing a heap VALUE in it.
// RB_GC_GUARD(value) keeps the ctor argument alive through the end of
// this method until the registered slot has been updated.
if (!RB_SPECIAL_CONST_P(value))
{
Anchor::registerExitHandler();
detail::protect(rb_gc_register_address, &this->value_);
this->registered_ = true;
}
this->value_ = value;
RB_GC_GUARD(value);
}

inline Anchor::~Anchor()
Expand Down
Loading