Skip to content

Commit def1fb9

Browse files
committed
apply review
1 parent c4c7629 commit def1fb9

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

crates/vm/src/stdlib/os.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,10 +1748,10 @@ pub(super) mod _os {
17481748
#[cfg(all(unix, not(target_os = "redox")))]
17491749
impl StatvfsResultData {
17501750
fn from_statvfs(st: libc::statvfs) -> Self {
1751-
// Handle f_fsid which may be a struct on some platforms
1752-
// On most Unix systems, we just use 0 or try to get the value
1751+
// f_fsid is a struct on some platforms (e.g., Linux fsid_t) and a scalar on others.
1752+
// We extract raw bytes and interpret as a native-endian integer.
1753+
// Note: The value may differ across architectures due to endianness.
17531754
let f_fsid = {
1754-
// Use pointer cast to get raw bytes from fsid struct
17551755
let ptr = std::ptr::addr_of!(st.f_fsid) as *const u8;
17561756
let size = std::mem::size_of_val(&st.f_fsid);
17571757
if size >= 8 {
@@ -1790,15 +1790,19 @@ pub(super) mod _os {
17901790
#[pyfunction(name = "fstatvfs")]
17911791
fn statvfs(path: OsPathOrFd<'_>, vm: &VirtualMachine) -> PyResult {
17921792
let mut st: libc::statvfs = unsafe { std::mem::zeroed() };
1793-
let ret = match path {
1794-
OsPathOrFd::Path(path) => {
1795-
let cpath = path.into_cstring(vm)?;
1793+
let ret = match &path {
1794+
OsPathOrFd::Path(p) => {
1795+
let cpath = p.clone().into_cstring(vm)?;
17961796
unsafe { libc::statvfs(cpath.as_ptr(), &mut st) }
17971797
}
17981798
OsPathOrFd::Fd(fd) => unsafe { libc::fstatvfs(fd.as_raw(), &mut st) },
17991799
};
18001800
if ret != 0 {
1801-
return Err(io::Error::last_os_error().into_pyexception(vm));
1801+
return Err(OSErrorBuilder::with_filename(
1802+
&io::Error::last_os_error(),
1803+
path,
1804+
vm,
1805+
));
18021806
}
18031807
Ok(StatvfsResultData::from_statvfs(st).to_pyobject(vm))
18041808
}

crates/vm/src/stdlib/thread.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ pub(crate) mod _thread {
228228
if !self.mu.is_locked() {
229229
return Err(vm.new_runtime_error("release unlocked lock"));
230230
}
231+
debug_assert!(
232+
self.count.load(std::sync::atomic::Ordering::Relaxed) > 0,
233+
"RLock count underflow"
234+
);
231235
self.count
232236
.fetch_sub(1, std::sync::atomic::Ordering::Relaxed);
233237
unsafe { self.mu.unlock() };

0 commit comments

Comments
 (0)