Skip to content

Commit

Permalink
stacker: 0.1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
nagisa committed Feb 21, 2025
1 parent 5eed05f commit 61411cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
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()))
}
}

0 comments on commit 61411cf

Please sign in to comment.