~pythonregexp2.7/python/issue2636-11

« back to all changes in this revision

Viewing changes to Objects/enumobject.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-21 17:53:26 UTC
  • mfrom: (39025.1.14 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080921175326-92vaej2hc3yuecxb
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
typedef struct {
6
6
        PyObject_HEAD
7
 
        long      en_index;        /* current index of enumeration */
 
7
        Py_ssize_t en_index;       /* current index of enumeration */
8
8
        PyObject* en_sit;          /* secondary iterator of enumeration */
9
9
        PyObject* en_result;       /* result tuple  */
10
 
        PyObject* en_longindex;    /* index for sequences >= LONG_MAX */
 
10
        PyObject* en_longindex;    /* index for sequences >= PY_SSIZE_T_MAX */
11
11
} enumobject;
12
12
 
13
13
static PyObject *
25
25
        en = (enumobject *)type->tp_alloc(type, 0);
26
26
        if (en == NULL)
27
27
                return NULL;
28
 
        if (start) {
 
28
        if (start != NULL) {
29
29
                start = PyNumber_Index(start);
30
30
                if (start == NULL) {
31
31
                        Py_DECREF(en);
32
32
                        return NULL;
33
33
                }
34
 
                if (PyLong_Check(start)) {
35
 
                        en->en_index = LONG_MAX;
 
34
                assert(PyInt_Check(start) || PyLong_Check(start));
 
35
                en->en_index = PyInt_AsSsize_t(start);
 
36
                if (en->en_index == -1 && PyErr_Occurred()) {
 
37
                        PyErr_Clear();
 
38
                        en->en_index = PY_SSIZE_T_MAX;
36
39
                        en->en_longindex = start;
37
40
                } else {
38
 
                        assert(PyInt_Check(start));
39
 
                        en->en_index = PyInt_AsLong(start);
40
41
                        en->en_longindex = NULL;
41
42
                        Py_DECREF(start);
42
43
                }
85
86
        PyObject *stepped_up;
86
87
 
87
88
        if (en->en_longindex == NULL) {
88
 
                en->en_longindex = PyInt_FromLong(LONG_MAX);
 
89
                en->en_longindex = PyInt_FromSsize_t(PY_SSIZE_T_MAX);
89
90
                if (en->en_longindex == NULL)
90
91
                        return NULL;
91
92
        }
130
131
        if (next_item == NULL)
131
132
                return NULL;
132
133
 
133
 
        if (en->en_index == LONG_MAX)
 
134
        if (en->en_index == PY_SSIZE_T_MAX)
134
135
                return enum_next_long(en, next_item);
135
136
 
136
 
        next_index = PyInt_FromLong(en->en_index);
 
137
        next_index = PyInt_FromSsize_t(en->en_index);
137
138
        if (next_index == NULL) {
138
139
                Py_DECREF(next_item);
139
140
                return NULL;