-
Notifications
You must be signed in to change notification settings - Fork 3
handle panics #66
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
handle panics #66
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| -- Load the memvfs extension and open a new connection using it | ||
| -- Build the memvfs extension using the following command: | ||
| -- cargo build --example memvfs --features dynamic,std | ||
|
|
||
| -- uncomment to enable verbose logs | ||
| -- .log stderr | ||
|
|
||
| .load target/debug/examples/libmemvfs.so | ||
| .open main.db | ||
| .mode table | ||
| .log stdout | ||
|
|
||
| .databases | ||
| .vfsinfo | ||
|
|
||
| -- ensure that panics are handled | ||
| pragma memvfs_panic; | ||
|
|
||
| -- but they cause all future calls to also fail! | ||
| CREATE TABLE t1(a, b); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #![no_std] | ||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
| extern crate alloc; | ||
|
|
||
| pub mod vars { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,9 @@ pub const DEFAULT_DEVICE_CHARACTERISTICS: i32 = | |||||
| /// A `SQLite3` extended error code | ||||||
| pub type SqliteErr = i32; | ||||||
|
|
||||||
| // construct a custom SQLITE_INTERNAL error code for tracking panics | ||||||
| pub const ERROR_PANIC: SqliteErr = vars::SQLITE_INTERNAL | (128 << 8); | ||||||
|
|
||||||
| pub type VfsResult<T> = Result<T, SqliteErr>; | ||||||
|
|
||||||
| // FileWrapper needs to be repr(C) and have sqlite3_file as it's first member | ||||||
|
|
@@ -79,6 +82,29 @@ impl PragmaErr { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[cfg(feature = "std")] | ||||||
| fn fallible(mut cb: impl FnMut() -> Result<i32, SqliteErr>) -> i32 { | ||||||
| use std::sync::atomic::Ordering; | ||||||
| use std::{panic::AssertUnwindSafe, sync::atomic::AtomicBool}; | ||||||
|
|
||||||
| // once we panic, all future calls into the VFS will also panic as we can't | ||||||
| // be sure that we are unwind safe | ||||||
| static POISONED: AtomicBool = AtomicBool::new(false); | ||||||
| if POISONED.load(Ordering::Relaxed) { | ||||||
|
||||||
| if POISONED.load(Ordering::Relaxed) { | |
| if POISONED.load(Ordering::Acquire) { |
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.
The public constant ERROR_PANIC lacks documentation. Since this is a public API that defines a custom SQLite extended error code for panic tracking, it should have a doc comment explaining its purpose, when it's returned, and how it's constructed from SQLITE_INTERNAL.