Chris@87
|
1
|
Chris@87
|
2 /* Function object interface */
|
Chris@87
|
3
|
Chris@87
|
4 #ifndef Py_FUNCOBJECT_H
|
Chris@87
|
5 #define Py_FUNCOBJECT_H
|
Chris@87
|
6 #ifdef __cplusplus
|
Chris@87
|
7 extern "C" {
|
Chris@87
|
8 #endif
|
Chris@87
|
9
|
Chris@87
|
10 /* Function objects and code objects should not be confused with each other:
|
Chris@87
|
11 *
|
Chris@87
|
12 * Function objects are created by the execution of the 'def' statement.
|
Chris@87
|
13 * They reference a code object in their func_code attribute, which is a
|
Chris@87
|
14 * purely syntactic object, i.e. nothing more than a compiled version of some
|
Chris@87
|
15 * source code lines. There is one code object per source code "fragment",
|
Chris@87
|
16 * but each code object can be referenced by zero or many function objects
|
Chris@87
|
17 * depending only on how many times the 'def' statement in the source was
|
Chris@87
|
18 * executed so far.
|
Chris@87
|
19 */
|
Chris@87
|
20
|
Chris@87
|
21 typedef struct {
|
Chris@87
|
22 PyObject_HEAD
|
Chris@87
|
23 PyObject *func_code; /* A code object */
|
Chris@87
|
24 PyObject *func_globals; /* A dictionary (other mappings won't do) */
|
Chris@87
|
25 PyObject *func_defaults; /* NULL or a tuple */
|
Chris@87
|
26 PyObject *func_closure; /* NULL or a tuple of cell objects */
|
Chris@87
|
27 PyObject *func_doc; /* The __doc__ attribute, can be anything */
|
Chris@87
|
28 PyObject *func_name; /* The __name__ attribute, a string object */
|
Chris@87
|
29 PyObject *func_dict; /* The __dict__ attribute, a dict or NULL */
|
Chris@87
|
30 PyObject *func_weakreflist; /* List of weak references */
|
Chris@87
|
31 PyObject *func_module; /* The __module__ attribute, can be anything */
|
Chris@87
|
32
|
Chris@87
|
33 /* Invariant:
|
Chris@87
|
34 * func_closure contains the bindings for func_code->co_freevars, so
|
Chris@87
|
35 * PyTuple_Size(func_closure) == PyCode_GetNumFree(func_code)
|
Chris@87
|
36 * (func_closure may be NULL if PyCode_GetNumFree(func_code) == 0).
|
Chris@87
|
37 */
|
Chris@87
|
38 } PyFunctionObject;
|
Chris@87
|
39
|
Chris@87
|
40 PyAPI_DATA(PyTypeObject) PyFunction_Type;
|
Chris@87
|
41
|
Chris@87
|
42 #define PyFunction_Check(op) (Py_TYPE(op) == &PyFunction_Type)
|
Chris@87
|
43
|
Chris@87
|
44 PyAPI_FUNC(PyObject *) PyFunction_New(PyObject *, PyObject *);
|
Chris@87
|
45 PyAPI_FUNC(PyObject *) PyFunction_GetCode(PyObject *);
|
Chris@87
|
46 PyAPI_FUNC(PyObject *) PyFunction_GetGlobals(PyObject *);
|
Chris@87
|
47 PyAPI_FUNC(PyObject *) PyFunction_GetModule(PyObject *);
|
Chris@87
|
48 PyAPI_FUNC(PyObject *) PyFunction_GetDefaults(PyObject *);
|
Chris@87
|
49 PyAPI_FUNC(int) PyFunction_SetDefaults(PyObject *, PyObject *);
|
Chris@87
|
50 PyAPI_FUNC(PyObject *) PyFunction_GetClosure(PyObject *);
|
Chris@87
|
51 PyAPI_FUNC(int) PyFunction_SetClosure(PyObject *, PyObject *);
|
Chris@87
|
52
|
Chris@87
|
53 /* Macros for direct access to these values. Type checks are *not*
|
Chris@87
|
54 done, so use with care. */
|
Chris@87
|
55 #define PyFunction_GET_CODE(func) \
|
Chris@87
|
56 (((PyFunctionObject *)func) -> func_code)
|
Chris@87
|
57 #define PyFunction_GET_GLOBALS(func) \
|
Chris@87
|
58 (((PyFunctionObject *)func) -> func_globals)
|
Chris@87
|
59 #define PyFunction_GET_MODULE(func) \
|
Chris@87
|
60 (((PyFunctionObject *)func) -> func_module)
|
Chris@87
|
61 #define PyFunction_GET_DEFAULTS(func) \
|
Chris@87
|
62 (((PyFunctionObject *)func) -> func_defaults)
|
Chris@87
|
63 #define PyFunction_GET_CLOSURE(func) \
|
Chris@87
|
64 (((PyFunctionObject *)func) -> func_closure)
|
Chris@87
|
65
|
Chris@87
|
66 /* The classmethod and staticmethod types lives here, too */
|
Chris@87
|
67 PyAPI_DATA(PyTypeObject) PyClassMethod_Type;
|
Chris@87
|
68 PyAPI_DATA(PyTypeObject) PyStaticMethod_Type;
|
Chris@87
|
69
|
Chris@87
|
70 PyAPI_FUNC(PyObject *) PyClassMethod_New(PyObject *);
|
Chris@87
|
71 PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *);
|
Chris@87
|
72
|
Chris@87
|
73 #ifdef __cplusplus
|
Chris@87
|
74 }
|
Chris@87
|
75 #endif
|
Chris@87
|
76 #endif /* !Py_FUNCOBJECT_H */
|