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

@@ -65,9 +65,10 @@
6565
6666 ## Notes
6767
68-The demo uses inline-quoted SQL with `Sql.q` for escaping, not bound
69-parameters. The reason: `sqlite3_bind_text`'s last argument is a
70-destructor callback (the `SQLITE_TRANSIENT` sentinel is `(void *)-1`),
71-and the MVP FFI can't yet construct a `:ptr` from a sentinel integer.
72-For real applications you'd write a tiny C helper that wraps `bind_text`
73-with `SQLITE_TRANSIENT` baked in and link it alongside.
68+The demo uses inline-quoted SQL with `Sql.q` for escaping, kept as the
69+minimal path through `prepare_v2` / `step` / `finalize`. For bound
70+parameters, `sqlite3_bind_text` is supported directly — pass `-1` as
71+the destructor argument to get `SQLITE_TRANSIENT` (`(void *)-1`); the
72+FFI accepts an integer literal in a `:ptr` arg slot and emits
73+`((void *)-1LL)`. See `sqlite3_lib.rb` for the `ffi_func` declaration
74+and `test/ffi_ptr_int_literal.rb` for the regression test.