@@ -23,7 +23,6 @@ _Py_IDENTIFIER(call_soon);
23
23
_Py_IDENTIFIER (cancel );
24
24
_Py_IDENTIFIER (get_event_loop );
25
25
_Py_IDENTIFIER (throw );
26
- _Py_IDENTIFIER (_check_future );
27
26
28
27
29
28
/* State of the _asyncio module */
@@ -1810,8 +1809,6 @@ class _asyncio.Task "TaskObj *" "&Task_Type"
1810
1809
static int task_call_step_soon (TaskObj * , PyObject * );
1811
1810
static PyObject * task_wakeup (TaskObj * , PyObject * );
1812
1811
static PyObject * task_step (TaskObj * , PyObject * );
1813
- static int task_check_future (TaskObj * , PyObject * );
1814
- static int task_check_future_exact (TaskObj * , PyObject * );
1815
1812
1816
1813
/* ----- Task._step wrapper */
1817
1814
@@ -2286,28 +2283,14 @@ Returns the remaining number of cancellation requests.
2286
2283
static PyObject *
2287
2284
_asyncio_Task_uncancel_impl (TaskObj * self )
2288
2285
/*[clinic end generated code: output=58184d236a817d3c input=68f81a4b90b46be2]*/
2286
+ /*[clinic end generated code]*/
2289
2287
{
2290
2288
if (self -> task_num_cancels_requested > 0 ) {
2291
2289
self -> task_num_cancels_requested -= 1 ;
2292
2290
}
2293
2291
return PyLong_FromLong (self -> task_num_cancels_requested );
2294
2292
}
2295
2293
2296
- /*[clinic input]
2297
- _asyncio.Task._check_future -> bool
2298
-
2299
- future: object
2300
-
2301
- Return False if task and future loops are not compatible.
2302
- [clinic start generated code]*/
2303
-
2304
- static int
2305
- _asyncio_Task__check_future_impl (TaskObj * self , PyObject * future )
2306
- /*[clinic end generated code: output=a3bfba79295c8d57 input=3b1d6dfd6fe90aa5]*/
2307
- {
2308
- return task_check_future_exact (self , future );
2309
- }
2310
-
2311
2294
/*[clinic input]
2312
2295
_asyncio.Task.get_stack
2313
2296
@@ -2533,7 +2516,6 @@ static PyMethodDef TaskType_methods[] = {
2533
2516
_ASYNCIO_TASK_CANCEL_METHODDEF
2534
2517
_ASYNCIO_TASK_CANCELLING_METHODDEF
2535
2518
_ASYNCIO_TASK_UNCANCEL_METHODDEF
2536
- _ASYNCIO_TASK__CHECK_FUTURE_METHODDEF
2537
2519
_ASYNCIO_TASK_GET_STACK_METHODDEF
2538
2520
_ASYNCIO_TASK_PRINT_STACK_METHODDEF
2539
2521
_ASYNCIO_TASK__MAKE_CANCELLED_ERROR_METHODDEF
@@ -2601,43 +2583,6 @@ TaskObj_dealloc(PyObject *self)
2601
2583
Py_TYPE (task )-> tp_free (task );
2602
2584
}
2603
2585
2604
- static int
2605
- task_check_future_exact (TaskObj * task , PyObject * future )
2606
- {
2607
- int res ;
2608
- if (Future_CheckExact (future ) || Task_CheckExact (future )) {
2609
- FutureObj * fut = (FutureObj * )future ;
2610
- res = (fut -> fut_loop == task -> task_loop );
2611
- } else {
2612
- PyObject * oloop = get_future_loop (future );
2613
- if (oloop == NULL ) {
2614
- return -1 ;
2615
- }
2616
- res = (oloop == task -> task_loop );
2617
- Py_DECREF (oloop );
2618
- }
2619
- return res ;
2620
- }
2621
-
2622
-
2623
- static int
2624
- task_check_future (TaskObj * task , PyObject * future )
2625
- {
2626
- if (Task_CheckExact (task )) {
2627
- return task_check_future_exact (task , future );
2628
- } else {
2629
- PyObject * ret = _PyObject_CallMethodIdOneArg ((PyObject * )task ,
2630
- & PyId__check_future ,
2631
- future );
2632
- if (ret == NULL ) {
2633
- return -1 ;
2634
- }
2635
- int is_true = PyObject_IsTrue (ret );
2636
- Py_DECREF (ret );
2637
- return is_true ;
2638
- }
2639
- }
2640
-
2641
2586
static int
2642
2587
task_call_step_soon (TaskObj * task , PyObject * arg )
2643
2588
{
@@ -2859,11 +2804,7 @@ task_step_impl(TaskObj *task, PyObject *exc)
2859
2804
FutureObj * fut = (FutureObj * )result ;
2860
2805
2861
2806
/* Check if `result` future is attached to a different loop */
2862
- res = task_check_future (task , result );
2863
- if (res == -1 ) {
2864
- goto fail ;
2865
- }
2866
- if (res == 0 ) {
2807
+ if (fut -> fut_loop != task -> task_loop ) {
2867
2808
goto different_loop ;
2868
2809
}
2869
2810
@@ -2935,13 +2876,15 @@ task_step_impl(TaskObj *task, PyObject *exc)
2935
2876
}
2936
2877
2937
2878
/* Check if `result` future is attached to a different loop */
2938
- res = task_check_future ( task , result );
2939
- if (res == -1 ) {
2879
+ PyObject * oloop = get_future_loop ( result );
2880
+ if (oloop == NULL ) {
2940
2881
goto fail ;
2941
2882
}
2942
- if (res == 0 ) {
2883
+ if (oloop != task -> task_loop ) {
2884
+ Py_DECREF (oloop );
2943
2885
goto different_loop ;
2944
2886
}
2887
+ Py_DECREF (oloop );
2945
2888
2946
2889
if (!blocking ) {
2947
2890
goto yield_insteadof_yf ;
0 commit comments