summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Objects/rangeobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/tools/python3/Objects/rangeobject.c')
-rw-r--r--contrib/tools/python3/Objects/rangeobject.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/contrib/tools/python3/Objects/rangeobject.c b/contrib/tools/python3/Objects/rangeobject.c
index beb86b9623b..57e1e008320 100644
--- a/contrib/tools/python3/Objects/rangeobject.c
+++ b/contrib/tools/python3/Objects/rangeobject.c
@@ -2,10 +2,12 @@
#include "Python.h"
#include "pycore_abstract.h" // _PyIndex_Check()
-#include "pycore_range.h"
+#include "pycore_ceval.h" // _PyEval_GetBuiltin()
#include "pycore_long.h" // _PyLong_GetZero()
+#include "pycore_modsupport.h" // _PyArg_NoKwnames()
+#include "pycore_range.h"
#include "pycore_tuple.h" // _PyTuple_ITEMS()
-#include "structmember.h" // PyMemberDef
+
/* Support objects whose length is > PY_SSIZE_T_MAX.
@@ -105,8 +107,8 @@ range_from_array(PyTypeObject *type, PyObject *const *args, Py_ssize_t num_args)
if (!stop) {
return NULL;
}
- start = Py_NewRef(_PyLong_GetZero());
- step = Py_NewRef(_PyLong_GetOne());
+ start = _PyLong_GetZero();
+ step = _PyLong_GetOne();
break;
case 0:
PyErr_SetString(PyExc_TypeError,
@@ -749,16 +751,16 @@ PyDoc_STRVAR(index_doc,
static PyMethodDef range_methods[] = {
{"__reversed__", range_reverse, METH_NOARGS, reverse_doc},
- {"__reduce__", (PyCFunction)range_reduce, METH_VARARGS},
+ {"__reduce__", (PyCFunction)range_reduce, METH_NOARGS},
{"count", (PyCFunction)range_count, METH_O, count_doc},
{"index", (PyCFunction)range_index, METH_O, index_doc},
{NULL, NULL} /* sentinel */
};
static PyMemberDef range_members[] = {
- {"start", T_OBJECT_EX, offsetof(rangeobject, start), READONLY},
- {"stop", T_OBJECT_EX, offsetof(rangeobject, stop), READONLY},
- {"step", T_OBJECT_EX, offsetof(rangeobject, step), READONLY},
+ {"start", Py_T_OBJECT_EX, offsetof(rangeobject, start), Py_READONLY},
+ {"stop", Py_T_OBJECT_EX, offsetof(rangeobject, stop), Py_READONLY},
+ {"step", Py_T_OBJECT_EX, offsetof(rangeobject, step), Py_READONLY},
{0}
};
@@ -1012,6 +1014,11 @@ longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored))
static PyObject *
longrangeiter_setstate(longrangeiterobject *r, PyObject *state)
{
+ if (!PyLong_CheckExact(state)) {
+ PyErr_Format(PyExc_TypeError, "state must be an int, not %T", state);
+ return NULL;
+ }
+
PyObject *zero = _PyLong_GetZero(); // borrowed reference
int cmp;