Sha256: 672b6e7368f5dfba784c93f6e6a15953aa3747767afc749f1378c980dcb441b7

Contents?: true

Size: 1.79 KB

Versions: 12

Compression:

Stored size: 1.79 KB

Contents

namespace Rice
{
  inline Address_Registration_Guard::Address_Registration_Guard(VALUE* address) : address_(address)
  {
    registerExitHandler();
    registerAddress();
  }

  inline Address_Registration_Guard::Address_Registration_Guard(Object* object)
    : address_(const_cast<VALUE*>(&object->value()))
  {
    registerExitHandler();
    registerAddress();
  }

  inline Address_Registration_Guard::~Address_Registration_Guard()
  {
    unregisterAddress();
  }

  inline Address_Registration_Guard::Address_Registration_Guard(Address_Registration_Guard&& other)
  {
    // We don't use the constructor because we don't want to double register this address
    address_ = other.address_;
    other.address_ = nullptr;
  }

  inline Address_Registration_Guard& Address_Registration_Guard::operator=(Address_Registration_Guard&& other)
  {
    this->unregisterAddress();

    this->address_ = other.address_;
    other.address_ = nullptr;
    return *this;
  }

  inline void Address_Registration_Guard::registerAddress() const
  {
    if (enabled)
    {
      detail::protect(rb_gc_register_address, address_);
    }
  }

  inline void Address_Registration_Guard::unregisterAddress()
  {
    if (enabled && address_)
    {
      detail::protect(rb_gc_unregister_address, address_);
    }

    address_ = nullptr;
  }

  inline VALUE* Address_Registration_Guard::address() const
  {
    return address_;
  }

  static void disable_all_guards(VALUE)
  {
    Address_Registration_Guard::disable();
  }

  inline void Address_Registration_Guard::registerExitHandler()
  {
    if (exit_handler_registered)
    {
      return;
    }

    detail::protect(rb_set_end_proc, &disable_all_guards, Qnil);
    exit_handler_registered = true;
  }

  inline void Address_Registration_Guard::disable()
  {
    enabled = false;
  }
} // Rice

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rice-4.3.3 rice/Address_Registration_Guard.ipp
rice-4.3.2 rice/Address_Registration_Guard.ipp
rice-4.3.1 rice/Address_Registration_Guard.ipp
rice-4.3.0 rice/Address_Registration_Guard.ipp
rice-4.2.1 rice/Address_Registration_Guard.ipp
rice-4.2.0 rice/Address_Registration_Guard.ipp
rice-4.1.0 rice/Address_Registration_Guard.ipp
rice-4.0.4 rice/Address_Registration_Guard.ipp
rice-4.0.3 rice/Address_Registration_Guard.ipp
rice-4.0.2 rice/Address_Registration_Guard.ipp
rice-4.0.1 rice/Address_Registration_Guard.ipp
rice-4.0.0 rice/Address_Registration_Guard.ipp