Class: Rupy::PyObject::AutoPyPointer
- Inherits:
-
FFI::AutoPointer
- Object
- FFI::AutoPointer
- Rupy::PyObject::AutoPyPointer
- Defined in:
- lib/rupy/pyobject.rb
Overview
This class wraps C PyObject*s so that the 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 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.
Class Attribute Details
.current_pointers ⇒ Object
Keeps track of which objects are associated with the currently running Python interpreter, so that RubyPython knows not to try to decrease the reference counts of the others when garbage collecting.
23 24 25 |
# File 'lib/rupy/pyobject.rb', line 23 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.
30 31 32 33 34 35 |
# File 'lib/rupy/pyobject.rb', line 30 def release(pointer) obj_id = pointer.object_id if (Python.Py_IsInitialized != 0) and @current_pointers.delete(obj_id) Python.Py_DecRef pointer end end |