From 4c483c4d8eac8603ff299adbd373e4f14da61ff9 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Wed, 5 Sep 2001 06:24:58 +0000 Subject: Make the error msgs in our pow() implementations consistent. --- Objects/floatobject.c | 4 ++-- Objects/intobject.c | 6 +++--- Objects/longobject.c | 13 ++++++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 8443aff..258c4dd 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -495,8 +495,8 @@ float_pow(PyObject *v, PyObject *w, PyObject *z) double iv, iw, ix; if ((PyObject *)z != Py_None) { - PyErr_SetString(PyExc_TypeError, - "3rd argument to floating pow() must be None"); + PyErr_SetString(PyExc_TypeError, "pow() 3rd argument not " + "allowed unless all other arguments are integers"); return NULL; } diff --git a/Objects/intobject.c b/Objects/intobject.c index 73d5e77..12edb51 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -589,8 +589,8 @@ int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z) CONVERT_TO_LONG(w, iw); if (iw < 0) { if ((PyObject *)z != Py_None) { - PyErr_SetString(PyExc_TypeError, "integer pow() arg " - "3 must not be specified when arg 2 is < 0"); + PyErr_SetString(PyExc_TypeError, "pow() 2nd argument " + "cannot be negative when 3rd argument specified"); return NULL; } /* Return a float. This works because we know that @@ -603,7 +603,7 @@ int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z) CONVERT_TO_LONG(z, iz); if (iz == 0) { PyErr_SetString(PyExc_ValueError, - "pow() arg 3 cannot be 0"); + "pow() 3rd argument cannot be 0"); return NULL; } } diff --git a/Objects/longobject.c b/Objects/longobject.c index 91e0b66..e9e408d 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -1685,15 +1685,22 @@ long_pow(PyObject *v, PyObject *w, PyObject *x) Py_INCREF(Py_NotImplemented); return Py_NotImplemented; } - + + if (c != Py_None && ((PyLongObject *)c)->ob_size == 0) { + PyErr_SetString(PyExc_ValueError, + "pow() 3rd argument cannot be 0"); + z = NULL; + goto error; + } + size_b = b->ob_size; if (size_b < 0) { Py_DECREF(a); Py_DECREF(b); Py_DECREF(c); if (x != Py_None) { - PyErr_SetString(PyExc_TypeError, "integer pow() arg " - "3 must not be specified when arg 2 is < 0"); + PyErr_SetString(PyExc_TypeError, "pow() 2nd argument " + "cannot be negative when 3rd argument specified"); return NULL; } /* Return a float. This works because we know that -- cgit v0.12