Skip to content

Commit 5677cf8

Browse files
committed
Apply coderabbit reviews
1 parent 35884dc commit 5677cf8

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

src/shell.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
152152
continuing_line = false;
153153
let result = match repl.readline(prompt) {
154154
ReadlineResult::Line(line) => {
155+
#[cfg(debug_assertions)]
155156
debug!("You entered {line:?}");
156157

157158
repl.add_history_entry(line.trim_end()).unwrap();

stdlib/src/csv.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,9 @@ mod _csv {
346346
if !rest.args.is_empty() {
347347
let arg_len = rest.args.len();
348348
if arg_len != 1 {
349-
return Err(vm.new_type_error(
350-
format!("field_size_limit() takes at most 1 argument ({arg_len} given)")
351-
.to_string(),
352-
));
349+
return Err(vm.new_type_error(format!(
350+
"field_size_limit() takes at most 1 argument ({arg_len} given)"
351+
)));
353352
}
354353
let Ok(new_size) = rest.args.first().unwrap().try_int(vm) else {
355354
return Err(vm.new_type_error("limit must be an integer".to_string()));

vm/src/frame.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,7 @@ impl ExecutingFrame<'_> {
16671667
.topmost_exception()
16681668
.ok_or_else(|| vm.new_runtime_error("No active exception to reraise".to_owned()))?,
16691669
};
1670+
#[cfg(debug_assertions)]
16701671
debug!("Exception raised: {exception:?} with cause: {cause:?}");
16711672
if let Some(cause) = cause {
16721673
exception.set_cause(cause);

vm/src/protocol/number.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl PyNumber<'_> {
476476
format!(
477477
"__int__ returned non-int (type {ret_class}). \
478478
The ability to return an instance of a strict subclass of int \
479-
is deprecated, and may be removed in a future version of Python.",
479+
is deprecated, and may be removed in a future version of Python."
480480
),
481481
1,
482482
vm,
@@ -509,7 +509,7 @@ impl PyNumber<'_> {
509509
format!(
510510
"__index__ returned non-int (type {ret_class}). \
511511
The ability to return an instance of a strict subclass of int \
512-
is deprecated, and may be removed in a future version of Python.",
512+
is deprecated, and may be removed in a future version of Python."
513513
),
514514
1,
515515
vm,
@@ -542,7 +542,7 @@ impl PyNumber<'_> {
542542
format!(
543543
"__float__ returned non-float (type {ret_class}). \
544544
The ability to return an instance of a strict subclass of float \
545-
is deprecated, and may be removed in a future version of Python.",
545+
is deprecated, and may be removed in a future version of Python."
546546
),
547547
1,
548548
vm,

vm/src/stdlib/ctypes/function.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use libffi::middle::{Arg, Cif, CodePtr, Type};
1313
use libloading::Symbol;
1414
use num_traits::ToPrimitive;
1515
use rustpython_common::lock::PyRwLock;
16+
use std::ffi::CString;
1617
use std::fmt::Debug;
1718

1819
// https://github.com/python/cpython/blob/4f8bb3947cfbc20f970ff9d9531e1132a9e95396/Modules/_ctypes/callproc.c#L15
@@ -77,10 +78,11 @@ impl Function {
7778
}
7879
})
7980
.collect::<PyResult<Vec<Type>>>()?;
80-
let terminated = format!("{function}\0");
81+
let c_function_name = CString::new(function)
82+
.map_err(|_| vm.new_value_error("Function name contains null bytes".to_string()))?;
8183
let pointer: Symbol<'_, FP> = unsafe {
8284
library
83-
.get(terminated.as_bytes())
85+
.get(c_function_name.as_bytes())
8486
.map_err(|err| err.to_string())
8587
.map_err(|err| vm.new_attribute_error(err))?
8688
};

0 commit comments

Comments
 (0)