blob: 7d9b4b6c1d7e81cb06b1a5c3dce99bcb173839bb [file] [log] [blame]
Alexandre Vassalotti7b82b402009-07-21 04:30:03 +00001.. highlightlang:: c
2
3.. _codeobjects:
4
5Code Objects
6------------
7
8.. sectionauthor:: Jeffrey Yasskin <jyasskin@gmail.com>
9
10
11.. index::
12 object: code
13
14Code objects are a low-level detail of the CPython implementation.
15Each one represents a chunk of executable code that hasn't yet been
16bound into a function.
17
Georg Brandl60203b42010-10-06 10:11:56 +000018.. c:type:: PyCodeObject
Alexandre Vassalotti7b82b402009-07-21 04:30:03 +000019
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
Georg Brandl60203b42010-10-06 10:11:56 +000024.. c:var:: PyTypeObject PyCode_Type
Alexandre Vassalotti7b82b402009-07-21 04:30:03 +000025
Georg Brandl60203b42010-10-06 10:11:56 +000026 This is an instance of :c:type:`PyTypeObject` representing the Python
Alexandre Vassalotti7b82b402009-07-21 04:30:03 +000027 :class:`code` type.
28
29
Georg Brandl60203b42010-10-06 10:11:56 +000030.. c:function:: int PyCode_Check(PyObject *co)
Alexandre Vassalotti7b82b402009-07-21 04:30:03 +000031
32 Return true if *co* is a :class:`code` object
33
Georg Brandl60203b42010-10-06 10:11:56 +000034.. c:function:: int PyCode_GetNumFree(PyObject *co)
Alexandre Vassalotti7b82b402009-07-21 04:30:03 +000035
36 Return the number of free variables in *co*.
37
Georg Brandl60203b42010-10-06 10:11:56 +000038.. 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)
Alexandre Vassalotti7b82b402009-07-21 04:30:03 +000039
40 Return a new code object. If you need a dummy code object to
Georg Brandl60203b42010-10-06 10:11:56 +000041 create a frame, use :c:func:`PyCode_NewEmpty` instead. Calling
42 :c:func:`PyCode_New` directly can bind you to a precise Python
Alexandre Vassalotti7b82b402009-07-21 04:30:03 +000043 version since the definition of the bytecode changes often.
44
45
Georg Brandl60203b42010-10-06 10:11:56 +000046.. c:function:: int PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
Alexandre Vassalotti7b82b402009-07-21 04:30:03 +000047
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.