Class: FFI::AutoPointer::Releaser Abstract
- Inherits:
-
Object
- Object
- FFI::AutoPointer::Releaser
- Defined in:
- lib/ffi/autopointer.rb
Overview
This class is abstract.
Base class for FFI::AutoPointer‘s releasers.
All subclasses of Releaser should define a #release(ptr) method.
A releaser is an object in charge of release an FFI::AutoPointer.
Instance Attribute Summary collapse
-
#autorelease ⇒ Object
Returns the value of attribute autorelease.
Instance Method Summary collapse
-
#call(*args) ⇒ Object
Release pointer if
autorelease
is set. -
#free ⇒ nil
Free pointer.
-
#initialize(ptr, proc) ⇒ nil
constructor
A new instance of Releaser.
-
#release(ptr) ⇒ nil
Release
ptr
by using Proc or Method defined atptr
initialization.
Constructor Details
#initialize(ptr, proc) ⇒ nil
A new instance of Releaser.
123 124 125 126 127 |
# File 'lib/ffi/autopointer.rb', line 123 def initialize(ptr, proc) @ptr = ptr @proc = proc @autorelease = true end |
Instance Attribute Details
#autorelease ⇒ Object
Returns the value of attribute autorelease.
117 118 119 |
# File 'lib/ffi/autopointer.rb', line 117 def autorelease @autorelease end |
Instance Method Details
#call(*args) ⇒ Object
Release pointer if autorelease
is set.
142 143 144 |
# File 'lib/ffi/autopointer.rb', line 142 def call(*args) release(@ptr) if @autorelease && @ptr end |
#free ⇒ nil
Free pointer.
131 132 133 134 135 136 137 138 |
# File 'lib/ffi/autopointer.rb', line 131 def free if @ptr release(@ptr) @autorelease = false @ptr = nil @proc = nil end end |
#release(ptr) ⇒ nil
Release ptr
by using Proc or Method defined at ptr
initialization.
151 152 153 |
# File 'lib/ffi/autopointer.rb', line 151 def release(ptr) @proc.call(ptr) end |