Skip to content
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

stacker: 0.1.19 #117

Merged
merged 1 commit into from
Feb 21, 2025
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stacker"
version = "0.1.18"
version = "0.1.19"
edition = "2021"
rust-version = "1.63"
authors = ["Alex Crichton <[email protected]>", "Simonas Kazlauskas <[email protected]>"]
Expand All @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/rust-lang/stacker"
homepage = "https://github.com/rust-lang/stacker"
documentation = "https://docs.rs/stacker/0.1.15"
documentation = "https://docs.rs/stacker/0.1.19"
description = """
A stack growth library useful when implementing deeply recursive algorithms that
may accidentally blow the stack.
Expand Down
3 changes: 2 additions & 1 deletion src/backends/openbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ pub unsafe fn guess_os_stack_limit() -> Option<usize> {
if res != 0 {
return None;
}
Some(stackinfo.assume_init().ss_sp as usize - stackinfo.assume_init().ss_size)
let stackinfo = stackinfo.assume_init();
Some(stackinfo.ss_sp as usize - stackinfo.ss_size)
}
28 changes: 5 additions & 23 deletions src/backends/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,19 @@ use libc::pthread_getattr_np as get_attr;

pub unsafe fn guess_os_stack_limit() -> Option<usize> {
let mut attr = PthreadAttr::new()?;

handle_pthread_err(get_attr(libc::pthread_self(), attr.as_mut_ptr()))?;

(get_attr(libc::pthread_self(), &mut attr.0) == 0).then_some(())?;
let mut stackaddr = std::ptr::null_mut();
let mut stacksize = 0;
handle_pthread_err(libc::pthread_attr_getstack(
attr.as_mut_ptr(),
&mut stackaddr,
&mut stacksize,
))?;

(libc::pthread_attr_getstack(&attr.0, &mut stackaddr, &mut stacksize) == 0).then_some(())?;
Some(stackaddr as usize)
}

struct PthreadAttr(std::mem::MaybeUninit<libc::pthread_attr_t>);
struct PthreadAttr(libc::pthread_attr_t);

impl Drop for PthreadAttr {
fn drop(&mut self) {
unsafe {
let ret = libc::pthread_attr_destroy(self.0.as_mut_ptr());
let ret = libc::pthread_attr_destroy(&mut self.0);
if ret != 0 {
let err = std::io::Error::last_os_error();
panic!(
Expand All @@ -36,23 +29,12 @@ impl Drop for PthreadAttr {
}
}

fn handle_pthread_err(ret: libc::c_int) -> Option<()> {
if ret != 0 {
return None;
}
Some(())
}

impl PthreadAttr {
unsafe fn new() -> Option<Self> {
let mut attr = std::mem::MaybeUninit::<libc::pthread_attr_t>::uninit();
if libc::pthread_attr_init(attr.as_mut_ptr()) != 0 {
return None;
}
Some(PthreadAttr(attr))
}

fn as_mut_ptr(&mut self) -> *mut libc::pthread_attr_t {
self.0.as_mut_ptr()
Some(PthreadAttr(attr.assume_init()))
}
}
Loading