Use richer assertions in test_mailbox (for better failure messages).
[python.git] / Doc / c-api / code.rst
blobc6ca8c5b40ffd5cde54e0f8571725b075fbc2b7e
1 .. highlightlang:: c
3 .. _codeobjects:
5 Code Objects
6 ------------
8 .. sectionauthor:: Jeffrey Yasskin <jyasskin@gmail.com>
11 .. index::
12    object: code
14 Code objects are a low-level detail of the CPython implementation.
15 Each one represents a chunk of executable code that hasn't yet been
16 bound into a function.
18 .. ctype:: PyCodeObject
20    The C structure of the objects used to describe code objects.  The
21    fields of this type are subject to change at any time.
24 .. cvar:: PyTypeObject PyCode_Type
26    This is an instance of :ctype:`PyTypeObject` representing the Python
27    :class:`code` type.
30 .. cfunction:: int PyCode_Check(PyObject *co)
32    Return true if *co* is a :class:`code` object
34 .. cfunction:: int PyCode_GetNumFree(PyObject *co)
36    Return the number of free variables in *co*.
38 .. cfunction:: PyCodeObject *PyCode_New(int argcount, int nlocals, int stacksize, int flags, PyObject *code, PyObject *consts, PyObject *names, PyObject *varnames, PyObject *freevars, PyObject *cellvars, PyObject *filename, PyObject *name, int firstlineno, PyObject *lnotab)
40    Return a new code object.  If you need a dummy code object to
41    create a frame, use :cfunc:`PyCode_NewEmpty` instead.  Calling
42    :cfunc:`PyCode_New` directly can bind you to a precise Python
43    version since the definition of the bytecode changes often.
46 .. cfunction:: int PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
48    Return a new empty code object with the specified filename,
49    function name, and first line number.  It is illegal to
50    :keyword:`exec` or :func:`eval` the resulting code object.