diff --git a/Cargo.toml b/Cargo.toml index edc2f0e..8f6ab88 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "microseh" -version = "1.0.3" +version = "1.0.4" authors = ["sonodima"] edition = "2021" @@ -20,3 +20,9 @@ cc = "1.0" [features] default = ["std"] std = [] + +[package.metadata.docs.rs] +default-target = "x86_64-pc-windows-msvc" +rustc-args = ["--cfg", "docsrs"] +rustdoc-args = ["--cfg", "docsrs"] +targets = ["i686-pc-windows-msvc", "x86_64-pc-windows-msvc"] diff --git a/build.rs b/build.rs index 91cd743..42d49c1 100755 --- a/build.rs +++ b/build.rs @@ -1,5 +1,11 @@ +#[cfg(not(docsrs))] extern crate cc; +#[cfg(not(docsrs))] fn main() { + if std::env::var("HOST").unwrap().contains("gnu") { return; } cc::Build::new().file("src/stub.c").compile("sehstub"); } + +#[cfg(docsrs)] +fn main() {} diff --git a/src/lib.rs b/src/lib.rs index a5d91fe..8ef0a81 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,11 +13,21 @@ type HandledProc = unsafe extern "system" fn(*mut c_void); const MS_CATCHED: u32 = 0x1; const MS_DISABLED: u32 = 0x2; +#[cfg(not(docsrs))] extern "C" { #[link_name = "HandlerStub"] fn handler_stub(proc: HandledProc, closure: *mut c_void, exception: *mut Exception) -> u32; } +#[cfg(docsrs)] +unsafe fn handler_stub( + _proc: HandledProc, + _closure: *mut c_void, + _exception: *mut Exception, +) -> u32 { + MS_DISABLED +} + unsafe extern "system" fn handled_proc(closure: *mut c_void) where F: FnMut(), @@ -41,7 +51,7 @@ where /// /// * `Ok(())` - If the closure executed without throwing any exceptions. /// * `Err(Exception)` - If an exception occurred during the execution of the closure. -/// +/// /// # Examples /// /// ``` @@ -53,18 +63,18 @@ where /// println!("an exception occurred: {:?}", e); /// } /// ``` -/// +/// /// # Caveats -/// +/// /// If an exception occours within the closure, resources that require cleanup via\ /// the `Drop` trait, may not be properly released. -/// +/// /// As a rule of thumb, it's recommended not to define resources that implement\ /// the `Drop` trait inside the closure. Instead, allocate and manage these resources\ /// outside the closure, ensuring proper cleanup even if an exception occurs. -/// +/// /// # Panics -/// +/// /// If exception handling is disabled in the build, which occurs when the library is\ /// not built on Windows with Microsoft Visual C++. pub fn try_seh(mut closure: F) -> Result<(), Exception> @@ -89,7 +99,6 @@ mod tests { const INVALID_PTR: *mut i32 = core::mem::align_of::() as _; - #[test] #[cfg(feature = "std")] fn all_good() { @@ -110,7 +119,6 @@ mod tests { assert_eq!(ex.unwrap_err().code(), ExceptionCode::AccessViolation); } - #[test] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn access_violation_asm() {