Skip to content

Commit affac62

Browse files
committed
Make PyNativeFunc Send + Sync
1 parent cef2689 commit affac62

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

vm/src/function.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ tuple_from_py_func_args!(A, B, C, D, E, F);
458458
pub type FunctionBox<T> = SmallBox<T, S1>;
459459

460460
/// A built-in Python function.
461-
pub type PyNativeFunc = FunctionBox<dyn Fn(&VirtualMachine, PyFuncArgs) -> PyResult + 'static>;
462-
// TODO: + Send + Sync
461+
pub type PyNativeFunc =
462+
FunctionBox<dyn Fn(&VirtualMachine, PyFuncArgs) -> PyResult + 'static + Send + Sync>;
463463

464464
/// Implemented by types that are or can generate built-in functions.
465465
///
@@ -481,7 +481,7 @@ pub trait IntoPyNativeFunc<T, R, VM> {
481481

482482
impl<F> IntoPyNativeFunc<PyFuncArgs, PyResult, VirtualMachine> for F
483483
where
484-
F: Fn(&VirtualMachine, PyFuncArgs) -> PyResult + 'static,
484+
F: Fn(&VirtualMachine, PyFuncArgs) -> PyResult + 'static + Send + Sync,
485485
{
486486
fn into_func(self) -> PyNativeFunc {
487487
smallbox!(self)
@@ -499,7 +499,7 @@ macro_rules! into_py_native_func_tuple {
499499
($(($n:tt, $T:ident)),*) => {
500500
impl<F, $($T,)* R> IntoPyNativeFunc<($(OwnedParam<$T>,)*), R, VirtualMachine> for F
501501
where
502-
F: Fn($($T,)* &VirtualMachine) -> R + 'static,
502+
F: Fn($($T,)* &VirtualMachine) -> R + 'static + Send + Sync,
503503
$($T: FromArgs,)*
504504
R: IntoPyObject,
505505
{
@@ -514,7 +514,7 @@ macro_rules! into_py_native_func_tuple {
514514

515515
impl<F, S, $($T,)* R> IntoPyNativeFunc<(RefParam<S>, $(OwnedParam<$T>,)*), R, VirtualMachine> for F
516516
where
517-
F: Fn(&S, $($T,)* &VirtualMachine) -> R + 'static,
517+
F: Fn(&S, $($T,)* &VirtualMachine) -> R + 'static + Send + Sync,
518518
S: PyValue,
519519
$($T: FromArgs,)*
520520
R: IntoPyObject,
@@ -530,7 +530,7 @@ macro_rules! into_py_native_func_tuple {
530530

531531
impl<F, $($T,)* R> IntoPyNativeFunc<($(OwnedParam<$T>,)*), R, ()> for F
532532
where
533-
F: Fn($($T,)*) -> R + 'static,
533+
F: Fn($($T,)*) -> R + 'static + Send + Sync,
534534
$($T: FromArgs,)*
535535
R: IntoPyObject,
536536
{
@@ -541,7 +541,7 @@ macro_rules! into_py_native_func_tuple {
541541

542542
impl<F, S, $($T,)* R> IntoPyNativeFunc<(RefParam<S>, $(OwnedParam<$T>,)*), R, ()> for F
543543
where
544-
F: Fn(&S, $($T,)*) -> R + 'static,
544+
F: Fn(&S, $($T,)*) -> R + 'static + Send + Sync,
545545
S: PyValue,
546546
$($T: FromArgs,)*
547547
R: IntoPyObject,

0 commit comments

Comments
 (0)