@@ -9,8 +9,8 @@ use std::{
9
9
sync:: atomic:: { AtomicPtr , Ordering } ,
10
10
} ;
11
11
12
- /// Defines what we need for method protocols.
13
- /// Stub implementations are for rust-numpy.
12
+ /// Defines all methods for object protocols.
13
+ // Note: stub implementations are for rust-numpy. Please remove them .
14
14
pub trait PyProtoMethods {
15
15
fn async_methods ( ) -> Option < NonNull < PyAsyncMethods > > {
16
16
None
@@ -41,42 +41,44 @@ pub trait PyProtoMethods {
41
41
}
42
42
}
43
43
44
- /// Indicates that a type has a protocol registry.
44
+ /// Indicates that a type has a protocol registry. Implemented by `#[pyclass]`.
45
45
#[ doc( hidden) ]
46
46
pub trait HasProtoRegistry : Sized + ' static {
47
47
fn registry ( ) -> & ' static PyProtoRegistry ;
48
48
}
49
49
50
50
impl < T : HasProtoRegistry > PyProtoMethods for T {
51
51
fn async_methods ( ) -> Option < NonNull < PyAsyncMethods > > {
52
- NonNull :: new ( Self :: registry ( ) . async_methods . load ( Ordering :: SeqCst ) )
52
+ NonNull :: new ( Self :: registry ( ) . async_methods . load ( Ordering :: Relaxed ) )
53
53
}
54
54
fn basic_methods ( ) -> Option < NonNull < PyObjectMethods > > {
55
- NonNull :: new ( Self :: registry ( ) . basic_methods . load ( Ordering :: SeqCst ) )
55
+ NonNull :: new ( Self :: registry ( ) . basic_methods . load ( Ordering :: Relaxed ) )
56
56
}
57
57
fn buffer_methods ( ) -> Option < NonNull < PyBufferProcs > > {
58
- NonNull :: new ( Self :: registry ( ) . buffer_methods . load ( Ordering :: SeqCst ) )
58
+ NonNull :: new ( Self :: registry ( ) . buffer_methods . load ( Ordering :: Relaxed ) )
59
59
}
60
60
fn descr_methods ( ) -> Option < NonNull < PyDescrMethods > > {
61
- NonNull :: new ( Self :: registry ( ) . descr_methods . load ( Ordering :: SeqCst ) )
61
+ NonNull :: new ( Self :: registry ( ) . descr_methods . load ( Ordering :: Relaxed ) )
62
62
}
63
63
fn gc_methods ( ) -> Option < NonNull < PyGCMethods > > {
64
- NonNull :: new ( Self :: registry ( ) . gc_methods . load ( Ordering :: SeqCst ) )
64
+ NonNull :: new ( Self :: registry ( ) . gc_methods . load ( Ordering :: Relaxed ) )
65
65
}
66
66
fn mapping_methods ( ) -> Option < NonNull < PyMappingMethods > > {
67
- NonNull :: new ( Self :: registry ( ) . mapping_methods . load ( Ordering :: SeqCst ) )
67
+ NonNull :: new ( Self :: registry ( ) . mapping_methods . load ( Ordering :: Relaxed ) )
68
68
}
69
69
fn number_methods ( ) -> Option < NonNull < PyNumberMethods > > {
70
- NonNull :: new ( Self :: registry ( ) . number_methods . load ( Ordering :: SeqCst ) )
70
+ NonNull :: new ( Self :: registry ( ) . number_methods . load ( Ordering :: Relaxed ) )
71
71
}
72
72
fn iter_methods ( ) -> Option < NonNull < PyIterMethods > > {
73
- NonNull :: new ( Self :: registry ( ) . iter_methods . load ( Ordering :: SeqCst ) )
73
+ NonNull :: new ( Self :: registry ( ) . iter_methods . load ( Ordering :: Relaxed ) )
74
74
}
75
75
fn sequence_methods ( ) -> Option < NonNull < PySequenceMethods > > {
76
- NonNull :: new ( Self :: registry ( ) . sequence_methods . load ( Ordering :: SeqCst ) )
76
+ NonNull :: new ( Self :: registry ( ) . sequence_methods . load ( Ordering :: Relaxed ) )
77
77
}
78
78
}
79
79
80
+ /// Stores all method protocols.
81
+ /// Used in the proc-macro code as a static variable.
80
82
#[ doc( hidden) ]
81
83
pub struct PyProtoRegistry {
82
84
/// Async protocols.
@@ -115,38 +117,38 @@ impl PyProtoRegistry {
115
117
}
116
118
pub fn set_async_methods ( & self , methods : PyAsyncMethods ) {
117
119
self . async_methods
118
- . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: SeqCst )
120
+ . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: Relaxed )
119
121
}
120
122
pub fn set_basic_methods ( & self , methods : PyObjectMethods ) {
121
123
self . basic_methods
122
- . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: SeqCst )
124
+ . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: Relaxed )
123
125
}
124
126
pub fn set_buffer_methods ( & self , methods : PyBufferProcs ) {
125
127
self . buffer_methods
126
- . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: SeqCst )
128
+ . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: Relaxed )
127
129
}
128
130
pub fn set_descr_methods ( & self , methods : PyDescrMethods ) {
129
131
self . descr_methods
130
- . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: SeqCst )
132
+ . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: Relaxed )
131
133
}
132
134
pub fn set_gc_methods ( & self , methods : PyGCMethods ) {
133
135
self . gc_methods
134
- . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: SeqCst )
136
+ . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: Relaxed )
135
137
}
136
138
pub fn set_mapping_methods ( & self , methods : PyMappingMethods ) {
137
139
self . mapping_methods
138
- . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: SeqCst )
140
+ . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: Relaxed )
139
141
}
140
142
pub fn set_number_methods ( & self , methods : PyNumberMethods ) {
141
143
self . number_methods
142
- . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: SeqCst )
144
+ . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: Relaxed )
143
145
}
144
146
pub fn set_iter_methods ( & self , methods : PyIterMethods ) {
145
147
self . iter_methods
146
- . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: SeqCst )
148
+ . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: Relaxed )
147
149
}
148
150
pub fn set_sequence_methods ( & self , methods : PySequenceMethods ) {
149
151
self . sequence_methods
150
- . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: SeqCst )
152
+ . store ( Box :: into_raw ( Box :: new ( methods) ) , Ordering :: Relaxed )
151
153
}
152
154
}
0 commit comments