Class: Libpng::StandardEncoder::CallbackSet

Inherits:
Object
  • Object
show all
Defined in:
lib/libpng/standard_encoder.rb

Overview

Holds FFI::Function callbacks alive for the duration of the libpng calls. FFI::Function objects are GC'd when no Ruby reference remains; libpng stores the raw function pointer but has no idea the underlying Ruby object needs to stay alive.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_accumulator) ⇒ CallbackSet

Returns a new instance of CallbackSet.



112
113
114
115
116
117
118
119
# File 'lib/libpng/standard_encoder.rb', line 112

def initialize(output_accumulator)
  @write_fn = FFI::Function.new(:void, %i[pointer pointer size_t]) do |_, data, len|
    output_accumulator << data.read_bytes(len)
  end
  @error_fn = FFI::Function.new(:void, %i[pointer string]) do |_, msg|
    raise Error, "libpng: #{msg}"
  end
end

Instance Attribute Details

#error_fnObject (readonly)

Returns the value of attribute error_fn.



110
111
112
# File 'lib/libpng/standard_encoder.rb', line 110

def error_fn
  @error_fn
end

#write_fnObject (readonly)

Returns the value of attribute write_fn.



110
111
112
# File 'lib/libpng/standard_encoder.rb', line 110

def write_fn
  @write_fn
end