-
Notifications
You must be signed in to change notification settings - Fork 0
Add FLOAT_ZERO_HEX database function and tests #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
48f2b1f
cfe4b3c
ad05a44
e058502
9e2049f
fb66731
b7e2259
c0ca462
18203be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||||||||||||||||||||||||||||||||
| use super::*; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| pub(crate) fn sqlite_transient() -> Option<unsafe extern "C" fn(*mut std::ffi::c_void)> { | ||||||||||||||||||||||||||||||||||||
| // SQLite uses the value -1 cast to a function pointer as a sentinel meaning | ||||||||||||||||||||||||||||||||||||
| // "make your own copy" for the result buffer (a.k.a. SQLITE_TRANSIENT). | ||||||||||||||||||||||||||||||||||||
| Some(unsafe { | ||||||||||||||||||||||||||||||||||||
| std::mem::transmute::<isize, unsafe extern "C" fn(*mut std::ffi::c_void)>(-1isize) | ||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /// Scalar SQLite function that returns the canonical zero Float as a hex string. | ||||||||||||||||||||||||||||||||||||
| pub(crate) unsafe extern "C" fn float_zero_hex( | ||||||||||||||||||||||||||||||||||||
| context: *mut sqlite3_context, | ||||||||||||||||||||||||||||||||||||
| argc: c_int, | ||||||||||||||||||||||||||||||||||||
| _argv: *mut *mut sqlite3_value, | ||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick Document FFI safety invariants. Brief “Safety” notes help maintainers keep this -/// Scalar SQLite function that returns the canonical zero Float as a hex string.
+/// Scalar SQLite function that returns the canonical zero Float as a hex string.
+///
+/// Safety:
+/// - Called by SQLite with a valid `context`.
+/// - `argc` must be 0; `_argv` may be null and is ignored.
+/// - Result uses SQLITE_TRANSIENT so no lifetime ties to Rust memory.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @findolor Understood, I'll skip the FFI safety documentation suggestion. Thanks for the clarification! 🧠 Learnings used |
||||||||||||||||||||||||||||||||||||
| if argc != 0 { | ||||||||||||||||||||||||||||||||||||
| sqlite3_result_error( | ||||||||||||||||||||||||||||||||||||
| context, | ||||||||||||||||||||||||||||||||||||
| c"FLOAT_ZERO_HEX() does not take any arguments".as_ptr(), | ||||||||||||||||||||||||||||||||||||
| -1, | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| sqlite3_result_error_code(context, SQLITE_MISUSE); | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| let zero_hex = Float::default().as_hex(); | ||||||||||||||||||||||||||||||||||||
| let zero_hex_ptr = zero_hex.as_ptr() as *const c_char; | ||||||||||||||||||||||||||||||||||||
| let zero_hex_len = zero_hex.len() as c_int; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| sqlite3_result_text(context, zero_hex_ptr, zero_hex_len, sqlite_transient()); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
0xgleb marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,4 +12,4 @@ | |
| "sideEffects": [ | ||
| "./snippets/*" | ||
| ] | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add some tests to this module?