Skip to content

Commit 5ce76e9

Browse files
committed
Proof of concept of using PEP384s PyType_Spec
1 parent 4a05f27 commit 5ce76e9

File tree

3 files changed

+317
-102
lines changed

3 files changed

+317
-102
lines changed

src/class/basic.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
//! [typeobj docs](https://docs.python.org/3/c-api/typeobj.html)
1010
1111
use crate::callback::{HashCallbackOutput, IntoPyCallbackOutput};
12+
use crate::pyclass::maybe_push_slot;
1213
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};
1415

1516
/// Operators for the __richcmp__ method
1617
#[derive(Debug)]
@@ -147,13 +148,38 @@ pub struct PyObjectMethods {
147148

148149
#[doc(hidden)]
149150
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+
);
157183
}
158184
// Set functions used by `#[pyproto]`.
159185
pub fn set_str<T>(&mut self)

0 commit comments

Comments
 (0)