W3cubDocs

/Ruby 3

class Fiddle::Pinned

Parent:
Object

Public Class Methods

Fiddle::Pinned.new(object) → pinned_object Show source
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;
}

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

Public Instance Methods

clear Show source
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;
}

Clear the reference to the object this is pinning.

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

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

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

Return the object that this pinned instance references.

Ruby Core © 1993–2020 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.