gh-111178: Change Argument Clinic signature for @staticmethod (#131157) (#131159)

Use "PyObject*", instead of "void*", for `@staticmethod` functions to
fix an undefined behavior.
This commit is contained in:
Victor Stinner 2025-03-13 10:22:58 +01:00 committed by GitHub
parent dd6d24e9d2
commit 2ed671b5e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 12 additions and 9 deletions

View 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]

View 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]*/

View 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]*/

View 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]*/

View 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"