Class: Fiddle::Pinned
Relationships & Source Files | |
Inherits: | Object |
Defined in: | ext/fiddle/pinned.c, ext/fiddle/lib/fiddle/ffi_backend.rb |
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
-
#clear
Clear the reference to the object this is pinning.
- #initialize(object) ⇒ Pinned constructor
-
#ref
Return the object that this pinned instance references.
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 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
# 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.
# 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.
# 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.
# 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"); } }