Class: FFI::StrPtrConverter

Inherits:
Object show all
Extended by:
DataConverter
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/types.rb

Overview

This will convert a pointer to a Ruby string (just like ‘:string`), but also allow to work with the pointer itself. This is useful when you want a Ruby string already containing a copy of the data, but also the pointer to the data for you to do something with it, like freeing it, in case the library handed the memory off to the caller (Ruby-FFI).

It’s typedef‘d as :strptr.

Class Method Summary collapse

Methods included from DataConverter

from_native, native_type, to_native

Class Method Details

.from_native(val, ctx) ⇒ Array(String, Pointer)

Returns a [ String, Pointer ] tuple so the C memory for the string can be freed

Parameters:

Returns:



166
167
168
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/types.rb', line 166

def self.from_native(val, ctx)
  [ val.null? ? nil : val.get_string(0), val ]
end