Commit 8379ca6e
8379ca6e8502Merged
Sam Ruby <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
test(ffi): regression test for integer literal in :ptr arg slot
The codegen arm for non-poly :ptr (compile_ffi_func_call) emits
((void *)<expr>), which makes integer literals usable as pointer
values at FFI call sites. This is the wire-shape that lets callers
pass sentinel pointer values like SQLITE_TRANSIENT
(((sqlite3_destructor_type)-1)) from Ruby as the literal -1 — the
same idiom ruby-ffi exposes via FFI::Pointer.new(-1).
The capability already works end-to-end. A round-trip spike against
sqlite3_bind_text(stmt, idx, "hello", 5, -1) + step + column_text
returns "hello" correctly; generated C is ((void *)-1LL), which
sqlite3 recognizes as SQLITE_TRANSIENT and copies the string
immediately. Test uses free(0) instead of sqlite3 to keep the
regression coverage independent of libsqlite3-dev availability in
CI — the meaningful regression is the codegen primitive, not the
sqlite path.
Updates examples/ffi/sqlite/sqlite3_lib.rb to reflect that bind_text with SQLITE_TRANSIENT is supported today, pointing at the new test for the underlying primitive.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 8379ca6e8502
- Parent
- f0063046556d
examples/ffi/sqlite/sqlite3_lib.rbmodifiedView file
# - exec for DDL + INSERT/UPDATE/DELETE# - prepare_v2 / step / finalize + column accessors for SELECT## Strings are passed inline into SQL; bind_text would also work but# requires the SQLITE_TRANSIENT destructor sentinel which the Spinel FFI# can't construct as a `:ptr` value yet. For string columns we escape# single quotes ourselves (`Sql.q`).# Strings are passed inline into SQL: `Sql.q` doubles single quotes# to handle the demo's well-known inputs. `bind_text` is also# supported — pass `-1` as the destructor argument for# `SQLITE_TRANSIENT` (`((sqlite3_destructor_type)-1)`), the same# wire-shape ruby-ffi exposes via `FFI::Pointer.new(-1)`. See# test/ffi_ptr_int_literal.rb for the underlying primitive.module SQL ffi_lib "sqlite3"test/ffi_ptr_int_literal.rbaddedView file
Loading diff…
test/ffi_ptr_int_literal.rb.expectedaddedView file
Loading diff…