summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2019-05-31 03:46:36 -0600
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-05-31 02:46:36 -0700
commitc7f803b08ed5211701c75f98ba9ada85d45ac155 (patch)
treea283b57dae8d45875c48b3143a11aef601fb3d9f /Modules
parentc7f7069e77c58e83b847c0bfe4d5aadf6add2e68 (diff)
downloadcpython-git-c7f803b08ed5211701c75f98ba9ada85d45ac155.tar.gz
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
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index ca6e87b79c..b42f41cc8d 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -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;