Register custom functions via the SQLite C API directly#8
Merged
Conversation
Call sqlite3_create_function_v2 with @convention(c) function pointers and a retained context pointer, instead of SQLite.swift's createFunction. SQLite.swift registers the callback as a @convention(block) closure cast to a raw pointer, which is unreliable off Apple platforms and segfaults on Linux (upstream stephencelis/SQLite.swift#1071). A plain C function pointer works everywhere. - New CustomFunction.swift: C-API registration, argument/result marshalling between sqlite3_value/context and AttributeValue, with the SQLite C module imported from the system SQLite3 on Apple and the embedded copy elsewhere. - Package.swift depends on stephencelis/CSQLite so the C API is available on Linux/Android where the system SQLite3 module isn't. - Removed the Darwin-only gate on the custom-function tests; they now run on every platform.
R*Tree is an optional SQLite compile-time feature (SQLITE_ENABLE_RTREE), present in the system SQLite on Apple platforms but not in the embedded SQLite used on Linux. Gate the app-managed R*Tree test on a runtime capability probe so it runs where rtree exists and is skipped otherwise. The custom-function tests themselves now pass on every platform via the C-API registration.
Compare distance filtering/sorting via the registered SQL `distance` function
(executed in SQLite) against fetching every row and filtering/sorting in Swift.
Two scenarios: a selective radius filter+sort, and a full sort with no filter.
Opt-in via the BENCHMARK environment variable so the 100k-row dataset doesn't
slow the normal test matrix:
BENCHMARK=1 swift test -c release --filter Benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.