@@ -126,10 +126,10 @@ impl PyClassArgs {
126126 let flag = exp. path . segments . first ( ) . unwrap ( ) . ident . to_string ( ) ;
127127 let path = match flag. as_str ( ) {
128128 "gc" => {
129- parse_quote ! { pyo3:: type_object :: PY_TYPE_FLAG_GC }
129+ parse_quote ! { pyo3:: type_flags :: GC }
130130 }
131131 "weakref" => {
132- parse_quote ! { pyo3:: type_object :: PY_TYPE_FLAG_WEAKREF }
132+ parse_quote ! { pyo3:: type_flags :: WEAKREF }
133133 }
134134 "subclass" => {
135135 if cfg ! ( not( feature = "unsound-subclass" ) ) {
@@ -138,10 +138,10 @@ impl PyClassArgs {
138138 "You need to activate the `unsound-subclass` feature if you want to use subclassing" ,
139139 ) ) ;
140140 }
141- parse_quote ! { pyo3:: type_object :: PY_TYPE_FLAG_BASETYPE }
141+ parse_quote ! { pyo3:: type_flags :: BASETYPE }
142142 }
143143 "dict" => {
144- parse_quote ! { pyo3:: type_object :: PY_TYPE_FLAG_DICT }
144+ parse_quote ! { pyo3:: type_flags :: DICT }
145145 }
146146 _ => {
147147 return Err ( syn:: Error :: new_spanned (
@@ -267,7 +267,7 @@ fn impl_class(
267267 let extra = {
268268 if let Some ( freelist) = & attr. freelist {
269269 quote ! {
270- impl pyo3:: freelist:: PyObjectWithFreeList for #cls {
270+ impl pyo3:: freelist:: PyClassWithFreeList for #cls {
271271 #[ inline]
272272 fn get_free_list( ) -> & ' static mut pyo3:: freelist:: FreeList <* mut pyo3:: ffi:: PyObject > {
273273 static mut FREELIST : * mut pyo3:: freelist:: FreeList <* mut pyo3:: ffi:: PyObject > = 0 as * mut _;
@@ -285,7 +285,7 @@ fn impl_class(
285285 }
286286 } else {
287287 quote ! {
288- impl pyo3:: type_object :: PyObjectAlloc for #cls { }
288+ impl pyo3:: pyclass :: PyClassAlloc for #cls { }
289289 }
290290 }
291291 } ;
@@ -308,24 +308,25 @@ fn impl_class(
308308 let mut has_gc = false ;
309309 for f in attr. flags . iter ( ) {
310310 if let syn:: Expr :: Path ( ref epath) = f {
311- if epath. path == parse_quote ! { pyo3:: type_object :: PY_TYPE_FLAG_WEAKREF } {
311+ if epath. path == parse_quote ! { pyo3:: type_flags :: WEAKREF } {
312312 has_weakref = true ;
313- } else if epath. path == parse_quote ! { pyo3:: type_object :: PY_TYPE_FLAG_DICT } {
313+ } else if epath. path == parse_quote ! { pyo3:: type_flags :: DICT } {
314314 has_dict = true ;
315- } else if epath. path == parse_quote ! { pyo3:: type_object :: PY_TYPE_FLAG_GC } {
315+ } else if epath. path == parse_quote ! { pyo3:: type_flags :: GC } {
316316 has_gc = true ;
317317 }
318318 }
319319 }
320+ // TODO: implement dict and weakref
320321 let weakref = if has_weakref {
321- quote ! { std :: mem :: size_of :: < * const pyo3:: ffi :: PyObject > ( ) }
322+ quote ! { type WeakRef = pyo3:: pyclass_slots :: PyClassWeakRefSlot ; }
322323 } else {
323- quote ! { 0 }
324+ quote ! { type WeakRef = pyo3 :: pyclass_slots :: PyClassDummySlot ; }
324325 } ;
325326 let dict = if has_dict {
326- quote ! { std :: mem :: size_of :: < * const pyo3:: ffi :: PyObject > ( ) }
327+ quote ! { type Dict = pyo3:: pyclass_slots :: PyClassDictSlot ; }
327328 } else {
328- quote ! { 0 }
329+ quote ! { type Dict = pyo3 :: pyclass_slots :: PyClassDummySlot ; }
329330 } ;
330331 let module = if let Some ( m) = & attr. module {
331332 quote ! { Some ( #m) }
@@ -358,32 +359,25 @@ fn impl_class(
358359 impl pyo3:: type_object:: PyTypeInfo for #cls {
359360 type Type = #cls;
360361 type BaseType = #base;
362+ type ConcreteLayout = pyo3:: pyclass:: PyClassShell <Self >;
361363
362364 const NAME : & ' static str = #cls_name;
363365 const MODULE : Option <& ' static str > = #module;
364366 const DESCRIPTION : & ' static str = #doc;
365367 const FLAGS : usize = #( #flags) |* ;
366368
367- const SIZE : usize = {
368- Self :: OFFSET as usize +
369- :: std:: mem:: size_of:: <#cls>( ) + #weakref + #dict
370- } ;
371- const OFFSET : isize = {
372- // round base_size up to next multiple of align
373- (
374- ( <#base as pyo3:: type_object:: PyTypeInfo >:: SIZE +
375- :: std:: mem:: align_of:: <#cls>( ) - 1 ) /
376- :: std:: mem:: align_of:: <#cls>( ) * :: std:: mem:: align_of:: <#cls>( )
377- ) as isize
378- } ;
379-
380369 #[ inline]
381370 unsafe fn type_object( ) -> & ' static mut pyo3:: ffi:: PyTypeObject {
382371 static mut TYPE_OBJECT : pyo3:: ffi:: PyTypeObject = pyo3:: ffi:: PyTypeObject_INIT ;
383372 & mut TYPE_OBJECT
384373 }
385374 }
386375
376+ impl pyo3:: PyClass for #cls {
377+ #dict
378+ #weakref
379+ }
380+
387381 impl pyo3:: IntoPy <PyObject > for #cls {
388382 fn into_py( self , py: pyo3:: Python ) -> pyo3:: PyObject {
389383 pyo3:: IntoPy :: into_py( pyo3:: Py :: new( py, self ) . unwrap( ) , py)
0 commit comments