|
1 | 1 | //! Implementation details of `#[pymodule]` which need to be accessible from proc-macro generated code. |
2 | 2 |
|
3 | | -#[cfg(Py_3_13)] |
4 | | -use std::sync::Once; |
5 | 3 | use std::{ |
6 | 4 | cell::UnsafeCell, |
7 | 5 | ffi::CStr, |
@@ -51,10 +49,6 @@ pub struct ModuleDef { |
51 | 49 | module: PyOnceLock<Py<PyModule>>, |
52 | 50 | /// Whether or not the module supports running without the GIL |
53 | 51 | gil_used: bool, |
54 | | - /// Guard to allow updating the `Py_mod_gil` slot within `ffi_def` |
55 | | - /// before first use. |
56 | | - #[cfg(Py_3_13)] |
57 | | - gil_used_once: Once, |
58 | 52 | } |
59 | 53 |
|
60 | 54 | unsafe impl Sync for ModuleDef {} |
@@ -102,21 +96,16 @@ impl ModuleDef { |
102 | 96 | interpreter: AtomicI64::new(-1), |
103 | 97 | module: PyOnceLock::new(), |
104 | 98 | gil_used: true, |
105 | | - #[cfg(Py_3_13)] |
106 | | - gil_used_once: Once::new(), |
107 | 99 | } |
108 | 100 | } |
109 | 101 |
|
110 | 102 | pub fn init_multi_phase(&'static self, _py: Python<'_>, _gil_used: bool) -> *mut ffi::PyObject { |
111 | | - // Once the ffi_def has been used, we can no longer modify, so we set the once. |
112 | | - #[cfg(Py_3_13)] |
113 | | - self.gil_used_once.call_once(|| {}); |
114 | 103 | unsafe { ffi::PyModuleDef_Init(self.ffi_def.get()) } |
115 | 104 | } |
116 | 105 |
|
117 | 106 | /// Builds a module object directly. Used for [`#[pymodule]`][crate::pymodule] submodules. |
118 | 107 | #[cfg_attr(any(Py_LIMITED_API, not(Py_GIL_DISABLED)), allow(unused_variables))] |
119 | | - pub fn make_module(&'static self, py: Python<'_>, gil_used: bool) -> PyResult<Py<PyModule>> { |
| 108 | + pub fn make_module(&'static self, py: Python<'_>, _gil_used: bool) -> PyResult<Py<PyModule>> { |
120 | 109 | // Check the interpreter ID has not changed, since we currently have no way to guarantee |
121 | 110 | // that static data is not reused across interpreters. |
122 | 111 | // |
@@ -171,42 +160,6 @@ impl ModuleDef { |
171 | 160 | kwargs.set_item("name", name)?; |
172 | 161 | let spec = simple_ns.call((), Some(&kwargs))?; |
173 | 162 |
|
174 | | - // If the first time writing this ffi def, we can inherit `gil_used` from parent |
175 | | - // modules. |
176 | | - // |
177 | | - // TODO: remove this once we default to `gil_used = false` (i.e. assume free-threading |
178 | | - // support in extensions). This is purely a convenience so that users only need to |
179 | | - // annotate the top-level module. |
180 | | - // |
181 | | - // SAFETY: |
182 | | - // - ffi_def is known to be non-null |
183 | | - // - we check slots is non-null |
184 | | - // - it is valid for a slot to be zeroed |
185 | | - // - we are writing to the slot under the protection of a `Once`. |
186 | | - #[cfg(Py_3_13)] |
187 | | - self.gil_used_once.call_once(|| { |
188 | | - // SAFETY: ffi_def is non-null |
189 | | - let slots = unsafe { (*ffi_def).m_slots }; |
190 | | - if !slots.is_null() { |
191 | | - let mut slot_ptr = slots; |
192 | | - // SAFETY: non-null slots pointer |
193 | | - while unsafe { *slot_ptr != ZEROED_SLOT } { |
194 | | - // SAFETY: no other accessors due to call_once guard |
195 | | - let slot = unsafe { &mut *slot_ptr }; |
196 | | - if slot.slot == ffi::Py_mod_gil { |
197 | | - slot.value = if gil_used { |
198 | | - ffi::Py_MOD_GIL_USED |
199 | | - } else { |
200 | | - ffi::Py_MOD_GIL_NOT_USED |
201 | | - }; |
202 | | - break; |
203 | | - } |
204 | | - // SAFETY: we have guaranteed there is a trailer zeroed slot |
205 | | - slot_ptr = unsafe { slot_ptr.add(1) }; |
206 | | - } |
207 | | - } |
208 | | - }); |
209 | | - |
210 | 163 | self.module |
211 | 164 | .get_or_try_init(py, || { |
212 | 165 | let def = self.ffi_def.get(); |
|
0 commit comments