Skip to content

Commit

Permalink
Revert the FnMut changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentMazare committed Oct 14, 2021
1 parent 6e9ee4d commit 68c1932
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/types/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ unsafe extern "C" fn run_closure<F, R>(
kwargs: *mut ffi::PyObject,
) -> *mut ffi::PyObject
where
F: FnMut(&types::PyTuple, Option<&types::PyDict>) -> R + Send + 'static,
F: Fn(&types::PyTuple, Option<&types::PyDict>) -> R + Send + 'static,
R: crate::callback::IntoPyCallbackOutput<*mut ffi::PyObject>,
{
crate::callback_body!(py, {
let boxed_fn: &mut F = &mut *(ffi::PyCapsule_GetPointer(
capsule_ptr,
CLOSURE_CAPSULE_NAME.as_ptr() as *const _,
) as *mut F);
let boxed_fn: &F =
&*(ffi::PyCapsule_GetPointer(capsule_ptr, CLOSURE_CAPSULE_NAME.as_ptr() as *const _)
as *mut F);
let args = py.from_borrowed_ptr::<types::PyTuple>(args);
let kwargs = py.from_borrowed_ptr_or_opt::<types::PyDict>(kwargs);
boxed_fn(args, kwargs)
Expand All @@ -37,7 +36,7 @@ where

unsafe extern "C" fn drop_closure<F, R>(capsule_ptr: *mut ffi::PyObject)
where
F: FnMut(&types::PyTuple, Option<&types::PyDict>) -> R + Send + 'static,
F: Fn(&types::PyTuple, Option<&types::PyDict>) -> R + Send + 'static,
R: crate::callback::IntoPyCallbackOutput<*mut ffi::PyObject>,
{
let result = std::panic::catch_unwind(|| {
Expand Down Expand Up @@ -102,7 +101,7 @@ impl PyCFunction {
/// ```
pub fn new_closure<F, R>(f: F, py: Python) -> PyResult<&PyCFunction>
where
F: FnMut(&types::PyTuple, Option<&types::PyDict>) -> R + Send + 'static,
F: Fn(&types::PyTuple, Option<&types::PyDict>) -> R + Send + 'static,
R: crate::callback::IntoPyCallbackOutput<*mut ffi::PyObject>,
{
let function_ptr = Box::into_raw(Box::new(f));
Expand Down
3 changes: 2 additions & 1 deletion tests/test_pyfunction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ fn test_closure_counter() {
let gil = Python::acquire_gil();
let py = gil.python();

let mut counter = Box::new(0);
let counter = std::cell::RefCell::new(0);
let counter_fn =
move |_args: &types::PyTuple, _kwargs: Option<&types::PyDict>| -> PyResult<i32> {
let mut counter = counter.borrow_mut();
*counter += 1;
Ok(*counter)
};
Expand Down

0 comments on commit 68c1932

Please sign in to comment.