Commit ac73cd4f
ac73cd4fbf7fMerged
Sam Ruby <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
docs(examples/ffi/sqlite): retire stale "MVP FFI can't construct :ptr from sentinel" note
The Notes section described sqlite3_bind_text as unreachable from
Ruby because the FFI couldn't pass SQLITE_TRANSIENT ((void *)-1)
through a :ptr slot. That constraint was lifted by #576 — integer
literals in :ptr arg positions now compile to ((void *)<expr>),
and test/ffi_ptr_int_literal.rb guards the primitive. The header
comment in sqlite3_lib.rb (after 3db7ff0) already describes
bind_text as supported and declares the ffi_func, so the Notes
paragraph contradicts the same file's other voices.
Rewrite the Notes to reflect current reality: the demo keeps inline-
quoting as the minimal path, but bind_text works directly with -1
as the destructor argument, with pointers from sqlite3_lib.rb and
the regression test.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- ac73cd4fbf7f
- Parent
- aa69596f090f
examples/ffi/sqlite/README.mdmodifiedView file
## NotesThe demo uses inline-quoted SQL with `Sql.q` for escaping, not boundparameters. The reason: `sqlite3_bind_text`'s last argument is adestructor callback (the `SQLITE_TRANSIENT` sentinel is `(void *)-1`),and the MVP FFI can't yet construct a `:ptr` from a sentinel integer.For real applications you'd write a tiny C helper that wraps `bind_text`with `SQLITE_TRANSIENT` baked in and link it alongside.The demo uses inline-quoted SQL with `Sql.q` for escaping, kept as theminimal path through `prepare_v2` / `step` / `finalize`. For boundparameters, `sqlite3_bind_text` is supported directly — pass `-1` asthe destructor argument to get `SQLITE_TRANSIENT` (`(void *)-1`); theFFI accepts an integer literal in a `:ptr` arg slot and emits`((void *)-1LL)`. See `sqlite3_lib.rb` for the `ffi_func` declarationand `test/ffi_ptr_int_literal.rb` for the regression test.