Ivan FB 24a56032af
Fix Rust callbacks dereference msg without a null check (rust.nim:272, 317). CStr::from_ptr(msg) is UB if msg == nullptr. The C++ side guards with msg ? ... : "". The Nim side
appears to always pass a non-null pointer, but soundness across an FFI boundary shouldn't hinge on a producer's discipline — the Rust receiver should null-check. Especially
  since the C ABI signature here is the one downstream consumers will rely on indefinitely.
2026-05-11 09:40:33 +02:00
..
2026-05-10 11:38:42 +02:00
2026-05-10 11:38:41 +02:00

nim_timer example

This example is a self-contained Nimble project demonstrating how to import nim-ffi and use the .ffiCtor. / .ffi. abstraction.

Usage

  1. Change into the example directory:

    cd examples/nim_timer
    
  2. Install the local ffi dependency:

    nimble install -y ../..
    
  3. Build the example library:

    nimble build
    
  4. Generate bindings:

    nimble genbindings_rust
    nimble genbindings_cpp
    

Rust example clients

The Rust client lives in examples/nim_timer/rust_client.

  • Run the sync example:

    cd examples/nim_timer/rust_client
    cargo run --bin rust_client
    
  • Run the Tokio example:

    cd examples/nim_timer/rust_client
    cargo run --bin tokio_client
    

C++ example

The generated C++ example lives in examples/nim_timer/cpp_bindings.

Build and run it with:

cd examples/nim_timer/cpp_bindings
cmake -S . -B build
cmake --build build
./build/example