~pythonregexp2.7/python/issue2636-01+09-01-01

« back to all changes in this revision

Viewing changes to Objects/tupleobject.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-22 00:02:12 UTC
  • mfrom: (39022.1.34 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080922000212-7r0q4f4ugiq57jph
Merged in changes from the Atomic Grouping / Possessive Qualifiers branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
                Py_ssize_t nbytes = size * sizeof(PyObject *);
61
61
                /* Check for overflow */
62
62
                if (nbytes / sizeof(PyObject *) != (size_t)size ||
63
 
                    (nbytes += sizeof(PyTupleObject) - sizeof(PyObject *))
64
 
                    <= 0)
 
63
                    (nbytes > PY_SSIZE_T_MAX - sizeof(PyTupleObject) - sizeof(PyObject *)))
65
64
                {
66
65
                        return PyErr_NoMemory();
67
66
                }
 
67
                nbytes += sizeof(PyTupleObject) - sizeof(PyObject *);
 
68
 
68
69
                op = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size);
69
70
                if (op == NULL)
70
71
                        return NULL;
708
709
        
709
710
}
710
711
 
 
712
static PyObject *
 
713
tuple_sizeof(PyTupleObject *self)
 
714
{
 
715
        Py_ssize_t res;
 
716
 
 
717
        res = PyTuple_Type.tp_basicsize + Py_SIZE(self) * sizeof(PyObject *);
 
718
        return PyInt_FromSsize_t(res);
 
719
}
 
720
 
711
721
PyDoc_STRVAR(index_doc,
712
722
"T.index(value, [start, [stop]]) -> integer -- return first index of value");
713
723
PyDoc_STRVAR(count_doc,
714
724
"T.count(value) -> integer -- return number of occurrences of value");
 
725
PyDoc_STRVAR(sizeof_doc,
 
726
"T.__sizeof__() -- size of T in memory, in bytes");
715
727
 
716
728
static PyMethodDef tuple_methods[] = {
717
729
        {"__getnewargs__",      (PyCFunction)tuple_getnewargs,  METH_NOARGS},
 
730
        {"__sizeof__",  (PyCFunction)tuple_sizeof, METH_NOARGS, sizeof_doc},
718
731
        {"index",       (PyCFunction)tupleindex,  METH_VARARGS, index_doc},
719
732
        {"count",       (PyCFunction)tuplecount,  METH_O, count_doc},
720
733
        {NULL,          NULL}           /* sentinel */