Class: FFI::AutoPointer::Releaser Abstract
Relationships & Source Files | |
Inherits: | Object |
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
.
Class Method Summary
-
.new(ptr, proc) ⇒ nil
constructor
A new instance of
Releaser
.
Instance Attribute Summary
- #autorelease rw
Instance Method Summary
-
#call(*args)
Release pointer if #autorelease is set.
-
#free ⇒ nil
Free pointer.
-
#release(ptr) ⇒ nil
Release
ptr
by using Proc or Method defined atptr
initialization
.
Constructor Details
.new(ptr, proc) ⇒ nil
A new instance of Releaser
.
# File 'lib/ffi/autopointer.rb', line 123
def initialize(ptr, proc) @ptr = ptr @proc = proc @autorelease = true end
Instance Attribute Details
#autorelease (rw)
[ GitHub ]# File 'lib/ffi/autopointer.rb', line 117
attr_accessor :autorelease
Instance Method Details
#call(*args)
Release pointer if #autorelease is set.
# File 'lib/ffi/autopointer.rb', line 142
def call(*args) release(@ptr) if @autorelease && @ptr end
#free ⇒ nil
Free pointer.
# 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
.
# File 'lib/ffi/autopointer.rb', line 151
def release(ptr) @proc.call(ptr) end