Class: Fiddle::Pinned

Inherits:
Object
  • Object
show all
Defined in:
pinned.c

Instance Method Summary collapse

Constructor Details

#Fiddle::Pinned.new(object) ⇒ Object

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



48
49
50
51
52
53
54
55
# File '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 Method Details

#clearObject

Clear the reference to the object this is pinning.



79
80
81
82
83
84
85
86
# File '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;
}

#cleared?Boolean

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

Returns:

  • (Boolean)


93
94
95
96
97
98
99
100
101
102
103
# File '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;
    }
}

#refObject

Return the object that this pinned instance references.



62
63
64
65
66
67
68
69
70
71
72
# File '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");
    }
}