nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: GuillaumeGomez/sysinfo
Pull request #1285 (2024-06-14 16:24:51)

Patched #1279 and #1284

GuillaumeGomez: Seems like some lints were released but they seem invalid. Going to take a look into another PR. Thanks for this fix!

Patch:
diff --git a/src/common/component.rs b/src/common/component.rs
index a92a4a3..531934d 100644
--- a/src/common/component.rs
+++ b/src/common/component.rs
@@ -170,6 +170,9 @@ impl Components {
     /// let mut components = Components::new();
     /// components.refresh_list();
     /// ```
+    ///
+    /// ⚠️ This function is not doing anything on macOS until
+    /// [this issue](https://github.com/GuillaumeGomez/sysinfo/issues/1279) is fixed.
     pub fn refresh_list(&mut self) {
         self.inner.refresh_list()
     }
diff --git a/src/lib.rs b/src/lib.rs
index 8142c05..477ba58 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -420,6 +420,13 @@ mod test {
         }
     }
 
+    #[test]
+    fn test_components_mac_m1() {
+        let mut components = Components::new();
+        components.refresh_list();
+        components.refresh_list();
+    }
+
     #[test]
     fn ensure_is_supported_is_set_correctly() {
         if MIN_USERS > 0 {
diff --git a/src/unix/apple/macos/component/arm.rs b/src/unix/apple/macos/component/arm.rs
index c5e4dce..2bd021c 100644
--- a/src/unix/apple/macos/component/arm.rs
+++ b/src/unix/apple/macos/component/arm.rs
@@ -50,7 +50,11 @@ impl ComponentsInner {
         &mut self.components
     }
 
+    #[allow(unreachable_code)]
     pub(crate) fn refresh_list(&mut self) {
+        // See issue https://github.com/GuillaumeGomez/sysinfo/issues/1279
+        return;
+
         self.components.clear();
 
         unsafe {


Test patch:
diff --git a/tests/system.rs b/tests/system.rs
index 8127290..08b18f9 100644
--- a/tests/system.rs
+++ b/tests/system.rs
@@ -213,8 +213,12 @@ fn test_refresh_memory() {
     }
 
     s.refresh_memory_specifics(sysinfo::MemoryRefreshKind::new().with_swap());
-    assert_ne!(s.total_swap(), 0);
-    assert_ne!(s.free_swap(), 0);
+    // SWAP can be 0 on macOS so this test is disabled
+    #[cfg(not(target_os = "macos"))]
+    {
+        assert_ne!(s.total_swap(), 0);
+        assert_ne!(s.free_swap(), 0);
+    }
 
     if is_linux {
         assert_ne!(s.total_memory(), 0);
@@ -226,8 +230,12 @@ fn test_refresh_memory() {
 
     let mut s = System::new();
     s.refresh_memory();
-    assert_ne!(s.total_swap(), 0);
-    assert_ne!(s.free_swap(), 0);
+    // SWAP can be 0 on macOS so this test is disabled
+    #[cfg(not(target_os = "macos"))]
+    {
+        assert_ne!(s.total_swap(), 0);
+        assert_ne!(s.free_swap(), 0);
+    }
     assert_ne!(s.total_memory(), 0);
     assert_ne!(s.free_memory(), 0);
 }
Repository: GuillaumeGomez/sysinfo
Pull request #904 (2023-01-01 07:30:54)

Fix processes_by_name(_exact) lifetimes
For these two functions, the lifetime of the returned process is currently coerced into being the smaller lifetime of either the System or the &str. This works fine when the System's lifetime is shorter than the &str, but creates errors when you do things like:
```rs
let process = system.processes_by_exact_name(&String::from("str")).next().unwrap();
```
This can be fixed by changing the bounds to say that the iterator needs to live as long as the System and &str, but the returned Process reference only needs to live as long as the System.


Patch:
diff --git a/src/traits.rs b/src/traits.rs
index e328386..ab7b69f 100644
--- a/src/traits.rs
+++ b/src/traits.rs
@@ -934,10 +934,10 @@ pub trait SystemExt: Sized + Debug + Default + Send + Sync {
     /// }
     /// ```
     // FIXME: replace the returned type with `impl Iterator<Item = &Process>` when it's supported!
-    fn processes_by_name<'a>(
+    fn processes_by_name<'a: 'b, 'b>(
         &'a self,
-        name: &'a str,
-    ) -> Box<dyn Iterator<Item = &'a Process> + 'a> {
+        name: &'b str,
+    ) -> Box<dyn Iterator<Item = &'a Process> + 'b> {
         Box::new(
             self.processes()
                 .values()
@@ -965,10 +965,10 @@ pub trait SystemExt: Sized + Debug + Default + Send + Sync {
     /// }
     /// ```
     // FIXME: replace the returned type with `impl Iterator<Item = &Process>` when it's supported!
-    fn processes_by_exact_name<'a>(
+    fn processes_by_exact_name<'a: 'b, 'b>(
         &'a self,
-        name: &'a str,
-    ) -> Box<dyn Iterator<Item = &'a Process> + 'a> {
+        name: &'b str,
+    ) -> Box<dyn Iterator<Item = &'a Process> + 'b> {
         Box::new(
             self.processes()
                 .values()


Test patch:
diff --git a/tests/process.rs b/tests/process.rs
index 3073ca6..f8f0576 100644
--- a/tests/process.rs
+++ b/tests/process.rs
@@ -517,3 +517,29 @@ fn test_wait_non_child() {
     assert!(before.elapsed() > std::time::Duration::from_millis(2000));
     assert!(before.elapsed() < std::time::Duration::from_millis(3000));
 }
+
+#[test]
+fn test_process_iterator_lifetimes() {
+    if !sysinfo::System::IS_SUPPORTED || cfg!(feature = "apple-sandbox") {
+        return;
+    }
+
+    let s = sysinfo::System::new_with_specifics(
+        sysinfo::RefreshKind::new().with_processes(sysinfo::ProcessRefreshKind::new()),
+    );
+
+    let process: Option<&sysinfo::Process>;
+    {
+        let name = String::from("");
+        // errors before PR #904: name does not live long enough
+        process = s.processes_by_name(&name).next();
+    }
+    process.unwrap();
+
+    let process: Option<&sysinfo::Process>;
+    {
+        // worked fine before and after: &'static str lives longer than System, error couldn't appear
+        process = s.processes_by_name("").next();
+    }
+    process.unwrap();
+}