summaryrefslogtreecommitdiffstats
path: root/Objects/tupleobject.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-02-15 17:27:45 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2006-02-15 17:27:45 (GMT)
commit18e165558b24d29e7e0ca501842b9236589b012a (patch)
tree841678b5dc1aff3aa48701fee33a6ba7be00a72b /Objects/tupleobject.c
parent44829297348d9121a03fc7df2fac557b583cc7fa (diff)
downloadcpython-18e165558b24d29e7e0ca501842b9236589b012a.zip
cpython-18e165558b24d29e7e0ca501842b9236589b012a.tar.gz
cpython-18e165558b24d29e7e0ca501842b9236589b012a.tar.bz2
Merge ssize_t branch.
Diffstat (limited to 'Objects/tupleobject.c')
-rw-r--r--Objects/tupleobject.c92
1 files changed, 44 insertions, 48 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index 8ea29f0..2de2899 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -24,10 +24,10 @@ int tuple_zero_allocs;
#endif
PyObject *
-PyTuple_New(register int size)
+PyTuple_New(register Py_ssize_t size)
{
register PyTupleObject *op;
- int i;
+ Py_ssize_t i;
if (size < 0) {
PyErr_BadInternalCall();
return NULL;
@@ -57,7 +57,7 @@ PyTuple_New(register int size)
else
#endif
{
- int nbytes = size * sizeof(PyObject *);
+ Py_ssize_t nbytes = size * sizeof(PyObject *);
/* Check for overflow */
if (nbytes / sizeof(PyObject *) != (size_t)size ||
(nbytes += sizeof(PyTupleObject) - sizeof(PyObject *))
@@ -82,7 +82,7 @@ PyTuple_New(register int size)
return (PyObject *) op;
}
-int
+Py_ssize_t
PyTuple_Size(register PyObject *op)
{
if (!PyTuple_Check(op)) {
@@ -94,7 +94,7 @@ PyTuple_Size(register PyObject *op)
}
PyObject *
-PyTuple_GetItem(register PyObject *op, register int i)
+PyTuple_GetItem(register PyObject *op, register Py_ssize_t i)
{
if (!PyTuple_Check(op)) {
PyErr_BadInternalCall();
@@ -108,7 +108,7 @@ PyTuple_GetItem(register PyObject *op, register int i)
}
int
-PyTuple_SetItem(register PyObject *op, register int i, PyObject *newitem)
+PyTuple_SetItem(register PyObject *op, register Py_ssize_t i, PyObject *newitem)
{
register PyObject *olditem;
register PyObject **p;
@@ -131,9 +131,9 @@ PyTuple_SetItem(register PyObject *op, register int i, PyObject *newitem)
}
PyObject *
-PyTuple_Pack(int n, ...)
+PyTuple_Pack(Py_ssize_t n, ...)
{
- int i;
+ Py_ssize_t i;
PyObject *o;
PyObject *result;
PyObject **items;
@@ -159,8 +159,8 @@ PyTuple_Pack(int n, ...)
static void
tupledealloc(register PyTupleObject *op)
{
- register int i;
- register int len = op->ob_size;
+ register Py_ssize_t i;
+ register Py_ssize_t len = op->ob_size;
PyObject_GC_UnTrack(op);
Py_TRASHCAN_SAFE_BEGIN(op)
if (len > 0) {
@@ -187,7 +187,7 @@ done:
static int
tupleprint(PyTupleObject *op, FILE *fp, int flags)
{
- int i;
+ Py_ssize_t i;
fprintf(fp, "(");
for (i = 0; i < op->ob_size; i++) {
if (i > 0)
@@ -204,7 +204,7 @@ tupleprint(PyTupleObject *op, FILE *fp, int flags)
static PyObject *
tuplerepr(PyTupleObject *v)
{
- int i, n;
+ Py_ssize_t i, n;
PyObject *s, *temp;
PyObject *pieces, *result = NULL;
@@ -268,7 +268,7 @@ static long
tuplehash(PyTupleObject *v)
{
register long x, y;
- register int len = v->ob_size;
+ register Py_ssize_t len = v->ob_size;
register PyObject **p;
long mult = 1000003L;
x = 0x345678L;
@@ -286,7 +286,7 @@ tuplehash(PyTupleObject *v)
return x;
}
-static int
+static Py_ssize_t
tuplelength(PyTupleObject *a)
{
return a->ob_size;
@@ -295,7 +295,8 @@ tuplelength(PyTupleObject *a)
static int
tuplecontains(PyTupleObject *a, PyObject *el)
{
- int i, cmp;
+ Py_ssize_t i;
+ int cmp;
for (i = 0, cmp = 0 ; cmp == 0 && i < a->ob_size; ++i)
cmp = PyObject_RichCompareBool(el, PyTuple_GET_ITEM(a, i),
@@ -304,7 +305,7 @@ tuplecontains(PyTupleObject *a, PyObject *el)
}
static PyObject *
-tupleitem(register PyTupleObject *a, register int i)
+tupleitem(register PyTupleObject *a, register Py_ssize_t i)
{
if (i < 0 || i >= a->ob_size) {
PyErr_SetString(PyExc_IndexError, "tuple index out of range");
@@ -315,12 +316,13 @@ tupleitem(register PyTupleObject *a, register int i)
}
static PyObject *
-tupleslice(register PyTupleObject *a, register int ilow, register int ihigh)
+tupleslice(register PyTupleObject *a, register Py_ssize_t ilow,
+ register Py_ssize_t ihigh)
{
register PyTupleObject *np;
PyObject **src, **dest;
- register int i;
- int len;
+ register Py_ssize_t i;
+ Py_ssize_t len;
if (ilow < 0)
ilow = 0;
if (ihigh > a->ob_size)
@@ -346,7 +348,7 @@ tupleslice(register PyTupleObject *a, register int ilow, register int ihigh)
}
PyObject *
-PyTuple_GetSlice(PyObject *op, int i, int j)
+PyTuple_GetSlice(PyObject *op, Py_ssize_t i, Py_ssize_t j)
{
if (op == NULL || !PyTuple_Check(op)) {
PyErr_BadInternalCall();
@@ -358,8 +360,8 @@ PyTuple_GetSlice(PyObject *op, int i, int j)
static PyObject *
tupleconcat(register PyTupleObject *a, register PyObject *bb)
{
- register int size;
- register int i;
+ register Py_ssize_t size;
+ register Py_ssize_t i;
PyObject **src, **dest;
PyTupleObject *np;
if (!PyTuple_Check(bb)) {
@@ -395,10 +397,10 @@ tupleconcat(register PyTupleObject *a, register PyObject *bb)
}
static PyObject *
-tuplerepeat(PyTupleObject *a, int n)
+tuplerepeat(PyTupleObject *a, Py_ssize_t n)
{
- int i, j;
- int size;
+ Py_ssize_t i, j;
+ Py_ssize_t size;
PyTupleObject *np;
PyObject **p, **items;
if (n < 0)
@@ -434,13 +436,13 @@ tuplerepeat(PyTupleObject *a, int n)
static int
tupletraverse(PyTupleObject *o, visitproc visit, void *arg)
{
- int i, err;
+ Py_ssize_t i;
PyObject *x;
for (i = o->ob_size; --i >= 0; ) {
x = o->ob_item[i];
if (x != NULL) {
- err = visit(x, arg);
+ int err = visit(x, arg);
if (err)
return err;
}
@@ -452,8 +454,8 @@ static PyObject *
tuplerichcompare(PyObject *v, PyObject *w, int op)
{
PyTupleObject *vt, *wt;
- int i;
- int vlen, wlen;
+ Py_ssize_t i;
+ Py_ssize_t vlen, wlen;
if (!PyTuple_Check(v) || !PyTuple_Check(w)) {
Py_INCREF(Py_NotImplemented);
@@ -545,7 +547,7 @@ static PyObject *
tuple_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *tmp, *new, *item;
- int i, n;
+ Py_ssize_t i, n;
assert(PyType_IsSubtype(type, &PyTuple_Type));
tmp = tuple_new(&PyTuple_Type, args, kwds);
@@ -571,11 +573,11 @@ PyDoc_STRVAR(tuple_doc,
"If the argument is a tuple, the return value is the same object.");
static PySequenceMethods tuple_as_sequence = {
- (inquiry)tuplelength, /* sq_length */
+ (lenfunc)tuplelength, /* sq_length */
(binaryfunc)tupleconcat, /* sq_concat */
- (intargfunc)tuplerepeat, /* sq_repeat */
- (intargfunc)tupleitem, /* sq_item */
- (intintargfunc)tupleslice, /* sq_slice */
+ (ssizeargfunc)tuplerepeat, /* sq_repeat */
+ (ssizeargfunc)tupleitem, /* sq_item */
+ (ssizessizeargfunc)tupleslice, /* sq_slice */
0, /* sq_ass_item */
0, /* sq_ass_slice */
(objobjproc)tuplecontains, /* sq_contains */
@@ -584,14 +586,8 @@ static PySequenceMethods tuple_as_sequence = {
static PyObject*
tuplesubscript(PyTupleObject* self, PyObject* item)
{
- if (PyInt_Check(item)) {
- long i = PyInt_AS_LONG(item);
- if (i < 0)
- i += PyTuple_GET_SIZE(self);
- return tupleitem(self, i);
- }
- else if (PyLong_Check(item)) {
- long i = PyLong_AsLong(item);
+ if (PyInt_Check(item) || PyLong_Check(item)) {
+ Py_ssize_t i = PyInt_AsSsize_t(item);
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)
@@ -599,7 +595,7 @@ tuplesubscript(PyTupleObject* self, PyObject* item)
return tupleitem(self, i);
}
else if (PySlice_Check(item)) {
- int start, stop, step, slicelength, cur, i;
+ Py_ssize_t start, stop, step, slicelength, cur, i;
PyObject* result;
PyObject* it;
PyObject **src, **dest;
@@ -648,7 +644,7 @@ static PyMethodDef tuple_methods[] = {
};
static PyMappingMethods tuple_as_mapping = {
- (inquiry)tuplelength,
+ (lenfunc)tuplelength,
(binaryfunc)tuplesubscript,
0
};
@@ -707,12 +703,12 @@ PyTypeObject PyTuple_Type = {
known to some other part of the code. */
int
-_PyTuple_Resize(PyObject **pv, int newsize)
+_PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
{
register PyTupleObject *v;
register PyTupleObject *sv;
- int i;
- int oldsize;
+ Py_ssize_t i;
+ Py_ssize_t oldsize;
v = (PyTupleObject *) *pv;
if (v == NULL || v->ob_type != &PyTuple_Type ||
@@ -854,7 +850,7 @@ tupleiter_next(tupleiterobject *it)
static PyObject *
tupleiter_len(tupleiterobject *it)
{
- int len = 0;
+ long len = 0;
if (it->it_seq)
len = PyTuple_GET_SIZE(it->it_seq) - it->it_index;
return PyInt_FromLong(len);