123456789_123456789_123456789_123456789_123456789_

Class: Fiddle::Pinned

Relationships & Source Files
Inherits: Object
Defined in: ext/fiddle/pinned.c,
ext/fiddle/lib/fiddle/ffi_backend.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

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 52

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

#initialize(object) ⇒ Pinned

[ GitHub ]

  
# File 'ext/fiddle/lib/fiddle/ffi_backend.rb', line 546

def initialize(object)
  @object = object
end

Instance Attribute Details

#cleared?Boolean (readonly)

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

[ GitHub ]

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

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 83

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 66

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