Alexandre Vassalotti | 7b82b40 | 2009-07-21 04:30:03 +0000 | [diff] [blame] | 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 | .. ctype:: 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 | .. cvar:: PyTypeObject PyCode_Type |
| 25 | |
| 26 | This is an instance of :ctype:`PyTypeObject` representing the Python |
| 27 | :class:`code` type. |
| 28 | |
| 29 | |
| 30 | .. cfunction:: int PyCode_Check(PyObject *co) |
| 31 | |
| 32 | Return true if *co* is a :class:`code` object |
| 33 | |
| 34 | .. cfunction:: int PyCode_GetNumFree(PyObject *co) |
| 35 | |
| 36 | Return the number of free variables in *co*. |
| 37 | |
| 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) |
| 39 | |
| 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. |
| 44 | |
| 45 | |
| 46 | .. cfunction:: 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. |