class FFI::AutoPointer
def initialize(ptr, proc=nil, &block)
- Note: -
Note: - The safest, and therefore preferred, calling
Note: - WARNING: passing a block will cause your pointer to never be GC'd. This is bad.
Note: - WARNING: passing a proc _may_ cause your pointer to never be GC'd, unless you're
Returns:
-
(self)
- -
(self)
- -
(self)
- -
(self)
-
Parameters:
-
pointer
(Pointer
) -- -
pointer
(Pointer
) -- -
pointer
(Pointer
) -- -
method
(Method
) -- -
pointer
(Pointer
) --
Overloads:
-
initialize(pointer)
-
initialize(pointer) { |p| ... }
-
initialize(pointer, proc)
-
initialize(pointer, method)
Other tags:
- Yieldparam: p - +pointer+ passed to the block
def initialize(ptr, proc=nil, &block) super(ptr) raise TypeError, "Invalid pointer" if ptr.nil? || !ptr.kind_of?(Pointer) \ || ptr.kind_of?(MemoryPointer) || ptr.kind_of?(AutoPointer) @releaser = if proc raise RuntimeError.new("proc must be callable") unless proc.respond_to?(:call) CallableReleaser.new(ptr, proc) else raise RuntimeError.new("no release method defined") unless self.class.respond_to?(:release) DefaultReleaser.new(ptr, self.class) end ObjectSpace.define_finalizer(self, @releaser) self end