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