Use catch_unwind in init_auto_extension (#1489)

Use catch_unwind in init_auto_extension
This commit is contained in:
gwenn 2024-03-31 13:22:00 +02:00 committed by GitHub
parent d8bcd4d28a
commit a0b410eb86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View File

@ -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<()>;
@ -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,
}

View File

@ -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
@ -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,
@ -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"),
@ -375,7 +371,6 @@ impl error::Error for Error {
#[cfg(feature = "vtab")]
Error::ModuleError(_) => None,
#[cfg(feature = "functions")]
Error::UnwindingPanic => None,
#[cfg(feature = "functions")]