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:
Zackery Spytz 2019-05-31 03:46:36 -06:00 committed by Miss Islington (bot)
parent c7f7069e77
commit c7f803b08e
4 changed files with 36 additions and 1 deletions

View file

@ -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;