From 1ad2f1e4f5f288043e37303b8cd32ebe0030fcec Mon Sep 17 00:00:00 2001 From: AN Long Date: Sat, 10 Feb 2024 19:52:46 +0800 Subject: [PATCH 1/8] Apply Clinic Argument _lsprof --- .../pycore_global_objects_fini_generated.h | 5 + Include/internal/pycore_global_strings.h | 5 + .../internal/pycore_runtime_init_generated.h | 5 + .../internal/pycore_unicodeobject_generated.h | 15 + Modules/_lsprof.c | 159 +++++--- Modules/clinic/_lsprof.c.h | 368 +++++++++++++++++- 6 files changed, 503 insertions(+), 54 deletions(-) diff --git a/Include/internal/pycore_global_objects_fini_generated.h b/Include/internal/pycore_global_objects_fini_generated.h index 932738c3049882..da9f28406bd27b 100644 --- a/Include/internal/pycore_global_objects_fini_generated.h +++ b/Include/internal/pycore_global_objects_fini_generated.h @@ -829,6 +829,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(call)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(call_exception_handler)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(call_soon)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(callable)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(callback)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(cancel)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(capath)); @@ -999,6 +1000,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(input)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(insert_comments)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(insert_pis)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(instruction_offset)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(instructions)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(intern)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(intersection)); @@ -1169,6 +1171,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(reset)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(resetids)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(return)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(retval)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(reverse)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(reversed)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(s)); @@ -1180,6 +1183,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(seekable)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(selectors)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(self)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(self_arg)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(send)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(sep)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(sequence)); @@ -1221,6 +1225,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(strict_mode)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(string)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(sub_key)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(subclass)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(symmetric_difference_update)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(tabsize)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(tag)); diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index da62b4f0a951ff..664202d4ca46ab 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -318,6 +318,7 @@ struct _Py_global_strings { STRUCT_FOR_ID(call) STRUCT_FOR_ID(call_exception_handler) STRUCT_FOR_ID(call_soon) + STRUCT_FOR_ID(callable) STRUCT_FOR_ID(callback) STRUCT_FOR_ID(cancel) STRUCT_FOR_ID(capath) @@ -488,6 +489,7 @@ struct _Py_global_strings { STRUCT_FOR_ID(input) STRUCT_FOR_ID(insert_comments) STRUCT_FOR_ID(insert_pis) + STRUCT_FOR_ID(instruction_offset) STRUCT_FOR_ID(instructions) STRUCT_FOR_ID(intern) STRUCT_FOR_ID(intersection) @@ -658,6 +660,7 @@ struct _Py_global_strings { STRUCT_FOR_ID(reset) STRUCT_FOR_ID(resetids) STRUCT_FOR_ID(return) + STRUCT_FOR_ID(retval) STRUCT_FOR_ID(reverse) STRUCT_FOR_ID(reversed) STRUCT_FOR_ID(s) @@ -669,6 +672,7 @@ struct _Py_global_strings { STRUCT_FOR_ID(seekable) STRUCT_FOR_ID(selectors) STRUCT_FOR_ID(self) + STRUCT_FOR_ID(self_arg) STRUCT_FOR_ID(send) STRUCT_FOR_ID(sep) STRUCT_FOR_ID(sequence) @@ -710,6 +714,7 @@ struct _Py_global_strings { STRUCT_FOR_ID(strict_mode) STRUCT_FOR_ID(string) STRUCT_FOR_ID(sub_key) + STRUCT_FOR_ID(subclass) STRUCT_FOR_ID(symmetric_difference_update) STRUCT_FOR_ID(tabsize) STRUCT_FOR_ID(tag) diff --git a/Include/internal/pycore_runtime_init_generated.h b/Include/internal/pycore_runtime_init_generated.h index 68fbbcb4378e17..3799dfd9767a79 100644 --- a/Include/internal/pycore_runtime_init_generated.h +++ b/Include/internal/pycore_runtime_init_generated.h @@ -827,6 +827,7 @@ extern "C" { INIT_ID(call), \ INIT_ID(call_exception_handler), \ INIT_ID(call_soon), \ + INIT_ID(callable), \ INIT_ID(callback), \ INIT_ID(cancel), \ INIT_ID(capath), \ @@ -997,6 +998,7 @@ extern "C" { INIT_ID(input), \ INIT_ID(insert_comments), \ INIT_ID(insert_pis), \ + INIT_ID(instruction_offset), \ INIT_ID(instructions), \ INIT_ID(intern), \ INIT_ID(intersection), \ @@ -1167,6 +1169,7 @@ extern "C" { INIT_ID(reset), \ INIT_ID(resetids), \ INIT_ID(return), \ + INIT_ID(retval), \ INIT_ID(reverse), \ INIT_ID(reversed), \ INIT_ID(s), \ @@ -1178,6 +1181,7 @@ extern "C" { INIT_ID(seekable), \ INIT_ID(selectors), \ INIT_ID(self), \ + INIT_ID(self_arg), \ INIT_ID(send), \ INIT_ID(sep), \ INIT_ID(sequence), \ @@ -1219,6 +1223,7 @@ extern "C" { INIT_ID(strict_mode), \ INIT_ID(string), \ INIT_ID(sub_key), \ + INIT_ID(subclass), \ INIT_ID(symmetric_difference_update), \ INIT_ID(tabsize), \ INIT_ID(tag), \ diff --git a/Include/internal/pycore_unicodeobject_generated.h b/Include/internal/pycore_unicodeobject_generated.h index c8458b4e36ccc9..6298cc39d71de9 100644 --- a/Include/internal/pycore_unicodeobject_generated.h +++ b/Include/internal/pycore_unicodeobject_generated.h @@ -795,6 +795,9 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { string = &_Py_ID(call_soon); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); + string = &_Py_ID(callable); + assert(_PyUnicode_CheckConsistency(string, 1)); + _PyUnicode_InternInPlace(interp, &string); string = &_Py_ID(callback); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); @@ -1305,6 +1308,9 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { string = &_Py_ID(insert_pis); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); + string = &_Py_ID(instruction_offset); + assert(_PyUnicode_CheckConsistency(string, 1)); + _PyUnicode_InternInPlace(interp, &string); string = &_Py_ID(instructions); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); @@ -1815,6 +1821,9 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { string = &_Py_ID(return); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); + string = &_Py_ID(retval); + assert(_PyUnicode_CheckConsistency(string, 1)); + _PyUnicode_InternInPlace(interp, &string); string = &_Py_ID(reverse); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); @@ -1848,6 +1857,9 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { string = &_Py_ID(self); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); + string = &_Py_ID(self_arg); + assert(_PyUnicode_CheckConsistency(string, 1)); + _PyUnicode_InternInPlace(interp, &string); string = &_Py_ID(send); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); @@ -1971,6 +1983,9 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { string = &_Py_ID(sub_key); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); + string = &_Py_ID(subclass); + assert(_PyUnicode_CheckConsistency(string, 1)); + _PyUnicode_InternInPlace(interp, &string); string = &_Py_ID(symmetric_difference_update); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 8f09204097529f..043f8f9f942afc 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -68,6 +68,8 @@ class _lsprof.Profiler "ProfilerObject *" "&ProfilerType" #include "clinic/_lsprof.c.h" +static struct PyModuleDef _lsprofmodule; + typedef struct { PyTypeObject *profiler_type; PyTypeObject *stats_entry_type; @@ -596,17 +598,43 @@ setBuiltins(ProfilerObject *pObj, int nvalue) return 0; } -PyObject* pystart_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t size) +/*[clinic input] +_lsprof.Profiler._pystart_callback + + cls: defining_class + code: object + instruction_offset: int + +[clinic start generated code]*/ + +static PyObject * +_lsprof_Profiler__pystart_callback_impl(ProfilerObject *self, + PyTypeObject *cls, PyObject *code, + int instruction_offset) +/*[clinic end generated code: output=18c97a9f41e8dd68 input=9a52e348d39c8b79]*/ { - PyObject* code = args[0]; ptrace_enter_call((PyObject*)self, (void *)code, (PyObject *)code); Py_RETURN_NONE; } -PyObject* pyreturn_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t size) +/*[clinic input] +_lsprof.Profiler._pyreturn_callback + + cls: defining_class + code: object + instruction_offset: int + retval: object + +[clinic start generated code]*/ + +static PyObject * +_lsprof_Profiler__pyreturn_callback_impl(ProfilerObject *self, + PyTypeObject *cls, PyObject *code, + int instruction_offset, + PyObject *retval) +/*[clinic end generated code: output=6d798ecfcd20ca7d input=3b5f03997ea10d90]*/ { - PyObject* code = args[0]; ptrace_leave_call((PyObject*)self, (void *)code); Py_RETURN_NONE; @@ -639,11 +667,25 @@ PyObject* get_cfunc_from_callable(PyObject* callable, PyObject* self_arg, PyObje return NULL; } -PyObject* ccall_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t size) +/*[clinic input] +_lsprof.Profiler._ccall_callback + + cls: defining_class + code: object + instruction_offset: int + callable: object + self_arg: object + +[clinic start generated code]*/ + +static PyObject * +_lsprof_Profiler__ccall_callback_impl(ProfilerObject *self, + PyTypeObject *cls, PyObject *code, + int instruction_offset, + PyObject *callable, PyObject *self_arg) +/*[clinic end generated code: output=b505501f78e9b4b6 input=722128bc0faa9ca2]*/ { if (self->flags & POF_BUILTINS) { - PyObject* callable = args[2]; - PyObject* self_arg = args[3]; PyObject* cfunc = get_cfunc_from_callable(callable, self_arg, self->missing); @@ -657,11 +699,26 @@ PyObject* ccall_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t Py_RETURN_NONE; } -PyObject* creturn_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t size) +/*[clinic input] +_lsprof.Profiler._creturn_callback + + cls: defining_class + code: object + instruction_offset: int + callable: object + self_arg: object + +[clinic start generated code]*/ + +static PyObject * +_lsprof_Profiler__creturn_callback_impl(ProfilerObject *self, + PyTypeObject *cls, PyObject *code, + int instruction_offset, + PyObject *callable, + PyObject *self_arg) +/*[clinic end generated code: output=4647808fadffcfdb input=fc695ffb36ce0e4a]*/ { if (self->flags & POF_BUILTINS) { - PyObject* callable = args[2]; - PyObject* self_arg = args[3]; PyObject* cfunc = get_cfunc_from_callable(callable, self_arg, self->missing); @@ -690,31 +747,30 @@ static const struct { {0, NULL} }; -PyDoc_STRVAR(enable_doc, "\ -enable(subcalls=True, builtins=True)\n\ -\n\ -Start collecting profiling information.\n\ -If 'subcalls' is True, also records for each function\n\ -statistics separated according to its current caller.\n\ -If 'builtins' is True, records the time spent in\n\ -built-in functions separately from their caller.\n\ -"); -static PyObject* -profiler_enable(ProfilerObject *self, PyObject *args, PyObject *kwds) + +/*[clinic input] +_lsprof.Profiler.enable + + cls: defining_class + subclass: bool = True + builtins: bool = True + +Start collecting profiling information. + +If 'subcalls' is True, also records for each function +statistics separated according to its current caller. +If 'builtins' is True, records the time spent in +built-in functions separately from their caller. +[clinic start generated code]*/ + +static PyObject * +_lsprof_Profiler_enable_impl(ProfilerObject *self, PyTypeObject *cls, + int subclass, int builtins) +/*[clinic end generated code: output=fd728a3f2aebd1ab input=83411b9d1486d8d6]*/ { - int subcalls = -1; - int builtins = -1; - static char *kwlist[] = {"subcalls", "builtins", 0}; int all_events = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|pp:enable", - kwlist, &subcalls, &builtins)) - return NULL; - if (setSubcalls(self, subcalls) < 0 || setBuiltins(self, builtins) < 0) { - return NULL; - } - PyObject* monitoring = _PyImport_GetModuleAttrString("sys", "monitoring"); if (!monitoring) { return NULL; @@ -766,14 +822,18 @@ flush_unmatched(ProfilerObject *pObj) } -PyDoc_STRVAR(disable_doc, "\ -disable()\n\ -\n\ -Stop collecting profiling information.\n\ -"); -static PyObject* -profiler_disable(ProfilerObject *self, PyObject* noarg) +/*[clinic input] +_lsprof.Profiler.disable + + cls: defining_class + +Stop collecting profiling information. +[clinic start generated code]*/ + +static PyObject * +_lsprof_Profiler_disable_impl(ProfilerObject *self, PyTypeObject *cls) +/*[clinic end generated code: output=5e8e1b3df7fc0923 input=e14fc1835664fe9c]*/ { if (self->flags & POF_ENABLED) { PyObject* result = NULL; @@ -842,7 +902,7 @@ profiler_traverse(ProfilerObject *op, visitproc visit, void *arg) static void profiler_dealloc(ProfilerObject *op) { - PyObject_GC_UnTrack(op); + PyObject_GC_UnTrack(op); if (op->flags & POF_ENABLED) { PyThreadState *tstate = _PyThreadState_GET(); if (_PyEval_SetProfile(tstate, NULL, NULL) < 0) { @@ -894,20 +954,13 @@ profiler_init(ProfilerObject *pObj, PyObject *args, PyObject *kw) static PyMethodDef profiler_methods[] = { _LSPROF_PROFILER_GETSTATS_METHODDEF - {"enable", _PyCFunction_CAST(profiler_enable), - METH_VARARGS | METH_KEYWORDS, enable_doc}, - {"disable", (PyCFunction)profiler_disable, - METH_NOARGS, disable_doc}, - {"clear", (PyCFunction)profiler_clear, - METH_NOARGS, clear_doc}, - {"_pystart_callback", _PyCFunction_CAST(pystart_callback), - METH_FASTCALL, NULL}, - {"_pyreturn_callback", _PyCFunction_CAST(pyreturn_callback), - METH_FASTCALL, NULL}, - {"_ccall_callback", _PyCFunction_CAST(ccall_callback), - METH_FASTCALL, NULL}, - {"_creturn_callback", _PyCFunction_CAST(creturn_callback), - METH_FASTCALL, NULL}, + _LSPROF_PROFILER_ENABLE_METHODDEF + _LSPROF_PROFILER_DISABLE_METHODDEF + _LSPROF_PROFILER__PYSTART_CALLBACK_METHODDEF + _LSPROF_PROFILER__PYRETURN_CALLBACK_METHODDEF + _LSPROF_PROFILER__CCALL_CALLBACK_METHODDEF + _LSPROF_PROFILER__CRETURN_CALLBACK_METHODDEF + {"clear", (PyCFunction)profiler_clear, METH_NOARGS, clear_doc}, {NULL, NULL} }; diff --git a/Modules/clinic/_lsprof.c.h b/Modules/clinic/_lsprof.c.h index b3b7fda5660bfd..175dd5b2f15ff0 100644 --- a/Modules/clinic/_lsprof.c.h +++ b/Modules/clinic/_lsprof.c.h @@ -2,6 +2,12 @@ preserve [clinic start generated code]*/ +#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) +# include "pycore_gc.h" // PyGC_Head +# include "pycore_runtime.h" // _Py_ID() +#endif +#include "pycore_modsupport.h" // _PyArg_UnpackKeywords() + PyDoc_STRVAR(_lsprof_Profiler_getstats__doc__, "getstats($self, /)\n" "--\n" @@ -45,4 +51,364 @@ _lsprof_Profiler_getstats(ProfilerObject *self, PyTypeObject *cls, PyObject *con } return _lsprof_Profiler_getstats_impl(self, cls); } -/*[clinic end generated code: output=5c9d87d89863dc83 input=a9049054013a1b77]*/ + +PyDoc_STRVAR(_lsprof_Profiler__pystart_callback__doc__, +"_pystart_callback($self, /, code, instruction_offset)\n" +"--\n" +"\n"); + +#define _LSPROF_PROFILER__PYSTART_CALLBACK_METHODDEF \ + {"_pystart_callback", _PyCFunction_CAST(_lsprof_Profiler__pystart_callback), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _lsprof_Profiler__pystart_callback__doc__}, + +static PyObject * +_lsprof_Profiler__pystart_callback_impl(ProfilerObject *self, + PyTypeObject *cls, PyObject *code, + int instruction_offset); + +static PyObject * +_lsprof_Profiler__pystart_callback(ProfilerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 3 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { &_Py_ID(code), &_Py_ID(instruction_offset), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"code", "instruction_offset", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "_pystart_callback", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; + PyObject *code; + int instruction_offset; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); + if (!args) { + goto exit; + } + code = args[0]; + instruction_offset = PyLong_AsInt(args[1]); + if (instruction_offset == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = _lsprof_Profiler__pystart_callback_impl(self, cls, code, instruction_offset); + +exit: + return return_value; +} + +PyDoc_STRVAR(_lsprof_Profiler__pyreturn_callback__doc__, +"_pyreturn_callback($self, /, code, instruction_offset, retval)\n" +"--\n" +"\n"); + +#define _LSPROF_PROFILER__PYRETURN_CALLBACK_METHODDEF \ + {"_pyreturn_callback", _PyCFunction_CAST(_lsprof_Profiler__pyreturn_callback), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _lsprof_Profiler__pyreturn_callback__doc__}, + +static PyObject * +_lsprof_Profiler__pyreturn_callback_impl(ProfilerObject *self, + PyTypeObject *cls, PyObject *code, + int instruction_offset, + PyObject *retval); + +static PyObject * +_lsprof_Profiler__pyreturn_callback(ProfilerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 4 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { &_Py_ID(code), &_Py_ID(instruction_offset), &_Py_ID(retval), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"code", "instruction_offset", "retval", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "_pyreturn_callback", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[3]; + PyObject *code; + int instruction_offset; + PyObject *retval; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); + if (!args) { + goto exit; + } + code = args[0]; + instruction_offset = PyLong_AsInt(args[1]); + if (instruction_offset == -1 && PyErr_Occurred()) { + goto exit; + } + retval = args[2]; + return_value = _lsprof_Profiler__pyreturn_callback_impl(self, cls, code, instruction_offset, retval); + +exit: + return return_value; +} + +PyDoc_STRVAR(_lsprof_Profiler__ccall_callback__doc__, +"_ccall_callback($self, /, code, instruction_offset, callable, self_arg)\n" +"--\n" +"\n"); + +#define _LSPROF_PROFILER__CCALL_CALLBACK_METHODDEF \ + {"_ccall_callback", _PyCFunction_CAST(_lsprof_Profiler__ccall_callback), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _lsprof_Profiler__ccall_callback__doc__}, + +static PyObject * +_lsprof_Profiler__ccall_callback_impl(ProfilerObject *self, + PyTypeObject *cls, PyObject *code, + int instruction_offset, + PyObject *callable, PyObject *self_arg); + +static PyObject * +_lsprof_Profiler__ccall_callback(ProfilerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 5 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { &_Py_ID(code), &_Py_ID(instruction_offset), &_Py_ID(callable), &_Py_ID(self_arg), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"code", "instruction_offset", "callable", "self_arg", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "_ccall_callback", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[4]; + PyObject *code; + int instruction_offset; + PyObject *callable; + PyObject *self_arg; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 4, 0, argsbuf); + if (!args) { + goto exit; + } + code = args[0]; + instruction_offset = PyLong_AsInt(args[1]); + if (instruction_offset == -1 && PyErr_Occurred()) { + goto exit; + } + callable = args[2]; + self_arg = args[3]; + return_value = _lsprof_Profiler__ccall_callback_impl(self, cls, code, instruction_offset, callable, self_arg); + +exit: + return return_value; +} + +PyDoc_STRVAR(_lsprof_Profiler__creturn_callback__doc__, +"_creturn_callback($self, /, code, instruction_offset, callable,\n" +" self_arg)\n" +"--\n" +"\n"); + +#define _LSPROF_PROFILER__CRETURN_CALLBACK_METHODDEF \ + {"_creturn_callback", _PyCFunction_CAST(_lsprof_Profiler__creturn_callback), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _lsprof_Profiler__creturn_callback__doc__}, + +static PyObject * +_lsprof_Profiler__creturn_callback_impl(ProfilerObject *self, + PyTypeObject *cls, PyObject *code, + int instruction_offset, + PyObject *callable, + PyObject *self_arg); + +static PyObject * +_lsprof_Profiler__creturn_callback(ProfilerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 5 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { &_Py_ID(code), &_Py_ID(instruction_offset), &_Py_ID(callable), &_Py_ID(self_arg), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"code", "instruction_offset", "callable", "self_arg", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "_creturn_callback", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[4]; + PyObject *code; + int instruction_offset; + PyObject *callable; + PyObject *self_arg; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 4, 0, argsbuf); + if (!args) { + goto exit; + } + code = args[0]; + instruction_offset = PyLong_AsInt(args[1]); + if (instruction_offset == -1 && PyErr_Occurred()) { + goto exit; + } + callable = args[2]; + self_arg = args[3]; + return_value = _lsprof_Profiler__creturn_callback_impl(self, cls, code, instruction_offset, callable, self_arg); + +exit: + return return_value; +} + +PyDoc_STRVAR(_lsprof_Profiler_enable__doc__, +"enable($self, /, subclass=True, builtins=True)\n" +"--\n" +"\n" +"Start collecting profiling information.\n" +"\n" +"If \'subcalls\' is True, also records for each function\n" +"statistics separated according to its current caller.\n" +"If \'builtins\' is True, records the time spent in\n" +"built-in functions separately from their caller."); + +#define _LSPROF_PROFILER_ENABLE_METHODDEF \ + {"enable", _PyCFunction_CAST(_lsprof_Profiler_enable), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _lsprof_Profiler_enable__doc__}, + +static PyObject * +_lsprof_Profiler_enable_impl(ProfilerObject *self, PyTypeObject *cls, + int subclass, int builtins); + +static PyObject * +_lsprof_Profiler_enable(ProfilerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 3 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { &_Py_ID(subclass), &_Py_ID(builtins), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"subclass", "builtins", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "enable", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; + int subclass = 1; + int builtins = 1; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + if (args[0]) { + subclass = PyObject_IsTrue(args[0]); + if (subclass < 0) { + goto exit; + } + if (!--noptargs) { + goto skip_optional_pos; + } + } + builtins = PyObject_IsTrue(args[1]); + if (builtins < 0) { + goto exit; + } +skip_optional_pos: + return_value = _lsprof_Profiler_enable_impl(self, cls, subclass, builtins); + +exit: + return return_value; +} + +PyDoc_STRVAR(_lsprof_Profiler_disable__doc__, +"disable($self, /)\n" +"--\n" +"\n" +"Stop collecting profiling information."); + +#define _LSPROF_PROFILER_DISABLE_METHODDEF \ + {"disable", _PyCFunction_CAST(_lsprof_Profiler_disable), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _lsprof_Profiler_disable__doc__}, + +static PyObject * +_lsprof_Profiler_disable_impl(ProfilerObject *self, PyTypeObject *cls); + +static PyObject * +_lsprof_Profiler_disable(ProfilerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { + PyErr_SetString(PyExc_TypeError, "disable() takes no arguments"); + return NULL; + } + return _lsprof_Profiler_disable_impl(self, cls); +} +/*[clinic end generated code: output=2ac943b3f8180cdb input=a9049054013a1b77]*/ From 3a7cd9df08d64466a236da5abfff3b3e0746c602 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sat, 10 Feb 2024 20:01:15 +0800 Subject: [PATCH 2/8] Apply CA to clear method --- Modules/_lsprof.c | 19 ++++++++++--------- Modules/clinic/_lsprof.c.h | 20 +++++++++++++++++++- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 043f8f9f942afc..a0c6bbd7e1f5db 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -879,16 +879,17 @@ _lsprof_Profiler_disable_impl(ProfilerObject *self, PyTypeObject *cls) Py_RETURN_NONE; } -PyDoc_STRVAR(clear_doc, "\ -clear()\n\ -\n\ -Clear all profiling information collected so far.\n\ -"); +/*[clinic input] +_lsprof.Profiler.clear -static PyObject* -profiler_clear(ProfilerObject *pObj, PyObject* noarg) +Clear all profiling information collected so far. +[clinic start generated code]*/ + +static PyObject * +_lsprof_Profiler_clear_impl(ProfilerObject *self) +/*[clinic end generated code: output=dd1c668fb84b1335 input=fbe1f88c28be4f98]*/ { - clearEntries(pObj); + clearEntries(self); Py_RETURN_NONE; } @@ -955,12 +956,12 @@ profiler_init(ProfilerObject *pObj, PyObject *args, PyObject *kw) static PyMethodDef profiler_methods[] = { _LSPROF_PROFILER_GETSTATS_METHODDEF _LSPROF_PROFILER_ENABLE_METHODDEF + _LSPROF_PROFILER_CLEAR_METHODDEF _LSPROF_PROFILER_DISABLE_METHODDEF _LSPROF_PROFILER__PYSTART_CALLBACK_METHODDEF _LSPROF_PROFILER__PYRETURN_CALLBACK_METHODDEF _LSPROF_PROFILER__CCALL_CALLBACK_METHODDEF _LSPROF_PROFILER__CRETURN_CALLBACK_METHODDEF - {"clear", (PyCFunction)profiler_clear, METH_NOARGS, clear_doc}, {NULL, NULL} }; diff --git a/Modules/clinic/_lsprof.c.h b/Modules/clinic/_lsprof.c.h index 175dd5b2f15ff0..21793b8cd24a84 100644 --- a/Modules/clinic/_lsprof.c.h +++ b/Modules/clinic/_lsprof.c.h @@ -411,4 +411,22 @@ _lsprof_Profiler_disable(ProfilerObject *self, PyTypeObject *cls, PyObject *cons } return _lsprof_Profiler_disable_impl(self, cls); } -/*[clinic end generated code: output=2ac943b3f8180cdb input=a9049054013a1b77]*/ + +PyDoc_STRVAR(_lsprof_Profiler_clear__doc__, +"clear($self, /)\n" +"--\n" +"\n" +"Clear all profiling information collected so far."); + +#define _LSPROF_PROFILER_CLEAR_METHODDEF \ + {"clear", (PyCFunction)_lsprof_Profiler_clear, METH_NOARGS, _lsprof_Profiler_clear__doc__}, + +static PyObject * +_lsprof_Profiler_clear_impl(ProfilerObject *self); + +static PyObject * +_lsprof_Profiler_clear(ProfilerObject *self, PyObject *Py_UNUSED(ignored)) +{ + return _lsprof_Profiler_clear_impl(self); +} +/*[clinic end generated code: output=93734254d71b6773 input=a9049054013a1b77]*/ From 05d0f09eb17910a73cc794fdd6135a44848ab44a Mon Sep 17 00:00:00 2001 From: AN Long Date: Sat, 10 Feb 2024 20:02:35 +0800 Subject: [PATCH 3/8] Revert unused change --- Modules/_lsprof.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index a0c6bbd7e1f5db..e998d68e2920c1 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -68,8 +68,6 @@ class _lsprof.Profiler "ProfilerObject *" "&ProfilerType" #include "clinic/_lsprof.c.h" -static struct PyModuleDef _lsprofmodule; - typedef struct { PyTypeObject *profiler_type; PyTypeObject *stats_entry_type; From 06df9c13ef98230056afe4560da806040a91862f Mon Sep 17 00:00:00 2001 From: AN Long Date: Sat, 10 Feb 2024 20:18:51 +0800 Subject: [PATCH 4/8] Revert change which has been edited by accident --- Modules/_lsprof.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index e998d68e2920c1..93a81458a7eafd 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -901,7 +901,7 @@ profiler_traverse(ProfilerObject *op, visitproc visit, void *arg) static void profiler_dealloc(ProfilerObject *op) { - PyObject_GC_UnTrack(op); + PyObject_GC_UnTrack(op); if (op->flags & POF_ENABLED) { PyThreadState *tstate = _PyThreadState_GET(); if (_PyEval_SetProfile(tstate, NULL, NULL) < 0) { From ca454e247b04efd14a8fe5425f511ad8c0cb3370 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sat, 10 Feb 2024 20:20:28 +0800 Subject: [PATCH 5/8] Re-order the Profiler methods in codes --- Modules/_lsprof.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 93a81458a7eafd..df031e3968e802 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -954,8 +954,8 @@ profiler_init(ProfilerObject *pObj, PyObject *args, PyObject *kw) static PyMethodDef profiler_methods[] = { _LSPROF_PROFILER_GETSTATS_METHODDEF _LSPROF_PROFILER_ENABLE_METHODDEF - _LSPROF_PROFILER_CLEAR_METHODDEF _LSPROF_PROFILER_DISABLE_METHODDEF + _LSPROF_PROFILER_CLEAR_METHODDEF _LSPROF_PROFILER__PYSTART_CALLBACK_METHODDEF _LSPROF_PROFILER__PYRETURN_CALLBACK_METHODDEF _LSPROF_PROFILER__CCALL_CALLBACK_METHODDEF From 74f2532a2ecf25a06438e545069592af612c8250 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sun, 11 Feb 2024 14:43:39 +0800 Subject: [PATCH 6/8] refator usage of clinic --- Modules/_lsprof.c | 29 +++++++++++++---------------- Modules/clinic/_lsprof.c.h | 12 ++++++------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index df031e3968e802..e4918abc806e34 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -521,6 +521,7 @@ static int statsForEntry(rotating_node_t *node, void *arg) _lsprof.Profiler.getstats cls: defining_class + / list of profiler_entry objects. @@ -598,18 +599,17 @@ setBuiltins(ProfilerObject *pObj, int nvalue) /*[clinic input] _lsprof.Profiler._pystart_callback - cls: defining_class + / code: object instruction_offset: int - [clinic start generated code]*/ static PyObject * _lsprof_Profiler__pystart_callback_impl(ProfilerObject *self, PyTypeObject *cls, PyObject *code, int instruction_offset) -/*[clinic end generated code: output=18c97a9f41e8dd68 input=9a52e348d39c8b79]*/ +/*[clinic end generated code: output=18c97a9f41e8dd68 input=ab8b4e94ed02f782]*/ { ptrace_enter_call((PyObject*)self, (void *)code, (PyObject *)code); @@ -618,12 +618,11 @@ _lsprof_Profiler__pystart_callback_impl(ProfilerObject *self, /*[clinic input] _lsprof.Profiler._pyreturn_callback - cls: defining_class + / code: object instruction_offset: int retval: object - [clinic start generated code]*/ static PyObject * @@ -631,7 +630,7 @@ _lsprof_Profiler__pyreturn_callback_impl(ProfilerObject *self, PyTypeObject *cls, PyObject *code, int instruction_offset, PyObject *retval) -/*[clinic end generated code: output=6d798ecfcd20ca7d input=3b5f03997ea10d90]*/ +/*[clinic end generated code: output=6d798ecfcd20ca7d input=560dd9213f4d9b17]*/ { ptrace_leave_call((PyObject*)self, (void *)code); @@ -667,13 +666,12 @@ PyObject* get_cfunc_from_callable(PyObject* callable, PyObject* self_arg, PyObje /*[clinic input] _lsprof.Profiler._ccall_callback - cls: defining_class + / code: object instruction_offset: int callable: object self_arg: object - [clinic start generated code]*/ static PyObject * @@ -681,7 +679,7 @@ _lsprof_Profiler__ccall_callback_impl(ProfilerObject *self, PyTypeObject *cls, PyObject *code, int instruction_offset, PyObject *callable, PyObject *self_arg) -/*[clinic end generated code: output=b505501f78e9b4b6 input=722128bc0faa9ca2]*/ +/*[clinic end generated code: output=b505501f78e9b4b6 input=60eb261659ed4b81]*/ { if (self->flags & POF_BUILTINS) { @@ -699,13 +697,12 @@ _lsprof_Profiler__ccall_callback_impl(ProfilerObject *self, /*[clinic input] _lsprof.Profiler._creturn_callback - cls: defining_class + / code: object instruction_offset: int callable: object self_arg: object - [clinic start generated code]*/ static PyObject * @@ -714,7 +711,7 @@ _lsprof_Profiler__creturn_callback_impl(ProfilerObject *self, int instruction_offset, PyObject *callable, PyObject *self_arg) -/*[clinic end generated code: output=4647808fadffcfdb input=fc695ffb36ce0e4a]*/ +/*[clinic end generated code: output=4647808fadffcfdb input=d50d45d197c9218f]*/ { if (self->flags & POF_BUILTINS) { @@ -749,8 +746,8 @@ static const struct { /*[clinic input] _lsprof.Profiler.enable - cls: defining_class + / subclass: bool = True builtins: bool = True @@ -765,7 +762,7 @@ built-in functions separately from their caller. static PyObject * _lsprof_Profiler_enable_impl(ProfilerObject *self, PyTypeObject *cls, int subclass, int builtins) -/*[clinic end generated code: output=fd728a3f2aebd1ab input=83411b9d1486d8d6]*/ +/*[clinic end generated code: output=fd728a3f2aebd1ab input=740c799bccb56181]*/ { int all_events = 0; @@ -823,15 +820,15 @@ flush_unmatched(ProfilerObject *pObj) /*[clinic input] _lsprof.Profiler.disable - cls: defining_class + / Stop collecting profiling information. [clinic start generated code]*/ static PyObject * _lsprof_Profiler_disable_impl(ProfilerObject *self, PyTypeObject *cls) -/*[clinic end generated code: output=5e8e1b3df7fc0923 input=e14fc1835664fe9c]*/ +/*[clinic end generated code: output=5e8e1b3df7fc0923 input=e53b58786d88e721]*/ { if (self->flags & POF_ENABLED) { PyObject* result = NULL; diff --git a/Modules/clinic/_lsprof.c.h b/Modules/clinic/_lsprof.c.h index 21793b8cd24a84..31212e08405140 100644 --- a/Modules/clinic/_lsprof.c.h +++ b/Modules/clinic/_lsprof.c.h @@ -71,7 +71,7 @@ _lsprof_Profiler__pystart_callback(ProfilerObject *self, PyTypeObject *cls, PyOb PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - #define NUM_KEYWORDS 3 + #define NUM_KEYWORDS 2 static struct { PyGC_Head _this_is_not_used; PyObject_VAR_HEAD @@ -133,7 +133,7 @@ _lsprof_Profiler__pyreturn_callback(ProfilerObject *self, PyTypeObject *cls, PyO PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - #define NUM_KEYWORDS 4 + #define NUM_KEYWORDS 3 static struct { PyGC_Head _this_is_not_used; PyObject_VAR_HEAD @@ -197,7 +197,7 @@ _lsprof_Profiler__ccall_callback(ProfilerObject *self, PyTypeObject *cls, PyObje PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - #define NUM_KEYWORDS 5 + #define NUM_KEYWORDS 4 static struct { PyGC_Head _this_is_not_used; PyObject_VAR_HEAD @@ -265,7 +265,7 @@ _lsprof_Profiler__creturn_callback(ProfilerObject *self, PyTypeObject *cls, PyOb PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - #define NUM_KEYWORDS 5 + #define NUM_KEYWORDS 4 static struct { PyGC_Head _this_is_not_used; PyObject_VAR_HEAD @@ -335,7 +335,7 @@ _lsprof_Profiler_enable(ProfilerObject *self, PyTypeObject *cls, PyObject *const PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - #define NUM_KEYWORDS 3 + #define NUM_KEYWORDS 2 static struct { PyGC_Head _this_is_not_used; PyObject_VAR_HEAD @@ -429,4 +429,4 @@ _lsprof_Profiler_clear(ProfilerObject *self, PyObject *Py_UNUSED(ignored)) { return _lsprof_Profiler_clear_impl(self); } -/*[clinic end generated code: output=93734254d71b6773 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fe970481919361bf input=a9049054013a1b77]*/ From 5ba4b1a665053fa2bf9af9cfdc0ef462cd0520ef Mon Sep 17 00:00:00 2001 From: AN Long Date: Sun, 11 Feb 2024 15:07:23 +0800 Subject: [PATCH 7/8] Utilize the Clinic clone feature --- Modules/_lsprof.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index e4918abc806e34..2d5ed71a5fca82 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -519,7 +519,6 @@ static int statsForEntry(rotating_node_t *node, void *arg) /*[clinic input] _lsprof.Profiler.getstats - cls: defining_class / @@ -550,7 +549,7 @@ profiler_subentry objects: static PyObject * _lsprof_Profiler_getstats_impl(ProfilerObject *self, PyTypeObject *cls) -/*[clinic end generated code: output=1806ef720019ee03 input=445e193ef4522902]*/ +/*[clinic end generated code: output=1806ef720019ee03 input=a66d05fbc92b6861]*/ { statscollector_t collect; collect.state = _PyType_GetModuleState(cls); @@ -630,7 +629,7 @@ _lsprof_Profiler__pyreturn_callback_impl(ProfilerObject *self, PyTypeObject *cls, PyObject *code, int instruction_offset, PyObject *retval) -/*[clinic end generated code: output=6d798ecfcd20ca7d input=560dd9213f4d9b17]*/ +/*[clinic end generated code: output=6d798ecfcd20ca7d input=0950f661a3ff4304]*/ { ptrace_leave_call((PyObject*)self, (void *)code); @@ -679,7 +678,7 @@ _lsprof_Profiler__ccall_callback_impl(ProfilerObject *self, PyTypeObject *cls, PyObject *code, int instruction_offset, PyObject *callable, PyObject *self_arg) -/*[clinic end generated code: output=b505501f78e9b4b6 input=60eb261659ed4b81]*/ +/*[clinic end generated code: output=b505501f78e9b4b6 input=72b4c825f0162b76]*/ { if (self->flags & POF_BUILTINS) { @@ -696,13 +695,7 @@ _lsprof_Profiler__ccall_callback_impl(ProfilerObject *self, } /*[clinic input] -_lsprof.Profiler._creturn_callback - cls: defining_class - / - code: object - instruction_offset: int - callable: object - self_arg: object +_lsprof.Profiler._creturn_callback = _lsprof.Profiler._ccall_callback [clinic start generated code]*/ static PyObject * @@ -711,7 +704,7 @@ _lsprof_Profiler__creturn_callback_impl(ProfilerObject *self, int instruction_offset, PyObject *callable, PyObject *self_arg) -/*[clinic end generated code: output=4647808fadffcfdb input=d50d45d197c9218f]*/ +/*[clinic end generated code: output=4647808fadffcfdb input=7b5a200798ba4798]*/ { if (self->flags & POF_BUILTINS) { @@ -762,7 +755,7 @@ built-in functions separately from their caller. static PyObject * _lsprof_Profiler_enable_impl(ProfilerObject *self, PyTypeObject *cls, int subclass, int builtins) -/*[clinic end generated code: output=fd728a3f2aebd1ab input=740c799bccb56181]*/ +/*[clinic end generated code: output=fd728a3f2aebd1ab input=754c80dbfb9ea99d]*/ { int all_events = 0; From b22dd884182a6813e870c037a38a4fda24497194 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sun, 11 Feb 2024 15:39:50 +0800 Subject: [PATCH 8/8] Update generated file --- Modules/_lsprof.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 2d5ed71a5fca82..fc5acac41064b9 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -549,7 +549,7 @@ profiler_subentry objects: static PyObject * _lsprof_Profiler_getstats_impl(ProfilerObject *self, PyTypeObject *cls) -/*[clinic end generated code: output=1806ef720019ee03 input=a66d05fbc92b6861]*/ +/*[clinic end generated code: output=1806ef720019ee03 input=6c8c9c28626af2da]*/ { statscollector_t collect; collect.state = _PyType_GetModuleState(cls);