diff options
author | Raymond Hettinger <python@rcn.com> | 2008-07-24 19:38:45 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-07-24 19:38:45 (GMT) |
commit | d4d478d1c693481466a054cf12ee51b8f7061f99 (patch) | |
tree | 6e61758099e19d9a232adf49ff70a9e47e1c051a /Objects/enumobject.c | |
parent | 6e6f59b1c9fc01d2cf0404c775214819e6f07b34 (diff) | |
download | cpython-d4d478d1c693481466a054cf12ee51b8f7061f99.zip cpython-d4d478d1c693481466a054cf12ee51b8f7061f99.tar.gz cpython-d4d478d1c693481466a054cf12ee51b8f7061f99.tar.bz2 |
Merge 65215: convert uses of int to Py_Ssize_t.
Diffstat (limited to 'Objects/enumobject.c')
-rw-r--r-- | Objects/enumobject.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/Objects/enumobject.c b/Objects/enumobject.c index c1a1872..2b114a3 100644 --- a/Objects/enumobject.c +++ b/Objects/enumobject.c @@ -4,10 +4,10 @@ typedef struct { PyObject_HEAD - long en_index; /* current index of enumeration */ + Py_ssize_t en_index; /* current index of enumeration */ PyObject* en_sit; /* secondary iterator of enumeration */ PyObject* en_result; /* result tuple */ - PyObject* en_longindex; /* index for sequences >= LONG_MAX */ + PyObject* en_longindex; /* index for sequences >= PY_SSIZE_T_MAX */ } enumobject; static PyObject * @@ -25,14 +25,21 @@ enum_new(PyTypeObject *type, PyObject *args, PyObject *kwds) en = (enumobject *)type->tp_alloc(type, 0); if (en == NULL) return NULL; - if (start) { + if (start != NULL) { start = PyNumber_Index(start); if (start == NULL) { Py_DECREF(en); return NULL; } - en->en_index = LONG_MAX; - en->en_longindex = start; + en->en_index = PyLong_AsSsize_t(start); + if (en->en_index == -1 && PyErr_Occurred()) { + PyErr_Clear(); + en->en_index = PY_SSIZE_T_MAX; + en->en_longindex = start; + } else { + en->en_longindex = NULL; + Py_DECREF(start); + } } else { en->en_index = 0; en->en_longindex = NULL; @@ -78,7 +85,7 @@ enum_next_long(enumobject *en, PyObject* next_item) PyObject *stepped_up; if (en->en_longindex == NULL) { - en->en_longindex = PyLong_FromLong(LONG_MAX); + en->en_longindex = PyLong_FromSsize_t(PY_SSIZE_T_MAX); if (en->en_longindex == NULL) return NULL; } @@ -123,10 +130,10 @@ enum_next(enumobject *en) if (next_item == NULL) return NULL; - if (en->en_index == LONG_MAX) + if (en->en_index == PY_SSIZE_T_MAX) return enum_next_long(en, next_item); - next_index = PyLong_FromLong(en->en_index); + next_index = PyLong_FromSsize_t(en->en_index); if (next_index == NULL) { Py_DECREF(next_item); return NULL; |