@@ -51,7 +51,7 @@ pub mod module {
51
51
fs, io,
52
52
os:: unix:: { ffi as ffi_ext, io:: RawFd } ,
53
53
} ;
54
- use strum_macros:: { EnumString , EnumVariantNames } ;
54
+ use strum_macros:: { EnumIter , EnumString } ;
55
55
56
56
#[ pyattr]
57
57
use libc:: { PRIO_PGRP , PRIO_PROCESS , PRIO_USER } ;
@@ -1681,7 +1681,7 @@ pub mod module {
1681
1681
1682
1682
// Copy from [nix::unistd::PathconfVar](https://docs.rs/nix/0.21.0/nix/unistd/enum.PathconfVar.html)
1683
1683
// Change enum name to fit python doc
1684
- #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq , EnumString , EnumVariantNames ) ]
1684
+ #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq , EnumIter , EnumString ) ]
1685
1685
#[ repr( i32 ) ]
1686
1686
#[ allow( non_camel_case_types) ]
1687
1687
pub enum PathconfVar {
@@ -1856,6 +1856,7 @@ pub mod module {
1856
1856
use nix:: errno:: { self , Errno } ;
1857
1857
1858
1858
Errno :: clear ( ) ;
1859
+ debug_assert_eq ! ( errno:: errno( ) , 0 ) ;
1859
1860
let raw = match path {
1860
1861
PathOrFd :: Path ( path) => {
1861
1862
let path = CString :: new ( path. into_bytes ( ) )
@@ -1881,22 +1882,18 @@ pub mod module {
1881
1882
pathconf ( PathOrFd :: Fd ( fd) , name, vm)
1882
1883
}
1883
1884
1884
- // TODO: this is expected to be run on macOS as a unix, but somehow not.
1885
- #[ cfg( target_os = "linux" ) ]
1886
1885
#[ pyattr]
1887
1886
fn pathconf_names ( vm : & VirtualMachine ) -> PyDictRef {
1888
- use std:: str:: FromStr ;
1889
- use strum:: VariantNames ;
1887
+ use strum:: IntoEnumIterator ;
1890
1888
let pathname = vm. ctx . new_dict ( ) ;
1891
- for variant in PathconfVar :: VARIANTS {
1889
+ for variant in PathconfVar :: iter ( ) {
1892
1890
// get the name of variant as a string to use as the dictionary key
1893
- let key = vm. ctx . new_str ( variant . to_string ( ) ) ;
1891
+ let key = vm. ctx . new_str ( format ! ( "{:?}" , variant ) ) ;
1894
1892
// get the enum from the string and convert it to an integer for the dictionary value
1895
- let value: PyObjectRef = vm
1896
- . ctx
1897
- . new_int ( PathconfVar :: from_str ( variant) . unwrap ( ) as u8 )
1898
- . into ( ) ;
1899
- pathname. set_item ( & * key, value, vm) . unwrap ( ) ;
1893
+ let value = vm. ctx . new_int ( variant as u8 ) ;
1894
+ pathname
1895
+ . set_item ( & * key, value. into ( ) , vm)
1896
+ . expect ( "dict set_item unexpectedly failed" ) ;
1900
1897
}
1901
1898
pathname
1902
1899
}
0 commit comments