@@ -19,7 +19,7 @@ pub fn set_inheritable(fd: BorrowedFd<'_>, inheritable: bool) -> nix::Result<()>
1919pub mod module {
2020 use crate :: {
2121 AsObject , Py , PyObjectRef , PyPayload , PyResult , VirtualMachine ,
22- builtins:: { PyDictRef , PyInt , PyListRef , PyStr , PyStrRef , PyTupleRef , PyType } ,
22+ builtins:: { PyDictRef , PyInt , PyListRef , PyStr , PyTupleRef , PyType } ,
2323 convert:: { IntoPyException , ToPyObject , TryFromObject } ,
2424 exceptions:: OSErrorBuilder ,
2525 function:: { Either , KwArgs , OptionalArg } ,
@@ -29,8 +29,14 @@ pub mod module {
2929 warn_if_bool_fd,
3030 } ,
3131 types:: { Constructor , Representable } ,
32- utils:: ToCString ,
3332 } ;
33+ #[ cfg( any(
34+ target_os = "android" ,
35+ target_os = "freebsd" ,
36+ target_os = "linux" ,
37+ target_os = "openbsd"
38+ ) ) ]
39+ use crate :: { builtins:: PyStrRef , utils:: ToCString } ;
3440 use alloc:: ffi:: CString ;
3541 use bitflags:: bitflags;
3642 use core:: ffi:: CStr ;
@@ -281,6 +287,7 @@ pub mod module {
281287
282288 impl TryFromObject for BorrowedFd < ' _ > {
283289 fn try_from_object ( vm : & VirtualMachine , obj : PyObjectRef ) -> PyResult < Self > {
290+ crate :: stdlib:: os:: warn_if_bool_fd ( & obj, vm) ?;
284291 let fd = i32:: try_from_object ( vm, obj) ?;
285292 if fd == -1 {
286293 return Err ( io:: Error :: from_raw_os_error ( libc:: EBADF ) . into_pyexception ( vm) ) ;
@@ -904,6 +911,37 @@ pub mod module {
904911 self . sched_priority . clone ( ) . to_pyobject ( vm)
905912 }
906913
914+ #[ pymethod]
915+ fn __reduce__ ( zelf : crate :: PyRef < Self > , vm : & VirtualMachine ) -> PyTupleRef {
916+ vm. new_tuple ( ( zelf. class ( ) . to_owned ( ) , ( zelf. sched_priority . clone ( ) , ) ) )
917+ }
918+
919+ #[ pymethod]
920+ fn __replace__ (
921+ zelf : crate :: PyRef < Self > ,
922+ args : crate :: function:: FuncArgs ,
923+ vm : & VirtualMachine ,
924+ ) -> PyResult < Self > {
925+ if !args. args . is_empty ( ) {
926+ return Err (
927+ vm. new_type_error ( "__replace__() takes no positional arguments" . to_owned ( ) )
928+ ) ;
929+ }
930+ let sched_priority = match args. kwargs . get ( "sched_priority" ) {
931+ Some ( v) => v. clone ( ) ,
932+ None => zelf. sched_priority . clone ( ) ,
933+ } ;
934+ // Check for unexpected keyword arguments
935+ for key in args. kwargs . keys ( ) {
936+ if key. as_str ( ) != "sched_priority" {
937+ return Err ( vm. new_type_error ( format ! (
938+ "__replace__() got an unexpected keyword argument '{key}'"
939+ ) ) ) ;
940+ }
941+ }
942+ Ok ( Self { sched_priority } )
943+ }
944+
907945 #[ cfg( any(
908946 target_os = "linux" ,
909947 target_os = "netbsd" ,
@@ -2091,7 +2129,11 @@ pub mod module {
20912129 let i = match obj. downcast :: < PyInt > ( ) {
20922130 Ok ( int) => int. try_to_primitive ( vm) ?,
20932131 Err ( obj) => {
2094- let s = PyStrRef :: try_from_object ( vm, obj) ?;
2132+ let s = obj. downcast :: < PyStr > ( ) . map_err ( |_| {
2133+ vm. new_type_error (
2134+ "configuration names must be strings or integers" . to_owned ( ) ,
2135+ )
2136+ } ) ?;
20952137 s. as_str ( )
20962138 . parse :: < PathconfVar > ( )
20972139 . map_err ( |_| vm. new_value_error ( "unrecognized configuration name" ) ) ?
0 commit comments