https://github.com/python/cpython/commit/2ed671b5e3a64183ed2af220dd37c6b5182f52d3
commit: 2ed671b5e3a64183ed2af220dd37c6b5182f52d3
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2025-03-13T10:22:58+01:00
summary:
gh-111178: Change Argument Clinic signature for `@staticmethod` (#131157)
(#131159)
Use "PyObject*", instead of "void*", for `@staticmethod` functions to
fix an undefined behavior.
files:
M Lib/test/clinic.test.c
M Objects/clinic/bytearrayobject.c.h
M Objects/clinic/bytesobject.c.h
M Objects/clinic/unicodeobject.c.h
M Tools/clinic/libclinic/converters.py
diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c
index 68330051771222..cf7cff857a538c 100644
--- a/Lib/test/clinic.test.c
+++ b/Lib/test/clinic.test.c
@@ -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]
diff --git a/Objects/clinic/bytearrayobject.c.h
b/Objects/clinic/bytearrayobject.c.h
index 5f41c53a365534..262438f830a9ad 100644
--- a/Objects/clinic/bytearrayobject.c.h
+++ b/Objects/clinic/bytearrayobject.c.h
@@ -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]*/
diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h
index d50daeffd74ed2..f1f16de0c8af54 100644
--- a/Objects/clinic/bytesobject.c.h
+++ b/Objects/clinic/bytesobject.c.h
@@ -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 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject
*kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=60d6a9f1333b76f0 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c607024162df3ea8 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h
index 99651f3c64bc5a..c299cf2cfc8bc1 100644
--- a/Objects/clinic/unicodeobject.c.h
+++ b/Objects/clinic/unicodeobject.c.h
@@ -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 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject
*kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=db37497bf38a2c17 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=81d703159f829f1f input=a9049054013a1b77]*/
diff --git a/Tools/clinic/libclinic/converters.py
b/Tools/clinic/libclinic/converters.py
index 572768190ae121..871d7542ba0763 100644
--- a/Tools/clinic/libclinic/converters.py
+++ b/Tools/clinic/libclinic/converters.py
@@ -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"
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]