Skip to content

Commit 2f017e6

Browse files
committed
fix merge
1 parent ac857bc commit 2f017e6

File tree

13 files changed

+67
-32
lines changed

13 files changed

+67
-32
lines changed

crates/stdlib/src/mmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ mod mmap {
388388
type Args = MmapNewArgs;
389389

390390
#[cfg(unix)]
391-
fn py_new(cls: &Py<PyType>,, args: Self::Args, vm: &VirtualMachine) -> PyResult {
391+
fn py_new(cls: &Py<PyType>, args: Self::Args, vm: &VirtualMachine) -> PyResult<Self> {
392392
use libc::{MAP_PRIVATE, MAP_SHARED, PROT_READ, PROT_WRITE};
393393

394394
let mut map_size = args.validate_new_args(vm)?;

crates/stdlib/src/openssl.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,8 +3552,8 @@ mod _ssl {
35523552
let entries = read_dir(root)
35533553
.map_err(|err| vm.new_simple_os_error(format!("read cert root: {}", err)))?;
35543554
for entry in entries {
3555-
let entry =
3556-
entry.map_err(|err| vm.new_simple_os_error(format!("iter cert root: {}", err)))?;
3555+
let entry = entry
3556+
.map_err(|err| vm.new_simple_os_error(format!("iter cert root: {}", err)))?;
35573557

35583558
let path = entry.path();
35593559
if !path.is_file() {
@@ -3563,7 +3563,11 @@ mod _ssl {
35633563
File::open(&path)
35643564
.and_then(|mut file| file.read_to_string(&mut combined_pem))
35653565
.map_err(|err| {
3566-
vm.new_simple_os_error(format!("open cert file {}: {}", path.display(), err))
3566+
vm.new_simple_os_error(format!(
3567+
"open cert file {}: {}",
3568+
path.display(),
3569+
err
3570+
))
35673571
})?;
35683572

35693573
combined_pem.push('\n');

crates/stdlib/src/socket.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,10 @@ mod _socket {
944944
ArgStrOrBytesLike::Buf(_) => ffi::OsStr::from_bytes(bytes).into(),
945945
ArgStrOrBytesLike::Str(s) => vm.fsencode(s)?,
946946
};
947-
socket2::SockAddr::unix(path)
948-
.map_err(|_| vm.new_simple_os_error("AF_UNIX path too long".to_owned()).into())
947+
socket2::SockAddr::unix(path).map_err(|_| {
948+
vm.new_simple_os_error("AF_UNIX path too long".to_owned())
949+
.into()
950+
})
949951
}
950952
c::AF_INET => {
951953
let tuple: PyTupleRef = addr.downcast().map_err(|obj| {
@@ -996,7 +998,9 @@ mod _socket {
996998
}
997999
Ok(addr6.into())
9981000
}
999-
_ => Err(vm.new_simple_os_error(format!("{caller}(): bad family")).into()),
1001+
_ => Err(vm
1002+
.new_simple_os_error(format!("{caller}(): bad family"))
1003+
.into()),
10001004
}
10011005
}
10021006

@@ -1762,8 +1766,9 @@ mod _socket {
17621766
#[pyfunction]
17631767
fn inet_ntoa(packed_ip: ArgBytesLike, vm: &VirtualMachine) -> PyResult<PyStrRef> {
17641768
let packed_ip = packed_ip.borrow_buf();
1765-
let packed_ip = <&[u8; 4]>::try_from(&*packed_ip)
1766-
.map_err(|_| vm.new_simple_os_error("packed IP wrong length for inet_ntoa".to_owned()))?;
1769+
let packed_ip = <&[u8; 4]>::try_from(&*packed_ip).map_err(|_| {
1770+
vm.new_simple_os_error("packed IP wrong length for inet_ntoa".to_owned())
1771+
})?;
17671772
Ok(vm.ctx.new_str(Ipv4Addr::from(*packed_ip).to_string()))
17681773
}
17691774

@@ -2033,7 +2038,11 @@ mod _socket {
20332038
.map_err(|_| vm.new_simple_os_error(ERROR_MSG.to_owned()))?
20342039
.octets()
20352040
.to_vec(),
2036-
_ => return Err(vm.new_simple_os_error("Address family not supported by protocol".to_owned())),
2041+
_ => {
2042+
return Err(
2043+
vm.new_simple_os_error("Address family not supported by protocol".to_owned())
2044+
);
2045+
}
20372046
};
20382047
Ok(ip_addr)
20392048
}

crates/stdlib/src/ssl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ mod _ssl {
15431543
// If there were errors but some certs loaded, just continue
15441544
// If NO certs loaded and there were errors, report the first error
15451545
if *self.x509_cert_count.read() == 0 && !result.errors.is_empty() {
1546-
return Err(vm.new_os_error(format!(
1546+
return Err(vm.new_simple_os_error(format!(
15471547
"Failed to load native certificates: {}",
15481548
result.errors[0]
15491549
)));
@@ -1889,8 +1889,8 @@ mod _ssl {
18891889

18901890
// Validate that the file contains DH parameters
18911891
// Read the file and check for DH PARAMETERS header
1892-
let contents =
1893-
std::fs::read_to_string(&path_str).map_err(|e| vm.new_simple_os_error(e.to_string()))?;
1892+
let contents = std::fs::read_to_string(&path_str)
1893+
.map_err(|e| vm.new_simple_os_error(e.to_string()))?;
18941894

18951895
if !contents.contains("BEGIN DH PARAMETERS")
18961896
&& !contents.contains("BEGIN X9.42 DH PARAMETERS")

crates/vm/src/builtins/bytes.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use crate::{
1515
common::{hash::PyHash, lock::PyMutex},
1616
convert::{ToPyObject, ToPyResult},
1717
function::{
18-
ArgBytesLike, ArgIndex, ArgIterable, Either, OptionalArg, OptionalOption, PyComparisonValue,
18+
ArgBytesLike, ArgIndex, ArgIterable, Either, FuncArgs, OptionalArg, OptionalOption,
19+
PyComparisonValue,
1920
},
2021
protocol::{
2122
BufferDescriptor, BufferMethods, PyBuffer, PyIterReturn, PyMappingMethods, PyNumberMethods,
@@ -93,7 +94,15 @@ pub(crate) fn init(context: &Context) {
9394
impl Constructor for PyBytes {
9495
type Args = ByteInnerNewOptions;
9596

96-
// TODO: Needs refactoring - get_bytes returns PyBytesRef, not PyResult<Self>
97+
fn py_new_ref(
98+
cls: PyRef<PyType>,
99+
args: FuncArgs,
100+
vm: &VirtualMachine,
101+
) -> PyResult<PyRef<Self>> {
102+
let options: Self::Args = args.bind(vm)?;
103+
options.get_bytes(cls, vm)
104+
}
105+
97106
fn py_new(cls: &Py<PyType>, options: Self::Args, vm: &VirtualMachine) -> PyResult<Self> {
98107
let _ = (cls, options, vm);
99108
todo!("PyBytes::py_new needs refactoring")

crates/vm/src/builtins/int.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl Constructor for PyInt {
214214

215215
// Optimization: return exact int as-is
216216
if cls.is(vm.ctx.types.int_type) && args.args.len() == 1 && args.kwargs.is_empty() {
217-
unsafe {
217+
unsafe {
218218
if args.args[0].class().is(vm.ctx.types.int_type) {
219219
let mut args = args;
220220
let int_arg = args.args.pop().expect("length checked");

crates/vm/src/builtins/type.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,10 @@ impl PyType {
500500
}
501501
debug_assert!(
502502
slots.basicsize >= base.slots.basicsize,
503-
"subclass basicsize ({}) must be >= base basicsize ({})",
503+
"subclass {} basicsize ({}) must be >= base {} basicsize ({})",
504+
slots.name,
504505
slots.basicsize,
506+
base.slots.name,
505507
base.slots.basicsize
506508
);
507509

crates/vm/src/exceptions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,8 @@ pub(super) mod types {
11951195
AsObject, Py, PyAtomicRef, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
11961196
VirtualMachine,
11971197
builtins::{
1198-
PyInt, PyStrRef, PyTupleRef, PyTypeRef, traceback::PyTracebackRef, tuple::IntoPyTuple,
1198+
PyInt, PyStrRef, PyTupleRef, PyType, PyTypeRef, traceback::PyTracebackRef,
1199+
tuple::IntoPyTuple,
11991200
},
12001201
convert::ToPyResult,
12011202
function::{ArgBytesLike, FuncArgs},

crates/vm/src/stdlib/io.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -880,9 +880,9 @@ mod _io {
880880
let ret = vm.call_method(self.check_init(vm)?, "seek", (pos, whence))?;
881881
let offset = get_offset(ret, vm)?;
882882
if offset < 0 {
883-
return Err(
884-
vm.new_simple_os_error(format!("Raw stream returned invalid position {offset}"))
885-
);
883+
return Err(vm.new_simple_os_error(format!(
884+
"Raw stream returned invalid position {offset}"
885+
)));
886886
}
887887
self.abs_pos = offset;
888888
Ok(offset)
@@ -926,9 +926,9 @@ mod _io {
926926
let ret = vm.call_method(raw, "tell", ())?;
927927
let offset = get_offset(ret, vm)?;
928928
if offset < 0 {
929-
return Err(
930-
vm.new_simple_os_error(format!("Raw stream returned invalid position {offset}"))
931-
);
929+
return Err(vm.new_simple_os_error(format!(
930+
"Raw stream returned invalid position {offset}"
931+
)));
932932
}
933933
self.abs_pos = offset;
934934
Ok(offset)
@@ -2748,7 +2748,9 @@ mod _io {
27482748
let final_decoded_chars = n_decoded.chars + decoded.char_len();
27492749
cookie.need_eof = true;
27502750
if final_decoded_chars < num_to_skip.chars {
2751-
return Err(vm.new_simple_os_error("can't reconstruct logical file position"));
2751+
return Err(
2752+
vm.new_simple_os_error("can't reconstruct logical file position")
2753+
);
27522754
}
27532755
}
27542756
}

crates/vm/src/stdlib/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ pub(super) mod _os {
480480
),
481481
);
482482

483-
return Err(unsafe {std::mem::transmute(x)} );
483+
return Err(unsafe { std::mem::transmute(x) });
484484
}
485485
// For unsetenv, size is key + '=' (no value, just clearing)
486486
#[cfg(windows)]

0 commit comments

Comments
 (0)