From 70861ec34a2a9eb2395f1ac2eb93fc1638389bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:33:48 +0100 Subject: [PATCH 01/20] remove un-necessary casts to PyCFunction --- Modules/_cursesmodule.c | 2 +- Modules/_functoolsmodule.c | 12 ++++---- Modules/_io/winconsoleio.c | 2 +- Modules/_lzmamodule.c | 2 +- Modules/_testcapi/docstring.c | 48 +++++++++++++++--------------- Modules/_testcapi/mem.c | 2 +- Modules/_testcapi/watchers.c | 17 +++++------ Modules/_xxtestfuzz/_xxtestfuzz.c | 2 +- Modules/_zoneinfo.c | 6 ++-- Modules/atexitmodule.c | 16 +++++----- Modules/cjkcodecs/cjkcodecs.h | 2 +- Modules/faulthandler.c | 4 +-- Objects/stringlib/unicode_format.h | 4 +-- Objects/unicodeobject.c | 6 ++-- 14 files changed, 61 insertions(+), 64 deletions(-) diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index 2025724953969b..bf18cb51605075 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -2709,7 +2709,7 @@ static PyMethodDef PyCursesWindow_methods[] = { _CURSES_WINDOW_SETSCRREG_METHODDEF {"standend", PyCursesWindow_wstandend, METH_NOARGS}, {"standout", PyCursesWindow_wstandout, METH_NOARGS}, - {"subpad", (PyCFunction)_curses_window_subwin, METH_VARARGS, _curses_window_subwin__doc__}, + {"subpad", _curses_window_subwin, METH_VARARGS, _curses_window_subwin__doc__}, _CURSES_WINDOW_SUBWIN_METHODDEF {"syncdown", PyCursesWindow_wsyncdown, METH_NOARGS}, #ifdef HAVE_CURSES_SYNCOK diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index f91fa9a7327a3d..c2fabeda052f56 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -1636,19 +1636,19 @@ _functools__lru_cache_wrapper_cache_clear_impl(PyObject *self) } static PyObject * -lru_cache_reduce(PyObject *self, PyObject *unused) +lru_cache_reduce(PyObject *self, PyObject *Py_UNUSED(ignored)) { return PyObject_GetAttrString(self, "__qualname__"); } static PyObject * -lru_cache_copy(PyObject *self, PyObject *unused) +lru_cache_copy(PyObject *self, PyObject *Py_UNUSED(args)) { return Py_NewRef(self); } static PyObject * -lru_cache_deepcopy(PyObject *self, PyObject *unused) +lru_cache_deepcopy(PyObject *self, PyObject *Py_UNUSED(args)) { return Py_NewRef(self); } @@ -1695,9 +1695,9 @@ cache_info_type: namedtuple class with the fields:\n\ static PyMethodDef lru_cache_methods[] = { _FUNCTOOLS__LRU_CACHE_WRAPPER_CACHE_INFO_METHODDEF _FUNCTOOLS__LRU_CACHE_WRAPPER_CACHE_CLEAR_METHODDEF - {"__reduce__", (PyCFunction)lru_cache_reduce, METH_NOARGS}, - {"__copy__", (PyCFunction)lru_cache_copy, METH_VARARGS}, - {"__deepcopy__", (PyCFunction)lru_cache_deepcopy, METH_VARARGS}, + {"__reduce__", lru_cache_reduce, METH_NOARGS}, + {"__copy__", lru_cache_copy, METH_VARARGS}, + {"__deepcopy__", lru_cache_deepcopy, METH_VARARGS}, {NULL} }; diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index 77fe5259e4af1e..3e783b9da45652 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -1195,7 +1195,7 @@ static PyMethodDef winconsoleio_methods[] = { _IO__WINDOWSCONSOLEIO_WRITABLE_METHODDEF _IO__WINDOWSCONSOLEIO_FILENO_METHODDEF _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF - {"_isatty_open_only", (PyCFunction)_io__WindowsConsoleIO_isatty, METH_NOARGS}, + {"_isatty_open_only", _io__WindowsConsoleIO_isatty, METH_NOARGS}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c index 0058e2eec2ef16..c05cc8a4e4cb49 100644 --- a/Modules/_lzmamodule.c +++ b/Modules/_lzmamodule.c @@ -1410,7 +1410,7 @@ PyDoc_STRVAR(_lzma__encode_filter_properties__doc__, "The result does not include the filter ID itself, only the options."); #define _LZMA__ENCODE_FILTER_PROPERTIES_METHODDEF \ - {"_encode_filter_properties", (PyCFunction)_lzma__encode_filter_properties, METH_O, _lzma__encode_filter_properties__doc__}, + {"_encode_filter_properties", _lzma__encode_filter_properties, METH_O, _lzma__encode_filter_properties__doc__}, static PyObject * _lzma__encode_filter_properties_impl(PyObject *module, lzma_filter filter); diff --git a/Modules/_testcapi/docstring.c b/Modules/_testcapi/docstring.c index 3f7acbae1b181b..efb889cba8796e 100644 --- a/Modules/_testcapi/docstring.c +++ b/Modules/_testcapi/docstring.c @@ -66,42 +66,42 @@ test_with_docstring(PyObject *self, PyObject *Py_UNUSED(ignored)) static PyMethodDef test_methods[] = { {"docstring_empty", - (PyCFunction)test_with_docstring, METH_VARARGS, + test_with_docstring, METH_VARARGS, docstring_empty}, {"docstring_no_signature", - (PyCFunction)test_with_docstring, METH_VARARGS, + test_with_docstring, METH_VARARGS, docstring_no_signature}, {"docstring_no_signature_noargs", - (PyCFunction)test_with_docstring, METH_NOARGS, + test_with_docstring, METH_NOARGS, docstring_no_signature}, {"docstring_no_signature_o", - (PyCFunction)test_with_docstring, METH_O, + test_with_docstring, METH_O, docstring_no_signature}, {"docstring_with_invalid_signature", - (PyCFunction)test_with_docstring, METH_VARARGS, + test_with_docstring, METH_VARARGS, docstring_with_invalid_signature}, {"docstring_with_invalid_signature2", - (PyCFunction)test_with_docstring, METH_VARARGS, + test_with_docstring, METH_VARARGS, docstring_with_invalid_signature2}, {"docstring_with_signature", - (PyCFunction)test_with_docstring, METH_VARARGS, + test_with_docstring, METH_VARARGS, docstring_with_signature}, {"docstring_with_signature_and_extra_newlines", - (PyCFunction)test_with_docstring, METH_VARARGS, + test_with_docstring, METH_VARARGS, docstring_with_signature_and_extra_newlines}, {"docstring_with_signature_but_no_doc", - (PyCFunction)test_with_docstring, METH_VARARGS, + test_with_docstring, METH_VARARGS, docstring_with_signature_but_no_doc}, {"docstring_with_signature_with_defaults", - (PyCFunction)test_with_docstring, METH_VARARGS, + test_with_docstring, METH_VARARGS, docstring_with_signature_with_defaults}, {"no_docstring", - (PyCFunction)test_with_docstring, METH_VARARGS}, + test_with_docstring, METH_VARARGS}, {"test_with_docstring", test_with_docstring, METH_VARARGS, PyDoc_STR("This is a pretty normal docstring.")}, {"func_with_unrepresentable_signature", - (PyCFunction)test_with_docstring, METH_VARARGS, + test_with_docstring, METH_VARARGS, PyDoc_STR( "func_with_unrepresentable_signature($module, /, a, b=)\n" "--\n\n" @@ -112,28 +112,28 @@ static PyMethodDef test_methods[] = { static PyMethodDef DocStringNoSignatureTest_methods[] = { {"meth_noargs", - (PyCFunction)test_with_docstring, METH_NOARGS, + test_with_docstring, METH_NOARGS, docstring_no_signature}, {"meth_o", - (PyCFunction)test_with_docstring, METH_O, + test_with_docstring, METH_O, docstring_no_signature}, {"meth_noargs_class", - (PyCFunction)test_with_docstring, METH_NOARGS|METH_CLASS, + test_with_docstring, METH_NOARGS|METH_CLASS, docstring_no_signature}, {"meth_o_class", - (PyCFunction)test_with_docstring, METH_O|METH_CLASS, + test_with_docstring, METH_O|METH_CLASS, docstring_no_signature}, {"meth_noargs_static", - (PyCFunction)test_with_docstring, METH_NOARGS|METH_STATIC, + test_with_docstring, METH_NOARGS|METH_STATIC, docstring_no_signature}, {"meth_o_static", - (PyCFunction)test_with_docstring, METH_O|METH_STATIC, + test_with_docstring, METH_O|METH_STATIC, docstring_no_signature}, {"meth_noargs_coexist", - (PyCFunction)test_with_docstring, METH_NOARGS|METH_COEXIST, + test_with_docstring, METH_NOARGS|METH_COEXIST, docstring_no_signature}, {"meth_o_coexist", - (PyCFunction)test_with_docstring, METH_O|METH_COEXIST, + test_with_docstring, METH_O|METH_COEXIST, docstring_no_signature}, {NULL}, }; @@ -149,28 +149,28 @@ static PyTypeObject DocStringNoSignatureTest = { static PyMethodDef DocStringUnrepresentableSignatureTest_methods[] = { {"meth", - (PyCFunction)test_with_docstring, METH_VARARGS, + test_with_docstring, METH_VARARGS, PyDoc_STR( "meth($self, /, a, b=)\n" "--\n\n" "This docstring has a signature with unrepresentable default." )}, {"classmeth", - (PyCFunction)test_with_docstring, METH_VARARGS|METH_CLASS, + test_with_docstring, METH_VARARGS|METH_CLASS, PyDoc_STR( "classmeth($type, /, a, b=)\n" "--\n\n" "This docstring has a signature with unrepresentable default." )}, {"staticmeth", - (PyCFunction)test_with_docstring, METH_VARARGS|METH_STATIC, + test_with_docstring, METH_VARARGS|METH_STATIC, PyDoc_STR( "staticmeth(a, b=)\n" "--\n\n" "This docstring has a signature with unrepresentable default." )}, {"with_default", - (PyCFunction)test_with_docstring, METH_VARARGS, + test_with_docstring, METH_VARARGS, PyDoc_STR( "with_default($self, /, x=ONE)\n" "--\n\n" diff --git a/Modules/_testcapi/mem.c b/Modules/_testcapi/mem.c index 7237fb94c3f51f..b4896f984510bd 100644 --- a/Modules/_testcapi/mem.c +++ b/Modules/_testcapi/mem.c @@ -691,7 +691,7 @@ static PyMethodDef test_methods[] = { {"pyobject_malloc_without_gil", pyobject_malloc_without_gil, METH_NOARGS}, {"remove_mem_hooks", remove_mem_hooks, METH_NOARGS, PyDoc_STR("Remove memory hooks.")}, - {"set_nomemory", (PyCFunction)set_nomemory, METH_VARARGS, + {"set_nomemory", set_nomemory, METH_VARARGS, PyDoc_STR("set_nomemory(start:int, stop:int = 0)")}, {"test_pymem_alloc0", test_pymem_alloc0, METH_NOARGS}, {"test_pymem_setallocators", test_pymem_setallocators, METH_NOARGS}, diff --git a/Modules/_testcapi/watchers.c b/Modules/_testcapi/watchers.c index 6a5136ef8c9ecc..3586929cad223d 100644 --- a/Modules/_testcapi/watchers.c +++ b/Modules/_testcapi/watchers.c @@ -162,7 +162,7 @@ _testcapi_unwatch_dict_impl(PyObject *module, int watcher_id, PyObject *dict) } static PyObject * -get_dict_watcher_events(PyObject *self, PyObject *Py_UNUSED(args)) +get_dict_watcher_events(PyObject *self, PyObject *Py_UNUSED(ignored)) { if (!g_dict_watch_events) { PyErr_SetString(PyExc_RuntimeError, "no watchers active"); @@ -255,7 +255,7 @@ clear_type_watcher(PyObject *self, PyObject *watcher_id) } static PyObject * -get_type_modified_events(PyObject *self, PyObject *Py_UNUSED(args)) +get_type_modified_events(PyObject *self, PyObject *Py_UNUSED(ignored)) { if (!g_type_modified_events) { PyErr_SetString(PyExc_RuntimeError, "no watchers active"); @@ -413,7 +413,7 @@ get_code_watcher_num_destroyed_events(PyObject *self, PyObject *watcher_id) } static PyObject * -allocate_too_many_code_watchers(PyObject *self, PyObject *args) +allocate_too_many_code_watchers(PyObject *self, PyObject *Py_UNUSED(ignored)) { int watcher_ids[CODE_MAX_WATCHERS + 1]; int num_watchers = 0; @@ -742,7 +742,7 @@ get_context_switches(PyObject *Py_UNUSED(self), PyObject *watcher_id) } static PyObject * -allocate_too_many_context_watchers(PyObject *self, PyObject *args) +allocate_too_many_context_watchers(PyObject *self, PyObject *Py_UNUSED(ignored)) { int watcher_ids[CONTEXT_MAX_WATCHERS + 1]; int num_watchers = 0; @@ -811,8 +811,7 @@ static PyMethodDef test_methods[] = { {"clear_dict_watcher", clear_dict_watcher, METH_O, NULL}, _TESTCAPI_WATCH_DICT_METHODDEF _TESTCAPI_UNWATCH_DICT_METHODDEF - {"get_dict_watcher_events", - (PyCFunction) get_dict_watcher_events, METH_NOARGS, NULL}, + {"get_dict_watcher_events", get_dict_watcher_events, METH_NOARGS, NULL}, // Type watchers. {"add_type_watcher", add_type_watcher, METH_O, NULL}, @@ -820,7 +819,7 @@ static PyMethodDef test_methods[] = { _TESTCAPI_WATCH_TYPE_METHODDEF _TESTCAPI_UNWATCH_TYPE_METHODDEF {"get_type_modified_events", - (PyCFunction) get_type_modified_events, METH_NOARGS, NULL}, + get_type_modified_events, METH_NOARGS, NULL}, // Code object watchers. {"add_code_watcher", add_code_watcher, METH_O, NULL}, @@ -830,7 +829,7 @@ static PyMethodDef test_methods[] = { {"get_code_watcher_num_destroyed_events", get_code_watcher_num_destroyed_events, METH_O, NULL}, {"allocate_too_many_code_watchers", - (PyCFunction) allocate_too_many_code_watchers, METH_NOARGS, NULL}, + allocate_too_many_code_watchers, METH_NOARGS, NULL}, // Function watchers. {"add_func_watcher", add_func_watcher, METH_O, NULL}, @@ -846,7 +845,7 @@ static PyMethodDef test_methods[] = { {"clear_context_stack", clear_context_stack, METH_NOARGS, NULL}, {"get_context_switches", get_context_switches, METH_O, NULL}, {"allocate_too_many_context_watchers", - (PyCFunction) allocate_too_many_context_watchers, METH_NOARGS, NULL}, + allocate_too_many_context_watchers, METH_NOARGS, NULL}, {NULL}, }; diff --git a/Modules/_xxtestfuzz/_xxtestfuzz.c b/Modules/_xxtestfuzz/_xxtestfuzz.c index 2952d7043e01fe..0e0ca5f95fa449 100644 --- a/Modules/_xxtestfuzz/_xxtestfuzz.c +++ b/Modules/_xxtestfuzz/_xxtestfuzz.c @@ -24,7 +24,7 @@ static PyObject* _fuzz_run(PyObject* self, PyObject* args) { } static PyMethodDef module_methods[] = { - {"run", (PyCFunction)_fuzz_run, METH_VARARGS, ""}, + {"run", _fuzz_run, METH_VARARGS, ""}, {NULL}, }; diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index 7e761b287792e1..fe78645dda15ba 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -2605,13 +2605,13 @@ static PyMethodDef zoneinfo_methods[] = { ZONEINFO_ZONEINFO_UTCOFFSET_METHODDEF ZONEINFO_ZONEINFO_DST_METHODDEF ZONEINFO_ZONEINFO_TZNAME_METHODDEF - {"fromutc", (PyCFunction)zoneinfo_fromutc, METH_O, + {"fromutc", zoneinfo_fromutc, METH_O, PyDoc_STR("Given a datetime with local time in UTC, retrieve an adjusted " "datetime in local time.")}, - {"__reduce__", (PyCFunction)zoneinfo_reduce, METH_NOARGS, + {"__reduce__", zoneinfo_reduce, METH_NOARGS, PyDoc_STR("Function for serialization with the pickle protocol.")}, ZONEINFO_ZONEINFO__UNPICKLE_METHODDEF - {"__init_subclass__", (PyCFunction)(void (*)(void))zoneinfo_init_subclass, + {"__init_subclass__", _PyCFunction_CAST(zoneinfo_init_subclass), METH_VARARGS | METH_KEYWORDS | METH_CLASS, PyDoc_STR("Function to initialize subclasses.")}, {NULL} /* Sentinel */ diff --git a/Modules/atexitmodule.c b/Modules/atexitmodule.c index 2bfdda53af8cb2..c84cb05d85e913 100644 --- a/Modules/atexitmodule.c +++ b/Modules/atexitmodule.c @@ -217,7 +217,7 @@ Run all registered exit functions.\n\ If a callback raises an exception, it is logged with sys.unraisablehook."); static PyObject * -atexit_run_exitfuncs(PyObject *module, PyObject *unused) +atexit_run_exitfuncs(PyObject *module, PyObject *Py_UNUSED(ignored)) { struct atexit_state *state = get_atexit_state(); atexit_callfuncs(state); @@ -231,7 +231,7 @@ PyDoc_STRVAR(atexit_clear__doc__, Clear the list of previously registered exit functions."); static PyObject * -atexit_clear(PyObject *module, PyObject *unused) +atexit_clear(PyObject *module, PyObject *Py_UNUSED(ignored)) { atexit_cleanup(get_atexit_state()); Py_RETURN_NONE; @@ -244,7 +244,7 @@ PyDoc_STRVAR(atexit_ncallbacks__doc__, Return the number of registered exit functions."); static PyObject * -atexit_ncallbacks(PyObject *module, PyObject *unused) +atexit_ncallbacks(PyObject *module, PyObject *Py_UNUSED(ignored)) { struct atexit_state *state = get_atexit_state(); assert(state->callbacks != NULL); @@ -300,13 +300,11 @@ atexit_unregister(PyObject *module, PyObject *func) static PyMethodDef atexit_methods[] = { {"register", _PyCFunction_CAST(atexit_register), METH_VARARGS|METH_KEYWORDS, atexit_register__doc__}, - {"_clear", (PyCFunction) atexit_clear, METH_NOARGS, - atexit_clear__doc__}, - {"unregister", (PyCFunction) atexit_unregister, METH_O, - atexit_unregister__doc__}, - {"_run_exitfuncs", (PyCFunction) atexit_run_exitfuncs, METH_NOARGS, + {"_clear", atexit_clear, METH_NOARGS, atexit_clear__doc__}, + {"unregister", atexit_unregister, METH_O, atexit_unregister__doc__}, + {"_run_exitfuncs", atexit_run_exitfuncs, METH_NOARGS, atexit_run_exitfuncs__doc__}, - {"_ncallbacks", (PyCFunction) atexit_ncallbacks, METH_NOARGS, + {"_ncallbacks", atexit_ncallbacks, METH_NOARGS, atexit_ncallbacks__doc__}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h index 737a7a042753a9..f66412237011d4 100644 --- a/Modules/cjkcodecs/cjkcodecs.h +++ b/Modules/cjkcodecs/cjkcodecs.h @@ -495,7 +495,7 @@ _cjk_free(void *mod) } static struct PyMethodDef _cjk_methods[] = { - {"getcodec", (PyCFunction)getcodec, METH_O, ""}, + {"getcodec", getcodec, METH_O, ""}, {NULL, NULL}, }; diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index 3b87864e1f2566..d7f0dff43319c0 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -1125,7 +1125,7 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args) } static PyObject* _Py_NO_SANITIZE_UNDEFINED -faulthandler_sigfpe(PyObject *self, PyObject *args) +faulthandler_sigfpe(PyObject *self, PyObject *Py_UNUSED(ignored)) { faulthandler_suppress_crash_report(); @@ -1291,7 +1291,7 @@ static PyMethodDef module_methods[] = { {"_sigabrt", faulthandler_sigabrt, METH_NOARGS, PyDoc_STR("_sigabrt($module, /)\n--\n\n" "Raise a SIGABRT signal.")}, - {"_sigfpe", (PyCFunction)faulthandler_sigfpe, METH_NOARGS, + {"_sigfpe", faulthandler_sigfpe, METH_NOARGS, PyDoc_STR("_sigfpe($module, /)\n--\n\n" "Raise a SIGFPE signal.")}, #ifdef FAULTHANDLER_STACK_OVERFLOW diff --git a/Objects/stringlib/unicode_format.h b/Objects/stringlib/unicode_format.h index 982fc5184a5b2a..ff32db65b11a0b 100644 --- a/Objects/stringlib/unicode_format.h +++ b/Objects/stringlib/unicode_format.h @@ -1100,7 +1100,7 @@ static PyTypeObject PyFormatterIter_Type = { describing the parsed elements. It's a wrapper around stringlib/string_format.h's MarkupIterator */ static PyObject * -formatter_parser(PyObject *ignored, PyObject *self) +formatter_parser(PyObject *Py_UNUSED(module), PyObject *self) { formatteriterobject *it; @@ -1236,7 +1236,7 @@ static PyTypeObject PyFieldNameIter_Type = { field_name_split. The iterator it returns is a FieldNameIterator */ static PyObject * -formatter_field_name_split(PyObject *ignored, PyObject *self) +formatter_field_name_split(PyObject *Py_UNUSED(module), PyObject *self) { SubString first; Py_ssize_t first_idx; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 3e0bd90c17995f..c48ab8e441fa6d 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -14316,7 +14316,7 @@ static PyMethodDef unicode_methods[] = { UNICODE_ISPRINTABLE_METHODDEF UNICODE_ZFILL_METHODDEF {"format", _PyCFunction_CAST(do_string_format), METH_VARARGS | METH_KEYWORDS, format__doc__}, - {"format_map", (PyCFunction) do_string_format_map, METH_O, format_map__doc__}, + {"format_map", do_string_format_map, METH_O, format_map__doc__}, UNICODE___FORMAT___METHODDEF UNICODE_MAKETRANS_METHODDEF UNICODE_SIZEOF_METHODDEF @@ -16474,9 +16474,9 @@ _PyUnicode_Fini(PyInterpreterState *interp) to the string.Formatter class implemented in Python. */ static PyMethodDef _string_methods[] = { - {"formatter_field_name_split", (PyCFunction) formatter_field_name_split, + {"formatter_field_name_split", formatter_field_name_split, METH_O, PyDoc_STR("split the argument as a field name")}, - {"formatter_parser", (PyCFunction) formatter_parser, + {"formatter_parser", formatter_parser, METH_O, PyDoc_STR("parse the argument as a format string")}, {NULL, NULL} }; From d35646526c11a7c4cc484cd00fef71a7585784d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:37:36 +0100 Subject: [PATCH 02/20] remove un-necessary casts to `getter` --- Modules/_testcapi/gc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_testcapi/gc.c b/Modules/_testcapi/gc.c index 3691796302e500..863cb52980f942 100644 --- a/Modules/_testcapi/gc.c +++ b/Modules/_testcapi/gc.c @@ -265,7 +265,7 @@ obj_extra_data_set(PyObject *self, PyObject *newval, void *Py_UNUSED(ignored)) } static PyGetSetDef obj_extra_data_getset[] = { - {"extra", (getter)obj_extra_data_get, (setter)obj_extra_data_set, NULL}, + {"extra", obj_extra_data_get, obj_extra_data_set, NULL}, {NULL} }; From f641773ae89b2afec622ec2ea483a024088e879d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:39:04 +0100 Subject: [PATCH 03/20] remove un-necessary casts to `setter` --- Modules/_functoolsmodule.c | 2 +- Modules/_testcapi/watchers.c | 8 ++++---- Modules/atexitmodule.c | 6 +++--- Modules/faulthandler.c | 4 ++-- Objects/dictobject.c | 2 +- Objects/genericaliasobject.c | 4 ++-- Objects/longobject.c | 8 ++++---- Objects/unionobject.c | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index c2fabeda052f56..1ef5443bd1a475 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -1636,7 +1636,7 @@ _functools__lru_cache_wrapper_cache_clear_impl(PyObject *self) } static PyObject * -lru_cache_reduce(PyObject *self, PyObject *Py_UNUSED(ignored)) +lru_cache_reduce(PyObject *self, PyObject *Py_UNUSED(dummy)) { return PyObject_GetAttrString(self, "__qualname__"); } diff --git a/Modules/_testcapi/watchers.c b/Modules/_testcapi/watchers.c index 3586929cad223d..6d061bb8d51040 100644 --- a/Modules/_testcapi/watchers.c +++ b/Modules/_testcapi/watchers.c @@ -162,7 +162,7 @@ _testcapi_unwatch_dict_impl(PyObject *module, int watcher_id, PyObject *dict) } static PyObject * -get_dict_watcher_events(PyObject *self, PyObject *Py_UNUSED(ignored)) +get_dict_watcher_events(PyObject *self, PyObject *Py_UNUSED(args)) { if (!g_dict_watch_events) { PyErr_SetString(PyExc_RuntimeError, "no watchers active"); @@ -255,7 +255,7 @@ clear_type_watcher(PyObject *self, PyObject *watcher_id) } static PyObject * -get_type_modified_events(PyObject *self, PyObject *Py_UNUSED(ignored)) +get_type_modified_events(PyObject *self, PyObject *Py_UNUSED(args)) { if (!g_type_modified_events) { PyErr_SetString(PyExc_RuntimeError, "no watchers active"); @@ -413,7 +413,7 @@ get_code_watcher_num_destroyed_events(PyObject *self, PyObject *watcher_id) } static PyObject * -allocate_too_many_code_watchers(PyObject *self, PyObject *Py_UNUSED(ignored)) +allocate_too_many_code_watchers(PyObject *self, PyObject *Py_UNUSED(args)) { int watcher_ids[CODE_MAX_WATCHERS + 1]; int num_watchers = 0; @@ -742,7 +742,7 @@ get_context_switches(PyObject *Py_UNUSED(self), PyObject *watcher_id) } static PyObject * -allocate_too_many_context_watchers(PyObject *self, PyObject *Py_UNUSED(ignored)) +allocate_too_many_context_watchers(PyObject *self, PyObject *Py_UNUSED(args)) { int watcher_ids[CONTEXT_MAX_WATCHERS + 1]; int num_watchers = 0; diff --git a/Modules/atexitmodule.c b/Modules/atexitmodule.c index c84cb05d85e913..4b068967a6ca6e 100644 --- a/Modules/atexitmodule.c +++ b/Modules/atexitmodule.c @@ -217,7 +217,7 @@ Run all registered exit functions.\n\ If a callback raises an exception, it is logged with sys.unraisablehook."); static PyObject * -atexit_run_exitfuncs(PyObject *module, PyObject *Py_UNUSED(ignored)) +atexit_run_exitfuncs(PyObject *module, PyObject *Py_UNUSED(dummy)) { struct atexit_state *state = get_atexit_state(); atexit_callfuncs(state); @@ -231,7 +231,7 @@ PyDoc_STRVAR(atexit_clear__doc__, Clear the list of previously registered exit functions."); static PyObject * -atexit_clear(PyObject *module, PyObject *Py_UNUSED(ignored)) +atexit_clear(PyObject *module, PyObject *Py_UNUSED(dummy)) { atexit_cleanup(get_atexit_state()); Py_RETURN_NONE; @@ -244,7 +244,7 @@ PyDoc_STRVAR(atexit_ncallbacks__doc__, Return the number of registered exit functions."); static PyObject * -atexit_ncallbacks(PyObject *module, PyObject *Py_UNUSED(ignored)) +atexit_ncallbacks(PyObject *module, PyObject *Py_UNUSED(dummy)) { struct atexit_state *state = get_atexit_state(); assert(state->callbacks != NULL); diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index d7f0dff43319c0..c9249574c1e2b9 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -1124,8 +1124,8 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args) Py_RETURN_NONE; } -static PyObject* _Py_NO_SANITIZE_UNDEFINED -faulthandler_sigfpe(PyObject *self, PyObject *Py_UNUSED(ignored)) +static PyObject * _Py_NO_SANITIZE_UNDEFINED +faulthandler_sigfpe(PyObject *self, PyObject *Py_UNUSED(dummy)) { faulthandler_suppress_crash_report(); diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 614c12bb250ada..11d65bad847cd3 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -5922,7 +5922,7 @@ dictview_mapping(PyObject *view, void *Py_UNUSED(ignored)) { } static PyGetSetDef dictview_getset[] = { - {"mapping", dictview_mapping, (setter)NULL, + {"mapping", dictview_mapping, NULL, PyDoc_STR("dictionary that this view refers to"), NULL}, {0} }; diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c index a56ed908d71133..e3bc68f7453dd9 100644 --- a/Objects/genericaliasobject.c +++ b/Objects/genericaliasobject.c @@ -824,8 +824,8 @@ ga_unpacked_tuple_args(PyObject *self, void *unused) } static PyGetSetDef ga_properties[] = { - {"__parameters__", ga_parameters, (setter)NULL, PyDoc_STR("Type variables in the GenericAlias."), NULL}, - {"__typing_unpacked_tuple_args__", ga_unpacked_tuple_args, (setter)NULL, NULL}, + {"__parameters__", ga_parameters, NULL, PyDoc_STR("Type variables in the GenericAlias."), NULL}, + {"__typing_unpacked_tuple_args__", ga_unpacked_tuple_args, NULL, NULL}, {0} }; diff --git a/Objects/longobject.c b/Objects/longobject.c index 984381ff4969d0..e91d2738e02af2 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -6540,19 +6540,19 @@ static PyMethodDef long_methods[] = { static PyGetSetDef long_getset[] = { {"real", - long_long_getter, (setter)NULL, + long_long_getter, NULL, "the real part of a complex number", NULL}, {"imag", - long_get0, (setter)NULL, + long_get0, NULL, "the imaginary part of a complex number", NULL}, {"numerator", - long_long_getter, (setter)NULL, + long_long_getter, NULL, "the numerator of a rational number in lowest terms", NULL}, {"denominator", - long_get1, (setter)NULL, + long_get1, NULL, "the denominator of a rational number in lowest terms", NULL}, {NULL} /* Sentinel */ diff --git a/Objects/unionobject.c b/Objects/unionobject.c index 08422662e8118a..0b7d4c72bffb97 100644 --- a/Objects/unionobject.c +++ b/Objects/unionobject.c @@ -380,7 +380,7 @@ static PyGetSetDef union_properties[] = { PyDoc_STR("Qualified name of the type"), NULL}, {"__origin__", union_origin, NULL, PyDoc_STR("Always returns the type"), NULL}, - {"__parameters__", union_parameters, (setter)NULL, + {"__parameters__", union_parameters, NULL, PyDoc_STR("Type variables in the types.UnionType."), NULL}, {0} }; From a197210165814bdaf7174466af5295fb9d47db53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 20 Mar 2025 16:32:01 +0100 Subject: [PATCH 04/20] remove un-necessary casts for `initproc` --- Modules/_asynciomodule.c | 2 +- Modules/_testcapi/exceptions.c | 2 +- Objects/bytearrayobject.c | 2 +- Objects/listobject.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 28234c4f902a34..80ddcba051211b 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -2956,7 +2956,7 @@ static PyType_Slot Task_slots[] = { {Py_tp_iter, future_new_iter}, {Py_tp_methods, TaskType_methods}, {Py_tp_getset, TaskType_getsetlist}, - {Py_tp_init, (initproc)_asyncio_Task___init__}, + {Py_tp_init, _asyncio_Task___init__}, {Py_tp_new, PyType_GenericNew}, {Py_tp_finalize, TaskObj_finalize}, diff --git a/Modules/_testcapi/exceptions.c b/Modules/_testcapi/exceptions.c index b647bfc71eae24..0604b413e33f61 100644 --- a/Modules/_testcapi/exceptions.c +++ b/Modules/_testcapi/exceptions.c @@ -538,7 +538,7 @@ static PyTypeObject PyRecursingInfinitelyError_Type = { .tp_basicsize = sizeof(PyBaseExceptionObject), .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .tp_doc = PyDoc_STR("Instantiating this exception starts infinite recursion."), - .tp_init = (initproc)recurse_infinitely_error_init, + .tp_init = recurse_infinitely_error_init, }; static PyMethodDef test_methods[] = { diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 8f2d2dd02151c1..b5d5ca9178ebdb 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2832,7 +2832,7 @@ PyTypeObject PyByteArray_Type = { 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)bytearray___init__, /* tp_init */ + bytearray___init__, /* tp_init */ PyType_GenericAlloc, /* tp_alloc */ PyType_GenericNew, /* tp_new */ PyObject_Free, /* tp_free */ diff --git a/Objects/listobject.c b/Objects/listobject.c index 917bef1a66ddff..12d5b33414a92a 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -3873,7 +3873,7 @@ PyTypeObject PyList_Type = { 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)list___init__, /* tp_init */ + list___init__, /* tp_init */ PyType_GenericAlloc, /* tp_alloc */ PyType_GenericNew, /* tp_new */ PyObject_GC_Del, /* tp_free */ From 5a39cb7cce72a7cd5bad5196b5856a957c7453ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 20 Mar 2025 17:33:16 +0100 Subject: [PATCH 05/20] add TODO note to remove casts to `destructor` --- Include/cpython/object.h | 3 ++- Python/ceval.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Include/cpython/object.h b/Include/cpython/object.h index e2300aee7a207a..8bab8aa130e689 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -494,7 +494,8 @@ PyAPI_FUNC(int) _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate, int m #define Py_TRASHCAN_BEGIN(op, dealloc) \ do { \ PyThreadState *tstate = PyThreadState_Get(); \ - if (_Py_ReachedRecursionLimitWithMargin(tstate, 2) && Py_TYPE(op)->tp_dealloc == (destructor)dealloc) { \ + /* TODO(picnixz): remove '(destructor)' cast to detect runtime UBs */ \ + if (tstate->c_recursion_remaining <= Py_TRASHCAN_HEADROOM && Py_TYPE(op)->tp_dealloc == (destructor)dealloc) { \ _PyTrash_thread_deposit_object(tstate, (PyObject *)op); \ break; \ } diff --git a/Python/ceval.c b/Python/ceval.c index 363f263ad2a083..5177bc446b4189 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -102,6 +102,7 @@ _Py_DECREF_STAT_INC(); \ if (--op->ob_refcnt == 0) { \ _PyReftracerTrack(op, PyRefTracer_DESTROY); \ + /* TODO(picnixz): remove '(destructor)' cast to detect runtime UBs */ \ destructor d = (destructor)(dealloc); \ d(op); \ } \ From 222b6623a3996e3153e6955bc1e36cec3ae69abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 20 Mar 2025 16:39:27 +0100 Subject: [PATCH 06/20] un-necessary cast for module free functions --- Modules/_asynciomodule.c | 2 +- Modules/_interpchannelsmodule.c | 2 +- Modules/_testinternalcapi.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 80ddcba051211b..d938955e8cb0e3 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -4396,7 +4396,7 @@ static struct PyModuleDef _asynciomodule = { .m_slots = module_slots, .m_traverse = module_traverse, .m_clear = module_clear, - .m_free = (freefunc)module_free, + .m_free = module_free, }; PyMODINIT_FUNC diff --git a/Modules/_interpchannelsmodule.c b/Modules/_interpchannelsmodule.c index ae64037d56cac0..6cc1a5b828627f 100644 --- a/Modules/_interpchannelsmodule.c +++ b/Modules/_interpchannelsmodule.c @@ -3595,7 +3595,7 @@ static struct PyModuleDef moduledef = { .m_slots = module_slots, .m_traverse = module_traverse, .m_clear = module_clear, - .m_free = (freefunc)module_free, + .m_free = module_free, }; PyMODINIT_FUNC diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c index 56e3408652a6a0..1858ce2b00c824 100644 --- a/Modules/_testinternalcapi.c +++ b/Modules/_testinternalcapi.c @@ -2212,7 +2212,7 @@ static struct PyModuleDef _testcapimodule = { .m_slots = module_slots, .m_traverse = module_traverse, .m_clear = module_clear, - .m_free = (freefunc)module_free, + .m_free = module_free, }; From ad434c0f20f39186eda43cee30c50e60c9f5b028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 20 Mar 2025 16:33:44 +0100 Subject: [PATCH 07/20] fixup: None and NoneType --- Objects/object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Objects/object.c b/Objects/object.c index ecc5a86901a347..523390c99161a1 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -2094,7 +2094,7 @@ static PyNumberMethods none_as_number = { 0, /* nb_negative */ 0, /* nb_positive */ 0, /* nb_absolute */ - (inquiry)none_bool, /* nb_bool */ + none_bool, /* nb_bool */ 0, /* nb_invert */ 0, /* nb_lshift */ 0, /* nb_rshift */ @@ -2140,7 +2140,7 @@ PyTypeObject _PyNone_Type = { &none_as_number, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ - (hashfunc)none_hash,/*tp_hash */ + none_hash, /*tp_hash */ 0, /*tp_call */ 0, /*tp_str */ 0, /*tp_getattro */ From 2fea60f8a7dfafe3b37fcc0bd838fad0c71b48cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 20 Mar 2025 16:11:13 +0100 Subject: [PATCH 08/20] fixup: _PyDictViewObject --- Objects/dictobject.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 11d65bad847cd3..dc2267d6c65ab5 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -6339,7 +6339,7 @@ dictviews_xor(PyObject* self, PyObject *other) static PyNumberMethods dictviews_as_number = { 0, /*nb_add*/ - (binaryfunc)dictviews_sub, /*nb_subtract*/ + dictviews_sub, /*nb_subtract*/ 0, /*nb_multiply*/ 0, /*nb_remainder*/ 0, /*nb_divmod*/ @@ -6351,9 +6351,9 @@ static PyNumberMethods dictviews_as_number = { 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ - (binaryfunc)_PyDictView_Intersect, /*nb_and*/ - (binaryfunc)dictviews_xor, /*nb_xor*/ - (binaryfunc)dictviews_or, /*nb_or*/ + _PyDictView_Intersect, /*nb_and*/ + dictviews_xor, /*nb_xor*/ + dictviews_or, /*nb_or*/ }; static PyObject* @@ -6611,7 +6611,7 @@ static PySequenceMethods dictvalues_as_sequence = { 0, /* sq_slice */ 0, /* sq_ass_item */ 0, /* sq_ass_slice */ - (objobjproc)0, /* sq_contains */ + 0, /* sq_contains */ }; static PyObject* dictvalues_reversed(PyObject *dv, PyObject *Py_UNUSED(ignored)); From 47bc0ee4135b589f23af5329cca273e0605bab00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 20 Mar 2025 16:08:48 +0100 Subject: [PATCH 09/20] fixup: bool_invert --- Objects/boolobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/boolobject.c b/Objects/boolobject.c index a88a8ad0cfd560..b694691ae4d0d1 100644 --- a/Objects/boolobject.c +++ b/Objects/boolobject.c @@ -130,7 +130,7 @@ static PyNumberMethods bool_as_number = { 0, /* nb_positive */ 0, /* nb_absolute */ 0, /* nb_bool */ - (unaryfunc)bool_invert, /* nb_invert */ + bool_invert, /* nb_invert */ 0, /* nb_lshift */ 0, /* nb_rshift */ bool_and, /* nb_and */ From a894c4cc802ae270507e36e2e03ae9822c9ac31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 20 Mar 2025 16:10:05 +0100 Subject: [PATCH 10/20] fixup: PyUnicodeObject methods --- Objects/unicodeobject.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index c48ab8e441fa6d..7c735685e89389 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -14340,14 +14340,14 @@ static PyNumberMethods unicode_as_number = { }; static PySequenceMethods unicode_as_sequence = { - (lenfunc) unicode_length, /* sq_length */ - PyUnicode_Concat, /* sq_concat */ - (ssizeargfunc) unicode_repeat, /* sq_repeat */ - (ssizeargfunc) unicode_getitem, /* sq_item */ + unicode_length, /* sq_length */ + PyUnicode_Concat, /* sq_concat */ + unicode_repeat, /* sq_repeat */ + unicode_getitem, /* sq_item */ 0, /* sq_slice */ 0, /* sq_ass_item */ 0, /* sq_ass_slice */ - PyUnicode_Contains, /* sq_contains */ + PyUnicode_Contains, /* sq_contains */ }; static PyObject* @@ -14421,9 +14421,9 @@ unicode_subscript(PyObject* self, PyObject* item) } static PyMappingMethods unicode_as_mapping = { - (lenfunc)unicode_length, /* mp_length */ - (binaryfunc)unicode_subscript, /* mp_subscript */ - (objobjargproc)0, /* mp_ass_subscript */ + unicode_length, /* mp_length */ + unicode_subscript, /* mp_subscript */ + 0, /* mp_ass_subscript */ }; @@ -15566,7 +15566,7 @@ PyTypeObject PyUnicode_Type = { sizeof(PyUnicodeObject), /* tp_basicsize */ 0, /* tp_itemsize */ /* Slots */ - (destructor)unicode_dealloc, /* tp_dealloc */ + unicode_dealloc, /* tp_dealloc */ 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ @@ -15575,9 +15575,9 @@ PyTypeObject PyUnicode_Type = { &unicode_as_number, /* tp_as_number */ &unicode_as_sequence, /* tp_as_sequence */ &unicode_as_mapping, /* tp_as_mapping */ - (hashfunc) unicode_hash, /* tp_hash*/ + unicode_hash, /* tp_hash*/ 0, /* tp_call*/ - (reprfunc) unicode_str, /* tp_str */ + unicode_str, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ From 1c17bfcfe74fd3a75474831147d5e310b8f37173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 20 Mar 2025 16:21:29 +0100 Subject: [PATCH 11/20] fixup: rangeobject --- Objects/rangeobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index d5cc2b09427dee..24f9ce807fd24e 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -733,7 +733,7 @@ range_subscript(PyObject *op, PyObject *item) static PyMappingMethods range_as_mapping = { range_length, /* mp_length */ range_subscript, /* mp_subscript */ - (objobjargproc)0, /* mp_ass_subscript */ + 0, /* mp_ass_subscript */ }; static int From e4157397eaedce43ed484aa73546a3def2c855bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 20 Mar 2025 21:26:28 +0100 Subject: [PATCH 12/20] fixup: zoneinfo_init_subclass --- Modules/_zoneinfo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index fe78645dda15ba..3f202790673340 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -2580,14 +2580,14 @@ initialize_caches(zoneinfo_state *state) } static PyObject * -zoneinfo_init_subclass(PyTypeObject *cls, PyObject *args, PyObject **kwargs) +zoneinfo_init_subclass(PyObject *cls, PyObject *args, PyObject **kwargs) { PyObject *weak_cache = new_weak_cache(); if (weak_cache == NULL) { return NULL; } - if (PyObject_SetAttrString((PyObject *)cls, "_weak_cache", + if (PyObject_SetAttrString(cls, "_weak_cache", weak_cache) < 0) { Py_DECREF(weak_cache); return NULL; From 86bc47cbee2bc6f55032e06c21a3eece9dc29780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Mon, 24 Mar 2025 11:57:56 +0100 Subject: [PATCH 13/20] fixup: ga_iter --- Objects/genericaliasobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c index e3bc68f7453dd9..ec3d01f00a3c3c 100644 --- a/Objects/genericaliasobject.c +++ b/Objects/genericaliasobject.c @@ -1000,7 +1000,7 @@ PyTypeObject Py_GenericAliasType = { .tp_new = ga_new, .tp_free = PyObject_GC_Del, .tp_getset = ga_properties, - .tp_iter = (getiterfunc)ga_iter, + .tp_iter = ga_iter, .tp_vectorcall_offset = offsetof(gaobject, vectorcall), }; From 5d98a84cfd874d4baae86300fa8a3f76b7e92fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Mon, 24 Mar 2025 11:58:25 +0100 Subject: [PATCH 14/20] fixup: hamt_baseiter_tp_iternext --- Python/hamt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/hamt.c b/Python/hamt.c index 42a0baffd9def9..e4d1e1663dd573 100644 --- a/Python/hamt.c +++ b/Python/hamt.c @@ -2516,7 +2516,7 @@ hamt_baseiter_new(PyTypeObject *type, binaryfunc yield, PyHamtObject *o) .tp_traverse = hamt_baseiter_tp_traverse, \ .tp_clear = hamt_baseiter_tp_clear, \ .tp_iter = PyObject_SelfIter, \ - .tp_iternext = (iternextfunc)hamt_baseiter_tp_iternext, + .tp_iternext = hamt_baseiter_tp_iternext, /////////////////////////////////// _PyHamtItems_Type From 1053101cdd8d6c95c9b782dc19f86ae2a75591fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Mon, 24 Mar 2025 12:56:14 +0100 Subject: [PATCH 15/20] remove dead code --- Modules/_io/textio.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 377c85f5ac67a6..e77d8448310fba 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -3386,8 +3386,6 @@ static PyMemberDef textiowrapper_members[] = { static PyGetSetDef textiowrapper_getset[] = { _IO_TEXTIOWRAPPER_NAME_GETSETDEF _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF -/* {"mode", (getter)TextIOWrapper_mode_get, NULL, NULL}, -*/ _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF From 9c780ad2838353a3728fbf568c0b9d2493b67479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Mon, 24 Mar 2025 18:52:53 +0100 Subject: [PATCH 16/20] Update Include/cpython/object.h --- Include/cpython/object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 8bab8aa130e689..548d7ee5140b3f 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -495,7 +495,7 @@ PyAPI_FUNC(int) _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate, int m do { \ PyThreadState *tstate = PyThreadState_Get(); \ /* TODO(picnixz): remove '(destructor)' cast to detect runtime UBs */ \ - if (tstate->c_recursion_remaining <= Py_TRASHCAN_HEADROOM && Py_TYPE(op)->tp_dealloc == (destructor)dealloc) { \ + if (_Py_ReachedRecursionLimitWithMargin(tstate, 2) && Py_TYPE(op)->tp_dealloc == (destructor)dealloc) { \ _PyTrash_thread_deposit_object(tstate, (PyObject *)op); \ break; \ } From 92d648e03547f3589b86893a614e8f577720ea53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sun, 30 Mar 2025 11:10:23 +0200 Subject: [PATCH 17/20] fixup comments --- Include/cpython/object.h | 2 +- Python/ceval.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 548d7ee5140b3f..0b320714f97608 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -494,7 +494,7 @@ PyAPI_FUNC(int) _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate, int m #define Py_TRASHCAN_BEGIN(op, dealloc) \ do { \ PyThreadState *tstate = PyThreadState_Get(); \ - /* TODO(picnixz): remove '(destructor)' cast to detect runtime UBs */ \ + /* TODO(picnixz): remove cast to detect incorrect macro usages */ \ if (_Py_ReachedRecursionLimitWithMargin(tstate, 2) && Py_TYPE(op)->tp_dealloc == (destructor)dealloc) { \ _PyTrash_thread_deposit_object(tstate, (PyObject *)op); \ break; \ diff --git a/Python/ceval.c b/Python/ceval.c index 5177bc446b4189..1b86a34a8a7922 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -102,7 +102,7 @@ _Py_DECREF_STAT_INC(); \ if (--op->ob_refcnt == 0) { \ _PyReftracerTrack(op, PyRefTracer_DESTROY); \ - /* TODO(picnixz): remove '(destructor)' cast to detect runtime UBs */ \ + /* TODO(picnixz): remove cast to detect incorrect macro usages */ \ destructor d = (destructor)(dealloc); \ d(op); \ } \ From 4bf2a1e5e880c8a6e261bb90619f64f705ae5009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Tue, 1 Apr 2025 15:41:23 +0200 Subject: [PATCH 18/20] Update Modules/faulthandler.c Co-authored-by: Victor Stinner --- Modules/faulthandler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index e5b05a018196a2..cc5ecdcc4f96e9 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -1107,7 +1107,7 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args) Py_RETURN_NONE; } -static PyObject * _Py_NO_SANITIZE_UNDEFINED +static PyObject* _Py_NO_SANITIZE_UNDEFINED faulthandler_sigfpe(PyObject *self, PyObject *Py_UNUSED(dummy)) { faulthandler_suppress_crash_report(); From db5dae1e85ab06bde2d2143aebee5a47adefa877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Tue, 1 Apr 2025 15:45:43 +0200 Subject: [PATCH 19/20] Update Include/cpython/object.h --- Include/cpython/object.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 0b320714f97608..e2300aee7a207a 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -494,7 +494,6 @@ PyAPI_FUNC(int) _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate, int m #define Py_TRASHCAN_BEGIN(op, dealloc) \ do { \ PyThreadState *tstate = PyThreadState_Get(); \ - /* TODO(picnixz): remove cast to detect incorrect macro usages */ \ if (_Py_ReachedRecursionLimitWithMargin(tstate, 2) && Py_TYPE(op)->tp_dealloc == (destructor)dealloc) { \ _PyTrash_thread_deposit_object(tstate, (PyObject *)op); \ break; \ From 6cfed6c10b4b9db0c10cc922f80c242d3c511fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Tue, 1 Apr 2025 15:47:42 +0200 Subject: [PATCH 20/20] Update Python/ceval.c --- Python/ceval.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index 1b86a34a8a7922..363f263ad2a083 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -102,7 +102,6 @@ _Py_DECREF_STAT_INC(); \ if (--op->ob_refcnt == 0) { \ _PyReftracerTrack(op, PyRefTracer_DESTROY); \ - /* TODO(picnixz): remove cast to detect incorrect macro usages */ \ destructor d = (destructor)(dealloc); \ d(op); \ } \