Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/auto_extension.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Automatic axtension loading
use super::ffi;
use crate::error::{check, to_sqlite_error};
use crate::{Connection, Result};
use crate::{Connection, Error, Result};
use std::os::raw::{c_char, c_int};
use std::panic::catch_unwind;

/// Automatic extension initialization routine
pub type AutoExtension = fn(Connection) -> Result<()>;
Expand All @@ -27,8 +28,12 @@ pub unsafe fn init_auto_extension(
pz_err_msg: *mut *mut c_char,
ax: AutoExtension,
) -> c_int {
let c = Connection::from_handle(db);
match c.and_then(ax) {
let r = catch_unwind(|| {
let c = Connection::from_handle(db);
c.and_then(ax)
})
.unwrap_or_else(|_| Err(Error::UnwindingPanic));
match r {
Err(e) => to_sqlite_error(&e, pz_err_msg),
_ => ffi::SQLITE_OK,
}
Expand Down
5 changes: 0 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ pub enum Error {
ModuleError(String),

/// An unwinding panic occurs in an UDF (user-defined function).
#[cfg(feature = "functions")]
#[cfg_attr(docsrs, doc(cfg(feature = "functions")))]
UnwindingPanic,

/// An error returned when
Expand Down Expand Up @@ -185,7 +183,6 @@ impl PartialEq for Error {
(Error::InvalidQuery, Error::InvalidQuery) => true,
#[cfg(feature = "vtab")]
(Error::ModuleError(s1), Error::ModuleError(s2)) => s1 == s2,
#[cfg(feature = "functions")]
(Error::UnwindingPanic, Error::UnwindingPanic) => true,
#[cfg(feature = "functions")]
(Error::GetAuxWrongType, Error::GetAuxWrongType) => true,
Expand Down Expand Up @@ -318,7 +315,6 @@ impl fmt::Display for Error {
Error::InvalidQuery => write!(f, "Query is not read-only"),
#[cfg(feature = "vtab")]
Error::ModuleError(ref desc) => write!(f, "{desc}"),
#[cfg(feature = "functions")]
Error::UnwindingPanic => write!(f, "unwinding panic"),
#[cfg(feature = "functions")]
Error::GetAuxWrongType => write!(f, "get_aux called with wrong type"),
Expand Down Expand Up @@ -375,7 +371,6 @@ impl error::Error for Error {
#[cfg(feature = "vtab")]
Error::ModuleError(_) => None,

#[cfg(feature = "functions")]
Error::UnwindingPanic => None,

#[cfg(feature = "functions")]
Expand Down