Blame Objects/genobject.c

rpm-build 2bd099
/* Generator object implementation */
rpm-build 2bd099
rpm-build 2bd099
#include "Python.h"
rpm-build 2bd099
#include "frameobject.h"
rpm-build 2bd099
#include "structmember.h"
rpm-build 2bd099
#include "opcode.h"
rpm-build 2bd099
rpm-build 2bd099
static PyObject *gen_close(PyGenObject *, PyObject *);
rpm-build 2bd099
static PyObject *async_gen_asend_new(PyAsyncGenObject *, PyObject *);
rpm-build 2bd099
static PyObject *async_gen_athrow_new(PyAsyncGenObject *, PyObject *);
rpm-build 2bd099
rpm-build 2bd099
static char *NON_INIT_CORO_MSG = "can't send non-None value to a "
rpm-build 2bd099
                                 "just-started coroutine";
rpm-build 2bd099
rpm-build 2bd099
static char *ASYNC_GEN_IGNORED_EXIT_MSG =
rpm-build 2bd099
                                 "async generator ignored GeneratorExit";
rpm-build 2bd099
rpm-build 2bd099
static int
rpm-build 2bd099
gen_traverse(PyGenObject *gen, visitproc visit, void *arg)
rpm-build 2bd099
{
rpm-build 2bd099
    Py_VISIT((PyObject *)gen->gi_frame);
rpm-build 2bd099
    Py_VISIT(gen->gi_code);
rpm-build 2bd099
    Py_VISIT(gen->gi_name);
rpm-build 2bd099
    Py_VISIT(gen->gi_qualname);
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
void
rpm-build 2bd099
_PyGen_Finalize(PyObject *self)
rpm-build 2bd099
{
rpm-build 2bd099
    PyGenObject *gen = (PyGenObject *)self;
rpm-build 2bd099
    PyObject *res = NULL;
rpm-build 2bd099
    PyObject *error_type, *error_value, *error_traceback;
rpm-build 2bd099
rpm-build 2bd099
    if (gen->gi_frame == NULL || gen->gi_frame->f_stacktop == NULL)
rpm-build 2bd099
        /* Generator isn't paused, so no need to close */
rpm-build 2bd099
        return;
rpm-build 2bd099
rpm-build 2bd099
    if (PyAsyncGen_CheckExact(self)) {
rpm-build 2bd099
        PyAsyncGenObject *agen = (PyAsyncGenObject*)self;
rpm-build 2bd099
        PyObject *finalizer = agen->ag_finalizer;
rpm-build 2bd099
        if (finalizer && !agen->ag_closed) {
rpm-build 2bd099
            /* Save the current exception, if any. */
rpm-build 2bd099
            PyErr_Fetch(&error_type, &error_value, &error_traceback);
rpm-build 2bd099
rpm-build 2bd099
            res = PyObject_CallFunctionObjArgs(finalizer, self, NULL);
rpm-build 2bd099
rpm-build 2bd099
            if (res == NULL) {
rpm-build 2bd099
                PyErr_WriteUnraisable(self);
rpm-build 2bd099
            } else {
rpm-build 2bd099
                Py_DECREF(res);
rpm-build 2bd099
            }
rpm-build 2bd099
            /* Restore the saved exception. */
rpm-build 2bd099
            PyErr_Restore(error_type, error_value, error_traceback);
rpm-build 2bd099
            return;
rpm-build 2bd099
        }
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    /* Save the current exception, if any. */
rpm-build 2bd099
    PyErr_Fetch(&error_type, &error_value, &error_traceback);
rpm-build 2bd099
rpm-build 2bd099
    /* If `gen` is a coroutine, and if it was never awaited on,
rpm-build 2bd099
       issue a RuntimeWarning. */
rpm-build 2bd099
    if (gen->gi_code != NULL &&
rpm-build 2bd099
        ((PyCodeObject *)gen->gi_code)->co_flags & CO_COROUTINE &&
rpm-build 2bd099
        gen->gi_frame->f_lasti == -1) {
rpm-build 2bd099
        if (!error_value) {
rpm-build 2bd099
            PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
rpm-build 2bd099
                             "coroutine '%.50S' was never awaited",
rpm-build 2bd099
                             gen->gi_qualname);
rpm-build 2bd099
        }
rpm-build 2bd099
    }
rpm-build 2bd099
    else {
rpm-build 2bd099
        res = gen_close(gen, NULL);
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    if (res == NULL) {
rpm-build 2bd099
        if (PyErr_Occurred())
rpm-build 2bd099
            PyErr_WriteUnraisable(self);
rpm-build 2bd099
    }
rpm-build 2bd099
    else {
rpm-build 2bd099
        Py_DECREF(res);
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    /* Restore the saved exception. */
rpm-build 2bd099
    PyErr_Restore(error_type, error_value, error_traceback);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static void
rpm-build 2bd099
gen_dealloc(PyGenObject *gen)
rpm-build 2bd099
{
rpm-build 2bd099
    PyObject *self = (PyObject *) gen;
rpm-build 2bd099
rpm-build 2bd099
    _PyObject_GC_UNTRACK(gen);
rpm-build 2bd099
rpm-build 2bd099
    if (gen->gi_weakreflist != NULL)
rpm-build 2bd099
        PyObject_ClearWeakRefs(self);
rpm-build 2bd099
rpm-build 2bd099
    _PyObject_GC_TRACK(self);
rpm-build 2bd099
rpm-build 2bd099
    if (PyObject_CallFinalizerFromDealloc(self))
rpm-build 2bd099
        return;                     /* resurrected.  :( */
rpm-build 2bd099
rpm-build 2bd099
    _PyObject_GC_UNTRACK(self);
rpm-build 2bd099
    if (PyAsyncGen_CheckExact(gen)) {
rpm-build 2bd099
        /* We have to handle this case for asynchronous generators
rpm-build 2bd099
           right here, because this code has to be between UNTRACK
rpm-build 2bd099
           and GC_Del. */
rpm-build 2bd099
        Py_CLEAR(((PyAsyncGenObject*)gen)->ag_finalizer);
rpm-build 2bd099
    }
rpm-build 2bd099
    if (gen->gi_frame != NULL) {
rpm-build 2bd099
        gen->gi_frame->f_gen = NULL;
rpm-build 2bd099
        Py_CLEAR(gen->gi_frame);
rpm-build 2bd099
    }
rpm-build 2bd099
    Py_CLEAR(gen->gi_code);
rpm-build 2bd099
    Py_CLEAR(gen->gi_name);
rpm-build 2bd099
    Py_CLEAR(gen->gi_qualname);
rpm-build 2bd099
    PyObject_GC_Del(gen);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
rpm-build 2bd099
{
rpm-build 2bd099
    PyThreadState *tstate = PyThreadState_GET();
rpm-build 2bd099
    PyFrameObject *f = gen->gi_frame;
rpm-build 2bd099
    PyObject *result;
rpm-build 2bd099
rpm-build 2bd099
    if (gen->gi_running) {
rpm-build 2bd099
        char *msg = "generator already executing";
rpm-build 2bd099
        if (PyCoro_CheckExact(gen)) {
rpm-build 2bd099
            msg = "coroutine already executing";
rpm-build 2bd099
        }
rpm-build 2bd099
        else if (PyAsyncGen_CheckExact(gen)) {
rpm-build 2bd099
            msg = "async generator already executing";
rpm-build 2bd099
        }
rpm-build 2bd099
        PyErr_SetString(PyExc_ValueError, msg);
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
    if (f == NULL || f->f_stacktop == NULL) {
rpm-build 2bd099
        if (PyCoro_CheckExact(gen) && !closing) {
rpm-build 2bd099
            /* `gen` is an exhausted coroutine: raise an error,
rpm-build 2bd099
               except when called from gen_close(), which should
rpm-build 2bd099
               always be a silent method. */
rpm-build 2bd099
            PyErr_SetString(
rpm-build 2bd099
                PyExc_RuntimeError,
rpm-build 2bd099
                "cannot reuse already awaited coroutine");
rpm-build 2bd099
        }
rpm-build 2bd099
        else if (arg && !exc) {
rpm-build 2bd099
            /* `gen` is an exhausted generator:
rpm-build 2bd099
               only set exception if called from send(). */
rpm-build 2bd099
            if (PyAsyncGen_CheckExact(gen)) {
rpm-build 2bd099
                PyErr_SetNone(PyExc_StopAsyncIteration);
rpm-build 2bd099
            }
rpm-build 2bd099
            else {
rpm-build 2bd099
                PyErr_SetNone(PyExc_StopIteration);
rpm-build 2bd099
            }
rpm-build 2bd099
        }
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    if (f->f_lasti == -1) {
rpm-build 2bd099
        if (arg && arg != Py_None) {
rpm-build 2bd099
            char *msg = "can't send non-None value to a "
rpm-build 2bd099
                        "just-started generator";
rpm-build 2bd099
            if (PyCoro_CheckExact(gen)) {
rpm-build 2bd099
                msg = NON_INIT_CORO_MSG;
rpm-build 2bd099
            }
rpm-build 2bd099
            else if (PyAsyncGen_CheckExact(gen)) {
rpm-build 2bd099
                msg = "can't send non-None value to a "
rpm-build 2bd099
                      "just-started async generator";
rpm-build 2bd099
            }
rpm-build 2bd099
            PyErr_SetString(PyExc_TypeError, msg);
rpm-build 2bd099
            return NULL;
rpm-build 2bd099
        }
rpm-build 2bd099
    } else {
rpm-build 2bd099
        /* Push arg onto the frame's value stack */
rpm-build 2bd099
        result = arg ? arg : Py_None;
rpm-build 2bd099
        Py_INCREF(result);
rpm-build 2bd099
        *(f->f_stacktop++) = result;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    /* Generators always return to their most recent caller, not
rpm-build 2bd099
     * necessarily their creator. */
rpm-build 2bd099
    Py_XINCREF(tstate->frame);
rpm-build 2bd099
    assert(f->f_back == NULL);
rpm-build 2bd099
    f->f_back = tstate->frame;
rpm-build 2bd099
rpm-build 2bd099
    gen->gi_running = 1;
rpm-build 2bd099
    result = PyEval_EvalFrameEx(f, exc);
rpm-build 2bd099
    gen->gi_running = 0;
rpm-build 2bd099
rpm-build 2bd099
    /* Don't keep the reference to f_back any longer than necessary.  It
rpm-build 2bd099
     * may keep a chain of frames alive or it could create a reference
rpm-build 2bd099
     * cycle. */
rpm-build 2bd099
    assert(f->f_back == tstate->frame);
rpm-build 2bd099
    Py_CLEAR(f->f_back);
rpm-build 2bd099
rpm-build 2bd099
    /* If the generator just returned (as opposed to yielding), signal
rpm-build 2bd099
     * that the generator is exhausted. */
rpm-build 2bd099
    if (result && f->f_stacktop == NULL) {
rpm-build 2bd099
        if (result == Py_None) {
rpm-build 2bd099
            /* Delay exception instantiation if we can */
rpm-build 2bd099
            if (PyAsyncGen_CheckExact(gen)) {
rpm-build 2bd099
                PyErr_SetNone(PyExc_StopAsyncIteration);
rpm-build 2bd099
            }
rpm-build 2bd099
            else {
rpm-build 2bd099
                PyErr_SetNone(PyExc_StopIteration);
rpm-build 2bd099
            }
rpm-build 2bd099
        }
rpm-build 2bd099
        else {
rpm-build 2bd099
            /* Async generators cannot return anything but None */
rpm-build 2bd099
            assert(!PyAsyncGen_CheckExact(gen));
rpm-build 2bd099
            _PyGen_SetStopIterationValue(result);
rpm-build 2bd099
        }
rpm-build 2bd099
        Py_CLEAR(result);
rpm-build 2bd099
    }
rpm-build 2bd099
    else if (!result && PyErr_ExceptionMatches(PyExc_StopIteration)) {
rpm-build 2bd099
        /* Check for __future__ generator_stop and conditionally turn
rpm-build 2bd099
         * a leaking StopIteration into RuntimeError (with its cause
rpm-build 2bd099
         * set appropriately). */
rpm-build 2bd099
rpm-build 2bd099
        const int check_stop_iter_error_flags = CO_FUTURE_GENERATOR_STOP |
rpm-build 2bd099
                                                CO_COROUTINE |
rpm-build 2bd099
                                                CO_ITERABLE_COROUTINE |
rpm-build 2bd099
                                                CO_ASYNC_GENERATOR;
rpm-build 2bd099
rpm-build 2bd099
        if (gen->gi_code != NULL &&
rpm-build 2bd099
            ((PyCodeObject *)gen->gi_code)->co_flags &
rpm-build 2bd099
                check_stop_iter_error_flags)
rpm-build 2bd099
        {
rpm-build 2bd099
            /* `gen` is either:
rpm-build 2bd099
                  * a generator with CO_FUTURE_GENERATOR_STOP flag;
rpm-build 2bd099
                  * a coroutine;
rpm-build 2bd099
                  * a generator with CO_ITERABLE_COROUTINE flag
rpm-build 2bd099
                    (decorated with types.coroutine decorator);
rpm-build 2bd099
                  * an async generator.
rpm-build 2bd099
            */
rpm-build 2bd099
            const char *msg = "generator raised StopIteration";
rpm-build 2bd099
            if (PyCoro_CheckExact(gen)) {
rpm-build 2bd099
                msg = "coroutine raised StopIteration";
rpm-build 2bd099
            }
rpm-build 2bd099
            else if PyAsyncGen_CheckExact(gen) {
rpm-build 2bd099
                msg = "async generator raised StopIteration";
rpm-build 2bd099
            }
rpm-build 2bd099
            _PyErr_FormatFromCause(PyExc_RuntimeError, "%s", msg);
rpm-build 2bd099
        }
rpm-build 2bd099
        else {
rpm-build 2bd099
            /* `gen` is an ordinary generator without
rpm-build 2bd099
               CO_FUTURE_GENERATOR_STOP flag.
rpm-build 2bd099
            */
rpm-build 2bd099
rpm-build 2bd099
            PyObject *exc, *val, *tb;
rpm-build 2bd099
rpm-build 2bd099
            /* Pop the exception before issuing a warning. */
rpm-build 2bd099
            PyErr_Fetch(&exc, &val, &tb);
rpm-build 2bd099
rpm-build 2bd099
            if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
rpm-build 2bd099
                                 "generator '%.50S' raised StopIteration",
rpm-build 2bd099
                                 gen->gi_qualname)) {
rpm-build 2bd099
                /* Warning was converted to an error. */
rpm-build 2bd099
                Py_XDECREF(exc);
rpm-build 2bd099
                Py_XDECREF(val);
rpm-build 2bd099
                Py_XDECREF(tb);
rpm-build 2bd099
            }
rpm-build 2bd099
            else {
rpm-build 2bd099
                PyErr_Restore(exc, val, tb);
rpm-build 2bd099
            }
rpm-build 2bd099
        }
rpm-build 2bd099
    }
rpm-build 2bd099
    else if (PyAsyncGen_CheckExact(gen) && !result &&
rpm-build 2bd099
             PyErr_ExceptionMatches(PyExc_StopAsyncIteration))
rpm-build 2bd099
    {
rpm-build 2bd099
        /* code in `gen` raised a StopAsyncIteration error:
rpm-build 2bd099
           raise a RuntimeError.
rpm-build 2bd099
        */
rpm-build 2bd099
        const char *msg = "async generator raised StopAsyncIteration";
rpm-build 2bd099
        _PyErr_FormatFromCause(PyExc_RuntimeError, "%s", msg);
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    if (!result || f->f_stacktop == NULL) {
rpm-build 2bd099
        /* generator can't be rerun, so release the frame */
rpm-build 2bd099
        /* first clean reference cycle through stored exception traceback */
rpm-build 2bd099
        PyObject *t, *v, *tb;
rpm-build 2bd099
        t = f->f_exc_type;
rpm-build 2bd099
        v = f->f_exc_value;
rpm-build 2bd099
        tb = f->f_exc_traceback;
rpm-build 2bd099
        f->f_exc_type = NULL;
rpm-build 2bd099
        f->f_exc_value = NULL;
rpm-build 2bd099
        f->f_exc_traceback = NULL;
rpm-build 2bd099
        Py_XDECREF(t);
rpm-build 2bd099
        Py_XDECREF(v);
rpm-build 2bd099
        Py_XDECREF(tb);
rpm-build 2bd099
        gen->gi_frame->f_gen = NULL;
rpm-build 2bd099
        gen->gi_frame = NULL;
rpm-build 2bd099
        Py_DECREF(f);
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    return result;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
PyDoc_STRVAR(send_doc,
rpm-build 2bd099
"send(arg) -> send 'arg' into generator,\n\
rpm-build 2bd099
return next yielded value or raise StopIteration.");
rpm-build 2bd099
rpm-build 2bd099
PyObject *
rpm-build 2bd099
_PyGen_Send(PyGenObject *gen, PyObject *arg)
rpm-build 2bd099
{
rpm-build 2bd099
    return gen_send_ex(gen, arg, 0, 0);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
PyDoc_STRVAR(close_doc,
rpm-build 2bd099
"close() -> raise GeneratorExit inside generator.");
rpm-build 2bd099
rpm-build 2bd099
/*
rpm-build 2bd099
 *   This helper function is used by gen_close and gen_throw to
rpm-build 2bd099
 *   close a subiterator being delegated to by yield-from.
rpm-build 2bd099
 */
rpm-build 2bd099
rpm-build 2bd099
static int
rpm-build 2bd099
gen_close_iter(PyObject *yf)
rpm-build 2bd099
{
rpm-build 2bd099
    PyObject *retval = NULL;
rpm-build 2bd099
    _Py_IDENTIFIER(close);
rpm-build 2bd099
rpm-build 2bd099
    if (PyGen_CheckExact(yf) || PyCoro_CheckExact(yf)) {
rpm-build 2bd099
        retval = gen_close((PyGenObject *)yf, NULL);
rpm-build 2bd099
        if (retval == NULL)
rpm-build 2bd099
            return -1;
rpm-build 2bd099
    }
rpm-build 2bd099
    else {
rpm-build 2bd099
        PyObject *meth = _PyObject_GetAttrId(yf, &PyId_close);
rpm-build 2bd099
        if (meth == NULL) {
rpm-build 2bd099
            if (!PyErr_ExceptionMatches(PyExc_AttributeError))
rpm-build 2bd099
                PyErr_WriteUnraisable(yf);
rpm-build 2bd099
            PyErr_Clear();
rpm-build 2bd099
        }
rpm-build 2bd099
        else {
rpm-build 2bd099
            retval = _PyObject_CallNoArg(meth);
rpm-build 2bd099
            Py_DECREF(meth);
rpm-build 2bd099
            if (retval == NULL)
rpm-build 2bd099
                return -1;
rpm-build 2bd099
        }
rpm-build 2bd099
    }
rpm-build 2bd099
    Py_XDECREF(retval);
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
PyObject *
rpm-build 2bd099
_PyGen_yf(PyGenObject *gen)
rpm-build 2bd099
{
rpm-build 2bd099
    PyObject *yf = NULL;
rpm-build 2bd099
    PyFrameObject *f = gen->gi_frame;
rpm-build 2bd099
rpm-build 2bd099
    if (f && f->f_stacktop) {
rpm-build 2bd099
        PyObject *bytecode = f->f_code->co_code;
rpm-build 2bd099
        unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode);
rpm-build 2bd099
rpm-build 2bd099
        if (f->f_lasti < 0) {
rpm-build 2bd099
            /* Return immediately if the frame didn't start yet. YIELD_FROM
rpm-build 2bd099
               always come after LOAD_CONST: a code object should not start
rpm-build 2bd099
               with YIELD_FROM */
rpm-build 2bd099
            assert(code[0] != YIELD_FROM);
rpm-build 2bd099
            return NULL;
rpm-build 2bd099
        }
rpm-build 2bd099
rpm-build 2bd099
        if (code[f->f_lasti + sizeof(_Py_CODEUNIT)] != YIELD_FROM)
rpm-build 2bd099
            return NULL;
rpm-build 2bd099
        yf = f->f_stacktop[-1];
rpm-build 2bd099
        Py_INCREF(yf);
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    return yf;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
gen_close(PyGenObject *gen, PyObject *args)
rpm-build 2bd099
{
rpm-build 2bd099
    PyObject *retval;
rpm-build 2bd099
    PyObject *yf = _PyGen_yf(gen);
rpm-build 2bd099
    int err = 0;
rpm-build 2bd099
rpm-build 2bd099
    if (yf) {
rpm-build 2bd099
        gen->gi_running = 1;
rpm-build 2bd099
        err = gen_close_iter(yf);
rpm-build 2bd099
        gen->gi_running = 0;
rpm-build 2bd099
        Py_DECREF(yf);
rpm-build 2bd099
    }
rpm-build 2bd099
    if (err == 0)
rpm-build 2bd099
        PyErr_SetNone(PyExc_GeneratorExit);
rpm-build 2bd099
    retval = gen_send_ex(gen, Py_None, 1, 1);
rpm-build 2bd099
    if (retval) {
rpm-build 2bd099
        char *msg = "generator ignored GeneratorExit";
rpm-build 2bd099
        if (PyCoro_CheckExact(gen)) {
rpm-build 2bd099
            msg = "coroutine ignored GeneratorExit";
rpm-build 2bd099
        } else if (PyAsyncGen_CheckExact(gen)) {
rpm-build 2bd099
            msg = ASYNC_GEN_IGNORED_EXIT_MSG;
rpm-build 2bd099
        }
rpm-build 2bd099
        Py_DECREF(retval);
rpm-build 2bd099
        PyErr_SetString(PyExc_RuntimeError, msg);
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
    if (PyErr_ExceptionMatches(PyExc_StopIteration)
rpm-build 2bd099
        || PyErr_ExceptionMatches(PyExc_GeneratorExit)) {
rpm-build 2bd099
        PyErr_Clear();          /* ignore these errors */
rpm-build 2bd099
        Py_INCREF(Py_None);
rpm-build 2bd099
        return Py_None;
rpm-build 2bd099
    }
rpm-build 2bd099
    return NULL;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
PyDoc_STRVAR(throw_doc,
rpm-build 2bd099
"throw(typ[,val[,tb]]) -> raise exception in generator,\n\
rpm-build 2bd099
return next yielded value or raise StopIteration.");
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
_gen_throw(PyGenObject *gen, int close_on_genexit,
rpm-build 2bd099
           PyObject *typ, PyObject *val, PyObject *tb)
rpm-build 2bd099
{
rpm-build 2bd099
    PyObject *yf = _PyGen_yf(gen);
rpm-build 2bd099
    _Py_IDENTIFIER(throw);
rpm-build 2bd099
rpm-build 2bd099
    if (yf) {
rpm-build 2bd099
        PyObject *ret;
rpm-build 2bd099
        int err;
rpm-build 2bd099
        if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) &&
rpm-build 2bd099
            close_on_genexit
rpm-build 2bd099
        ) {
rpm-build 2bd099
            /* Asynchronous generators *should not* be closed right away.
rpm-build 2bd099
               We have to allow some awaits to work it through, hence the
rpm-build 2bd099
               `close_on_genexit` parameter here.
rpm-build 2bd099
            */
rpm-build 2bd099
            gen->gi_running = 1;
rpm-build 2bd099
            err = gen_close_iter(yf);
rpm-build 2bd099
            gen->gi_running = 0;
rpm-build 2bd099
            Py_DECREF(yf);
rpm-build 2bd099
            if (err < 0)
rpm-build 2bd099
                return gen_send_ex(gen, Py_None, 1, 0);
rpm-build 2bd099
            goto throw_here;
rpm-build 2bd099
        }
rpm-build 2bd099
        if (PyGen_CheckExact(yf) || PyCoro_CheckExact(yf)) {
rpm-build 2bd099
            /* `yf` is a generator or a coroutine. */
rpm-build 2bd099
            gen->gi_running = 1;
rpm-build 2bd099
            /* Close the generator that we are currently iterating with
rpm-build 2bd099
               'yield from' or awaiting on with 'await'. */
rpm-build 2bd099
            ret = _gen_throw((PyGenObject *)yf, close_on_genexit,
rpm-build 2bd099
                             typ, val, tb);
rpm-build 2bd099
            gen->gi_running = 0;
rpm-build 2bd099
        } else {
rpm-build 2bd099
            /* `yf` is an iterator or a coroutine-like object. */
rpm-build 2bd099
            PyObject *meth = _PyObject_GetAttrId(yf, &PyId_throw);
rpm-build 2bd099
            if (meth == NULL) {
rpm-build 2bd099
                if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
rpm-build 2bd099
                    Py_DECREF(yf);
rpm-build 2bd099
                    return NULL;
rpm-build 2bd099
                }
rpm-build 2bd099
                PyErr_Clear();
rpm-build 2bd099
                Py_DECREF(yf);
rpm-build 2bd099
                goto throw_here;
rpm-build 2bd099
            }
rpm-build 2bd099
            gen->gi_running = 1;
rpm-build 2bd099
            ret = PyObject_CallFunctionObjArgs(meth, typ, val, tb, NULL);
rpm-build 2bd099
            gen->gi_running = 0;
rpm-build 2bd099
            Py_DECREF(meth);
rpm-build 2bd099
        }
rpm-build 2bd099
        Py_DECREF(yf);
rpm-build 2bd099
        if (!ret) {
rpm-build 2bd099
            PyObject *val;
rpm-build 2bd099
            /* Pop subiterator from stack */
rpm-build 2bd099
            ret = *(--gen->gi_frame->f_stacktop);
rpm-build 2bd099
            assert(ret == yf);
rpm-build 2bd099
            Py_DECREF(ret);
rpm-build 2bd099
            /* Termination repetition of YIELD_FROM */
rpm-build 2bd099
            assert(gen->gi_frame->f_lasti >= 0);
rpm-build 2bd099
            gen->gi_frame->f_lasti += sizeof(_Py_CODEUNIT);
rpm-build 2bd099
            if (_PyGen_FetchStopIterationValue(&val) == 0) {
rpm-build 2bd099
                ret = gen_send_ex(gen, val, 0, 0);
rpm-build 2bd099
                Py_DECREF(val);
rpm-build 2bd099
            } else {
rpm-build 2bd099
                ret = gen_send_ex(gen, Py_None, 1, 0);
rpm-build 2bd099
            }
rpm-build 2bd099
        }
rpm-build 2bd099
        return ret;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
throw_here:
rpm-build 2bd099
    /* First, check the traceback argument, replacing None with
rpm-build 2bd099
       NULL. */
rpm-build 2bd099
    if (tb == Py_None) {
rpm-build 2bd099
        tb = NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
rpm-build 2bd099
        PyErr_SetString(PyExc_TypeError,
rpm-build 2bd099
            "throw() third argument must be a traceback object");
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    Py_INCREF(typ);
rpm-build 2bd099
    Py_XINCREF(val);
rpm-build 2bd099
    Py_XINCREF(tb);
rpm-build 2bd099
rpm-build 2bd099
    if (PyExceptionClass_Check(typ))
rpm-build 2bd099
        PyErr_NormalizeException(&typ, &val, &tb);
rpm-build 2bd099
rpm-build 2bd099
    else if (PyExceptionInstance_Check(typ)) {
rpm-build 2bd099
        /* Raising an instance.  The value should be a dummy. */
rpm-build 2bd099
        if (val && val != Py_None) {
rpm-build 2bd099
            PyErr_SetString(PyExc_TypeError,
rpm-build 2bd099
              "instance exception may not have a separate value");
rpm-build 2bd099
            goto failed_throw;
rpm-build 2bd099
        }
rpm-build 2bd099
        else {
rpm-build 2bd099
            /* Normalize to raise <class>, <instance> */
rpm-build 2bd099
            Py_XDECREF(val);
rpm-build 2bd099
            val = typ;
rpm-build 2bd099
            typ = PyExceptionInstance_Class(typ);
rpm-build 2bd099
            Py_INCREF(typ);
rpm-build 2bd099
rpm-build 2bd099
            if (tb == NULL)
rpm-build 2bd099
                /* Returns NULL if there's no traceback */
rpm-build 2bd099
                tb = PyException_GetTraceback(val);
rpm-build 2bd099
        }
rpm-build 2bd099
    }
rpm-build 2bd099
    else {
rpm-build 2bd099
        /* Not something you can raise.  throw() fails. */
rpm-build 2bd099
        PyErr_Format(PyExc_TypeError,
rpm-build 2bd099
                     "exceptions must be classes or instances "
rpm-build 2bd099
                     "deriving from BaseException, not %s",
rpm-build 2bd099
                     Py_TYPE(typ)->tp_name);
rpm-build 2bd099
            goto failed_throw;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    PyErr_Restore(typ, val, tb);
rpm-build 2bd099
    return gen_send_ex(gen, Py_None, 1, 0);
rpm-build 2bd099
rpm-build 2bd099
failed_throw:
rpm-build 2bd099
    /* Didn't use our arguments, so restore their original refcounts */
rpm-build 2bd099
    Py_DECREF(typ);
rpm-build 2bd099
    Py_XDECREF(val);
rpm-build 2bd099
    Py_XDECREF(tb);
rpm-build 2bd099
    return NULL;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
gen_throw(PyGenObject *gen, PyObject *args)
rpm-build 2bd099
{
rpm-build 2bd099
    PyObject *typ;
rpm-build 2bd099
    PyObject *tb = NULL;
rpm-build 2bd099
    PyObject *val = NULL;
rpm-build 2bd099
rpm-build 2bd099
    if (!PyArg_UnpackTuple(args, "throw", 1, 3, &typ, &val, &tb)) {
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    return _gen_throw(gen, 1, typ, val, tb);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
gen_iternext(PyGenObject *gen)
rpm-build 2bd099
{
rpm-build 2bd099
    return gen_send_ex(gen, NULL, 0, 0);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
/*
rpm-build 2bd099
 * Set StopIteration with specified value.  Value can be arbitrary object
rpm-build 2bd099
 * or NULL.
rpm-build 2bd099
 *
rpm-build 2bd099
 * Returns 0 if StopIteration is set and -1 if any other exception is set.
rpm-build 2bd099
 */
rpm-build 2bd099
int
rpm-build 2bd099
_PyGen_SetStopIterationValue(PyObject *value)
rpm-build 2bd099
{
rpm-build 2bd099
    PyObject *e;
rpm-build 2bd099
rpm-build 2bd099
    if (value == NULL ||
rpm-build 2bd099
        (!PyTuple_Check(value) && !PyExceptionInstance_Check(value)))
rpm-build 2bd099
    {
rpm-build 2bd099
        /* Delay exception instantiation if we can */
rpm-build 2bd099
        PyErr_SetObject(PyExc_StopIteration, value);
rpm-build 2bd099
        return 0;
rpm-build 2bd099
    }
rpm-build 2bd099
    /* Construct an exception instance manually with
rpm-build 2bd099
     * PyObject_CallFunctionObjArgs and pass it to PyErr_SetObject.
rpm-build 2bd099
     *
rpm-build 2bd099
     * We do this to handle a situation when "value" is a tuple, in which
rpm-build 2bd099
     * case PyErr_SetObject would set the value of StopIteration to
rpm-build 2bd099
     * the first element of the tuple.
rpm-build 2bd099
     *
rpm-build 2bd099
     * (See PyErr_SetObject/_PyErr_CreateException code for details.)
rpm-build 2bd099
     */
rpm-build 2bd099
    e = PyObject_CallFunctionObjArgs(PyExc_StopIteration, value, NULL);
rpm-build 2bd099
    if (e == NULL) {
rpm-build 2bd099
        return -1;
rpm-build 2bd099
    }
rpm-build 2bd099
    PyErr_SetObject(PyExc_StopIteration, e);
rpm-build 2bd099
    Py_DECREF(e);
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
/*
rpm-build 2bd099
 *   If StopIteration exception is set, fetches its 'value'
rpm-build 2bd099
 *   attribute if any, otherwise sets pvalue to None.
rpm-build 2bd099
 *
rpm-build 2bd099
 *   Returns 0 if no exception or StopIteration is set.
rpm-build 2bd099
 *   If any other exception is set, returns -1 and leaves
rpm-build 2bd099
 *   pvalue unchanged.
rpm-build 2bd099
 */
rpm-build 2bd099
rpm-build 2bd099
int
rpm-build 2bd099
_PyGen_FetchStopIterationValue(PyObject **pvalue)
rpm-build 2bd099
{
rpm-build 2bd099
    PyObject *et, *ev, *tb;
rpm-build 2bd099
    PyObject *value = NULL;
rpm-build 2bd099
rpm-build 2bd099
    if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
rpm-build 2bd099
        PyErr_Fetch(&et, &ev, &tb);
rpm-build 2bd099
        if (ev) {
rpm-build 2bd099
            /* exception will usually be normalised already */
rpm-build 2bd099
            if (PyObject_TypeCheck(ev, (PyTypeObject *) et)) {
rpm-build 2bd099
                value = ((PyStopIterationObject *)ev)->value;
rpm-build 2bd099
                Py_INCREF(value);
rpm-build 2bd099
                Py_DECREF(ev);
rpm-build 2bd099
            } else if (et == PyExc_StopIteration && !PyTuple_Check(ev)) {
rpm-build 2bd099
                /* Avoid normalisation and take ev as value.
rpm-build 2bd099
                 *
rpm-build 2bd099
                 * Normalization is required if the value is a tuple, in
rpm-build 2bd099
                 * that case the value of StopIteration would be set to
rpm-build 2bd099
                 * the first element of the tuple.
rpm-build 2bd099
                 *
rpm-build 2bd099
                 * (See _PyErr_CreateException code for details.)
rpm-build 2bd099
                 */
rpm-build 2bd099
                value = ev;
rpm-build 2bd099
            } else {
rpm-build 2bd099
                /* normalisation required */
rpm-build 2bd099
                PyErr_NormalizeException(&et, &ev, &tb);
rpm-build 2bd099
                if (!PyObject_TypeCheck(ev, (PyTypeObject *)PyExc_StopIteration)) {
rpm-build 2bd099
                    PyErr_Restore(et, ev, tb);
rpm-build 2bd099
                    return -1;
rpm-build 2bd099
                }
rpm-build 2bd099
                value = ((PyStopIterationObject *)ev)->value;
rpm-build 2bd099
                Py_INCREF(value);
rpm-build 2bd099
                Py_DECREF(ev);
rpm-build 2bd099
            }
rpm-build 2bd099
        }
rpm-build 2bd099
        Py_XDECREF(et);
rpm-build 2bd099
        Py_XDECREF(tb);
rpm-build 2bd099
    } else if (PyErr_Occurred()) {
rpm-build 2bd099
        return -1;
rpm-build 2bd099
    }
rpm-build 2bd099
    if (value == NULL) {
rpm-build 2bd099
        value = Py_None;
rpm-build 2bd099
        Py_INCREF(value);
rpm-build 2bd099
    }
rpm-build 2bd099
    *pvalue = value;
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
gen_repr(PyGenObject *gen)
rpm-build 2bd099
{
rpm-build 2bd099
    return PyUnicode_FromFormat("<generator object %S at %p>",
rpm-build 2bd099
                                gen->gi_qualname, gen);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
gen_get_name(PyGenObject *op)
rpm-build 2bd099
{
rpm-build 2bd099
    Py_INCREF(op->gi_name);
rpm-build 2bd099
    return op->gi_name;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static int
rpm-build 2bd099
gen_set_name(PyGenObject *op, PyObject *value)
rpm-build 2bd099
{
rpm-build 2bd099
    /* Not legal to del gen.gi_name or to set it to anything
rpm-build 2bd099
     * other than a string object. */
rpm-build 2bd099
    if (value == NULL || !PyUnicode_Check(value)) {
rpm-build 2bd099
        PyErr_SetString(PyExc_TypeError,
rpm-build 2bd099
                        "__name__ must be set to a string object");
rpm-build 2bd099
        return -1;
rpm-build 2bd099
    }
rpm-build 2bd099
    Py_INCREF(value);
rpm-build 2bd099
    Py_XSETREF(op->gi_name, value);
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
gen_get_qualname(PyGenObject *op)
rpm-build 2bd099
{
rpm-build 2bd099
    Py_INCREF(op->gi_qualname);
rpm-build 2bd099
    return op->gi_qualname;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static int
rpm-build 2bd099
gen_set_qualname(PyGenObject *op, PyObject *value)
rpm-build 2bd099
{
rpm-build 2bd099
    /* Not legal to del gen.__qualname__ or to set it to anything
rpm-build 2bd099
     * other than a string object. */
rpm-build 2bd099
    if (value == NULL || !PyUnicode_Check(value)) {
rpm-build 2bd099
        PyErr_SetString(PyExc_TypeError,
rpm-build 2bd099
                        "__qualname__ must be set to a string object");
rpm-build 2bd099
        return -1;
rpm-build 2bd099
    }
rpm-build 2bd099
    Py_INCREF(value);
rpm-build 2bd099
    Py_XSETREF(op->gi_qualname, value);
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
gen_getyieldfrom(PyGenObject *gen)
rpm-build 2bd099
{
rpm-build 2bd099
    PyObject *yf = _PyGen_yf(gen);
rpm-build 2bd099
    if (yf == NULL)
rpm-build 2bd099
        Py_RETURN_NONE;
rpm-build 2bd099
    return yf;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyGetSetDef gen_getsetlist[] = {
rpm-build 2bd099
    {"__name__", (getter)gen_get_name, (setter)gen_set_name,
rpm-build 2bd099
     PyDoc_STR("name of the generator")},
rpm-build 2bd099
    {"__qualname__", (getter)gen_get_qualname, (setter)gen_set_qualname,
rpm-build 2bd099
     PyDoc_STR("qualified name of the generator")},
rpm-build 2bd099
    {"gi_yieldfrom", (getter)gen_getyieldfrom, NULL,
rpm-build 2bd099
     PyDoc_STR("object being iterated by yield from, or None")},
rpm-build 2bd099
    {NULL} /* Sentinel */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
static PyMemberDef gen_memberlist[] = {
rpm-build 2bd099
    {"gi_frame",     T_OBJECT, offsetof(PyGenObject, gi_frame),    READONLY},
rpm-build 2bd099
    {"gi_running",   T_BOOL,   offsetof(PyGenObject, gi_running),  READONLY},
rpm-build 2bd099
    {"gi_code",      T_OBJECT, offsetof(PyGenObject, gi_code),     READONLY},
rpm-build 2bd099
    {NULL}      /* Sentinel */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
static PyMethodDef gen_methods[] = {
rpm-build 2bd099
    {"send",(PyCFunction)_PyGen_Send, METH_O, send_doc},
rpm-build 2bd099
    {"throw",(PyCFunction)gen_throw, METH_VARARGS, throw_doc},
rpm-build 2bd099
    {"close",(PyCFunction)gen_close, METH_NOARGS, close_doc},
rpm-build 2bd099
    {NULL, NULL}        /* Sentinel */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
PyTypeObject PyGen_Type = {
rpm-build 2bd099
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
rpm-build 2bd099
    "generator",                                /* tp_name */
rpm-build 2bd099
    sizeof(PyGenObject),                        /* tp_basicsize */
rpm-build 2bd099
    0,                                          /* tp_itemsize */
rpm-build 2bd099
    /* methods */
rpm-build 2bd099
    (destructor)gen_dealloc,                    /* tp_dealloc */
rpm-build 2bd099
    0,                                          /* tp_print */
rpm-build 2bd099
    0,                                          /* tp_getattr */
rpm-build 2bd099
    0,                                          /* tp_setattr */
rpm-build 2bd099
    0,                                          /* tp_as_async */
rpm-build 2bd099
    (reprfunc)gen_repr,                         /* tp_repr */
rpm-build 2bd099
    0,                                          /* tp_as_number */
rpm-build 2bd099
    0,                                          /* tp_as_sequence */
rpm-build 2bd099
    0,                                          /* tp_as_mapping */
rpm-build 2bd099
    0,                                          /* tp_hash */
rpm-build 2bd099
    0,                                          /* tp_call */
rpm-build 2bd099
    0,                                          /* tp_str */
rpm-build 2bd099
    PyObject_GenericGetAttr,                    /* tp_getattro */
rpm-build 2bd099
    0,                                          /* tp_setattro */
rpm-build 2bd099
    0,                                          /* tp_as_buffer */
rpm-build 2bd099
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
rpm-build 2bd099
        Py_TPFLAGS_HAVE_FINALIZE,               /* tp_flags */
rpm-build 2bd099
    0,                                          /* tp_doc */
rpm-build 2bd099
    (traverseproc)gen_traverse,                 /* tp_traverse */
rpm-build 2bd099
    0,                                          /* tp_clear */
rpm-build 2bd099
    0,                                          /* tp_richcompare */
rpm-build 2bd099
    offsetof(PyGenObject, gi_weakreflist),      /* tp_weaklistoffset */
rpm-build 2bd099
    PyObject_SelfIter,                          /* tp_iter */
rpm-build 2bd099
    (iternextfunc)gen_iternext,                 /* tp_iternext */
rpm-build 2bd099
    gen_methods,                                /* tp_methods */
rpm-build 2bd099
    gen_memberlist,                             /* tp_members */
rpm-build 2bd099
    gen_getsetlist,                             /* tp_getset */
rpm-build 2bd099
    0,                                          /* tp_base */
rpm-build 2bd099
    0,                                          /* tp_dict */
rpm-build 2bd099
rpm-build 2bd099
    0,                                          /* tp_descr_get */
rpm-build 2bd099
    0,                                          /* tp_descr_set */
rpm-build 2bd099
    0,                                          /* tp_dictoffset */
rpm-build 2bd099
    0,                                          /* tp_init */
rpm-build 2bd099
    0,                                          /* tp_alloc */
rpm-build 2bd099
    0,                                          /* tp_new */
rpm-build 2bd099
    0,                                          /* tp_free */
rpm-build 2bd099
    0,                                          /* tp_is_gc */
rpm-build 2bd099
    0,                                          /* tp_bases */
rpm-build 2bd099
    0,                                          /* tp_mro */
rpm-build 2bd099
    0,                                          /* tp_cache */
rpm-build 2bd099
    0,                                          /* tp_subclasses */
rpm-build 2bd099
    0,                                          /* tp_weaklist */
rpm-build 2bd099
    0,                                          /* tp_del */
rpm-build 2bd099
    0,                                          /* tp_version_tag */
rpm-build 2bd099
    _PyGen_Finalize,                            /* tp_finalize */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f,
rpm-build 2bd099
                      PyObject *name, PyObject *qualname)
rpm-build 2bd099
{
rpm-build 2bd099
    PyGenObject *gen = PyObject_GC_New(PyGenObject, type);
rpm-build 2bd099
    if (gen == NULL) {
rpm-build 2bd099
        Py_DECREF(f);
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
    gen->gi_frame = f;
rpm-build 2bd099
    f->f_gen = (PyObject *) gen;
rpm-build 2bd099
    Py_INCREF(f->f_code);
rpm-build 2bd099
    gen->gi_code = (PyObject *)(f->f_code);
rpm-build 2bd099
    gen->gi_running = 0;
rpm-build 2bd099
    gen->gi_weakreflist = NULL;
rpm-build 2bd099
    if (name != NULL)
rpm-build 2bd099
        gen->gi_name = name;
rpm-build 2bd099
    else
rpm-build 2bd099
        gen->gi_name = ((PyCodeObject *)gen->gi_code)->co_name;
rpm-build 2bd099
    Py_INCREF(gen->gi_name);
rpm-build 2bd099
    if (qualname != NULL)
rpm-build 2bd099
        gen->gi_qualname = qualname;
rpm-build 2bd099
    else
rpm-build 2bd099
        gen->gi_qualname = gen->gi_name;
rpm-build 2bd099
    Py_INCREF(gen->gi_qualname);
rpm-build 2bd099
    _PyObject_GC_TRACK(gen);
rpm-build 2bd099
    return (PyObject *)gen;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
PyObject *
rpm-build 2bd099
PyGen_NewWithQualName(PyFrameObject *f, PyObject *name, PyObject *qualname)
rpm-build 2bd099
{
rpm-build 2bd099
    return gen_new_with_qualname(&PyGen_Type, f, name, qualname);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
PyObject *
rpm-build 2bd099
PyGen_New(PyFrameObject *f)
rpm-build 2bd099
{
rpm-build 2bd099
    return gen_new_with_qualname(&PyGen_Type, f, NULL, NULL);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
int
rpm-build 2bd099
PyGen_NeedsFinalizing(PyGenObject *gen)
rpm-build 2bd099
{
rpm-build 2bd099
    int i;
rpm-build 2bd099
    PyFrameObject *f = gen->gi_frame;
rpm-build 2bd099
rpm-build 2bd099
    if (f == NULL || f->f_stacktop == NULL)
rpm-build 2bd099
        return 0; /* no frame or empty blockstack == no finalization */
rpm-build 2bd099
rpm-build 2bd099
    /* Any block type besides a loop requires cleanup. */
rpm-build 2bd099
    for (i = 0; i < f->f_iblock; i++)
rpm-build 2bd099
        if (f->f_blockstack[i].b_type != SETUP_LOOP)
rpm-build 2bd099
            return 1;
rpm-build 2bd099
rpm-build 2bd099
    /* No blocks except loops, it's safe to skip finalization. */
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
/* Coroutine Object */
rpm-build 2bd099
rpm-build 2bd099
typedef struct {
rpm-build 2bd099
    PyObject_HEAD
rpm-build 2bd099
    PyCoroObject *cw_coroutine;
rpm-build 2bd099
} PyCoroWrapper;
rpm-build 2bd099
rpm-build 2bd099
static int
rpm-build 2bd099
gen_is_coroutine(PyObject *o)
rpm-build 2bd099
{
rpm-build 2bd099
    if (PyGen_CheckExact(o)) {
rpm-build 2bd099
        PyCodeObject *code = (PyCodeObject *)((PyGenObject*)o)->gi_code;
rpm-build 2bd099
        if (code->co_flags & CO_ITERABLE_COROUTINE) {
rpm-build 2bd099
            return 1;
rpm-build 2bd099
        }
rpm-build 2bd099
    }
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
/*
rpm-build 2bd099
 *   This helper function returns an awaitable for `o`:
rpm-build 2bd099
 *     - `o` if `o` is a coroutine-object;
rpm-build 2bd099
 *     - `type(o)->tp_as_async->am_await(o)`
rpm-build 2bd099
 *
rpm-build 2bd099
 *   Raises a TypeError if it's not possible to return
rpm-build 2bd099
 *   an awaitable and returns NULL.
rpm-build 2bd099
 */
rpm-build 2bd099
PyObject *
rpm-build 2bd099
_PyCoro_GetAwaitableIter(PyObject *o)
rpm-build 2bd099
{
rpm-build 2bd099
    unaryfunc getter = NULL;
rpm-build 2bd099
    PyTypeObject *ot;
rpm-build 2bd099
rpm-build 2bd099
    if (PyCoro_CheckExact(o) || gen_is_coroutine(o)) {
rpm-build 2bd099
        /* 'o' is a coroutine. */
rpm-build 2bd099
        Py_INCREF(o);
rpm-build 2bd099
        return o;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    ot = Py_TYPE(o);
rpm-build 2bd099
    if (ot->tp_as_async != NULL) {
rpm-build 2bd099
        getter = ot->tp_as_async->am_await;
rpm-build 2bd099
    }
rpm-build 2bd099
    if (getter != NULL) {
rpm-build 2bd099
        PyObject *res = (*getter)(o);
rpm-build 2bd099
        if (res != NULL) {
rpm-build 2bd099
            if (PyCoro_CheckExact(res) || gen_is_coroutine(res)) {
rpm-build 2bd099
                /* __await__ must return an *iterator*, not
rpm-build 2bd099
                   a coroutine or another awaitable (see PEP 492) */
rpm-build 2bd099
                PyErr_SetString(PyExc_TypeError,
rpm-build 2bd099
                                "__await__() returned a coroutine");
rpm-build 2bd099
                Py_CLEAR(res);
rpm-build 2bd099
            } else if (!PyIter_Check(res)) {
rpm-build 2bd099
                PyErr_Format(PyExc_TypeError,
rpm-build 2bd099
                             "__await__() returned non-iterator "
rpm-build 2bd099
                             "of type '%.100s'",
rpm-build 2bd099
                             Py_TYPE(res)->tp_name);
rpm-build 2bd099
                Py_CLEAR(res);
rpm-build 2bd099
            }
rpm-build 2bd099
        }
rpm-build 2bd099
        return res;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    PyErr_Format(PyExc_TypeError,
rpm-build 2bd099
                 "object %.100s can't be used in 'await' expression",
rpm-build 2bd099
                 ot->tp_name);
rpm-build 2bd099
    return NULL;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
coro_repr(PyCoroObject *coro)
rpm-build 2bd099
{
rpm-build 2bd099
    return PyUnicode_FromFormat("<coroutine object %S at %p>",
rpm-build 2bd099
                                coro->cr_qualname, coro);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
coro_await(PyCoroObject *coro)
rpm-build 2bd099
{
rpm-build 2bd099
    PyCoroWrapper *cw = PyObject_GC_New(PyCoroWrapper, &_PyCoroWrapper_Type);
rpm-build 2bd099
    if (cw == NULL) {
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
    Py_INCREF(coro);
rpm-build 2bd099
    cw->cw_coroutine = coro;
rpm-build 2bd099
    _PyObject_GC_TRACK(cw);
rpm-build 2bd099
    return (PyObject *)cw;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
coro_get_cr_await(PyCoroObject *coro)
rpm-build 2bd099
{
rpm-build 2bd099
    PyObject *yf = _PyGen_yf((PyGenObject *) coro);
rpm-build 2bd099
    if (yf == NULL)
rpm-build 2bd099
        Py_RETURN_NONE;
rpm-build 2bd099
    return yf;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyGetSetDef coro_getsetlist[] = {
rpm-build 2bd099
    {"__name__", (getter)gen_get_name, (setter)gen_set_name,
rpm-build 2bd099
     PyDoc_STR("name of the coroutine")},
rpm-build 2bd099
    {"__qualname__", (getter)gen_get_qualname, (setter)gen_set_qualname,
rpm-build 2bd099
     PyDoc_STR("qualified name of the coroutine")},
rpm-build 2bd099
    {"cr_await", (getter)coro_get_cr_await, NULL,
rpm-build 2bd099
     PyDoc_STR("object being awaited on, or None")},
rpm-build 2bd099
    {NULL} /* Sentinel */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
static PyMemberDef coro_memberlist[] = {
rpm-build 2bd099
    {"cr_frame",     T_OBJECT, offsetof(PyCoroObject, cr_frame),    READONLY},
rpm-build 2bd099
    {"cr_running",   T_BOOL,   offsetof(PyCoroObject, cr_running),  READONLY},
rpm-build 2bd099
    {"cr_code",      T_OBJECT, offsetof(PyCoroObject, cr_code),     READONLY},
rpm-build 2bd099
    {NULL}      /* Sentinel */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
PyDoc_STRVAR(coro_send_doc,
rpm-build 2bd099
"send(arg) -> send 'arg' into coroutine,\n\
rpm-build 2bd099
return next iterated value or raise StopIteration.");
rpm-build 2bd099
rpm-build 2bd099
PyDoc_STRVAR(coro_throw_doc,
rpm-build 2bd099
"throw(typ[,val[,tb]]) -> raise exception in coroutine,\n\
rpm-build 2bd099
return next iterated value or raise StopIteration.");
rpm-build 2bd099
rpm-build 2bd099
PyDoc_STRVAR(coro_close_doc,
rpm-build 2bd099
"close() -> raise GeneratorExit inside coroutine.");
rpm-build 2bd099
rpm-build 2bd099
static PyMethodDef coro_methods[] = {
rpm-build 2bd099
    {"send",(PyCFunction)_PyGen_Send, METH_O, coro_send_doc},
rpm-build 2bd099
    {"throw",(PyCFunction)gen_throw, METH_VARARGS, coro_throw_doc},
rpm-build 2bd099
    {"close",(PyCFunction)gen_close, METH_NOARGS, coro_close_doc},
rpm-build 2bd099
    {NULL, NULL}        /* Sentinel */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
static PyAsyncMethods coro_as_async = {
rpm-build 2bd099
    (unaryfunc)coro_await,                      /* am_await */
rpm-build 2bd099
    0,                                          /* am_aiter */
rpm-build 2bd099
    0                                           /* am_anext */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
PyTypeObject PyCoro_Type = {
rpm-build 2bd099
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
rpm-build 2bd099
    "coroutine",                                /* tp_name */
rpm-build 2bd099
    sizeof(PyCoroObject),                       /* tp_basicsize */
rpm-build 2bd099
    0,                                          /* tp_itemsize */
rpm-build 2bd099
    /* methods */
rpm-build 2bd099
    (destructor)gen_dealloc,                    /* tp_dealloc */
rpm-build 2bd099
    0,                                          /* tp_print */
rpm-build 2bd099
    0,                                          /* tp_getattr */
rpm-build 2bd099
    0,                                          /* tp_setattr */
rpm-build 2bd099
    &coro_as_async,                             /* tp_as_async */
rpm-build 2bd099
    (reprfunc)coro_repr,                        /* tp_repr */
rpm-build 2bd099
    0,                                          /* tp_as_number */
rpm-build 2bd099
    0,                                          /* tp_as_sequence */
rpm-build 2bd099
    0,                                          /* tp_as_mapping */
rpm-build 2bd099
    0,                                          /* tp_hash */
rpm-build 2bd099
    0,                                          /* tp_call */
rpm-build 2bd099
    0,                                          /* tp_str */
rpm-build 2bd099
    PyObject_GenericGetAttr,                    /* tp_getattro */
rpm-build 2bd099
    0,                                          /* tp_setattro */
rpm-build 2bd099
    0,                                          /* tp_as_buffer */
rpm-build 2bd099
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
rpm-build 2bd099
        Py_TPFLAGS_HAVE_FINALIZE,               /* tp_flags */
rpm-build 2bd099
    0,                                          /* tp_doc */
rpm-build 2bd099
    (traverseproc)gen_traverse,                 /* tp_traverse */
rpm-build 2bd099
    0,                                          /* tp_clear */
rpm-build 2bd099
    0,                                          /* tp_richcompare */
rpm-build 2bd099
    offsetof(PyCoroObject, cr_weakreflist),     /* tp_weaklistoffset */
rpm-build 2bd099
    0,                                          /* tp_iter */
rpm-build 2bd099
    0,                                          /* tp_iternext */
rpm-build 2bd099
    coro_methods,                               /* tp_methods */
rpm-build 2bd099
    coro_memberlist,                            /* tp_members */
rpm-build 2bd099
    coro_getsetlist,                            /* tp_getset */
rpm-build 2bd099
    0,                                          /* tp_base */
rpm-build 2bd099
    0,                                          /* tp_dict */
rpm-build 2bd099
    0,                                          /* tp_descr_get */
rpm-build 2bd099
    0,                                          /* tp_descr_set */
rpm-build 2bd099
    0,                                          /* tp_dictoffset */
rpm-build 2bd099
    0,                                          /* tp_init */
rpm-build 2bd099
    0,                                          /* tp_alloc */
rpm-build 2bd099
    0,                                          /* tp_new */
rpm-build 2bd099
    0,                                          /* tp_free */
rpm-build 2bd099
    0,                                          /* tp_is_gc */
rpm-build 2bd099
    0,                                          /* tp_bases */
rpm-build 2bd099
    0,                                          /* tp_mro */
rpm-build 2bd099
    0,                                          /* tp_cache */
rpm-build 2bd099
    0,                                          /* tp_subclasses */
rpm-build 2bd099
    0,                                          /* tp_weaklist */
rpm-build 2bd099
    0,                                          /* tp_del */
rpm-build 2bd099
    0,                                          /* tp_version_tag */
rpm-build 2bd099
    _PyGen_Finalize,                            /* tp_finalize */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
static void
rpm-build 2bd099
coro_wrapper_dealloc(PyCoroWrapper *cw)
rpm-build 2bd099
{
rpm-build 2bd099
    _PyObject_GC_UNTRACK((PyObject *)cw);
rpm-build 2bd099
    Py_CLEAR(cw->cw_coroutine);
rpm-build 2bd099
    PyObject_GC_Del(cw);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
coro_wrapper_iternext(PyCoroWrapper *cw)
rpm-build 2bd099
{
rpm-build 2bd099
    return gen_send_ex((PyGenObject *)cw->cw_coroutine, NULL, 0, 0);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
coro_wrapper_send(PyCoroWrapper *cw, PyObject *arg)
rpm-build 2bd099
{
rpm-build 2bd099
    return gen_send_ex((PyGenObject *)cw->cw_coroutine, arg, 0, 0);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
coro_wrapper_throw(PyCoroWrapper *cw, PyObject *args)
rpm-build 2bd099
{
rpm-build 2bd099
    return gen_throw((PyGenObject *)cw->cw_coroutine, args);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
coro_wrapper_close(PyCoroWrapper *cw, PyObject *args)
rpm-build 2bd099
{
rpm-build 2bd099
    return gen_close((PyGenObject *)cw->cw_coroutine, args);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static int
rpm-build 2bd099
coro_wrapper_traverse(PyCoroWrapper *cw, visitproc visit, void *arg)
rpm-build 2bd099
{
rpm-build 2bd099
    Py_VISIT((PyObject *)cw->cw_coroutine);
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyMethodDef coro_wrapper_methods[] = {
rpm-build 2bd099
    {"send",(PyCFunction)coro_wrapper_send, METH_O, coro_send_doc},
rpm-build 2bd099
    {"throw",(PyCFunction)coro_wrapper_throw, METH_VARARGS, coro_throw_doc},
rpm-build 2bd099
    {"close",(PyCFunction)coro_wrapper_close, METH_NOARGS, coro_close_doc},
rpm-build 2bd099
    {NULL, NULL}        /* Sentinel */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
PyTypeObject _PyCoroWrapper_Type = {
rpm-build 2bd099
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
rpm-build 2bd099
    "coroutine_wrapper",
rpm-build 2bd099
    sizeof(PyCoroWrapper),                      /* tp_basicsize */
rpm-build 2bd099
    0,                                          /* tp_itemsize */
rpm-build 2bd099
    (destructor)coro_wrapper_dealloc,           /* destructor tp_dealloc */
rpm-build 2bd099
    0,                                          /* tp_print */
rpm-build 2bd099
    0,                                          /* tp_getattr */
rpm-build 2bd099
    0,                                          /* tp_setattr */
rpm-build 2bd099
    0,                                          /* tp_as_async */
rpm-build 2bd099
    0,                                          /* tp_repr */
rpm-build 2bd099
    0,                                          /* tp_as_number */
rpm-build 2bd099
    0,                                          /* tp_as_sequence */
rpm-build 2bd099
    0,                                          /* tp_as_mapping */
rpm-build 2bd099
    0,                                          /* tp_hash */
rpm-build 2bd099
    0,                                          /* tp_call */
rpm-build 2bd099
    0,                                          /* tp_str */
rpm-build 2bd099
    PyObject_GenericGetAttr,                    /* tp_getattro */
rpm-build 2bd099
    0,                                          /* tp_setattro */
rpm-build 2bd099
    0,                                          /* tp_as_buffer */
rpm-build 2bd099
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,    /* tp_flags */
rpm-build 2bd099
    "A wrapper object implementing __await__ for coroutines.",
rpm-build 2bd099
    (traverseproc)coro_wrapper_traverse,        /* tp_traverse */
rpm-build 2bd099
    0,                                          /* tp_clear */
rpm-build 2bd099
    0,                                          /* tp_richcompare */
rpm-build 2bd099
    0,                                          /* tp_weaklistoffset */
rpm-build 2bd099
    PyObject_SelfIter,                          /* tp_iter */
rpm-build 2bd099
    (iternextfunc)coro_wrapper_iternext,        /* tp_iternext */
rpm-build 2bd099
    coro_wrapper_methods,                       /* tp_methods */
rpm-build 2bd099
    0,                                          /* tp_members */
rpm-build 2bd099
    0,                                          /* tp_getset */
rpm-build 2bd099
    0,                                          /* tp_base */
rpm-build 2bd099
    0,                                          /* tp_dict */
rpm-build 2bd099
    0,                                          /* tp_descr_get */
rpm-build 2bd099
    0,                                          /* tp_descr_set */
rpm-build 2bd099
    0,                                          /* tp_dictoffset */
rpm-build 2bd099
    0,                                          /* tp_init */
rpm-build 2bd099
    0,                                          /* tp_alloc */
rpm-build 2bd099
    0,                                          /* tp_new */
rpm-build 2bd099
    0,                                          /* tp_free */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
PyObject *
rpm-build 2bd099
PyCoro_New(PyFrameObject *f, PyObject *name, PyObject *qualname)
rpm-build 2bd099
{
rpm-build 2bd099
    return gen_new_with_qualname(&PyCoro_Type, f, name, qualname);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
/* __aiter__ wrapper; see http://bugs.python.org/issue27243 for details. */
rpm-build 2bd099
rpm-build 2bd099
typedef struct {
rpm-build 2bd099
    PyObject_HEAD
rpm-build 2bd099
    PyObject *ags_aiter;
rpm-build 2bd099
} PyAIterWrapper;
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
aiter_wrapper_iternext(PyAIterWrapper *aw)
rpm-build 2bd099
{
rpm-build 2bd099
    _PyGen_SetStopIterationValue(aw->ags_aiter);
rpm-build 2bd099
    return NULL;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static int
rpm-build 2bd099
aiter_wrapper_traverse(PyAIterWrapper *aw, visitproc visit, void *arg)
rpm-build 2bd099
{
rpm-build 2bd099
    Py_VISIT((PyObject *)aw->ags_aiter);
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static void
rpm-build 2bd099
aiter_wrapper_dealloc(PyAIterWrapper *aw)
rpm-build 2bd099
{
rpm-build 2bd099
    _PyObject_GC_UNTRACK((PyObject *)aw);
rpm-build 2bd099
    Py_CLEAR(aw->ags_aiter);
rpm-build 2bd099
    PyObject_GC_Del(aw);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyAsyncMethods aiter_wrapper_as_async = {
rpm-build 2bd099
    PyObject_SelfIter,                          /* am_await */
rpm-build 2bd099
    0,                                          /* am_aiter */
rpm-build 2bd099
    0                                           /* am_anext */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
PyTypeObject _PyAIterWrapper_Type = {
rpm-build 2bd099
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
rpm-build 2bd099
    "aiter_wrapper",
rpm-build 2bd099
    sizeof(PyAIterWrapper),                     /* tp_basicsize */
rpm-build 2bd099
    0,                                          /* tp_itemsize */
rpm-build 2bd099
    (destructor)aiter_wrapper_dealloc,          /* destructor tp_dealloc */
rpm-build 2bd099
    0,                                          /* tp_print */
rpm-build 2bd099
    0,                                          /* tp_getattr */
rpm-build 2bd099
    0,                                          /* tp_setattr */
rpm-build 2bd099
    &aiter_wrapper_as_async,                    /* tp_as_async */
rpm-build 2bd099
    0,                                          /* tp_repr */
rpm-build 2bd099
    0,                                          /* tp_as_number */
rpm-build 2bd099
    0,                                          /* tp_as_sequence */
rpm-build 2bd099
    0,                                          /* tp_as_mapping */
rpm-build 2bd099
    0,                                          /* tp_hash */
rpm-build 2bd099
    0,                                          /* tp_call */
rpm-build 2bd099
    0,                                          /* tp_str */
rpm-build 2bd099
    PyObject_GenericGetAttr,                    /* tp_getattro */
rpm-build 2bd099
    0,                                          /* tp_setattro */
rpm-build 2bd099
    0,                                          /* tp_as_buffer */
rpm-build 2bd099
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,    /* tp_flags */
rpm-build 2bd099
    "A wrapper object for __aiter__ bakwards compatibility.",
rpm-build 2bd099
    (traverseproc)aiter_wrapper_traverse,       /* tp_traverse */
rpm-build 2bd099
    0,                                          /* tp_clear */
rpm-build 2bd099
    0,                                          /* tp_richcompare */
rpm-build 2bd099
    0,                                          /* tp_weaklistoffset */
rpm-build 2bd099
    PyObject_SelfIter,                          /* tp_iter */
rpm-build 2bd099
    (iternextfunc)aiter_wrapper_iternext,       /* tp_iternext */
rpm-build 2bd099
    0,                                          /* tp_methods */
rpm-build 2bd099
    0,                                          /* tp_members */
rpm-build 2bd099
    0,                                          /* tp_getset */
rpm-build 2bd099
    0,                                          /* tp_base */
rpm-build 2bd099
    0,                                          /* tp_dict */
rpm-build 2bd099
    0,                                          /* tp_descr_get */
rpm-build 2bd099
    0,                                          /* tp_descr_set */
rpm-build 2bd099
    0,                                          /* tp_dictoffset */
rpm-build 2bd099
    0,                                          /* tp_init */
rpm-build 2bd099
    0,                                          /* tp_alloc */
rpm-build 2bd099
    0,                                          /* tp_new */
rpm-build 2bd099
    0,                                          /* tp_free */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
PyObject *
rpm-build 2bd099
_PyAIterWrapper_New(PyObject *aiter)
rpm-build 2bd099
{
rpm-build 2bd099
    PyAIterWrapper *aw = PyObject_GC_New(PyAIterWrapper,
rpm-build 2bd099
                                         &_PyAIterWrapper_Type);
rpm-build 2bd099
    if (aw == NULL) {
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
    Py_INCREF(aiter);
rpm-build 2bd099
    aw->ags_aiter = aiter;
rpm-build 2bd099
    _PyObject_GC_TRACK(aw);
rpm-build 2bd099
    return (PyObject *)aw;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
/* ========= Asynchronous Generators ========= */
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
typedef enum {
rpm-build 2bd099
    AWAITABLE_STATE_INIT,   /* new awaitable, has not yet been iterated */
rpm-build 2bd099
    AWAITABLE_STATE_ITER,   /* being iterated */
rpm-build 2bd099
    AWAITABLE_STATE_CLOSED, /* closed */
rpm-build 2bd099
} AwaitableState;
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
typedef struct {
rpm-build 2bd099
    PyObject_HEAD
rpm-build 2bd099
    PyAsyncGenObject *ags_gen;
rpm-build 2bd099
rpm-build 2bd099
    /* Can be NULL, when in the __anext__() mode
rpm-build 2bd099
       (equivalent of "asend(None)") */
rpm-build 2bd099
    PyObject *ags_sendval;
rpm-build 2bd099
rpm-build 2bd099
    AwaitableState ags_state;
rpm-build 2bd099
} PyAsyncGenASend;
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
typedef struct {
rpm-build 2bd099
    PyObject_HEAD
rpm-build 2bd099
    PyAsyncGenObject *agt_gen;
rpm-build 2bd099
rpm-build 2bd099
    /* Can be NULL, when in the "aclose()" mode
rpm-build 2bd099
       (equivalent of "athrow(GeneratorExit)") */
rpm-build 2bd099
    PyObject *agt_args;
rpm-build 2bd099
rpm-build 2bd099
    AwaitableState agt_state;
rpm-build 2bd099
} PyAsyncGenAThrow;
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
typedef struct {
rpm-build 2bd099
    PyObject_HEAD
rpm-build 2bd099
    PyObject *agw_val;
rpm-build 2bd099
} _PyAsyncGenWrappedValue;
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
#ifndef _PyAsyncGen_MAXFREELIST
rpm-build 2bd099
#define _PyAsyncGen_MAXFREELIST 80
rpm-build 2bd099
#endif
rpm-build 2bd099
rpm-build 2bd099
/* Freelists boost performance 6-10%; they also reduce memory
rpm-build 2bd099
   fragmentation, as _PyAsyncGenWrappedValue and PyAsyncGenASend
rpm-build 2bd099
   are short-living objects that are instantiated for every
rpm-build 2bd099
   __anext__ call.
rpm-build 2bd099
*/
rpm-build 2bd099
rpm-build 2bd099
static _PyAsyncGenWrappedValue *ag_value_freelist[_PyAsyncGen_MAXFREELIST];
rpm-build 2bd099
static int ag_value_freelist_free = 0;
rpm-build 2bd099
rpm-build 2bd099
static PyAsyncGenASend *ag_asend_freelist[_PyAsyncGen_MAXFREELIST];
rpm-build 2bd099
static int ag_asend_freelist_free = 0;
rpm-build 2bd099
rpm-build 2bd099
#define _PyAsyncGenWrappedValue_CheckExact(o) \
rpm-build 2bd099
                    (Py_TYPE(o) == &_PyAsyncGenWrappedValue_Type)
rpm-build 2bd099
rpm-build 2bd099
#define PyAsyncGenASend_CheckExact(o) \
rpm-build 2bd099
                    (Py_TYPE(o) == &_PyAsyncGenASend_Type)
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static int
rpm-build 2bd099
async_gen_traverse(PyAsyncGenObject *gen, visitproc visit, void *arg)
rpm-build 2bd099
{
rpm-build 2bd099
    Py_VISIT(gen->ag_finalizer);
rpm-build 2bd099
    return gen_traverse((PyGenObject*)gen, visit, arg);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_repr(PyAsyncGenObject *o)
rpm-build 2bd099
{
rpm-build 2bd099
    return PyUnicode_FromFormat("<async_generator object %S at %p>",
rpm-build 2bd099
                                o->ag_qualname, o);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static int
rpm-build 2bd099
async_gen_init_hooks(PyAsyncGenObject *o)
rpm-build 2bd099
{
rpm-build 2bd099
    PyThreadState *tstate;
rpm-build 2bd099
    PyObject *finalizer;
rpm-build 2bd099
    PyObject *firstiter;
rpm-build 2bd099
rpm-build 2bd099
    if (o->ag_hooks_inited) {
rpm-build 2bd099
        return 0;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    o->ag_hooks_inited = 1;
rpm-build 2bd099
rpm-build 2bd099
    tstate = PyThreadState_GET();
rpm-build 2bd099
rpm-build 2bd099
    finalizer = tstate->async_gen_finalizer;
rpm-build 2bd099
    if (finalizer) {
rpm-build 2bd099
        Py_INCREF(finalizer);
rpm-build 2bd099
        o->ag_finalizer = finalizer;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    firstiter = tstate->async_gen_firstiter;
rpm-build 2bd099
    if (firstiter) {
rpm-build 2bd099
        PyObject *res;
rpm-build 2bd099
rpm-build 2bd099
        Py_INCREF(firstiter);
rpm-build 2bd099
        res = PyObject_CallFunction(firstiter, "O", o);
rpm-build 2bd099
        Py_DECREF(firstiter);
rpm-build 2bd099
        if (res == NULL) {
rpm-build 2bd099
            return 1;
rpm-build 2bd099
        }
rpm-build 2bd099
        Py_DECREF(res);
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_anext(PyAsyncGenObject *o)
rpm-build 2bd099
{
rpm-build 2bd099
    if (async_gen_init_hooks(o)) {
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
    return async_gen_asend_new(o, NULL);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_asend(PyAsyncGenObject *o, PyObject *arg)
rpm-build 2bd099
{
rpm-build 2bd099
    if (async_gen_init_hooks(o)) {
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
    return async_gen_asend_new(o, arg);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_aclose(PyAsyncGenObject *o, PyObject *arg)
rpm-build 2bd099
{
rpm-build 2bd099
    if (async_gen_init_hooks(o)) {
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
    return async_gen_athrow_new(o, NULL);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_athrow(PyAsyncGenObject *o, PyObject *args)
rpm-build 2bd099
{
rpm-build 2bd099
    if (async_gen_init_hooks(o)) {
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
    return async_gen_athrow_new(o, args);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyGetSetDef async_gen_getsetlist[] = {
rpm-build 2bd099
    {"__name__", (getter)gen_get_name, (setter)gen_set_name,
rpm-build 2bd099
     PyDoc_STR("name of the async generator")},
rpm-build 2bd099
    {"__qualname__", (getter)gen_get_qualname, (setter)gen_set_qualname,
rpm-build 2bd099
     PyDoc_STR("qualified name of the async generator")},
rpm-build 2bd099
    {"ag_await", (getter)coro_get_cr_await, NULL,
rpm-build 2bd099
     PyDoc_STR("object being awaited on, or None")},
rpm-build 2bd099
    {NULL} /* Sentinel */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
static PyMemberDef async_gen_memberlist[] = {
rpm-build 2bd099
    {"ag_frame",   T_OBJECT, offsetof(PyAsyncGenObject, ag_frame),   READONLY},
rpm-build 2bd099
    {"ag_running", T_BOOL,   offsetof(PyAsyncGenObject, ag_running), READONLY},
rpm-build 2bd099
    {"ag_code",    T_OBJECT, offsetof(PyAsyncGenObject, ag_code),    READONLY},
rpm-build 2bd099
    {NULL}      /* Sentinel */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
PyDoc_STRVAR(async_aclose_doc,
rpm-build 2bd099
"aclose() -> raise GeneratorExit inside generator.");
rpm-build 2bd099
rpm-build 2bd099
PyDoc_STRVAR(async_asend_doc,
rpm-build 2bd099
"asend(v) -> send 'v' in generator.");
rpm-build 2bd099
rpm-build 2bd099
PyDoc_STRVAR(async_athrow_doc,
rpm-build 2bd099
"athrow(typ[,val[,tb]]) -> raise exception in generator.");
rpm-build 2bd099
rpm-build 2bd099
static PyMethodDef async_gen_methods[] = {
rpm-build 2bd099
    {"asend", (PyCFunction)async_gen_asend, METH_O, async_asend_doc},
rpm-build 2bd099
    {"athrow",(PyCFunction)async_gen_athrow, METH_VARARGS, async_athrow_doc},
rpm-build 2bd099
    {"aclose", (PyCFunction)async_gen_aclose, METH_NOARGS, async_aclose_doc},
rpm-build 2bd099
    {NULL, NULL}        /* Sentinel */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyAsyncMethods async_gen_as_async = {
rpm-build 2bd099
    0,                                          /* am_await */
rpm-build 2bd099
    PyObject_SelfIter,                          /* am_aiter */
rpm-build 2bd099
    (unaryfunc)async_gen_anext                  /* am_anext */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
PyTypeObject PyAsyncGen_Type = {
rpm-build 2bd099
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
rpm-build 2bd099
    "async_generator",                          /* tp_name */
rpm-build 2bd099
    sizeof(PyAsyncGenObject),                   /* tp_basicsize */
rpm-build 2bd099
    0,                                          /* tp_itemsize */
rpm-build 2bd099
    /* methods */
rpm-build 2bd099
    (destructor)gen_dealloc,                    /* tp_dealloc */
rpm-build 2bd099
    0,                                          /* tp_print */
rpm-build 2bd099
    0,                                          /* tp_getattr */
rpm-build 2bd099
    0,                                          /* tp_setattr */
rpm-build 2bd099
    &async_gen_as_async,                        /* tp_as_async */
rpm-build 2bd099
    (reprfunc)async_gen_repr,                   /* tp_repr */
rpm-build 2bd099
    0,                                          /* tp_as_number */
rpm-build 2bd099
    0,                                          /* tp_as_sequence */
rpm-build 2bd099
    0,                                          /* tp_as_mapping */
rpm-build 2bd099
    0,                                          /* tp_hash */
rpm-build 2bd099
    0,                                          /* tp_call */
rpm-build 2bd099
    0,                                          /* tp_str */
rpm-build 2bd099
    PyObject_GenericGetAttr,                    /* tp_getattro */
rpm-build 2bd099
    0,                                          /* tp_setattro */
rpm-build 2bd099
    0,                                          /* tp_as_buffer */
rpm-build 2bd099
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
rpm-build 2bd099
        Py_TPFLAGS_HAVE_FINALIZE,               /* tp_flags */
rpm-build 2bd099
    0,                                          /* tp_doc */
rpm-build 2bd099
    (traverseproc)async_gen_traverse,           /* tp_traverse */
rpm-build 2bd099
    0,                                          /* tp_clear */
rpm-build 2bd099
    0,                                          /* tp_richcompare */
rpm-build 2bd099
    offsetof(PyAsyncGenObject, ag_weakreflist), /* tp_weaklistoffset */
rpm-build 2bd099
    0,                                          /* tp_iter */
rpm-build 2bd099
    0,                                          /* tp_iternext */
rpm-build 2bd099
    async_gen_methods,                          /* tp_methods */
rpm-build 2bd099
    async_gen_memberlist,                       /* tp_members */
rpm-build 2bd099
    async_gen_getsetlist,                       /* tp_getset */
rpm-build 2bd099
    0,                                          /* tp_base */
rpm-build 2bd099
    0,                                          /* tp_dict */
rpm-build 2bd099
    0,                                          /* tp_descr_get */
rpm-build 2bd099
    0,                                          /* tp_descr_set */
rpm-build 2bd099
    0,                                          /* tp_dictoffset */
rpm-build 2bd099
    0,                                          /* tp_init */
rpm-build 2bd099
    0,                                          /* tp_alloc */
rpm-build 2bd099
    0,                                          /* tp_new */
rpm-build 2bd099
    0,                                          /* tp_free */
rpm-build 2bd099
    0,                                          /* tp_is_gc */
rpm-build 2bd099
    0,                                          /* tp_bases */
rpm-build 2bd099
    0,                                          /* tp_mro */
rpm-build 2bd099
    0,                                          /* tp_cache */
rpm-build 2bd099
    0,                                          /* tp_subclasses */
rpm-build 2bd099
    0,                                          /* tp_weaklist */
rpm-build 2bd099
    0,                                          /* tp_del */
rpm-build 2bd099
    0,                                          /* tp_version_tag */
rpm-build 2bd099
    _PyGen_Finalize,                            /* tp_finalize */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
PyObject *
rpm-build 2bd099
PyAsyncGen_New(PyFrameObject *f, PyObject *name, PyObject *qualname)
rpm-build 2bd099
{
rpm-build 2bd099
    PyAsyncGenObject *o;
rpm-build 2bd099
    o = (PyAsyncGenObject *)gen_new_with_qualname(
rpm-build 2bd099
        &PyAsyncGen_Type, f, name, qualname);
rpm-build 2bd099
    if (o == NULL) {
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
    o->ag_finalizer = NULL;
rpm-build 2bd099
    o->ag_closed = 0;
rpm-build 2bd099
    o->ag_hooks_inited = 0;
rpm-build 2bd099
    return (PyObject*)o;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
int
rpm-build 2bd099
PyAsyncGen_ClearFreeLists(void)
rpm-build 2bd099
{
rpm-build 2bd099
    int ret = ag_value_freelist_free + ag_asend_freelist_free;
rpm-build 2bd099
rpm-build 2bd099
    while (ag_value_freelist_free) {
rpm-build 2bd099
        _PyAsyncGenWrappedValue *o;
rpm-build 2bd099
        o = ag_value_freelist[--ag_value_freelist_free];
rpm-build 2bd099
        assert(_PyAsyncGenWrappedValue_CheckExact(o));
rpm-build 2bd099
        PyObject_GC_Del(o);
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    while (ag_asend_freelist_free) {
rpm-build 2bd099
        PyAsyncGenASend *o;
rpm-build 2bd099
        o = ag_asend_freelist[--ag_asend_freelist_free];
rpm-build 2bd099
        assert(Py_TYPE(o) == &_PyAsyncGenASend_Type);
rpm-build 2bd099
        PyObject_GC_Del(o);
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    return ret;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
void
rpm-build 2bd099
PyAsyncGen_Fini(void)
rpm-build 2bd099
{
rpm-build 2bd099
    PyAsyncGen_ClearFreeLists();
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_unwrap_value(PyAsyncGenObject *gen, PyObject *result)
rpm-build 2bd099
{
rpm-build 2bd099
    if (result == NULL) {
rpm-build 2bd099
        if (!PyErr_Occurred()) {
rpm-build 2bd099
            PyErr_SetNone(PyExc_StopAsyncIteration);
rpm-build 2bd099
        }
rpm-build 2bd099
rpm-build 2bd099
        if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration)
rpm-build 2bd099
            || PyErr_ExceptionMatches(PyExc_GeneratorExit)
rpm-build 2bd099
        ) {
rpm-build 2bd099
            gen->ag_closed = 1;
rpm-build 2bd099
        }
rpm-build 2bd099
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    if (_PyAsyncGenWrappedValue_CheckExact(result)) {
rpm-build 2bd099
        /* async yield */
rpm-build 2bd099
        _PyGen_SetStopIterationValue(((_PyAsyncGenWrappedValue*)result)->agw_val);
rpm-build 2bd099
        Py_DECREF(result);
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    return result;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
/* ---------- Async Generator ASend Awaitable ------------ */
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static void
rpm-build 2bd099
async_gen_asend_dealloc(PyAsyncGenASend *o)
rpm-build 2bd099
{
rpm-build 2bd099
    _PyObject_GC_UNTRACK((PyObject *)o);
rpm-build 2bd099
    Py_CLEAR(o->ags_gen);
rpm-build 2bd099
    Py_CLEAR(o->ags_sendval);
rpm-build 2bd099
    if (ag_asend_freelist_free < _PyAsyncGen_MAXFREELIST) {
rpm-build 2bd099
        assert(PyAsyncGenASend_CheckExact(o));
rpm-build 2bd099
        ag_asend_freelist[ag_asend_freelist_free++] = o;
rpm-build 2bd099
    } else {
rpm-build 2bd099
        PyObject_GC_Del(o);
rpm-build 2bd099
    }
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
static int
rpm-build 2bd099
async_gen_asend_traverse(PyAsyncGenASend *o, visitproc visit, void *arg)
rpm-build 2bd099
{
rpm-build 2bd099
    Py_VISIT(o->ags_gen);
rpm-build 2bd099
    Py_VISIT(o->ags_sendval);
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_asend_send(PyAsyncGenASend *o, PyObject *arg)
rpm-build 2bd099
{
rpm-build 2bd099
    PyObject *result;
rpm-build 2bd099
rpm-build 2bd099
    if (o->ags_state == AWAITABLE_STATE_CLOSED) {
rpm-build 2bd099
        PyErr_SetNone(PyExc_StopIteration);
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    if (o->ags_state == AWAITABLE_STATE_INIT) {
rpm-build 2bd099
        if (arg == NULL || arg == Py_None) {
rpm-build 2bd099
            arg = o->ags_sendval;
rpm-build 2bd099
        }
rpm-build 2bd099
        o->ags_state = AWAITABLE_STATE_ITER;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    result = gen_send_ex((PyGenObject*)o->ags_gen, arg, 0, 0);
rpm-build 2bd099
    result = async_gen_unwrap_value(o->ags_gen, result);
rpm-build 2bd099
rpm-build 2bd099
    if (result == NULL) {
rpm-build 2bd099
        o->ags_state = AWAITABLE_STATE_CLOSED;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    return result;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_asend_iternext(PyAsyncGenASend *o)
rpm-build 2bd099
{
rpm-build 2bd099
    return async_gen_asend_send(o, NULL);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_asend_throw(PyAsyncGenASend *o, PyObject *args)
rpm-build 2bd099
{
rpm-build 2bd099
    PyObject *result;
rpm-build 2bd099
rpm-build 2bd099
    if (o->ags_state == AWAITABLE_STATE_CLOSED) {
rpm-build 2bd099
        PyErr_SetNone(PyExc_StopIteration);
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    result = gen_throw((PyGenObject*)o->ags_gen, args);
rpm-build 2bd099
    result = async_gen_unwrap_value(o->ags_gen, result);
rpm-build 2bd099
rpm-build 2bd099
    if (result == NULL) {
rpm-build 2bd099
        o->ags_state = AWAITABLE_STATE_CLOSED;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    return result;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_asend_close(PyAsyncGenASend *o, PyObject *args)
rpm-build 2bd099
{
rpm-build 2bd099
    o->ags_state = AWAITABLE_STATE_CLOSED;
rpm-build 2bd099
    Py_RETURN_NONE;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyMethodDef async_gen_asend_methods[] = {
rpm-build 2bd099
    {"send", (PyCFunction)async_gen_asend_send, METH_O, send_doc},
rpm-build 2bd099
    {"throw", (PyCFunction)async_gen_asend_throw, METH_VARARGS, throw_doc},
rpm-build 2bd099
    {"close", (PyCFunction)async_gen_asend_close, METH_NOARGS, close_doc},
rpm-build 2bd099
    {NULL, NULL}        /* Sentinel */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyAsyncMethods async_gen_asend_as_async = {
rpm-build 2bd099
    PyObject_SelfIter,                          /* am_await */
rpm-build 2bd099
    0,                                          /* am_aiter */
rpm-build 2bd099
    0                                           /* am_anext */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
PyTypeObject _PyAsyncGenASend_Type = {
rpm-build 2bd099
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
rpm-build 2bd099
    "async_generator_asend",                    /* tp_name */
rpm-build 2bd099
    sizeof(PyAsyncGenASend),                    /* tp_basicsize */
rpm-build 2bd099
    0,                                          /* tp_itemsize */
rpm-build 2bd099
    /* methods */
rpm-build 2bd099
    (destructor)async_gen_asend_dealloc,        /* tp_dealloc */
rpm-build 2bd099
    0,                                          /* tp_print */
rpm-build 2bd099
    0,                                          /* tp_getattr */
rpm-build 2bd099
    0,                                          /* tp_setattr */
rpm-build 2bd099
    &async_gen_asend_as_async,                  /* tp_as_async */
rpm-build 2bd099
    0,                                          /* tp_repr */
rpm-build 2bd099
    0,                                          /* tp_as_number */
rpm-build 2bd099
    0,                                          /* tp_as_sequence */
rpm-build 2bd099
    0,                                          /* tp_as_mapping */
rpm-build 2bd099
    0,                                          /* tp_hash */
rpm-build 2bd099
    0,                                          /* tp_call */
rpm-build 2bd099
    0,                                          /* tp_str */
rpm-build 2bd099
    PyObject_GenericGetAttr,                    /* tp_getattro */
rpm-build 2bd099
    0,                                          /* tp_setattro */
rpm-build 2bd099
    0,                                          /* tp_as_buffer */
rpm-build 2bd099
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,    /* tp_flags */
rpm-build 2bd099
    0,                                          /* tp_doc */
rpm-build 2bd099
    (traverseproc)async_gen_asend_traverse,     /* tp_traverse */
rpm-build 2bd099
    0,                                          /* tp_clear */
rpm-build 2bd099
    0,                                          /* tp_richcompare */
rpm-build 2bd099
    0,                                          /* tp_weaklistoffset */
rpm-build 2bd099
    PyObject_SelfIter,                          /* tp_iter */
rpm-build 2bd099
    (iternextfunc)async_gen_asend_iternext,     /* tp_iternext */
rpm-build 2bd099
    async_gen_asend_methods,                    /* tp_methods */
rpm-build 2bd099
    0,                                          /* tp_members */
rpm-build 2bd099
    0,                                          /* tp_getset */
rpm-build 2bd099
    0,                                          /* tp_base */
rpm-build 2bd099
    0,                                          /* tp_dict */
rpm-build 2bd099
    0,                                          /* tp_descr_get */
rpm-build 2bd099
    0,                                          /* tp_descr_set */
rpm-build 2bd099
    0,                                          /* tp_dictoffset */
rpm-build 2bd099
    0,                                          /* tp_init */
rpm-build 2bd099
    0,                                          /* tp_alloc */
rpm-build 2bd099
    0,                                          /* tp_new */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_asend_new(PyAsyncGenObject *gen, PyObject *sendval)
rpm-build 2bd099
{
rpm-build 2bd099
    PyAsyncGenASend *o;
rpm-build 2bd099
    if (ag_asend_freelist_free) {
rpm-build 2bd099
        ag_asend_freelist_free--;
rpm-build 2bd099
        o = ag_asend_freelist[ag_asend_freelist_free];
rpm-build 2bd099
        _Py_NewReference((PyObject *)o);
rpm-build 2bd099
    } else {
rpm-build 2bd099
        o = PyObject_GC_New(PyAsyncGenASend, &_PyAsyncGenASend_Type);
rpm-build 2bd099
        if (o == NULL) {
rpm-build 2bd099
            return NULL;
rpm-build 2bd099
        }
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    Py_INCREF(gen);
rpm-build 2bd099
    o->ags_gen = gen;
rpm-build 2bd099
rpm-build 2bd099
    Py_XINCREF(sendval);
rpm-build 2bd099
    o->ags_sendval = sendval;
rpm-build 2bd099
rpm-build 2bd099
    o->ags_state = AWAITABLE_STATE_INIT;
rpm-build 2bd099
rpm-build 2bd099
    _PyObject_GC_TRACK((PyObject*)o);
rpm-build 2bd099
    return (PyObject*)o;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
/* ---------- Async Generator Value Wrapper ------------ */
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static void
rpm-build 2bd099
async_gen_wrapped_val_dealloc(_PyAsyncGenWrappedValue *o)
rpm-build 2bd099
{
rpm-build 2bd099
    _PyObject_GC_UNTRACK((PyObject *)o);
rpm-build 2bd099
    Py_CLEAR(o->agw_val);
rpm-build 2bd099
    if (ag_value_freelist_free < _PyAsyncGen_MAXFREELIST) {
rpm-build 2bd099
        assert(_PyAsyncGenWrappedValue_CheckExact(o));
rpm-build 2bd099
        ag_value_freelist[ag_value_freelist_free++] = o;
rpm-build 2bd099
    } else {
rpm-build 2bd099
        PyObject_GC_Del(o);
rpm-build 2bd099
    }
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static int
rpm-build 2bd099
async_gen_wrapped_val_traverse(_PyAsyncGenWrappedValue *o,
rpm-build 2bd099
                               visitproc visit, void *arg)
rpm-build 2bd099
{
rpm-build 2bd099
    Py_VISIT(o->agw_val);
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
PyTypeObject _PyAsyncGenWrappedValue_Type = {
rpm-build 2bd099
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
rpm-build 2bd099
    "async_generator_wrapped_value",            /* tp_name */
rpm-build 2bd099
    sizeof(_PyAsyncGenWrappedValue),            /* tp_basicsize */
rpm-build 2bd099
    0,                                          /* tp_itemsize */
rpm-build 2bd099
    /* methods */
rpm-build 2bd099
    (destructor)async_gen_wrapped_val_dealloc,  /* tp_dealloc */
rpm-build 2bd099
    0,                                          /* tp_print */
rpm-build 2bd099
    0,                                          /* tp_getattr */
rpm-build 2bd099
    0,                                          /* tp_setattr */
rpm-build 2bd099
    0,                                          /* tp_as_async */
rpm-build 2bd099
    0,                                          /* tp_repr */
rpm-build 2bd099
    0,                                          /* tp_as_number */
rpm-build 2bd099
    0,                                          /* tp_as_sequence */
rpm-build 2bd099
    0,                                          /* tp_as_mapping */
rpm-build 2bd099
    0,                                          /* tp_hash */
rpm-build 2bd099
    0,                                          /* tp_call */
rpm-build 2bd099
    0,                                          /* tp_str */
rpm-build 2bd099
    PyObject_GenericGetAttr,                    /* tp_getattro */
rpm-build 2bd099
    0,                                          /* tp_setattro */
rpm-build 2bd099
    0,                                          /* tp_as_buffer */
rpm-build 2bd099
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,    /* tp_flags */
rpm-build 2bd099
    0,                                          /* tp_doc */
rpm-build 2bd099
    (traverseproc)async_gen_wrapped_val_traverse, /* tp_traverse */
rpm-build 2bd099
    0,                                          /* tp_clear */
rpm-build 2bd099
    0,                                          /* tp_richcompare */
rpm-build 2bd099
    0,                                          /* tp_weaklistoffset */
rpm-build 2bd099
    0,                                          /* tp_iter */
rpm-build 2bd099
    0,                                          /* tp_iternext */
rpm-build 2bd099
    0,                                          /* tp_methods */
rpm-build 2bd099
    0,                                          /* tp_members */
rpm-build 2bd099
    0,                                          /* tp_getset */
rpm-build 2bd099
    0,                                          /* tp_base */
rpm-build 2bd099
    0,                                          /* tp_dict */
rpm-build 2bd099
    0,                                          /* tp_descr_get */
rpm-build 2bd099
    0,                                          /* tp_descr_set */
rpm-build 2bd099
    0,                                          /* tp_dictoffset */
rpm-build 2bd099
    0,                                          /* tp_init */
rpm-build 2bd099
    0,                                          /* tp_alloc */
rpm-build 2bd099
    0,                                          /* tp_new */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
PyObject *
rpm-build 2bd099
_PyAsyncGenValueWrapperNew(PyObject *val)
rpm-build 2bd099
{
rpm-build 2bd099
    _PyAsyncGenWrappedValue *o;
rpm-build 2bd099
    assert(val);
rpm-build 2bd099
rpm-build 2bd099
    if (ag_value_freelist_free) {
rpm-build 2bd099
        ag_value_freelist_free--;
rpm-build 2bd099
        o = ag_value_freelist[ag_value_freelist_free];
rpm-build 2bd099
        assert(_PyAsyncGenWrappedValue_CheckExact(o));
rpm-build 2bd099
        _Py_NewReference((PyObject*)o);
rpm-build 2bd099
    } else {
rpm-build 2bd099
        o = PyObject_GC_New(_PyAsyncGenWrappedValue,
rpm-build 2bd099
                            &_PyAsyncGenWrappedValue_Type);
rpm-build 2bd099
        if (o == NULL) {
rpm-build 2bd099
            return NULL;
rpm-build 2bd099
        }
rpm-build 2bd099
    }
rpm-build 2bd099
    o->agw_val = val;
rpm-build 2bd099
    Py_INCREF(val);
rpm-build 2bd099
    _PyObject_GC_TRACK((PyObject*)o);
rpm-build 2bd099
    return (PyObject*)o;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
/* ---------- Async Generator AThrow awaitable ------------ */
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static void
rpm-build 2bd099
async_gen_athrow_dealloc(PyAsyncGenAThrow *o)
rpm-build 2bd099
{
rpm-build 2bd099
    _PyObject_GC_UNTRACK((PyObject *)o);
rpm-build 2bd099
    Py_CLEAR(o->agt_gen);
rpm-build 2bd099
    Py_CLEAR(o->agt_args);
rpm-build 2bd099
    PyObject_GC_Del(o);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static int
rpm-build 2bd099
async_gen_athrow_traverse(PyAsyncGenAThrow *o, visitproc visit, void *arg)
rpm-build 2bd099
{
rpm-build 2bd099
    Py_VISIT(o->agt_gen);
rpm-build 2bd099
    Py_VISIT(o->agt_args);
rpm-build 2bd099
    return 0;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg)
rpm-build 2bd099
{
rpm-build 2bd099
    PyGenObject *gen = (PyGenObject*)o->agt_gen;
rpm-build 2bd099
    PyFrameObject *f = gen->gi_frame;
rpm-build 2bd099
    PyObject *retval;
rpm-build 2bd099
rpm-build 2bd099
    if (f == NULL || f->f_stacktop == NULL ||
rpm-build 2bd099
            o->agt_state == AWAITABLE_STATE_CLOSED) {
rpm-build 2bd099
        PyErr_SetNone(PyExc_StopIteration);
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    if (o->agt_state == AWAITABLE_STATE_INIT) {
rpm-build 2bd099
        if (o->agt_gen->ag_closed) {
rpm-build 2bd099
            PyErr_SetNone(PyExc_StopIteration);
rpm-build 2bd099
            return NULL;
rpm-build 2bd099
        }
rpm-build 2bd099
rpm-build 2bd099
        if (arg != Py_None) {
rpm-build 2bd099
            PyErr_SetString(PyExc_RuntimeError, NON_INIT_CORO_MSG);
rpm-build 2bd099
            return NULL;
rpm-build 2bd099
        }
rpm-build 2bd099
rpm-build 2bd099
        o->agt_state = AWAITABLE_STATE_ITER;
rpm-build 2bd099
rpm-build 2bd099
        if (o->agt_args == NULL) {
rpm-build 2bd099
            /* aclose() mode */
rpm-build 2bd099
            o->agt_gen->ag_closed = 1;
rpm-build 2bd099
rpm-build 2bd099
            retval = _gen_throw((PyGenObject *)gen,
rpm-build 2bd099
                                0,  /* Do not close generator when
rpm-build 2bd099
                                       PyExc_GeneratorExit is passed */
rpm-build 2bd099
                                PyExc_GeneratorExit, NULL, NULL);
rpm-build 2bd099
rpm-build 2bd099
            if (retval && _PyAsyncGenWrappedValue_CheckExact(retval)) {
rpm-build 2bd099
                Py_DECREF(retval);
rpm-build 2bd099
                goto yield_close;
rpm-build 2bd099
            }
rpm-build 2bd099
        } else {
rpm-build 2bd099
            PyObject *typ;
rpm-build 2bd099
            PyObject *tb = NULL;
rpm-build 2bd099
            PyObject *val = NULL;
rpm-build 2bd099
rpm-build 2bd099
            if (!PyArg_UnpackTuple(o->agt_args, "athrow", 1, 3,
rpm-build 2bd099
                                   &typ, &val, &tb)) {
rpm-build 2bd099
                return NULL;
rpm-build 2bd099
            }
rpm-build 2bd099
rpm-build 2bd099
            retval = _gen_throw((PyGenObject *)gen,
rpm-build 2bd099
                                0,  /* Do not close generator when
rpm-build 2bd099
                                       PyExc_GeneratorExit is passed */
rpm-build 2bd099
                                typ, val, tb);
rpm-build 2bd099
            retval = async_gen_unwrap_value(o->agt_gen, retval);
rpm-build 2bd099
        }
rpm-build 2bd099
        if (retval == NULL) {
rpm-build 2bd099
            goto check_error;
rpm-build 2bd099
        }
rpm-build 2bd099
        return retval;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    assert(o->agt_state == AWAITABLE_STATE_ITER);
rpm-build 2bd099
rpm-build 2bd099
    retval = gen_send_ex((PyGenObject *)gen, arg, 0, 0);
rpm-build 2bd099
    if (o->agt_args) {
rpm-build 2bd099
        return async_gen_unwrap_value(o->agt_gen, retval);
rpm-build 2bd099
    } else {
rpm-build 2bd099
        /* aclose() mode */
rpm-build 2bd099
        if (retval) {
rpm-build 2bd099
            if (_PyAsyncGenWrappedValue_CheckExact(retval)) {
rpm-build 2bd099
                Py_DECREF(retval);
rpm-build 2bd099
                goto yield_close;
rpm-build 2bd099
            }
rpm-build 2bd099
            else {
rpm-build 2bd099
                return retval;
rpm-build 2bd099
            }
rpm-build 2bd099
        }
rpm-build 2bd099
        else {
rpm-build 2bd099
            goto check_error;
rpm-build 2bd099
        }
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
yield_close:
rpm-build 2bd099
    PyErr_SetString(
rpm-build 2bd099
        PyExc_RuntimeError, ASYNC_GEN_IGNORED_EXIT_MSG);
rpm-build 2bd099
    return NULL;
rpm-build 2bd099
rpm-build 2bd099
check_error:
rpm-build 2bd099
    if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration)) {
rpm-build 2bd099
        o->agt_state = AWAITABLE_STATE_CLOSED;
rpm-build 2bd099
        if (o->agt_args == NULL) {
rpm-build 2bd099
            /* when aclose() is called we don't want to propagate
rpm-build 2bd099
               StopAsyncIteration; just raise StopIteration, signalling
rpm-build 2bd099
               that 'aclose()' is done. */
rpm-build 2bd099
            PyErr_Clear();
rpm-build 2bd099
            PyErr_SetNone(PyExc_StopIteration);
rpm-build 2bd099
        }
rpm-build 2bd099
    }
rpm-build 2bd099
    else if (PyErr_ExceptionMatches(PyExc_GeneratorExit)) {
rpm-build 2bd099
        o->agt_state = AWAITABLE_STATE_CLOSED;
rpm-build 2bd099
        PyErr_Clear();          /* ignore these errors */
rpm-build 2bd099
        PyErr_SetNone(PyExc_StopIteration);
rpm-build 2bd099
    }
rpm-build 2bd099
    return NULL;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *args)
rpm-build 2bd099
{
rpm-build 2bd099
    PyObject *retval;
rpm-build 2bd099
rpm-build 2bd099
    if (o->agt_state == AWAITABLE_STATE_INIT) {
rpm-build 2bd099
        PyErr_SetString(PyExc_RuntimeError, NON_INIT_CORO_MSG);
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    if (o->agt_state == AWAITABLE_STATE_CLOSED) {
rpm-build 2bd099
        PyErr_SetNone(PyExc_StopIteration);
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
rpm-build 2bd099
    retval = gen_throw((PyGenObject*)o->agt_gen, args);
rpm-build 2bd099
    if (o->agt_args) {
rpm-build 2bd099
        return async_gen_unwrap_value(o->agt_gen, retval);
rpm-build 2bd099
    } else {
rpm-build 2bd099
        /* aclose() mode */
rpm-build 2bd099
        if (retval && _PyAsyncGenWrappedValue_CheckExact(retval)) {
rpm-build 2bd099
            Py_DECREF(retval);
rpm-build 2bd099
            PyErr_SetString(PyExc_RuntimeError, ASYNC_GEN_IGNORED_EXIT_MSG);
rpm-build 2bd099
            return NULL;
rpm-build 2bd099
        }
rpm-build 2bd099
        return retval;
rpm-build 2bd099
    }
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_athrow_iternext(PyAsyncGenAThrow *o)
rpm-build 2bd099
{
rpm-build 2bd099
    return async_gen_athrow_send(o, Py_None);
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_athrow_close(PyAsyncGenAThrow *o, PyObject *args)
rpm-build 2bd099
{
rpm-build 2bd099
    o->agt_state = AWAITABLE_STATE_CLOSED;
rpm-build 2bd099
    Py_RETURN_NONE;
rpm-build 2bd099
}
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyMethodDef async_gen_athrow_methods[] = {
rpm-build 2bd099
    {"send", (PyCFunction)async_gen_athrow_send, METH_O, send_doc},
rpm-build 2bd099
    {"throw", (PyCFunction)async_gen_athrow_throw, METH_VARARGS, throw_doc},
rpm-build 2bd099
    {"close", (PyCFunction)async_gen_athrow_close, METH_NOARGS, close_doc},
rpm-build 2bd099
    {NULL, NULL}        /* Sentinel */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyAsyncMethods async_gen_athrow_as_async = {
rpm-build 2bd099
    PyObject_SelfIter,                          /* am_await */
rpm-build 2bd099
    0,                                          /* am_aiter */
rpm-build 2bd099
    0                                           /* am_anext */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
PyTypeObject _PyAsyncGenAThrow_Type = {
rpm-build 2bd099
    PyVarObject_HEAD_INIT(&PyType_Type, 0)
rpm-build 2bd099
    "async_generator_athrow",                   /* tp_name */
rpm-build 2bd099
    sizeof(PyAsyncGenAThrow),                   /* tp_basicsize */
rpm-build 2bd099
    0,                                          /* tp_itemsize */
rpm-build 2bd099
    /* methods */
rpm-build 2bd099
    (destructor)async_gen_athrow_dealloc,       /* tp_dealloc */
rpm-build 2bd099
    0,                                          /* tp_print */
rpm-build 2bd099
    0,                                          /* tp_getattr */
rpm-build 2bd099
    0,                                          /* tp_setattr */
rpm-build 2bd099
    &async_gen_athrow_as_async,                 /* tp_as_async */
rpm-build 2bd099
    0,                                          /* tp_repr */
rpm-build 2bd099
    0,                                          /* tp_as_number */
rpm-build 2bd099
    0,                                          /* tp_as_sequence */
rpm-build 2bd099
    0,                                          /* tp_as_mapping */
rpm-build 2bd099
    0,                                          /* tp_hash */
rpm-build 2bd099
    0,                                          /* tp_call */
rpm-build 2bd099
    0,                                          /* tp_str */
rpm-build 2bd099
    PyObject_GenericGetAttr,                    /* tp_getattro */
rpm-build 2bd099
    0,                                          /* tp_setattro */
rpm-build 2bd099
    0,                                          /* tp_as_buffer */
rpm-build 2bd099
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,    /* tp_flags */
rpm-build 2bd099
    0,                                          /* tp_doc */
rpm-build 2bd099
    (traverseproc)async_gen_athrow_traverse,    /* tp_traverse */
rpm-build 2bd099
    0,                                          /* tp_clear */
rpm-build 2bd099
    0,                                          /* tp_richcompare */
rpm-build 2bd099
    0,                                          /* tp_weaklistoffset */
rpm-build 2bd099
    PyObject_SelfIter,                          /* tp_iter */
rpm-build 2bd099
    (iternextfunc)async_gen_athrow_iternext,    /* tp_iternext */
rpm-build 2bd099
    async_gen_athrow_methods,                   /* tp_methods */
rpm-build 2bd099
    0,                                          /* tp_members */
rpm-build 2bd099
    0,                                          /* tp_getset */
rpm-build 2bd099
    0,                                          /* tp_base */
rpm-build 2bd099
    0,                                          /* tp_dict */
rpm-build 2bd099
    0,                                          /* tp_descr_get */
rpm-build 2bd099
    0,                                          /* tp_descr_set */
rpm-build 2bd099
    0,                                          /* tp_dictoffset */
rpm-build 2bd099
    0,                                          /* tp_init */
rpm-build 2bd099
    0,                                          /* tp_alloc */
rpm-build 2bd099
    0,                                          /* tp_new */
rpm-build 2bd099
};
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
static PyObject *
rpm-build 2bd099
async_gen_athrow_new(PyAsyncGenObject *gen, PyObject *args)
rpm-build 2bd099
{
rpm-build 2bd099
    PyAsyncGenAThrow *o;
rpm-build 2bd099
    o = PyObject_GC_New(PyAsyncGenAThrow, &_PyAsyncGenAThrow_Type);
rpm-build 2bd099
    if (o == NULL) {
rpm-build 2bd099
        return NULL;
rpm-build 2bd099
    }
rpm-build 2bd099
    o->agt_gen = gen;
rpm-build 2bd099
    o->agt_args = args;
rpm-build 2bd099
    o->agt_state = AWAITABLE_STATE_INIT;
rpm-build 2bd099
    Py_INCREF(gen);
rpm-build 2bd099
    Py_XINCREF(args);
rpm-build 2bd099
    _PyObject_GC_TRACK((PyObject*)o);
rpm-build 2bd099
    return (PyObject*)o;
rpm-build 2bd099
}