Questions tagged [ruby-ffi]

Ruby-FFI is a ruby extension for programmatically loading dynamic libraries, binding functions within them, and calling those functions from Ruby code.

Ruby-FFI is a ruby extension for programmatically loading dynamic libraries, binding functions within them, and calling those functions from Ruby code. It works without changes on Ruby and JRuby.

31 questions
5
votes
1 answer

How can I load Windows DLL files with Ruby fiddle?

I am trying to create a GR framework binding for ruby. I use Fiddle. Fiddle is a default extension to translate a foreign function interface (FFI) with ruby. It Works well on Linux and Mac. But on Windows, I got following error. code…
kojix2
  • 806
  • 7
  • 18
5
votes
0 answers

ruby ffi call function referenced by pointer in struct?

I'm trying to use libfluidsynth with ruby ffi and need to iterate over a soundfont to get all instruments. Specifically, the _fluid_sfont_t struct has iteration_start and iteration_next references that I need to…
eagspoo
  • 2,095
  • 3
  • 22
  • 31
4
votes
2 answers

Can I pass a ruby object pointer to a ruby-ffi callback?

I could really use a push in the right direction on this. Given this C code: typedef void cbfunc(void *data); void set_callback(cbfunc* cb); //do_stuff calls the callback multiple times with data as argument void do_stuff(void *data); This Ruby…
Daniel Wyatt
  • 379
  • 3
  • 7
3
votes
1 answer

Assigning to nested struct members in Ruby FFI

Consider the following two FFI structs: class A < FFI::Struct layout :data, :int end class B < FFI::Struct layout :nested, A end To instantiate them: a = A.new b = B.new Now when I try to assign a to b.nested like this: b[:nested] = a I get the…
G S
  • 35,511
  • 22
  • 84
  • 118
3
votes
0 answers

How to pass a struct with a string field to a native library, with pre-initialized string field of that struct, via FFI?

I have ruby code which passes a struct to a native Rust library, via FFI gem. A struct contains a string field. I need to be able to specify string on Ruby side. class MyStruct < FFI::Struct layout :s1, :string, :field2,…
3
votes
2 answers

Rust Vec to Ruby Array with FFI Segfaults

I am trying to return a struct that can be converted into a Ruby array from an external rust function but when I try to call the structs #to_a method I get a segfault. use libc::size_t; #[repr(C)] pub struct Array { len: libc::size_t, data:…
mpiccolo
  • 662
  • 5
  • 14
3
votes
1 answer

Error compiling the tesseract-ocr gem with ruby ffi-inliner

When I try and run the following code, require 'rubygems' require 'bundler/setup' Bundler.require(:default) I get the errors below $ bundle exec ruby test.rb…
Cameron Walsh
  • 786
  • 5
  • 9
2
votes
1 answer

Ruby Fiddle - Function behaves differently between C and Ruby

I am using Ruby Fiddle to access a C function to perform some heavy calculations. The C function works perfectly well when called directly, but when used via Fiddle it returns various rows of nans and infs in an unpredictable way. The function…
Rojj
  • 1,170
  • 1
  • 12
  • 32
2
votes
0 answers

Why is my Fiddle struct being filled with garbage?

I'm attempting to convert a very simple C Win32 API call over to Ruby utilizing Fiddle and I'm not having much success. The first two method calls work flawlessly, though when I get to the call which populates a struct I'm having a bit of…
cjones26
  • 3,459
  • 1
  • 34
  • 51
2
votes
1 answer

How do I use the ruby ffi gem to call a freestanding function in a rust library?

ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux] rustc 0.13.0-nightly (f168c12c5 2014-10-25 20:57:10 +0000) I want to use the ffi gem in conjunction with rust. I have read this (quite outdated) blog post, which shows how to do that. The…
le_me
  • 3,089
  • 3
  • 26
  • 28
2
votes
1 answer

Why does gem not auto compile my C extension

I build a Ruby gem, which needs some C extension. This one - once compiled - is bound via Ruby FFI into the gem. My setup: I use bundle for the gem scaffolding. Inside my gems folder I have a subfolder ext. This one includes a static Makefile,…
GeorgieF
  • 2,687
  • 5
  • 29
  • 43
1
vote
1 answer

Declaring char array in Ruby FFI

I have the following C code: typedef void (*mycallback) (char buf[128]); void take_callback(mycallback cb) { } I've written the equivalent Ruby FFI declarations as below (following advice for structs on FFI wiki): callback :mycallback, [[:char,…
G S
  • 35,511
  • 22
  • 84
  • 118
1
vote
1 answer

GENERAL_NAME_free error when using Aerospike from Ruby

I am trying to create a simple shared library libfoo.so which opens a connection to Aerospike server using a single function, waits for 3 seconds and closes the connection. libfoo.so has a single function open_then_close(char* host, int port). Then…
fade2black
  • 546
  • 1
  • 10
  • 26
1
vote
1 answer

Is it possible to make a function attached with ruby ffi private?

I have a share object lib that I attach functions from, using ruby ffi. I want to attach each function with an alias and make the alias' private, because calling them can be dangerous. I am wrapping each function in their own ruby module function,…
Rostepher
  • 201
  • 2
  • 8
1
vote
1 answer

How to bring methods from a module into the scope of the caller of a method in ruby?

The code should look like this: def bring_into_scope(module) #here the caller of the method should get methods from +module+ end class Bar def bar_method #do stuff end end class Foo def initialize(bar) bring_into_scope(bar) …
le_me
  • 3,089
  • 3
  • 26
  • 28
1
2 3