@@ -4,9 +4,12 @@ use std::sync::{atomic, Arc};
44use crate :: {
55 event_loop:: { EventLoop , EventLoopRunState } ,
66 log:: LogExc ,
7- py:: { run_in_ctx, run_in_ctx0, run_in_ctx1 } ,
7+ py:: { run_in_ctx, run_in_ctx0} ,
88} ;
99
10+ #[ cfg( not( PyPy ) ) ]
11+ use crate :: py:: run_in_ctx1;
12+
1013pub ( crate ) trait Handle {
1114 fn run ( self : Arc < Self > , py : Python , event_loop : & EventLoop , state : & mut EventLoopRunState ) ;
1215 fn cancel ( & self ) { }
@@ -119,6 +122,7 @@ impl Handle for CBHandleNoArgs {
119122impl Handle for CBHandleOneArg {
120123 handle_cancel_impl ! ( ) ;
121124
125+ #[ cfg( not( PyPy ) ) ]
122126 fn run ( self : Arc < Self > , py : Python , event_loop : & EventLoop , _state : & mut EventLoopRunState ) {
123127 let ctx = self . context . as_ptr ( ) ;
124128 let cb = self . callback . as_ptr ( ) ;
@@ -133,6 +137,22 @@ impl Handle for CBHandleOneArg {
133137 _ = event_loop. log_exception ( py, err_ctx) ;
134138 }
135139 }
140+
141+ #[ cfg( PyPy ) ]
142+ fn run ( self : Arc < Self > , py : Python , event_loop : & EventLoop , _state : & mut EventLoopRunState ) {
143+ let ctx = self . context . as_ptr ( ) ;
144+ let cb = self . callback . as_ptr ( ) ;
145+ let args = ( self . arg . clone_ref ( py) , ) . into_pyobject ( py) . unwrap ( ) . into_ptr ( ) ;
146+
147+ if let Err ( err) = run_in_ctx ! ( py, ctx, cb, args) {
148+ let err_ctx = LogExc :: cb_handle (
149+ err,
150+ format ! ( "Exception in callback {:?}" , self . callback. bind( py) ) ,
151+ PyHandle { handle : self } . into_py_any ( py) . unwrap ( ) ,
152+ ) ;
153+ _ = event_loop. log_exception ( py, err_ctx) ;
154+ }
155+ }
136156}
137157
138158#[ pyclass( frozen, name = "CBHandle" , module = "rloop._rloop" ) ]
0 commit comments