Skip to content

Suggestions for Ruby and Rust C-API #106

@misalcedo

Description

@misalcedo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions