Back to index

python3.2  3.2.2
Classes | Functions | Variables
iterobject.c File Reference
#include "Python.h"

Go to the source code of this file.

Classes

struct  seqiterobject
struct  calliterobject

Functions

PyObjectPySeqIter_New (PyObject *seq)
static void iter_dealloc (seqiterobject *it)
static int iter_traverse (seqiterobject *it, visitproc visit, void *arg)
static PyObjectiter_iternext (PyObject *iterator)
static PyObjectiter_len (seqiterobject *it)
 PyDoc_STRVAR (length_hint_doc,"Private method returning an estimate of len(list(it)).")
PyObjectPyCallIter_New (PyObject *callable, PyObject *sentinel)
static void calliter_dealloc (calliterobject *it)
static int calliter_traverse (calliterobject *it, visitproc visit, void *arg)
static PyObjectcalliter_iternext (calliterobject *it)

Variables

static PyMethodDef seqiter_methods []
PyTypeObject PySeqIter_Type
PyTypeObject PyCallIter_Type

Class Documentation

struct seqiterobject

Definition at line 5 of file iterobject.c.

Collaboration diagram for seqiterobject:
Class Members
PyObject_HEAD long it_index
PyObject * it_seq
struct calliterobject

Definition at line 131 of file iterobject.c.

Collaboration diagram for calliterobject:
Class Members
PyObject_HEAD PyObject * it_callable
PyObject * it_sentinel

Function Documentation

static void calliter_dealloc ( calliterobject it) [static]

Definition at line 152 of file iterobject.c.

Here is the call graph for this function:

static PyObject* calliter_iternext ( calliterobject it) [static]

Definition at line 169 of file iterobject.c.

{
    if (it->it_callable != NULL) {
        PyObject *args = PyTuple_New(0);
        PyObject *result;
        if (args == NULL)
            return NULL;
        result = PyObject_Call(it->it_callable, args, NULL);
        Py_DECREF(args);
        if (result != NULL) {
            int ok;
            ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ);               
            if (ok == 0)
                return result; /* Common case, fast path */
            Py_DECREF(result);
            if (ok > 0) {
                Py_CLEAR(it->it_callable);
                Py_CLEAR(it->it_sentinel);
            }
        }
        else if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
            PyErr_Clear();
            Py_CLEAR(it->it_callable);
            Py_CLEAR(it->it_sentinel);
        }
    }
    return NULL;
}

Here is the call graph for this function:

static int calliter_traverse ( calliterobject it,
visitproc  visit,
void arg 
) [static]

Definition at line 161 of file iterobject.c.

{
    Py_VISIT(it->it_callable);
    Py_VISIT(it->it_sentinel);
    return 0;
}
static void iter_dealloc ( seqiterobject it) [static]

Definition at line 31 of file iterobject.c.

Here is the call graph for this function:

static PyObject* iter_iternext ( PyObject iterator) [static]

Definition at line 46 of file iterobject.c.

{
    seqiterobject *it;
    PyObject *seq;
    PyObject *result;

    assert(PySeqIter_Check(iterator));
    it = (seqiterobject *)iterator;
    seq = it->it_seq;
    if (seq == NULL)
        return NULL;

    result = PySequence_GetItem(seq, it->it_index);
    if (result != NULL) {
        it->it_index++;
        return result;
    }
    if (PyErr_ExceptionMatches(PyExc_IndexError) ||
        PyErr_ExceptionMatches(PyExc_StopIteration))
    {
        PyErr_Clear();
        Py_DECREF(seq);
        it->it_seq = NULL;
    }
    return NULL;
}

Here is the call graph for this function:

static PyObject* iter_len ( seqiterobject it) [static]

Definition at line 74 of file iterobject.c.

{
    Py_ssize_t seqsize, len;

    if (it->it_seq) {
        seqsize = PySequence_Size(it->it_seq);
        if (seqsize == -1)
            return NULL;
        len = seqsize - it->it_index;
        if (len >= 0)
            return PyLong_FromSsize_t(len);
    }
    return PyLong_FromLong(0);
}

Here is the call graph for this function:

static int iter_traverse ( seqiterobject it,
visitproc  visit,
void arg 
) [static]

Definition at line 39 of file iterobject.c.

{
    Py_VISIT(it->it_seq);
    return 0;
}
PyObject* PyCallIter_New ( PyObject callable,
PyObject sentinel 
)

Definition at line 138 of file iterobject.c.

{
    calliterobject *it;
    it = PyObject_GC_New(calliterobject, &PyCallIter_Type);
    if (it == NULL)
        return NULL;
    Py_INCREF(callable);
    it->it_callable = callable;
    Py_INCREF(sentinel);
    it->it_sentinel = sentinel;
    _PyObject_GC_TRACK(it);
    return (PyObject *)it;
}

Here is the caller graph for this function:

PyDoc_STRVAR ( length_hint_doc  ,
"Private method returning an estimate of len(list(it))."   
)

Definition at line 12 of file iterobject.c.

{
    seqiterobject *it;

    if (!PySequence_Check(seq)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    it = PyObject_GC_New(seqiterobject, &PySeqIter_Type);
    if (it == NULL)
        return NULL;
    it->it_index = 0;
    Py_INCREF(seq);
    it->it_seq = seq;
    _PyObject_GC_TRACK(it);
    return (PyObject *)it;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 198 of file iterobject.c.

Definition at line 96 of file iterobject.c.

Initial value:
 {
    {"__length_hint__", (PyCFunction)iter_len, METH_NOARGS, length_hint_doc},
    {NULL,              NULL}           
}

Definition at line 91 of file iterobject.c.