~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Objects/listobject.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
                PyErr_BadInternalCall();
127
127
                return NULL;
128
128
        }
129
 
        nbytes = size * sizeof(PyObject *);
130
129
        /* Check for overflow without an actual overflow,
131
130
         *  which can cause compiler to optimise out */
132
 
        if (size > PY_SIZE_MAX / sizeof(PyObject *))
 
131
        if ((size_t)size > PY_SIZE_MAX / sizeof(PyObject *))
133
132
                return PyErr_NoMemory();
 
133
        nbytes = size * sizeof(PyObject *);
134
134
        if (numfree) {
135
135
                numfree--;
136
136
                op = free_list[numfree];
319
319
{
320
320
        int rc;
321
321
        Py_ssize_t i;
 
322
        PyObject *item;
322
323
 
323
324
        rc = Py_ReprEnter((PyObject*)op);
324
325
        if (rc != 0) {
333
334
        fprintf(fp, "[");
334
335
        Py_END_ALLOW_THREADS
335
336
        for (i = 0; i < Py_SIZE(op); i++) {
 
337
                item = op->ob_item[i];
 
338
                Py_INCREF(item);
336
339
                if (i > 0) {
337
340
                        Py_BEGIN_ALLOW_THREADS
338
341
                        fprintf(fp, ", ");
339
342
                        Py_END_ALLOW_THREADS
340
343
                }
341
 
                if (PyObject_Print(op->ob_item[i], fp, 0) != 0) {
 
344
                if (PyObject_Print(item, fp, 0) != 0) {
 
345
                        Py_DECREF(item);
342
346
                        Py_ReprLeave((PyObject *)op);
343
347
                        return -1;
344
348
                }
 
349
                Py_DECREF(item);
345
350
        }
346
351
        Py_BEGIN_ALLOW_THREADS
347
352
        fprintf(fp, "]");
1421
1426
         * we don't care what's in the block.
1422
1427
         */
1423
1428
        merge_freemem(ms);
1424
 
        if (need > PY_SSIZE_T_MAX / sizeof(PyObject*)) {
 
1429
        if ((size_t)need > PY_SSIZE_T_MAX / sizeof(PyObject*)) {
1425
1430
                PyErr_NoMemory();
1426
1431
                return -1;
1427
1432
        }
2511
2516
};
2512
2517
 
2513
2518
PyDoc_STRVAR(list_doc,
2514
 
"list() -> new list\n"
2515
 
"list(sequence) -> new list initialized from sequence's items");
 
2519
"list() -> new empty list\n"
 
2520
"list(iterable) -> new list initialized from iterable's items");
2516
2521
 
2517
2522
 
2518
2523
static PyObject *
2599
2604
                if (value == NULL) {
2600
2605
                        /* delete slice */
2601
2606
                        PyObject **garbage;
2602
 
                        Py_ssize_t cur, i;
 
2607
                        size_t cur;
 
2608
                        Py_ssize_t i;
2603
2609
 
2604
2610
                        if (slicelength <= 0)
2605
2611
                                return 0;
2610
2616
                                step = -step;
2611
2617
                        }
2612
2618
 
2613
 
                        assert(slicelength <= PY_SIZE_MAX / sizeof(PyObject*));
 
2619
                        assert((size_t)slicelength <=
 
2620
                               PY_SIZE_MAX / sizeof(PyObject*));
2614
2621
 
2615
2622
                        garbage = (PyObject**)
2616
2623
                                PyMem_MALLOC(slicelength*sizeof(PyObject*));
2626
2633
                           and then tail end of the list that was not
2627
2634
                           covered by the slice */
2628
2635
                        for (cur = start, i = 0;
2629
 
                             cur < stop;
 
2636
                             cur < (size_t)stop;
2630
2637
                             cur += step, i++) {
2631
2638
                                Py_ssize_t lim = step - 1;
2632
2639
 
2633
2640
                                garbage[i] = PyList_GET_ITEM(self, cur);
2634
2641
 
2635
 
                                if (cur + step >= Py_SIZE(self)) {
 
2642
                                if (cur + step >= (size_t)Py_SIZE(self)) {
2636
2643
                                        lim = Py_SIZE(self) - cur - 1;
2637
2644
                                }
2638
2645
 
2641
2648
                                        lim * sizeof(PyObject *));
2642
2649
                        }
2643
2650
                        cur = start + slicelength*step;
2644
 
                        if (cur < Py_SIZE(self)) {
 
2651
                        if (cur < (size_t)Py_SIZE(self)) {
2645
2652
                                memmove(self->ob_item + cur - slicelength,
2646
2653
                                        self->ob_item + cur,
2647
2654
                                        (Py_SIZE(self) - cur) *