Class: Fiddle::Pinned
Relationships & Source Files | |
Inherits: | Object |
Defined in: | ext/fiddle/pinned.c |
Class Method Summary
-
.new(object) ⇒ Pinned
constructor
Create a new pinned object reference.
Instance Attribute Summary
-
#cleared? ⇒ Boolean
readonly
Returns true if the reference has been cleared, otherwise returns false.
Instance Method Summary
Constructor Details
.new(object) ⇒ Pinned
Create a new pinned object reference. The Pinned
instance will prevent the GC from moving object
.
# 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.
# 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.
# 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.
# 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"); } }