diff options
author | Guido van Rossum <guido@python.org> | 1997-05-02 03:12:38 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-05-02 03:12:38 (GMT) |
commit | c0b618a2ccfb0fc39e07ee96dc09da77fbcce1b1 (patch) | |
tree | 41fcbbf4aa993b2172cce9c5cb26021268c82bd8 /Objects/rangeobject.c | |
parent | f4806c2a85dccb94a183b584f99b6b5b8f40e6db (diff) | |
download | cpython-c0b618a2ccfb0fc39e07ee96dc09da77fbcce1b1.zip cpython-c0b618a2ccfb0fc39e07ee96dc09da77fbcce1b1.tar.gz cpython-c0b618a2ccfb0fc39e07ee96dc09da77fbcce1b1.tar.bz2 |
Quickly renamed the last directory.
Diffstat (limited to 'Objects/rangeobject.c')
-rw-r--r-- | Objects/rangeobject.c | 81 |
1 files changed, 41 insertions, 40 deletions
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index ee7af08..0bf643f 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -31,10 +31,10 @@ PERFORMANCE OF THIS SOFTWARE. /* Range object implementation */ -#include "allobjects.h" +#include "Python.h" typedef struct { - OB_HEAD + PyObject_HEAD long start; long step; long len; @@ -42,39 +42,40 @@ typedef struct { } rangeobject; -object * -newrangeobject(start, len, step, reps) +PyObject * +PyRange_New(start, len, step, reps) long start, len, step; int reps; { - rangeobject *obj = NEWOBJ(rangeobject, &Rangetype); + rangeobject *obj = PyObject_NEW(rangeobject, &PyRange_Type); obj->start = start; obj->len = len; obj->step = step; obj->reps = reps; - return (object *) obj; + return (PyObject *) obj; } static void range_dealloc(r) rangeobject *r; { - DEL(r); + PyMem_DEL(r); } -static object * +static PyObject * range_item(r, i) rangeobject *r; int i; { if (i < 0 || i >= r->len * r->reps) { - err_setstr(IndexError, "range object index out of range"); + PyErr_SetString(PyExc_IndexError, + "range object index out of range"); return NULL; } - return newintobject(r->start + (i % r->len) * r->step); + return PyInt_FromLong(r->start + (i % r->len) * r->step); } static int @@ -107,7 +108,7 @@ range_print(r, fp, flags) return 0; } -static object * +static PyObject * range_repr(r) rangeobject *r; { @@ -117,33 +118,33 @@ range_repr(r) r->start + r->len * r->step, r->step, r->reps); - return newstringobject(buf); + return PyString_FromString(buf); } -static object * +static PyObject * range_concat(r, obj) rangeobject *r; - object *obj; + PyObject *obj; { - err_setstr(TypeError, "cannot concatenate range objects"); + PyErr_SetString(PyExc_TypeError, "cannot concatenate range objects"); return NULL; } -static object * +static PyObject * range_repeat(r, n) rangeobject *r; int n; { if (n < 0) - return (object *) newrangeobject(0, 0, 1, 1); + return (PyObject *) PyRange_New(0, 0, 1, 1); else if (n == 1) { - INCREF(r); - return (object *) r; + Py_INCREF(r); + return (PyObject *) r; } else - return (object *) newrangeobject( + return (PyObject *) PyRange_New( r->start, r->len, r->step, @@ -167,13 +168,14 @@ range_compare(r1, r2) return r1->reps - r2->reps; } -static object * +static PyObject * range_slice(r, low, high) rangeobject *r; int low, high; { if (r->reps != 1) { - err_setstr(TypeError, "cannot slice a replicated range"); + PyErr_SetString(PyExc_TypeError, + "cannot slice a replicated range"); return NULL; } if (low < 0) @@ -188,55 +190,54 @@ range_slice(r, low, high) high = r->len; if (low == 0 && high == r->len) { - INCREF(r); - return (object *) r; + Py_INCREF(r); + return (PyObject *) r; } - return (object *) newrangeobject( + return (PyObject *) PyRange_New( low * r->step + r->start, high - low, r->step, 1); } -static object * +static PyObject * range_tolist(self, args) rangeobject *self; -object *args; +PyObject *args; { - object *thelist; + PyObject *thelist; int j; int len = self->len * self->reps; - if (! getargs(args, "")) + if (! PyArg_Parse(args, "")) return NULL; - if ((thelist = newlistobject(len)) == NULL) + if ((thelist = PyList_New(len)) == NULL) return NULL; for (j = 0; j < len; ++j) - if ((setlistitem(thelist, j, - (object *) newintobject( - self->start + (j % self->len) * self->step))) < 0) + if ((PyList_SetItem(thelist, j, (PyObject *) PyInt_FromLong( + self->start + (j % self->len) * self->step))) < 0) return NULL; return thelist; } -static object * +static PyObject * range_getattr(r, name) rangeobject *r; char *name; { - static struct methodlist range_methods[] = { - {"tolist", (method)range_tolist}, + static PyMethodDef range_methods[] = { + {"tolist", (PyCFunction)range_tolist}, {NULL, NULL} }; - return findmethod(range_methods, (object *) r, name); + return Py_FindMethod(range_methods, (PyObject *) r, name); } -static sequence_methods range_as_sequence = { +static PySequenceMethods range_as_sequence = { (inquiry)range_length, /*sq_length*/ (binaryfunc)range_concat, /*sq_concat*/ (intargfunc)range_repeat, /*sq_repeat*/ @@ -246,8 +247,8 @@ static sequence_methods range_as_sequence = { 0, /*sq_ass_slice*/ }; -typeobject Rangetype = { - OB_HEAD_INIT(&Typetype) +PyTypeObject PyRange_Type = { + PyObject_HEAD_INIT(&PyType_Type) 0, /* Number of items for varobject */ "xrange", /* Name of this type */ sizeof(rangeobject), /* Basic object size */ |