Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e4526592
Commit
e4526592
authored
May 08, 2002
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #551410: Implement tp_getiter.
parent
01f94bda
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
1 deletion
+51
-1
Objects/rangeobject.c
Objects/rangeobject.c
+51
-1
No files found.
Objects/rangeobject.c
View file @
e4526592
...
...
@@ -8,6 +8,8 @@ typedef struct {
long
start
;
long
step
;
long
len
;
long
index
;
int
used
;
/* Set to 1 if called by range_getiter */
}
rangeobject
;
PyObject
*
...
...
@@ -43,6 +45,8 @@ PyRange_New(long start, long len, long step, int reps)
obj
->
start
=
start
;
obj
->
len
=
len
;
obj
->
step
=
step
;
obj
->
index
=
0
;
obj
->
used
=
0
;
return
(
PyObject
*
)
obj
;
}
...
...
@@ -86,6 +90,45 @@ range_repr(rangeobject *r)
return
rtn
;
}
static
PyObject
*
range_getiter
(
rangeobject
*
r
)
{
rangeobject
*
obj
;
if
(
r
->
used
==
0
||
r
->
index
>=
r
->
len
)
{
Py_INCREF
(
r
);
r
->
used
=
1
;
r
->
index
=
0
;
return
(
PyObject
*
)
r
;
}
obj
=
PyObject_NEW
(
rangeobject
,
&
PyRange_Type
);
if
(
obj
==
NULL
)
return
NULL
;
obj
->
start
=
r
->
start
;
obj
->
len
=
r
->
len
;
obj
->
step
=
r
->
step
;
obj
->
index
=
0
;
obj
->
used
=
1
;
return
(
PyObject
*
)
obj
;
}
static
PyObject
*
range_next
(
rangeobject
*
r
)
{
if
(
r
->
index
>=
r
->
len
)
{
PyErr_SetObject
(
PyExc_StopIteration
,
Py_None
);
return
NULL
;
}
return
PyInt_FromLong
(
r
->
start
+
(
r
->
index
++
)
*
r
->
step
);
}
static
PyMethodDef
range_methods
[]
=
{
{
"next"
,
(
PyCFunction
)
range_next
,
METH_NOARGS
,
"it.next() -- get the next value, or raise StopIteration"
},
{
NULL
,
NULL
}
/* sentinel */
};
static
PySequenceMethods
range_as_sequence
=
{
(
inquiry
)
range_length
,
/* sq_length */
0
,
/* sq_concat */
...
...
@@ -112,9 +155,16 @@ PyTypeObject PyRange_Type = {
0
,
/* tp_hash */
0
,
/* tp_call */
0
,
/* tp_str */
0
,
/* tp_getattro */
PyObject_GenericGetAttr
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
,
/* tp_flags */
0
,
/* tp_doc */
0
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
(
getiterfunc
)
range_getiter
,
/* tp_iter */
(
iternextfunc
)
range_next
,
/* tp_iternext */
range_methods
,
/* tp_methods */
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment