Class: FFI::AutoPointer::Releaser Abstract

Inherits:
Object
  • Object
show all
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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, proc) ⇒ nil

A new instance of Releaser.

Parameters:



123
124
125
126
127
# File 'lib/ffi/autopointer.rb', line 123

def initialize(ptr, proc)
  @ptr = ptr
  @proc = proc
  @autorelease = true
end

Instance Attribute Details

#autoreleaseObject

Returns the value of attribute autorelease.



117
118
119
# File 'lib/ffi/autopointer.rb', line 117

def autorelease
  @autorelease
end

Instance Method Details

#call(*args) ⇒ Object

Release pointer if autorelease is set.

Parameters:

  • args


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

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

#freenil

Free pointer.

Returns:

  • (nil)


131
132
133
134
135
136
137
138
# 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:

Returns:

  • (nil)


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

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