Class: FFI::AutoPointer
- Extended by:
- DataConverter
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb
Defined Under Namespace
Classes: CallableReleaser, DefaultReleaser, Releaser
Constant Summary
Constants inherited from Pointer
Class Method Summary collapse
-
.self.from_native(ptr, ctx) ⇒ AutoPointer
Create a new AutoPointer.
-
.native_type ⇒ Type::POINTER
Return native type of AutoPointer.
Instance Method Summary collapse
-
#autorelease=(autorelease) ⇒ Boolean
Set
autorelease
property. -
#autorelease? ⇒ Boolean
Get
autorelease
property. -
#free ⇒ nil
Free the pointer.
-
#initialize(ptr, proc = nil, &block) ⇒ AutoPointer
constructor
A new instance of AutoPointer.
Methods included from DataConverter
from_native, native_type, to_native
Methods inherited from Pointer
#read, #read_array_of_type, #read_string, #read_string_length, #read_string_to_null, size, #to_ptr, #write, #write_array_of_type, #write_string, #write_string_length
Constructor Details
#initialize(pointer, method) ⇒ self #initialize(pointer, proc) ⇒ self #initialize(pointer) {|p| ... } ⇒ self #initialize(pointer) ⇒ self
The safest, and therefore preferred, calling idiom is to pass a Method as the second parameter. Example usage:
class PointerHelper
def self.release(pointer)
...
end
end
p = AutoPointer.new(other_pointer, PointerHelper.method(:release))
The above code will cause PointerHelper#release to be invoked at GC time.
The last calling idiom (only one parameter) is generally only going to be useful if you subclass FFI::AutoPointer, and override #release, which by default does nothing.
Returns a new instance of AutoPointer.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb', line 78 def initialize(ptr, proc=nil, &block) super(ptr.type_size, ptr) raise TypeError, "Invalid pointer" if ptr.nil? || !ptr.kind_of?(Pointer) \ || ptr.kind_of?(MemoryPointer) || ptr.kind_of?(AutoPointer) @releaser = if proc if not proc.respond_to?(:call) raise RuntimeError.new("proc must be callable") end CallableReleaser.new(ptr, proc) else if not self.class.respond_to?(:release) raise RuntimeError.new("no release method defined") end DefaultReleaser.new(ptr, self.class) end ObjectSpace.define_finalizer(self, @releaser) self end |
Class Method Details
.self.from_native(ptr, ctx) ⇒ AutoPointer
Create a new AutoPointer.
Override DataConverter#from_native.
198 199 200 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb', line 198 def self.from_native(val, ctx) self.new(val) end |
.native_type ⇒ Type::POINTER
Return native type of AutoPointer.
Override DataConverter#native_type.
184 185 186 187 188 189 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb', line 184 def self.native_type if not self.respond_to?(:release) raise RuntimeError.new("no release method defined for #{self.inspect}") end Type::POINTER end |
Instance Method Details
#autorelease=(autorelease) ⇒ Boolean
Set autorelease
property. See Autorelease section at Pointer.
109 110 111 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb', line 109 def autorelease=(autorelease) @releaser.autorelease=(autorelease) end |
#autorelease? ⇒ Boolean
Get autorelease
property. See Autorelease section at Pointer.
115 116 117 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb', line 115 def autorelease? @releaser.autorelease end |
#free ⇒ nil
Free the pointer.
102 103 104 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb', line 102 def free @releaser.free end |