@@ -41,6 +41,7 @@ impl Default for PyTpFlags {
4141}
4242
4343pub ( crate ) type GenericMethod = fn ( PyObjectRef , PyFuncArgs , & VirtualMachine ) -> PyResult ;
44+ pub ( crate ) type DelFunc = fn ( & PyObjectRef , & VirtualMachine ) -> PyResult < ( ) > ;
4445pub ( crate ) type DescrGetFunc =
4546 fn ( PyObjectRef , Option < PyObjectRef > , Option < PyObjectRef > , & VirtualMachine ) -> PyResult ;
4647pub ( crate ) type HashFunc = fn ( & PyObjectRef , & VirtualMachine ) -> PyResult < PyHash > ;
@@ -50,6 +51,7 @@ pub struct PyClassSlots {
5051 pub flags : PyTpFlags ,
5152 pub name : PyRwLock < Option < String > > , // tp_name, not class name
5253 pub new : Option < PyNativeFunc > ,
54+ pub del : AtomicCell < Option < DelFunc > > ,
5355 pub call : AtomicCell < Option < GenericMethod > > ,
5456 pub descr_get : AtomicCell < Option < DescrGetFunc > > ,
5557 pub hash : AtomicCell < Option < HashFunc > > ,
@@ -82,6 +84,25 @@ impl std::fmt::Debug for PyClassSlots {
8284 }
8385}
8486
87+ #[ pyimpl]
88+ pub trait SlotDesctuctor : PyValue {
89+ #[ pyslot]
90+ fn tp_del ( zelf : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
91+ if let Some ( zelf) = zelf. downcast_ref ( ) {
92+ Self :: del ( zelf, vm)
93+ } else {
94+ Err ( vm. new_type_error ( "unexpected payload for __del__" . to_owned ( ) ) )
95+ }
96+ }
97+
98+ #[ pymethod( magic) ]
99+ fn __del__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < ( ) > {
100+ Self :: del ( & zelf, vm)
101+ }
102+
103+ fn del ( zelf : & PyRef < Self > , vm : & VirtualMachine ) -> PyResult < ( ) > ;
104+ }
105+
85106#[ pyimpl]
86107pub trait SlotCall : PyValue {
87108 #[ pymethod( magic) ]
0 commit comments