class Fiddle::Pinned

Public Class Methods

Fiddle::Pinned.new(object) → pinned_object

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

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;
}

Public Instance Methods

clear

Clear the reference to the object this is pinning.

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;
}
cleared?

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

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;
    }
}
ref

Return the object that this pinned instance references.

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");
    }
}