|
9 | 9 | //! [typeobj docs](https://docs.python.org/3/c-api/typeobj.html)
|
10 | 10 |
|
11 | 11 | use crate::callback::{HashCallbackOutput, IntoPyCallbackOutput};
|
| 12 | +use crate::pyclass::maybe_push_slot; |
12 | 13 | use crate::{exceptions, ffi, FromPyObject, PyAny, PyCell, PyClass, PyErr, PyObject, PyResult};
|
13 |
| -use std::os::raw::c_int; |
| 14 | +use std::os::raw::{c_int, c_void}; |
14 | 15 |
|
15 | 16 | /// Operators for the __richcmp__ method
|
16 | 17 | #[derive(Debug)]
|
@@ -147,13 +148,38 @@ pub struct PyObjectMethods {
|
147 | 148 |
|
148 | 149 | #[doc(hidden)]
|
149 | 150 | impl PyObjectMethods {
|
150 |
| - pub(crate) fn update_typeobj(&self, type_object: &mut ffi::PyTypeObject) { |
151 |
| - type_object.tp_str = self.tp_str; |
152 |
| - type_object.tp_repr = self.tp_repr; |
153 |
| - type_object.tp_hash = self.tp_hash; |
154 |
| - type_object.tp_getattro = self.tp_getattro; |
155 |
| - type_object.tp_richcompare = self.tp_richcompare; |
156 |
| - type_object.tp_setattro = self.tp_setattro; |
| 151 | + pub(crate) fn update_slots(&self, slots: &mut Vec<ffi::PyType_Slot>) { |
| 152 | + maybe_push_slot(slots, ffi::Py_tp_str, self.tp_str.map(|v| v as *mut c_void)); |
| 153 | + maybe_push_slot( |
| 154 | + slots, |
| 155 | + ffi::Py_tp_repr, |
| 156 | + self.tp_repr.map(|v| v as *mut c_void), |
| 157 | + ); |
| 158 | + maybe_push_slot( |
| 159 | + slots, |
| 160 | + ffi::Py_tp_hash, |
| 161 | + self.tp_hash.map(|v| v as *mut c_void), |
| 162 | + ); |
| 163 | + maybe_push_slot( |
| 164 | + slots, |
| 165 | + ffi::Py_tp_getattro, |
| 166 | + self.tp_getattro.map(|v| v as *mut c_void), |
| 167 | + ); |
| 168 | + maybe_push_slot( |
| 169 | + slots, |
| 170 | + ffi::Py_tp_richcompare, |
| 171 | + self.tp_richcompare.map(|v| v as *mut c_void), |
| 172 | + ); |
| 173 | + maybe_push_slot( |
| 174 | + slots, |
| 175 | + ffi::Py_tp_setattro, |
| 176 | + self.tp_setattro.map(|v| v as *mut c_void), |
| 177 | + ); |
| 178 | + maybe_push_slot( |
| 179 | + slots, |
| 180 | + ffi::Py_nb_bool, |
| 181 | + self.nb_bool.map(|v| v as *mut c_void), |
| 182 | + ); |
157 | 183 | }
|
158 | 184 | // Set functions used by `#[pyproto]`.
|
159 | 185 | pub fn set_str<T>(&mut self)
|
|
0 commit comments