1
1
#include "parts.h"
2
2
3
+ #include "clinic/watchers.c.h"
4
+
3
5
#define Py_BUILD_CORE
4
6
#include "pycore_function.h" // FUNC_MAX_WATCHERS
5
7
#include "pycore_code.h" // CODE_MAX_WATCHERS
6
8
9
+ /*[clinic input]
10
+ module _testcapi
11
+ [clinic start generated code]*/
12
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=6361033e795369fc]*/
13
+
7
14
// Test dict watching
8
15
static PyObject * g_dict_watch_events ;
9
16
static int g_dict_watchers_installed ;
@@ -119,28 +126,31 @@ clear_dict_watcher(PyObject *self, PyObject *watcher_id)
119
126
Py_RETURN_NONE ;
120
127
}
121
128
129
+ /*[clinic input]
130
+ _testcapi.watch_dict
131
+ watcher_id: int
132
+ dict: object
133
+ /
134
+ [clinic start generated code]*/
135
+
122
136
static PyObject *
123
- watch_dict (PyObject * self , PyObject * args )
137
+ _testcapi_watch_dict_impl (PyObject * module , int watcher_id , PyObject * dict )
138
+ /*[clinic end generated code: output=1426e0273cebe2d8 input=269b006d60c358bd]*/
124
139
{
125
- PyObject * dict ;
126
- int watcher_id ;
127
- if (!PyArg_ParseTuple (args , "iO" , & watcher_id , & dict )) {
128
- return NULL ;
129
- }
130
140
if (PyDict_Watch (watcher_id , dict )) {
131
141
return NULL ;
132
142
}
133
143
Py_RETURN_NONE ;
134
144
}
135
145
146
+ /*[clinic input]
147
+ _testcapi.unwatch_dict = _testcapi.watch_dict
148
+ [clinic start generated code]*/
149
+
136
150
static PyObject *
137
- unwatch_dict (PyObject * self , PyObject * args )
151
+ _testcapi_unwatch_dict_impl (PyObject * module , int watcher_id , PyObject * dict )
152
+ /*[clinic end generated code: output=512b1a71ae33c351 input=cae7dc1b6f7713b8]*/
138
153
{
139
- PyObject * dict ;
140
- int watcher_id ;
141
- if (!PyArg_ParseTuple (args , "iO" , & watcher_id , & dict )) {
142
- return NULL ;
143
- }
144
154
if (PyDict_Unwatch (watcher_id , dict )) {
145
155
return NULL ;
146
156
}
@@ -250,28 +260,31 @@ get_type_modified_events(PyObject *self, PyObject *Py_UNUSED(args))
250
260
return Py_NewRef (g_type_modified_events );
251
261
}
252
262
263
+ /*[clinic input]
264
+ _testcapi.watch_type
265
+ watcher_id: int
266
+ type: object
267
+ /
268
+ [clinic start generated code]*/
269
+
253
270
static PyObject *
254
- watch_type (PyObject * self , PyObject * args )
271
+ _testcapi_watch_type_impl (PyObject * module , int watcher_id , PyObject * type )
272
+ /*[clinic end generated code: output=fdf4777126724fc4 input=5a808bf12be7e3ed]*/
255
273
{
256
- PyObject * type ;
257
- int watcher_id ;
258
- if (!PyArg_ParseTuple (args , "iO" , & watcher_id , & type )) {
259
- return NULL ;
260
- }
261
274
if (PyType_Watch (watcher_id , type )) {
262
275
return NULL ;
263
276
}
264
277
Py_RETURN_NONE ;
265
278
}
266
279
280
+ /*[clinic input]
281
+ _testcapi.unwatch_type = _testcapi.watch_type
282
+ [clinic start generated code]*/
283
+
267
284
static PyObject *
268
- unwatch_type (PyObject * self , PyObject * args )
285
+ _testcapi_unwatch_type_impl (PyObject * module , int watcher_id , PyObject * type )
286
+ /*[clinic end generated code: output=0389672d4ad5f68b input=6701911fb45edc9e]*/
269
287
{
270
- PyObject * type ;
271
- int watcher_id ;
272
- if (!PyArg_ParseTuple (args , "iO" , & watcher_id , & type )) {
273
- return NULL ;
274
- }
275
288
if (PyType_Unwatch (watcher_id , type )) {
276
289
return NULL ;
277
290
}
@@ -605,29 +618,34 @@ allocate_too_many_func_watchers(PyObject *self, PyObject *args)
605
618
Py_RETURN_NONE ;
606
619
}
607
620
621
+ /*[clinic input]
622
+ _testcapi.set_func_defaults_via_capi
623
+ func: object
624
+ defaults: object
625
+ /
626
+ [clinic start generated code]*/
627
+
608
628
static PyObject *
609
- set_func_defaults (PyObject * self , PyObject * args )
629
+ _testcapi_set_func_defaults_via_capi_impl (PyObject * module , PyObject * func ,
630
+ PyObject * defaults )
631
+ /*[clinic end generated code: output=caf0cb39db31ac24 input=e04a8508ca9d42fc]*/
610
632
{
611
- PyObject * func = NULL ;
612
- PyObject * defaults = NULL ;
613
- if (!PyArg_ParseTuple (args , "OO" , & func , & defaults )) {
614
- return NULL ;
615
- }
616
633
if (PyFunction_SetDefaults (func , defaults ) < 0 ) {
617
634
return NULL ;
618
635
}
619
636
Py_RETURN_NONE ;
620
637
}
621
638
639
+ /*[clinic input]
640
+ _testcapi.set_func_kwdefaults_via_capi = _testcapi.set_func_defaults_via_capi
641
+ [clinic start generated code]*/
642
+
622
643
static PyObject *
623
- set_func_kwdefaults (PyObject * self , PyObject * args )
644
+ _testcapi_set_func_kwdefaults_via_capi_impl (PyObject * module , PyObject * func ,
645
+ PyObject * defaults )
646
+ /*[clinic end generated code: output=9ed3b08177025070 input=f3cd1ca3c18de8ce]*/
624
647
{
625
- PyObject * func = NULL ;
626
- PyObject * kwdefaults = NULL ;
627
- if (!PyArg_ParseTuple (args , "OO" , & func , & kwdefaults )) {
628
- return NULL ;
629
- }
630
- if (PyFunction_SetKwDefaults (func , kwdefaults ) < 0 ) {
648
+ if (PyFunction_SetKwDefaults (func , defaults ) < 0 ) {
631
649
return NULL ;
632
650
}
633
651
Py_RETURN_NONE ;
@@ -637,16 +655,16 @@ static PyMethodDef test_methods[] = {
637
655
// Dict watchers.
638
656
{"add_dict_watcher" , add_dict_watcher , METH_O , NULL },
639
657
{"clear_dict_watcher" , clear_dict_watcher , METH_O , NULL },
640
- { "watch_dict" , watch_dict , METH_VARARGS , NULL },
641
- { "unwatch_dict" , unwatch_dict , METH_VARARGS , NULL },
658
+ _TESTCAPI_WATCH_DICT_METHODDEF
659
+ _TESTCAPI_UNWATCH_DICT_METHODDEF
642
660
{"get_dict_watcher_events" ,
643
661
(PyCFunction ) get_dict_watcher_events , METH_NOARGS , NULL },
644
662
645
663
// Type watchers.
646
664
{"add_type_watcher" , add_type_watcher , METH_O , NULL },
647
665
{"clear_type_watcher" , clear_type_watcher , METH_O , NULL },
648
- { "watch_type" , watch_type , METH_VARARGS , NULL },
649
- { "unwatch_type" , unwatch_type , METH_VARARGS , NULL },
666
+ _TESTCAPI_WATCH_TYPE_METHODDEF
667
+ _TESTCAPI_UNWATCH_TYPE_METHODDEF
650
668
{"get_type_modified_events" ,
651
669
(PyCFunction ) get_type_modified_events , METH_NOARGS , NULL },
652
670
@@ -663,8 +681,8 @@ static PyMethodDef test_methods[] = {
663
681
// Function watchers.
664
682
{"add_func_watcher" , add_func_watcher , METH_O , NULL },
665
683
{"clear_func_watcher" , clear_func_watcher , METH_O , NULL },
666
- { "set_func_defaults_via_capi" , set_func_defaults , METH_VARARGS , NULL },
667
- { "set_func_kwdefaults_via_capi" , set_func_kwdefaults , METH_VARARGS , NULL },
684
+ _TESTCAPI_SET_FUNC_DEFAULTS_VIA_CAPI_METHODDEF
685
+ _TESTCAPI_SET_FUNC_KWDEFAULTS_VIA_CAPI_METHODDEF
668
686
{"allocate_too_many_func_watchers" , allocate_too_many_func_watchers ,
669
687
METH_NOARGS , NULL },
670
688
{NULL },
0 commit comments