]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111178: Change Argument Clinic signature for `@staticmethod` (#131157) (#131159)
authorVictor Stinner <vstinner@python.org>
Thu, 13 Mar 2025 09:22:58 +0000 (10:22 +0100)
committerGitHub <noreply@github.com>
Thu, 13 Mar 2025 09:22:58 +0000 (10:22 +0100)
Use "PyObject*", instead of "void*", for `@staticmethod` functions to
fix an undefined behavior.

Lib/test/clinic.test.c
Objects/clinic/bytearrayobject.c.h
Objects/clinic/bytesobject.c.h
Objects/clinic/unicodeobject.c.h
Tools/clinic/libclinic/converters.py

index 6833005177122287c814f1b090d990a06784b966..cf7cff857a538c83eba9ca78799eafdf0a84fdf7 100644 (file)
@@ -5262,14 +5262,14 @@ static PyObject *
 Test_static_method_impl();
 
 static PyObject *
-Test_static_method(void *null, PyObject *Py_UNUSED(ignored))
+Test_static_method(PyObject *null, PyObject *Py_UNUSED(ignored))
 {
     return Test_static_method_impl();
 }
 
 static PyObject *
 Test_static_method_impl()
-/*[clinic end generated code: output=82524a63025cf7ab input=dae892fac55ae72b]*/
+/*[clinic end generated code: output=9e401fb6ed56a4f3 input=dae892fac55ae72b]*/
 
 
 /*[clinic input]
index 5f41c53a365534de1d8f004ab1f0c6b831c6ea67..262438f830a9ad85fec2ef331739a90903f98b07 100644 (file)
@@ -719,7 +719,7 @@ static PyObject *
 bytearray_maketrans_impl(Py_buffer *frm, Py_buffer *to);
 
 static PyObject *
-bytearray_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
+bytearray_maketrans(PyObject *null, PyObject *const *args, Py_ssize_t nargs)
 {
     PyObject *return_value = NULL;
     Py_buffer frm = {NULL, NULL};
@@ -1782,4 +1782,4 @@ bytearray_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored))
 {
     return bytearray_sizeof_impl((PyByteArrayObject *)self);
 }
-/*[clinic end generated code: output=b1dce6c12ad1a9e2 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=0d1d1abc8b701ad9 input=a9049054013a1b77]*/
index d50daeffd74ed2d2b0f768c7c6005a709e45fbea..f1f16de0c8af54cdc81e16295fb66fd1ecb0882f 100644 (file)
@@ -752,7 +752,7 @@ static PyObject *
 bytes_maketrans_impl(Py_buffer *frm, Py_buffer *to);
 
 static PyObject *
-bytes_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
+bytes_maketrans(PyObject *null, PyObject *const *args, Py_ssize_t nargs)
 {
     PyObject *return_value = NULL;
     Py_buffer frm = {NULL, NULL};
@@ -1397,4 +1397,4 @@ skip_optional_pos:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=60d6a9f1333b76f0 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c607024162df3ea8 input=a9049054013a1b77]*/
index 99651f3c64bc5aa5fe48a6629d19c54d017bd855..c299cf2cfc8bc114f576eff24f7c6c73d407b98b 100644 (file)
@@ -1546,7 +1546,7 @@ static PyObject *
 unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z);
 
 static PyObject *
-unicode_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
+unicode_maketrans(PyObject *null, PyObject *const *args, Py_ssize_t nargs)
 {
     PyObject *return_value = NULL;
     PyObject *x;
@@ -1894,4 +1894,4 @@ skip_optional_pos:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=db37497bf38a2c17 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=81d703159f829f1f input=a9049054013a1b77]*/
index 572768190ae121233dfcc6a8812414dcc0886de5..871d7542ba07631fdf41ee6e33af8973076df86a 100644 (file)
@@ -1115,7 +1115,10 @@ def correct_name_for_self(
             return "PyObject *", "self"
         return "PyObject *", "module"
     if f.kind is STATIC_METHOD:
-        return "void *", "null"
+        if parser:
+            return "PyObject *", "null"
+        else:
+            return "void *", "null"
     if f.kind == CLASS_METHOD:
         if parser:
             return "PyObject *", "type"