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.

Direct Known Subclasses

CallableReleaser, DefaultReleaser

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (nil) initialize(ptr, proc)

A new instance of Releaser.

Parameters:



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

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

Instance Attribute Details

- (Object) autorelease

Returns the value of attribute autorelease



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

def autorelease
  @autorelease
end

Instance Method Details

- (Object) call(*args)

Release pointer if autorelease is set.

Parameters:

  • args


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

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

- (nil) free

Free pointer.

Returns:

  • (nil)


132
133
134
135
136
137
138
139
# File 'lib/ffi/autopointer.rb', line 132

def free
  if @ptr
    release(@ptr)
    @autorelease = false
    @ptr = nil
    @proc = nil
  end
end