Class: RubyPython::PyObject::AutoPyPointer
- Inherits:
-
FFI::AutoPointer
- Object
- FFI::AutoPointer
- RubyPython::PyObject::AutoPyPointer
- Defined in:
- lib/rubypython/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.
-
.update(status) ⇒ Object
For internal use only.
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.
21 22 23 |
# File 'lib/rubypython/pyobject.rb', line 21 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.
28 29 30 31 32 33 |
# File 'lib/rubypython/pyobject.rb', line 28 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 |
.update(status) ⇒ Object
For internal use only. Called by RubyPython when the interpreter is started or stopped so that the neccesary preperation or cleanup can be done.
39 40 41 |
# File 'lib/rubypython/pyobject.rb', line 39 def update(status) current_pointers.clear if status.equal? :stop end |