Class: FFI::AutoPointer
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
self,
Pointer ,
AbstractMemory
|
|
Inherits: |
FFI::Pointer
|
Defined in: | lib/ffi/autopointer.rb |
Constant Summary
Class Method Summary
-
.self.from_native(ptr, ctx) ⇒ AutoPointer
Create a new
AutoPointer
. -
.native_type ⇒ Type::POINTER
Return native type of
AutoPointer
. - .new(pointer, method) ⇒ self constructor
DataConverter
- Extended
from_native | Convert from a native type. |
native_type | Get native type. |
to_native | Convert to a native type. |
Pointer
- Inherited
Instance Attribute Summary
-
#autorelease=(autorelease) ⇒ Boolean
rw
Set
autorelease
property. -
#autorelease? ⇒ Boolean
rw
Get
autorelease
property.
Pointer
- Inherited
AbstractMemory
- Inherited
#size_limit? | Return |
Instance Method Summary
-
#free ⇒ nil
Free the pointer.
Pointer
- Inherited
#+, #==, | |
#address | Alias for Pointer#to_i. |
#free, | |
#initialize_copy | This method is internally used by |
#inspect | Alias for Pointer#to_s. |
#order | Get or set |
#read | Read pointer’s contents as |
#read_array_of_type | Read an array of |
#read_string | Read pointer’s contents as a string, or the first |
#read_string_length | Read the first |
#read_string_to_null | Read pointer’s contents as a string. |
#slice, #to_i, #to_ptr, #to_s, #type_size, | |
#write | Write |
#write_array_of_type | Write |
#write_string | Write |
#write_string_length | Write |
AbstractMemory
- Inherited
Constructor Details
.new(pointer, method) ⇒ self
.new(pointer, proc) ⇒ self
.new(pointer) ⇒ self
self
.new(pointer, proc) ⇒ self
.new(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 AutoPointer
, and override #release, which by default does nothing.
# File 'lib/ffi/autopointer.rb', line 70
def initialize(ptr, proc=nil) raise TypeError, "Invalid pointer" if ptr.nil? || !ptr.kind_of?(Pointer) || ptr.kind_of?(MemoryPointer) || ptr.kind_of?(AutoPointer) super(ptr.type_size, ptr) @releaser = if proc if not proc.respond_to?(:call) raise RuntimeError.new("proc must be callable") end Releaser.new(ptr, proc) else if not self.class.respond_to?(:release, true) raise RuntimeError.new("no release method defined") end Releaser.new(ptr, self.class.method(:release)) 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.
# File 'lib/ffi/autopointer.rb', line 175
def self.from_native(val, ctx) self.new(val) end
.native_type ⇒ Type::POINTER
Return native type of AutoPointer
.
Override DataConverter#native_type.
# File 'lib/ffi/autopointer.rb', line 161
def self.native_type if not self.respond_to?(:release, true) raise RuntimeError.new("no release method defined for #{self.inspect}") end Type::POINTER end
Instance Attribute Details
#autorelease=(autorelease) ⇒ Boolean
(rw)
Set autorelease
property. See Autorelease section at Pointer.
# File 'lib/ffi/autopointer.rb', line 101
def autorelease=(autorelease) raise FrozenError.new("can't modify frozen #{self.class}") if frozen? @releaser.autorelease=(autorelease) end
#autorelease? ⇒ Boolean
(rw)
Get autorelease
property. See Autorelease section at Pointer.
# File 'lib/ffi/autopointer.rb', line 108
def autorelease? @releaser.autorelease end
Instance Method Details
#free ⇒ nil
Free the pointer.
# File 'lib/ffi/autopointer.rb', line 94
def free @releaser.free end