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