@@ -710,36 +710,6 @@ clear_context_stack(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
710
710
Py_RETURN_NONE ;
711
711
}
712
712
713
- static PyObject *
714
- allocate_too_many_context_watchers (PyObject * self , PyObject * args )
715
- {
716
- int watcher_ids [CONTEXT_MAX_WATCHERS + 1 ];
717
- int num_watchers = 0 ;
718
- for (unsigned long i = 0 ; i < sizeof (watcher_ids ) / sizeof (int ); i ++ ) {
719
- int watcher_id = PyContext_AddWatcher (& context_watcher , NULL );
720
- if (watcher_id == -1 ) {
721
- break ;
722
- }
723
- watcher_ids [i ] = watcher_id ;
724
- num_watchers ++ ;
725
- }
726
- PyObject * exc = PyErr_GetRaisedException ();
727
- for (int i = 0 ; i < num_watchers ; i ++ ) {
728
- if (PyContext_ClearWatcher (watcher_ids [i ]) < 0 ) {
729
- PyErr_WriteUnraisable (Py_None );
730
- break ;
731
- }
732
- }
733
- if (exc ) {
734
- PyErr_SetRaisedException (exc );
735
- return NULL ;
736
- }
737
- else if (PyErr_Occurred ()) {
738
- return NULL ;
739
- }
740
- Py_RETURN_NONE ;
741
- }
742
-
743
713
/*[clinic input]
744
714
_testcapi.set_func_defaults_via_capi
745
715
func: object
@@ -812,8 +782,6 @@ static PyMethodDef test_methods[] = {
812
782
_TESTCAPI_ADD_CONTEXT_WATCHER_METHODDEF
813
783
_TESTCAPI_CLEAR_CONTEXT_WATCHER_METHODDEF
814
784
{"clear_context_stack ", clear_context_stack, METH_NOARGS, NULL},
815
- {"allocate_too_many_context_watchers" ,
816
- (PyCFunction ) allocate_too_many_context_watchers , METH_NOARGS , NULL },
817
785
{NULL },
818
786
};
819
787
@@ -824,6 +792,16 @@ _PyTestCapi_Init_Watchers(PyObject *mod)
824
792
return -1 ;
825
793
}
826
794
795
+ #define ADD_INT_CONST (INT ) \
796
+ do { \
797
+ if (PyModule_AddIntConstant(mod, #INT, INT) < 0) { \
798
+ return -1; \
799
+ } \
800
+ } while(0)
801
+ ADD_INT_CONST (CONTEXT_MAX_WATCHERS );
802
+ ADD_INT_CONST (Py_CONTEXT_SWITCHED );
803
+ #undef ADD_INT_CONST
804
+
827
805
/* Expose each event as an attribute on the module */
828
806
#define ADD_EVENT (event ) \
829
807
if (add_func_event(mod, "PYFUNC_EVENT_" #event, \
0 commit comments