Class: RubyPython::PyObject::AutoPyPointer
- Inherits:
-
FFI::AutoPointer
- Object
- FFI::AutoPointer
- RubyPython::PyObject::AutoPyPointer
- Defined in:
- lib/rubypython/pyobject.rb
Overview
This class wraps C Py…Object
s so that the RubyPython::Python reference count is automatically decreased when the Ruby object referencing them goes out of scope.
Class Attribute Summary collapse
-
.current_pointers ⇒ Object
Keeps track of which objects are associated with the currently running RubyPython::Python interpreter, so that RubyPython knows not to try to decrease the reference counts of the others when garbage collecting.
Class Method Summary collapse
-
.release(pointer) ⇒ Object
When used along with the FFI Library method is executed whenever a pointer is garbage collected so that cleanup can be done.
-
.update(status) ⇒ Object
Called by RubyPython when the interpreter is started or stopped so that the necessary preparation or cleanup can be done.
Class Attribute Details
.current_pointers ⇒ Object
Keeps track of which objects are associated with the currently running RubyPython::Python interpreter, so that RubyPython knows not to try to decrease the reference counts of the others when garbage collecting.
20 21 22 |
# File 'lib/rubypython/pyobject.rb', line 20 def current_pointers @current_pointers end |
Class Method Details
.release(pointer) ⇒ Object
When used along with the FFI Library method is executed whenever a pointer is garbage collected so that cleanup can be done. In our case we decrease the reference count of the held pointer as long as the object is still good. There is really no reason the end-user would need to the use this method directly.
27 28 29 30 31 32 33 |
# File 'lib/rubypython/pyobject.rb', line 27 def release(pointer) obj_id = pointer.object_id deleted = @current_pointers.delete(obj_id) if deleted and (RubyPython::Python.Py_IsInitialized != 0) RubyPython::Python.Py_DecRef pointer end end |
.update(status) ⇒ Object
Called by RubyPython when the interpreter is started or stopped so that the necessary preparation or cleanup can be done. For internal use only.
38 39 40 41 42 43 |
# File 'lib/rubypython/pyobject.rb', line 38 def update(status) case status when :stop current_pointers.clear end end |