@@ -7,13 +7,14 @@ use crate::{
77 coroutine:: { Coro , warn_deprecated_throw_signature} ,
88 frame:: FrameRef ,
99 function:: OptionalArg ,
10+ object:: { Traverse , TraverseFn } ,
1011 protocol:: PyIterReturn ,
1112 types:: { Destructor , IterNext , Iterable , Representable , SelfIter } ,
1213} ;
1314
1415use crossbeam_utils:: atomic:: AtomicCell ;
1516
16- #[ pyclass( name = "async_generator" , module = false ) ]
17+ #[ pyclass( name = "async_generator" , module = false , traverse = "manual" ) ]
1718#[ derive( Debug ) ]
1819pub struct PyAsyncGen {
1920 inner : Coro ,
@@ -23,6 +24,13 @@ pub struct PyAsyncGen {
2324 // ag_origin_or_finalizer - stores the finalizer callback
2425 ag_finalizer : PyMutex < Option < PyObjectRef > > ,
2526}
27+
28+ unsafe impl Traverse for PyAsyncGen {
29+ fn traverse ( & self , tracer_fn : & mut TraverseFn < ' _ > ) {
30+ self . inner . traverse ( tracer_fn) ;
31+ self . ag_finalizer . traverse ( tracer_fn) ;
32+ }
33+ }
2634type PyAsyncGenRef = PyRef < PyAsyncGen > ;
2735
2836impl PyPayload for PyAsyncGen {
@@ -199,9 +207,20 @@ impl Representable for PyAsyncGen {
199207 }
200208}
201209
202- #[ pyclass( module = false , name = "async_generator_wrapped_value" ) ]
210+ #[ pyclass(
211+ module = false ,
212+ name = "async_generator_wrapped_value" ,
213+ traverse = "manual"
214+ ) ]
203215#[ derive( Debug ) ]
204216pub ( crate ) struct PyAsyncGenWrappedValue ( pub PyObjectRef ) ;
217+
218+ unsafe impl Traverse for PyAsyncGenWrappedValue {
219+ fn traverse ( & self , tracer_fn : & mut TraverseFn < ' _ > ) {
220+ self . 0 . traverse ( tracer_fn) ;
221+ }
222+ }
223+
205224impl PyPayload for PyAsyncGenWrappedValue {
206225 #[ inline]
207226 fn class ( ctx : & Context ) -> & ' static Py < PyType > {
@@ -244,14 +263,21 @@ enum AwaitableState {
244263 Closed ,
245264}
246265
247- #[ pyclass( module = false , name = "async_generator_asend" ) ]
266+ #[ pyclass( module = false , name = "async_generator_asend" , traverse = "manual" ) ]
248267#[ derive( Debug ) ]
249268pub ( crate ) struct PyAsyncGenASend {
250269 ag : PyAsyncGenRef ,
251270 state : AtomicCell < AwaitableState > ,
252271 value : PyObjectRef ,
253272}
254273
274+ unsafe impl Traverse for PyAsyncGenASend {
275+ fn traverse ( & self , tracer_fn : & mut TraverseFn < ' _ > ) {
276+ self . ag . traverse ( tracer_fn) ;
277+ self . value . traverse ( tracer_fn) ;
278+ }
279+ }
280+
255281impl PyPayload for PyAsyncGenASend {
256282 #[ inline]
257283 fn class ( ctx : & Context ) -> & ' static Py < PyType > {
@@ -338,7 +364,7 @@ impl IterNext for PyAsyncGenASend {
338364 }
339365}
340366
341- #[ pyclass( module = false , name = "async_generator_athrow" ) ]
367+ #[ pyclass( module = false , name = "async_generator_athrow" , traverse = "manual" ) ]
342368#[ derive( Debug ) ]
343369pub ( crate ) struct PyAsyncGenAThrow {
344370 ag : PyAsyncGenRef ,
@@ -347,6 +373,13 @@ pub(crate) struct PyAsyncGenAThrow {
347373 value : ( PyObjectRef , PyObjectRef , PyObjectRef ) ,
348374}
349375
376+ unsafe impl Traverse for PyAsyncGenAThrow {
377+ fn traverse ( & self , tracer_fn : & mut TraverseFn < ' _ > ) {
378+ self . ag . traverse ( tracer_fn) ;
379+ self . value . traverse ( tracer_fn) ;
380+ }
381+ }
382+
350383impl PyPayload for PyAsyncGenAThrow {
351384 #[ inline]
352385 fn class ( ctx : & Context ) -> & ' static Py < PyType > {
@@ -489,14 +522,21 @@ impl IterNext for PyAsyncGenAThrow {
489522
490523/// Awaitable wrapper for anext() builtin with default value.
491524/// When StopAsyncIteration is raised, it converts it to StopIteration(default).
492- #[ pyclass( module = false , name = "anext_awaitable" ) ]
525+ #[ pyclass( module = false , name = "anext_awaitable" , traverse = "manual" ) ]
493526#[ derive( Debug ) ]
494527pub struct PyAnextAwaitable {
495528 wrapped : PyObjectRef ,
496529 default_value : PyObjectRef ,
497530 state : AtomicCell < AwaitableState > ,
498531}
499532
533+ unsafe impl Traverse for PyAnextAwaitable {
534+ fn traverse ( & self , tracer_fn : & mut TraverseFn < ' _ > ) {
535+ self . wrapped . traverse ( tracer_fn) ;
536+ self . default_value . traverse ( tracer_fn) ;
537+ }
538+ }
539+
500540impl PyPayload for PyAnextAwaitable {
501541 #[ inline]
502542 fn class ( ctx : & Context ) -> & ' static Py < PyType > {
0 commit comments