[388] | 1 | .. highlightlang:: c
|
---|
| 2 |
|
---|
| 3 | .. _codeobjects:
|
---|
| 4 |
|
---|
| 5 | Code Objects
|
---|
| 6 | ------------
|
---|
| 7 |
|
---|
| 8 | .. sectionauthor:: Jeffrey Yasskin <jyasskin@gmail.com>
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | .. index::
|
---|
| 12 | object: code
|
---|
| 13 |
|
---|
| 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.
|
---|
| 17 |
|
---|
| 18 | .. c:type:: PyCodeObject
|
---|
| 19 |
|
---|
| 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.
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | .. c:var:: PyTypeObject PyCode_Type
|
---|
| 25 |
|
---|
| 26 | This is an instance of :c:type:`PyTypeObject` representing the Python
|
---|
| 27 | :class:`code` type.
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | .. c:function:: int PyCode_Check(PyObject *co)
|
---|
| 31 |
|
---|
| 32 | Return true if *co* is a :class:`code` object
|
---|
| 33 |
|
---|
| 34 | .. c:function:: int PyCode_GetNumFree(PyObject *co)
|
---|
| 35 |
|
---|
| 36 | Return the number of free variables in *co*.
|
---|
| 37 |
|
---|
| 38 | .. c:function:: 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)
|
---|
| 39 |
|
---|
| 40 | Return a new code object. If you need a dummy code object to
|
---|
| 41 | create a frame, use :c:func:`PyCode_NewEmpty` instead. Calling
|
---|
| 42 | :c:func:`PyCode_New` directly can bind you to a precise Python
|
---|
| 43 | version since the definition of the bytecode changes often.
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 | .. c:function:: int PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
|
---|
| 47 |
|
---|
| 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.
|
---|