Skip to content

improve error handling #116

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

Merged
merged 16 commits into from
Feb 21, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make error handling code easier to read
  • Loading branch information
lovasoa committed Feb 18, 2025
commit 83c37faddc98e55279ed869f6955a74bbbdbf009
24 changes: 13 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
// Make sure the libstacker.a (implemented in C) is linked.
// See https://github.com/rust-lang/rust/issues/65610
#[link(name="stacker")]
extern {

Check warning on line 290 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Cargo.toml on windows-latest with nightly and

extern declarations without an explicit ABI are deprecated

Check warning on line 290 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Cargo.toml on windows-latest with nightly and --release

extern declarations without an explicit ABI are deprecated

Check warning on line 290 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Cargo.toml on windows-latest with nightly and -Zminimal-versions

extern declarations without an explicit ABI are deprecated

Check warning on line 290 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Cargo.toml on x86_64-pc-windows-gnu with nightly

extern declarations without an explicit ABI are deprecated

Check warning on line 290 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Cargo.toml on i686-pc-windows-gnu with nightly

extern declarations without an explicit ABI are deprecated
fn __stacker_get_current_fiber() -> *mut c_void;
}

Expand Down Expand Up @@ -422,10 +422,9 @@
unsafe fn handle_pthread_err(attr: *mut libc::pthread_attr_t, ret: libc::c_int) -> Option<()> {
if ret != 0 {
destroy_pthread_attr(attr);
None
} else {
Some(())
return None;
}
Some(())
}

unsafe fn guess_os_stack_limit() -> Option<usize> {
Expand All @@ -438,20 +437,23 @@
let pthread_ctx = attr.as_mut_ptr();

// Linux and BSD use different functions to get attributes of created thread
#[cfg(any(target_os = "linux", target_os="solaris", target_os = "netbsd"))]
let get_attr = libc::pthread_getattr_np;
#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "illumos"))]
let get_attr = libc::pthread_attr_get_np;
cfg_if! {
if #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "illumos"))] {
let get_attr = libc::pthread_attr_get_np;
} else {
let get_attr = libc::pthread_getattr_np;
}
};

// Get current thread's attributes
handle_pthread_err(pthread_ctx,
get_attr(libc::pthread_self(), pthread_ctx))?;
let res = get_attr(libc::pthread_self(), pthread_ctx);
handle_pthread_err(pthread_ctx, res)?;

// Get the stack address and size from attributes
let mut stackaddr = std::ptr::null_mut();
let mut stacksize = 0;
handle_pthread_err(pthread_ctx,
libc::pthread_attr_getstack(pthread_ctx, &mut stackaddr, &mut stacksize))?;
let res = libc::pthread_attr_getstack(pthread_ctx, &mut stackaddr, &mut stacksize);
handle_pthread_err(pthread_ctx, res)?;

destroy_pthread_attr(pthread_ctx);
Some(stackaddr as usize)
Expand Down
Loading