Class: FFI::AutoPointer::Releaser Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/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

#initialize(ptr, proc) ⇒ nil

A new instance of Releaser.

Parameters:



130
131
132
133
134
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb', line 130

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

Instance Attribute Details

#autoreleaseObject

Returns the value of attribute autorelease.



124
125
126
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb', line 124

def autorelease
  @autorelease
end

Instance Method Details

#call(*args) ⇒ Object

Release pointer if autorelease is set.

Parameters:

  • args


149
150
151
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb', line 149

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

#freenil

Free pointer.

Returns:

  • (nil)


138
139
140
141
142
143
144
145
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/autopointer.rb', line 138

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