Skip to content

Commit c30561a

Browse files
committed
Make PyGetSet ThreadSafe
1 parent 16887d3 commit c30561a

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

vm/src/obj/objgetset.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
use super::objtype::PyClassRef;
55
use crate::function::{FunctionBox, OptionalArg, OwnedParam, RefParam};
66
use crate::pyobject::{
7-
IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
8-
TypeProtocol,
7+
IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, ThreadSafe,
8+
TryFromObject, TypeProtocol,
99
};
1010
use crate::slots::SlotDescriptor;
1111
use crate::vm::VirtualMachine;
1212

13-
pub type PyGetterFunc = FunctionBox<dyn Fn(&VirtualMachine, PyObjectRef) -> PyResult>;
13+
pub type PyGetterFunc = FunctionBox<dyn Fn(&VirtualMachine, PyObjectRef) -> PyResult + Send + Sync>;
1414
pub type PySetterFunc =
15-
FunctionBox<dyn Fn(&VirtualMachine, PyObjectRef, PyObjectRef) -> PyResult<()>>;
15+
FunctionBox<dyn Fn(&VirtualMachine, PyObjectRef, PyObjectRef) -> PyResult<()> + Send + Sync>;
1616

1717
pub trait IntoPyGetterFunc<T> {
1818
fn into_getter(self) -> PyGetterFunc;
1919
}
2020

2121
impl<F, T, R> IntoPyGetterFunc<(OwnedParam<T>, R, VirtualMachine)> for F
2222
where
23-
F: Fn(T, &VirtualMachine) -> R + 'static,
23+
F: Fn(T, &VirtualMachine) -> R + 'static + Send + Sync,
2424
T: TryFromObject,
2525
R: IntoPyObject,
2626
{
@@ -34,7 +34,7 @@ where
3434

3535
impl<F, S, R> IntoPyGetterFunc<(RefParam<S>, R, VirtualMachine)> for F
3636
where
37-
F: Fn(&S, &VirtualMachine) -> R + 'static,
37+
F: Fn(&S, &VirtualMachine) -> R + 'static + Send + Sync,
3838
S: PyValue,
3939
R: IntoPyObject,
4040
{
@@ -48,7 +48,7 @@ where
4848

4949
impl<F, T, R> IntoPyGetterFunc<(OwnedParam<T>, R)> for F
5050
where
51-
F: Fn(T) -> R + 'static,
51+
F: Fn(T) -> R + 'static + Send + Sync,
5252
T: TryFromObject,
5353
R: IntoPyObject,
5454
{
@@ -59,7 +59,7 @@ where
5959

6060
impl<F, S, R> IntoPyGetterFunc<(RefParam<S>, R)> for F
6161
where
62-
F: Fn(&S) -> R + 'static,
62+
F: Fn(&S) -> R + 'static + Send + Sync,
6363
S: PyValue,
6464
R: IntoPyObject,
6565
{
@@ -90,7 +90,7 @@ pub trait IntoPySetterFunc<T> {
9090

9191
impl<F, T, V, R> IntoPySetterFunc<(OwnedParam<T>, V, R, VirtualMachine)> for F
9292
where
93-
F: Fn(T, V, &VirtualMachine) -> R + 'static,
93+
F: Fn(T, V, &VirtualMachine) -> R + 'static + Send + Sync,
9494
T: TryFromObject,
9595
V: TryFromObject,
9696
R: IntoPyNoResult,
@@ -106,7 +106,7 @@ where
106106

107107
impl<F, S, V, R> IntoPySetterFunc<(RefParam<S>, V, R, VirtualMachine)> for F
108108
where
109-
F: Fn(&S, V, &VirtualMachine) -> R + 'static,
109+
F: Fn(&S, V, &VirtualMachine) -> R + 'static + Send + Sync,
110110
S: PyValue,
111111
V: TryFromObject,
112112
R: IntoPyNoResult,
@@ -122,7 +122,7 @@ where
122122

123123
impl<F, T, V, R> IntoPySetterFunc<(OwnedParam<T>, V, R)> for F
124124
where
125-
F: Fn(T, V) -> R + 'static,
125+
F: Fn(T, V) -> R + 'static + Send + Sync,
126126
T: TryFromObject,
127127
V: TryFromObject,
128128
R: IntoPyNoResult,
@@ -134,7 +134,7 @@ where
134134

135135
impl<F, S, V, R> IntoPySetterFunc<(RefParam<S>, V, R)> for F
136136
where
137-
F: Fn(&S, V) -> R + 'static,
137+
F: Fn(&S, V) -> R + 'static + Send + Sync,
138138
S: PyValue,
139139
V: TryFromObject,
140140
R: IntoPyNoResult,
@@ -152,6 +152,8 @@ pub struct PyGetSet {
152152
// doc: Option<String>,
153153
}
154154

155+
impl ThreadSafe for PyGetSet {}
156+
155157
impl std::fmt::Debug for PyGetSet {
156158
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
157159
write!(

0 commit comments

Comments
 (0)