7
7
#include "pycore_tuple.h" // _PyTuple_ITEMS()
8
8
#include "structmember.h" // PyMemberDef
9
9
10
+ #include "clinic/_functoolsmodule.c.h"
11
+ /*[clinic input]
12
+ module _functools
13
+ class _functools._lru_cache_wrapper "PyObject *" "&lru_cache_type_spec"
14
+ [clinic start generated code]*/
15
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=bece4053896b09c0]*/
16
+
10
17
/* _functools module written and maintained
11
18
by Hye-Shik Chang <perky@FreeBSD.org>
12
19
with adaptations by Raymond Hettinger <python@rcn.com>
@@ -58,6 +65,7 @@ get_functools_state_by_type(PyTypeObject *type)
58
65
return get_functools_state (module );
59
66
}
60
67
68
+ // Not converted to argument clinic, because of `*args, **kwargs` arguments.
61
69
static PyObject *
62
70
partial_new (PyTypeObject * type , PyObject * args , PyObject * kw )
63
71
{
@@ -282,6 +290,7 @@ partial_setvectorcall(partialobject *pto)
282
290
}
283
291
284
292
293
+ // Not converted to argument clinic, because of `*args, **kwargs` arguments.
285
294
static PyObject *
286
295
partial_call (partialobject * pto , PyObject * args , PyObject * kwargs )
287
296
{
@@ -625,23 +634,29 @@ keyobject_richcompare(PyObject *ko, PyObject *other, int op)
625
634
return answer ;
626
635
}
627
636
637
+ /*[clinic input]
638
+ _functools.cmp_to_key
639
+
640
+ mycmp: object
641
+ Function that compares two objects.
642
+
643
+ Convert a cmp= function into a key= function.
644
+ [clinic start generated code]*/
645
+
628
646
static PyObject *
629
- functools_cmp_to_key (PyObject * self , PyObject * args , PyObject * kwds )
647
+ _functools_cmp_to_key_impl (PyObject * module , PyObject * mycmp )
648
+ /*[clinic end generated code: output=71eaad0f4fc81f33 input=d1b76f231c0dfeb3]*/
630
649
{
631
- PyObject * cmp ;
632
- static char * kwargs [] = {"mycmp" , NULL };
633
650
keyobject * object ;
634
651
_functools_state * state ;
652
+ state = get_functools_state (module );
635
653
636
- if (!PyArg_ParseTupleAndKeywords (args , kwds , "O:cmp_to_key" , kwargs , & cmp ))
637
- return NULL ;
638
-
639
- state = get_functools_state (self );
654
+ state = get_functools_state (module );
640
655
object = PyObject_GC_New (keyobject , state -> keyobject_type );
641
656
if (!object )
642
657
return NULL ;
643
- Py_INCREF (cmp );
644
- object -> cmp = cmp ;
658
+ Py_INCREF (mycmp );
659
+ object -> cmp = mycmp ;
645
660
object -> object = NULL ;
646
661
PyObject_GC_Track (object );
647
662
return (PyObject * )object ;
@@ -652,6 +667,8 @@ PyDoc_STRVAR(functools_cmp_to_key_doc,
652
667
653
668
/* reduce (used to be a builtin) ********************************************/
654
669
670
+ // Not converted to argument clinic, because of `args` in-place modification.
671
+ // AC will affect performance.
655
672
static PyObject *
656
673
functools_reduce (PyObject * self , PyObject * args )
657
674
{
@@ -1299,25 +1316,41 @@ lru_cache_descr_get(PyObject *self, PyObject *obj, PyObject *type)
1299
1316
return PyMethod_New (self , obj );
1300
1317
}
1301
1318
1319
+ /*[clinic input]
1320
+ _functools._lru_cache_wrapper.cache_info
1321
+
1322
+ Report cache statistics
1323
+ [clinic start generated code]*/
1324
+
1302
1325
static PyObject *
1303
- lru_cache_cache_info (lru_cache_object * self , PyObject * unused )
1326
+ _functools__lru_cache_wrapper_cache_info_impl (PyObject * self )
1327
+ /*[clinic end generated code: output=cc796a0b06dbd717 input=f05e5b6ebfe38645]*/
1304
1328
{
1305
- if (self -> maxsize == -1 ) {
1306
- return PyObject_CallFunction (self -> cache_info_type , "nnOn" ,
1307
- self -> hits , self -> misses , Py_None ,
1308
- PyDict_GET_SIZE (self -> cache ));
1309
- }
1310
- return PyObject_CallFunction (self -> cache_info_type , "nnnn" ,
1311
- self -> hits , self -> misses , self -> maxsize ,
1312
- PyDict_GET_SIZE (self -> cache ));
1329
+ lru_cache_object * _self = (lru_cache_object * ) self ;
1330
+ if (_self -> maxsize == -1 ) {
1331
+ return PyObject_CallFunction (_self -> cache_info_type , "nnOn" ,
1332
+ _self -> hits , _self -> misses , Py_None ,
1333
+ PyDict_GET_SIZE (_self -> cache ));
1334
+ }
1335
+ return PyObject_CallFunction (_self -> cache_info_type , "nnnn" ,
1336
+ _self -> hits , _self -> misses , _self -> maxsize ,
1337
+ PyDict_GET_SIZE (_self -> cache ));
1313
1338
}
1314
1339
1340
+ /*[clinic input]
1341
+ _functools._lru_cache_wrapper.cache_clear
1342
+
1343
+ Clear the cache and cache statistics
1344
+ [clinic start generated code]*/
1345
+
1315
1346
static PyObject *
1316
- lru_cache_cache_clear (lru_cache_object * self , PyObject * unused )
1347
+ _functools__lru_cache_wrapper_cache_clear_impl (PyObject * self )
1348
+ /*[clinic end generated code: output=58423b35efc3e381 input=6ca59dba09b12584]*/
1317
1349
{
1318
- lru_list_elem * list = lru_cache_unlink_list (self );
1319
- self -> hits = self -> misses = 0 ;
1320
- PyDict_Clear (self -> cache );
1350
+ lru_cache_object * _self = (lru_cache_object * ) self ;
1351
+ lru_list_elem * list = lru_cache_unlink_list (_self );
1352
+ _self -> hits = _self -> misses = 0 ;
1353
+ PyDict_Clear (_self -> cache );
1321
1354
lru_cache_clear_list (list );
1322
1355
Py_RETURN_NONE ;
1323
1356
}
@@ -1381,8 +1414,8 @@ cache_info_type: namedtuple class with the fields:\n\
1381
1414
);
1382
1415
1383
1416
static PyMethodDef lru_cache_methods [] = {
1384
- { "cache_info" , ( PyCFunction ) lru_cache_cache_info , METH_NOARGS },
1385
- { "cache_clear" , ( PyCFunction ) lru_cache_cache_clear , METH_NOARGS },
1417
+ _FUNCTOOLS__LRU_CACHE_WRAPPER_CACHE_INFO_METHODDEF
1418
+ _FUNCTOOLS__LRU_CACHE_WRAPPER_CACHE_CLEAR_METHODDEF
1386
1419
{"__reduce__" , (PyCFunction )lru_cache_reduce , METH_NOARGS },
1387
1420
{"__copy__" , (PyCFunction )lru_cache_copy , METH_VARARGS },
1388
1421
{"__deepcopy__" , (PyCFunction )lru_cache_deepcopy , METH_VARARGS },
@@ -1432,8 +1465,7 @@ PyDoc_STRVAR(_functools_doc,
1432
1465
1433
1466
static PyMethodDef _functools_methods [] = {
1434
1467
{"reduce" , functools_reduce , METH_VARARGS , functools_reduce_doc },
1435
- {"cmp_to_key" , _PyCFunction_CAST (functools_cmp_to_key ),
1436
- METH_VARARGS | METH_KEYWORDS , functools_cmp_to_key_doc },
1468
+ _FUNCTOOLS_CMP_TO_KEY_METHODDEF
1437
1469
{NULL , NULL } /* sentinel */
1438
1470
};
1439
1471
0 commit comments