mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +00:00
bpo-36379: __ipow__ must be a ternaryfunc, not a binaryfunc (GH-13546)
If a type's __ipow__ method was implemented in C, attempting to use the *modulo* parameter would cause crashes. https://bugs.python.org/issue36379
This commit is contained in:
parent
c7f7069e77
commit
c7f803b08e
4 changed files with 36 additions and 1 deletions
|
|
@ -5522,6 +5522,27 @@ static PyTypeObject matmulType = {
|
|||
PyObject_Del, /* tp_free */
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} ipowObject;
|
||||
|
||||
static PyObject *
|
||||
ipowType_ipow(PyObject *self, PyObject *other, PyObject *mod)
|
||||
{
|
||||
return Py_BuildValue("OO", other, mod);
|
||||
}
|
||||
|
||||
static PyNumberMethods ipowType_as_number = {
|
||||
.nb_inplace_power = ipowType_ipow
|
||||
};
|
||||
|
||||
static PyTypeObject ipowType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
.tp_name = "ipowType",
|
||||
.tp_basicsize = sizeof(ipowObject),
|
||||
.tp_as_number = &ipowType_as_number,
|
||||
.tp_new = PyType_GenericNew
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
|
|
@ -5947,6 +5968,11 @@ PyInit__testcapi(void)
|
|||
return NULL;
|
||||
Py_INCREF(&matmulType);
|
||||
PyModule_AddObject(m, "matmulType", (PyObject *)&matmulType);
|
||||
if (PyType_Ready(&ipowType) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
Py_INCREF(&ipowType);
|
||||
PyModule_AddObject(m, "ipowType", (PyObject *)&ipowType);
|
||||
|
||||
if (PyType_Ready(&awaitType) < 0)
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue