Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions crates/vm/src/stdlib/_ctypes/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,9 @@ fn build_result(
let mut result = convert_raw_result(&call_result, call_info, vm)?;

// Apply errcheck if set
if let Some(errcheck) = zelf.errcheck.read().as_ref() {
// Clone before calling Python so the callback can change errcheck.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the existing errcheck comment

The removed // Apply errcheck if set comment remains accurate after this refactor, so replacing it violates AGENTS.md's explicit restriction against rewriting existing comments unless they are factually wrong or contradict the new code. Retain the original comment and add the lock-lifetime explanation separately.

AGENTS.md reference: AGENTS.md:L165-L165

Useful? React with 👍 / 👎.

let errcheck = zelf.errcheck.read().clone();
if let Some(errcheck) = errcheck.as_ref() {
let args_tuple = PyTuple::new_ref(args.args.clone(), &vm.ctx);
let func_obj = zelf.as_object().to_owned();
let result_obj = result.clone().unwrap_or_else(|| vm.ctx.none());
Expand Down Expand Up @@ -1892,13 +1894,16 @@ impl Py<PyCFuncPtr> {

#[pygetset(setter)]
fn set_errcheck(&self, value: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
if vm.is_none(&value) {
*self.errcheck.write() = None;
let value = if vm.is_none(&value) {
None
} else if value.is_callable() {
*self.errcheck.write() = Some(value);
Some(value)
} else {
return Err(vm.new_type_error("errcheck must be a callable or None"));
}
};
let old = core::mem::replace(&mut *self.errcheck.write(), value);
// Finalizers on the previous callable can re-enter this setter.
drop(old);
Ok(())
}

Expand Down
Loading