@@ -432,9 +432,9 @@ allocate_too_many_code_watchers(PyObject *self, PyObject *args)
432
432
433
433
// Test function watchers
434
434
435
- #define NUM_FUNC_WATCHERS 2
436
- static PyObject * pyfunc_watchers [NUM_FUNC_WATCHERS ];
437
- static int func_watcher_ids [NUM_FUNC_WATCHERS ] = {-1 , -1 };
435
+ #define NUM_TEST_FUNC_WATCHERS 2
436
+ static PyObject * pyfunc_watchers [NUM_TEST_FUNC_WATCHERS ];
437
+ static int func_watcher_ids [NUM_TEST_FUNC_WATCHERS ] = {-1 , -1 };
438
438
439
439
static PyObject *
440
440
get_id (PyObject * obj )
@@ -508,7 +508,7 @@ second_func_watcher_callback(PyFunction_WatchEvent event,
508
508
return call_pyfunc_watcher (pyfunc_watchers [1 ], event , func , new_value );
509
509
}
510
510
511
- static PyFunction_WatchCallback func_watcher_callbacks [NUM_FUNC_WATCHERS ] = {
511
+ static PyFunction_WatchCallback func_watcher_callbacks [NUM_TEST_FUNC_WATCHERS ] = {
512
512
first_func_watcher_callback ,
513
513
second_func_watcher_callback
514
514
};
@@ -533,26 +533,25 @@ add_func_watcher(PyObject *self, PyObject *func)
533
533
return NULL ;
534
534
}
535
535
int idx = -1 ;
536
- for (int i = 0 ; i < NUM_FUNC_WATCHERS ; i ++ ) {
536
+ for (int i = 0 ; i < NUM_TEST_FUNC_WATCHERS ; i ++ ) {
537
537
if (func_watcher_ids [i ] == -1 ) {
538
538
idx = i ;
539
539
break ;
540
540
}
541
541
}
542
542
if (idx == -1 ) {
543
- PyErr_SetString (PyExc_RuntimeError , "no free watchers" );
544
- return NULL ;
545
- }
546
- PyObject * result = PyLong_FromLong (idx );
547
- if (result == NULL ) {
543
+ PyErr_SetString (PyExc_RuntimeError , "no free test watchers" );
548
544
return NULL ;
549
545
}
550
546
func_watcher_ids [idx ] = PyFunction_AddWatcher (func_watcher_callbacks [idx ]);
551
547
if (func_watcher_ids [idx ] < 0 ) {
552
- Py_DECREF (result );
553
548
return NULL ;
554
549
}
555
550
pyfunc_watchers [idx ] = Py_NewRef (func );
551
+ PyObject * result = PyLong_FromLong (func_watcher_ids [idx ]);
552
+ if (result == NULL ) {
553
+ return NULL ;
554
+ }
556
555
return result ;
557
556
}
558
557
@@ -569,7 +568,7 @@ clear_func_watcher(PyObject *self, PyObject *watcher_id_obj)
569
568
return NULL ;
570
569
}
571
570
int idx = -1 ;
572
- for (int i = 0 ; i < NUM_FUNC_WATCHERS ; i ++ ) {
571
+ for (int i = 0 ; i < NUM_TEST_FUNC_WATCHERS ; i ++ ) {
573
572
if (func_watcher_ids [i ] == wid ) {
574
573
idx = i ;
575
574
break ;
0 commit comments