~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_static_tuple_c.c

  • Committer: John Arbash Meinel
  • Date: 2009-10-27 14:07:16 UTC
  • mto: This revision was merged to the branch mainline in revision 4774.
  • Revision ID: john@arbash-meinel.com-20091027140716-ggors1mphschb5yo
Clean up the C code a bit, using a goto.

Show diffs side-by-side

added added

removed removed

Lines of Context:
183
183
static StaticTuple *
184
184
StaticTuple_FromSequence(PyObject *sequence)
185
185
{
186
 
    StaticTuple *new;
 
186
    StaticTuple *new = NULL;
187
187
    PyObject *as_tuple = NULL;
188
188
    PyObject *item;
189
189
    Py_ssize_t i, size;
194
194
    }
195
195
    if (!PySequence_Check(sequence)) {
196
196
        as_tuple = PySequence_Tuple(sequence);
 
197
        if (as_tuple == NULL)
 
198
            goto done;
197
199
        sequence = as_tuple;
198
200
    }
199
201
    size = PySequence_Size(sequence);
200
202
    if (size == -1) {
201
 
        Py_XDECREF(as_tuple);
202
 
        return NULL;
 
203
        goto done;
203
204
    }
204
205
    new = StaticTuple_New(size);
205
206
    if (new == NULL) {
206
 
        Py_XDECREF(as_tuple);
207
 
        return NULL;
 
207
        goto done;
208
208
    }
209
209
    for (i = 0; i < size; ++i) {
210
210
        // This returns a new reference, which we then 'steal' with 
212
212
        item = PySequence_GetItem(sequence, i);
213
213
        if (item == NULL) {
214
214
            Py_DECREF(new);
215
 
            Py_XDECREF(as_tuple);
216
 
            return NULL;
 
215
            new = NULL;
 
216
            goto done;
217
217
        }
218
218
        StaticTuple_SET_ITEM(new, i, item);
219
219
    }
 
220
done:
220
221
    Py_XDECREF(as_tuple);
221
222
    return (StaticTuple *)new;
222
223
}