File: c_api.rst

package info (click to toggle)
python-greenlet 3.2.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,096 kB
  • sloc: cpp: 5,078; python: 3,197; ansic: 1,129; makefile: 145; asm: 120; sh: 72
file content (99 lines) | stat: -rw-r--r-- 3,377 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
=================
 C API Reference
=================

Greenlets can be created and manipulated from extension modules written in C or
C++, or from applications that embed Python. The ``greenlet.h`` header is
provided, and exposes the entire API available to pure Python modules.

Note that much of the API is implemented in terms of macros, meaning
that it is not necessarily ABI stable.

Types
=====

.. c:type:: PyGreenlet

   The C name corresponding to the Python :class:`greenlet.greenlet`.

Exceptions
==========

.. c:type:: PyExc_GreenletError

   The C name corresponding to the Python :exc:`greenlet.error`

.. c:type:: PyExc_GreenletExit

   The C name corresponding to the Python :exc:`greenlet.GreenletExit`

Functions
=========

.. c:function:: void PyGreenlet_Import(void)

   A macro that imports the greenlet module and initializes the C API. This
   must be called once for each extension module that uses the greenlet C API,
   usually in the module's init function.

.. c:function:: int PyGreenlet_Check(PyObject* p)

   Macro that returns true if the argument is a :c:type:`PyGreenlet`.

.. c:function:: int PyGreenlet_STARTED(PyGreenlet* g)

   Macro that returns true if the greenlet *g* has started.

.. c:function:: int PyGreenlet_ACTIVE(PyGreenlet* g)

    Macro that returns true if the greenlet *g* has started and has not died.

.. c:function:: PyGreenlet* PyGreenlet_GetParent(PyGreenlet* g)

    Macro that returns the parent greenlet of *g*. Returns a non-null
    pointer if there is a parent, or a null pointer on an error or if
    there is no parent. If this returns a non-null pointer, you must
    decrement its reference.

.. c:function:: int PyGreenlet_SetParent(PyGreenlet* g, PyGreenlet* nparent)

    Set the parent greenlet of *g*.

    :return: 0 for success, or -1 on error. When an error is returned,
             *g* is not a pointer to a greenlet, and an
             :exc:`AttributeError` has been raised.

.. c:function:: PyGreenlet* PyGreenlet_GetCurrent(void)

    Returns the currently active greenlet object.


.. c:function:: PyGreenlet* PyGreenlet_New(PyObject* run, PyObject* parent)

    Creates a new greenlet object with the callable *run* and parent
    *parent*. Both parameters are optional and may be ``NULL``.

    :param run: If ``NULL``, the greenlet will be created, but will
                fail when switched to.
    :param parent: If ``NULL``, the parent is automatically set to the
                   current greenlet.

.. c:function:: PyObject* PyGreenlet_Switch(PyGreenlet* g, PyObject* args, PyObject* kwargs)

    Switches to the greenlet *g*. Besides *g*, the remaining
    parameters are optional and may be ``NULL``.

    :param args: If ``args`` is NULL, an empty tuple is passed to the
                 target greenlet. If given, must be a :class:`tuple`.

    :param kwargs: If kwargs is ``NULL``, no keyword arguments are
                   passed to the target greenlet. If given, must be a
                   :class:`dict`.

.. c:function:: PyObject* PyGreenlet_Throw(PyGreenlet* g, PyObject* typ, PyObject* val, PyObject* tb)

    Switches to greenlet *g*, but immediately raise an exception of type
    *typ* with the value *val*, and optionally, the traceback object
    *tb*. *tb* can be ``NULL``.

    The arguments *typ*, *val* and *tb* are interpreted as for :c:func:`PyErr_Restore`.