summaryrefslogtreecommitdiff
path: root/Objects/rangeobject.c
diff options
context:
space:
mode:
authorMariatta Wijaya <mariatta.wijaya@gmail.com>2017-02-06 20:16:58 -0800
committerMariatta Wijaya <mariatta.wijaya@gmail.com>2017-02-06 20:16:58 -0800
commitda79bcf8ac7ae72218ab023e1ed54390bc1a3a27 (patch)
tree74845e2dbd9521d9748b9c32f1922f4123083bf3 /Objects/rangeobject.c
parente3c7e835bdfc97750eb9b7fc0ad2493108c2d438 (diff)
parent1fe806ac56f8b83694d24ab604eb695d00bc8497 (diff)
downloadcpython-da79bcf8ac7ae72218ab023e1ed54390bc1a3a27.tar.gz
Issue #29371: merge with 3.5
Diffstat (limited to 'Objects/rangeobject.c')
-rw-r--r--Objects/rangeobject.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index 899697aa3a..8449fc7a24 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -6,7 +6,7 @@
/* Support objects whose length is > PY_SSIZE_T_MAX.
This could be sped up for small PyLongs if they fit in a Py_ssize_t.
- This only matters on Win64. Though we could use PY_LONG_LONG which
+ This only matters on Win64. Though we could use long long which
would presumably help perf.
*/
@@ -29,17 +29,10 @@ validate_step(PyObject *step)
return PyLong_FromLong(1);
step = PyNumber_Index(step);
- if (step) {
- Py_ssize_t istep = PyNumber_AsSsize_t(step, NULL);
- if (istep == -1 && PyErr_Occurred()) {
- /* Ignore OverflowError, we know the value isn't 0. */
- PyErr_Clear();
- }
- else if (istep == 0) {
- PyErr_SetString(PyExc_ValueError,
- "range() arg 3 must not be zero");
- Py_CLEAR(step);
- }
+ if (step && _PyLong_Sign(step) == 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "range() arg 3 must not be zero");
+ Py_CLEAR(step);
}
return step;
@@ -129,9 +122,9 @@ range_new(PyTypeObject *type, PyObject *args, PyObject *kw)
return (PyObject *) obj;
/* Failed to create object, release attributes */
- Py_XDECREF(start);
- Py_XDECREF(stop);
- Py_XDECREF(step);
+ Py_DECREF(start);
+ Py_DECREF(stop);
+ Py_DECREF(step);
return NULL;
}
@@ -196,7 +189,7 @@ compute_range_length(PyObject *start, PyObject *stop, PyObject *step)
/* if (lo >= hi), return length of 0. */
cmp_result = PyObject_RichCompareBool(lo, hi, Py_GE);
if (cmp_result != 0) {
- Py_XDECREF(step);
+ Py_DECREF(step);
if (cmp_result < 0)
return NULL;
return PyLong_FromLong(0);
@@ -225,9 +218,9 @@ compute_range_length(PyObject *start, PyObject *stop, PyObject *step)
return result;
Fail:
+ Py_DECREF(step);
Py_XDECREF(tmp2);
Py_XDECREF(diff);
- Py_XDECREF(step);
Py_XDECREF(tmp1);
Py_XDECREF(one);
return NULL;
@@ -937,6 +930,13 @@ rangeiter_new(PyTypeObject *type, PyObject *args, PyObject *kw)
{
long start, stop, step;
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "range_iterator(): creating instances of range_iterator "
+ "by calling range_iterator type is deprecated",
+ 1)) {
+ return NULL;
+ }
+
if (!_PyArg_NoKeywords("range_iterator()", kw)) {
return NULL;
}