123456789_123456789_123456789_123456789_123456789_

Class: Fiddle::Pinned

Relationships & Source Files
Inherits: Object
Defined in: ext/fiddle/pinned.c

Class Method Summary

Instance Attribute Summary

Instance Method Summary

  • #clear

    Clear the reference to the object this is pinning.

  • #ref

    Return the object that this pinned instance references.

Constructor Details

.new(object) ⇒ Pinned

Create a new pinned object reference. The Pinned instance will prevent the GC from moving object.

[ GitHub ]

  
# File 'ext/fiddle/pinned.c', line 48

static VALUE
initialize(VALUE self, VALUE ref)
{
    struct pinned_data *data;
    TypedData_Get_Struct(self, struct pinned_data, &pinned_data_type, data);
    RB_OBJ_WRITE(self, &data->ptr, ref);
    return self;
}

Instance Attribute Details

#cleared?Boolean (readonly)

Returns true if the reference has been cleared, otherwise returns false.

[ GitHub ]

  
# File 'ext/fiddle/pinned.c', line 93

static VALUE
cleared_p(VALUE self)
{
    struct pinned_data *data;
    TypedData_Get_Struct(self, struct pinned_data, &pinned_data_type, data);
    if (data->ptr) {
        return Qfalse;
    } else {
        return Qtrue;
    }
}

Instance Method Details

#clear

Clear the reference to the object this is pinning.

[ GitHub ]

  
# File 'ext/fiddle/pinned.c', line 79

static VALUE
clear(VALUE self)
{
    struct pinned_data *data;
    TypedData_Get_Struct(self, struct pinned_data, &pinned_data_type, data);
    data->ptr = 0;
    return self;
}

#ref

Return the object that this pinned instance references.

[ GitHub ]

  
# File 'ext/fiddle/pinned.c', line 62

static VALUE
ref(VALUE self)
{
    struct pinned_data *data;
    TypedData_Get_Struct(self, struct pinned_data, &pinned_data_type, data);
    if (data->ptr) {
      return data->ptr;
    } else {
      rb_raise(rb_eFiddleClearedReferenceError, "`ref` called on a cleared object");
    }
}