123456789_123456789_123456789_123456789_123456789_

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

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(ptr, proc) ⇒ nil

A new instance of Releaser.

Parameters:

[ GitHub ]

  
# 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.

Parameters:

  • args
[ GitHub ]

  
# File 'lib/ffi/autopointer.rb', line 142

def call(*args)
  release(@ptr) if @autorelease && @ptr
end

#freenil

Free pointer.

[ GitHub ]

  
# 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.

Parameters:

[ GitHub ]

  
# File 'lib/ffi/autopointer.rb', line 151

def release(ptr)
  @proc.call(ptr)
end