Repository navigation
Conversation
The external pointer of a result now owns a `DbResultPtr`, a `boost::shared_ptr<DbResult>`, as that of a connection owns a `DbConnectionPtr`, so that a later layer can give an Arrow stream a share of the result. R's share is the only one, so a result is freed at the same moments as before, by `dbClearResult()` or by the finalizer. `~DbResult()` is virtual, because the shared pointer deletes a `SqliteResult` through a `DbResult*`. The result tag and the busy guard work as before. Ported from #856. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Question: make the disconnect test independent of the journal mode and the busy timeout?Carried over from #856's question, which nobody answered; this pull request ports #856 and its disconnect test, whose code comment now says what it relies on. The code links below point at #856's lines. The new test "disconnecting with an open result warns, the result holds the connection" checks that the finalizer releases the last result after
Kirill decides. If nobody decides, the test stays as it is, and the limitation stays checked in the "Accepted limitations". Generated by Claude Code |
…ude/rb-result-ptr Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
`result_create()` holds the new `DbResultPtr` in a `std::unique_ptr` until the finalizer of its external pointer is registered, so that a failed allocation in R no longer leaks the result, its statement and its share of the connection. It registers the finalizer through `cpp11::safe` for the same reason, and returns the external pointer's SEXP, as cpp11's move constructor would drop the tag and the finalizer. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
No change of behavior. The external pointer of a result now owns a
DbResultPtr, aboost::shared_ptr<DbResult>, as the external pointer of a connection owns aDbConnectionPtr. A later layer gives an Arrow stream a share of the result, so that the stream can share the result's lifetime.DbResult.hdeclaresDbResultPtrnext toDbConnectionPtrand makes~DbResult()virtual, because the shared pointer deletes theSqliteResultthatcreate_and_send_query()returns through aDbResult*.result_create()wraps the new result in a heap-allocatedDbResultPtrowned by the tagged external pointer.dbClearResult()(result_release()) and the finalizer delete thatDbResultPtr, which drops R's share. R's share is the only one, so a result, its statement and its share of the connection are freed at the same moments as before.as_cpp()conversions forDbResult*andSqliteResult*still check theRSQLite_resulttag, then read the result through the shared pointer.result_release()andresult_valid()keep the NULL-address handling for cleared, restored and untagged pointers, and the busy guard of fix:dbClearResult()refuses a result while one of its fetches or binds runs #934 looks through the shared pointer.result_fetch()and its error value from fix: The error of a fetch carries the rows it read before the error #945 are unchanged, as is the connection handling of fix: Connection entry points refuse a disconnected or foreign pointer #942. The checks for an empty shared pointer never fire today, becausecreate_and_send_query()throws instead of returningNULL.Tests: five tests ported from #856 to
test-dbClearResult.Rpin validity before and afterdbClearResult(), the error of every use of a cleared result, a result cleared by the next query, a result collected bygc()without being cleared, anddbDisconnect()with results in use, after which the last result keeps a read lock until it is collected. With the finalizer disabled, the last two fail. The new tests pass on the base as well. The full suite passes withNOT_CRAN=true(FAIL 0, WARN 3 from unavailable locales, SKIP 63, PASS 11328). A script of lifetime scenarios (clear thengc(), a clear refused while a fetch runs and done after,dbDisconnect()first, the connection collected before or together with an uncleared result, failing creates and create/clear loops, a serialized result, objects left to the exit finalizers) prints the same on the base and on this branch, also with a garbage collection every 20 allocations (gctorture2(20), with fewer loop iterations), and valgrind's memcheck reports no errors and no definitely or indirectly lost bytes.Still applies from #856: the disconnect test sees the finalizer through "database is locked" from a second connection, so it relies on SQLite's default rollback journal and on RSQLite setting no busy timeout by default (question on #856, #856 (comment), default kept: the test stays as it is and is adjusted if either default changes; a comment in the test now says so). #856's two review points are carried in: the virtual destructor, and the disconnect test's check that collecting the last result releases its lock.
Layer R2 of the rebuilt chain, planned in #880; based on #947. Ported from #856 (draft).
Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code