Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestions for Ruby and Rust C-API #106

Open
misalcedo opened this issue Jun 30, 2021 · 0 comments
Open

Suggestions for Ruby and Rust C-API #106

misalcedo opened this issue Jun 30, 2021 · 0 comments

Comments

@misalcedo
Copy link

misalcedo commented Jun 30, 2021

I have an example repo of a bloom filter to learn about FFI. There I compare FFI gem, to C-extension, to pure ruby.
In writing the FFI version your docs were invaluable.

I have suggested improvements for ruby:

  1. ffi_lib can fail to load the library on macos as there seem to be some issues with setting the LD_LIBRARY_PATH when using rake and rspec. I worked around this by telling the FFI gem to search via normal means, but fallback to looking at Ruby's load path if that does not work. I am looking into it, but can't seem to find any existing docs on this behavior.
  2. Instead of exposing the auto-pointer class, create a pointer wrapper class so that the class is fully ruby-like to users (no need to expose the binding module. Also, by attaching the functions to the enclosing module callers can use an object-based API or a c-style api under the same namespace.

See https://github.com/misalcedo/bloom/blob/master/lib/bloom_ffi.rb

Only 1 for rust:
Using optionals for any of the method-like functions works really well compared to checking for null pointers and mapping the raw pointer to a reference ourselves.

See https://github.com/misalcedo/bloom/blob/master/src/lib.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant