jpayne@69: jpayne@69: /* Function object interface */ jpayne@69: #ifndef Py_LIMITED_API jpayne@69: #ifndef Py_FUNCOBJECT_H jpayne@69: #define Py_FUNCOBJECT_H jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: /* Function objects and code objects should not be confused with each other: jpayne@69: * jpayne@69: * Function objects are created by the execution of the 'def' statement. jpayne@69: * They reference a code object in their __code__ attribute, which is a jpayne@69: * purely syntactic object, i.e. nothing more than a compiled version of some jpayne@69: * source code lines. There is one code object per source code "fragment", jpayne@69: * but each code object can be referenced by zero or many function objects jpayne@69: * depending only on how many times the 'def' statement in the source was jpayne@69: * executed so far. jpayne@69: */ jpayne@69: jpayne@69: typedef struct { jpayne@69: PyObject_HEAD jpayne@69: PyObject *func_code; /* A code object, the __code__ attribute */ jpayne@69: PyObject *func_globals; /* A dictionary (other mappings won't do) */ jpayne@69: PyObject *func_defaults; /* NULL or a tuple */ jpayne@69: PyObject *func_kwdefaults; /* NULL or a dict */ jpayne@69: PyObject *func_closure; /* NULL or a tuple of cell objects */ jpayne@69: PyObject *func_doc; /* The __doc__ attribute, can be anything */ jpayne@69: PyObject *func_name; /* The __name__ attribute, a string object */ jpayne@69: PyObject *func_dict; /* The __dict__ attribute, a dict or NULL */ jpayne@69: PyObject *func_weakreflist; /* List of weak references */ jpayne@69: PyObject *func_module; /* The __module__ attribute, can be anything */ jpayne@69: PyObject *func_annotations; /* Annotations, a dict or NULL */ jpayne@69: PyObject *func_qualname; /* The qualified name */ jpayne@69: vectorcallfunc vectorcall; jpayne@69: jpayne@69: /* Invariant: jpayne@69: * func_closure contains the bindings for func_code->co_freevars, so jpayne@69: * PyTuple_Size(func_closure) == PyCode_GetNumFree(func_code) jpayne@69: * (func_closure may be NULL if PyCode_GetNumFree(func_code) == 0). jpayne@69: */ jpayne@69: } PyFunctionObject; jpayne@69: jpayne@69: PyAPI_DATA(PyTypeObject) PyFunction_Type; jpayne@69: jpayne@69: #define PyFunction_Check(op) (Py_TYPE(op) == &PyFunction_Type) jpayne@69: jpayne@69: PyAPI_FUNC(PyObject *) PyFunction_New(PyObject *, PyObject *); jpayne@69: PyAPI_FUNC(PyObject *) PyFunction_NewWithQualName(PyObject *, PyObject *, PyObject *); jpayne@69: PyAPI_FUNC(PyObject *) PyFunction_GetCode(PyObject *); jpayne@69: PyAPI_FUNC(PyObject *) PyFunction_GetGlobals(PyObject *); jpayne@69: PyAPI_FUNC(PyObject *) PyFunction_GetModule(PyObject *); jpayne@69: PyAPI_FUNC(PyObject *) PyFunction_GetDefaults(PyObject *); jpayne@69: PyAPI_FUNC(int) PyFunction_SetDefaults(PyObject *, PyObject *); jpayne@69: PyAPI_FUNC(PyObject *) PyFunction_GetKwDefaults(PyObject *); jpayne@69: PyAPI_FUNC(int) PyFunction_SetKwDefaults(PyObject *, PyObject *); jpayne@69: PyAPI_FUNC(PyObject *) PyFunction_GetClosure(PyObject *); jpayne@69: PyAPI_FUNC(int) PyFunction_SetClosure(PyObject *, PyObject *); jpayne@69: PyAPI_FUNC(PyObject *) PyFunction_GetAnnotations(PyObject *); jpayne@69: PyAPI_FUNC(int) PyFunction_SetAnnotations(PyObject *, PyObject *); jpayne@69: jpayne@69: #ifndef Py_LIMITED_API jpayne@69: PyAPI_FUNC(PyObject *) _PyFunction_FastCallDict( jpayne@69: PyObject *func, jpayne@69: PyObject *const *args, jpayne@69: Py_ssize_t nargs, jpayne@69: PyObject *kwargs); jpayne@69: jpayne@69: PyAPI_FUNC(PyObject *) _PyFunction_Vectorcall( jpayne@69: PyObject *func, jpayne@69: PyObject *const *stack, jpayne@69: size_t nargsf, jpayne@69: PyObject *kwnames); jpayne@69: #endif jpayne@69: jpayne@69: /* Macros for direct access to these values. Type checks are *not* jpayne@69: done, so use with care. */ jpayne@69: #define PyFunction_GET_CODE(func) \ jpayne@69: (((PyFunctionObject *)func) -> func_code) jpayne@69: #define PyFunction_GET_GLOBALS(func) \ jpayne@69: (((PyFunctionObject *)func) -> func_globals) jpayne@69: #define PyFunction_GET_MODULE(func) \ jpayne@69: (((PyFunctionObject *)func) -> func_module) jpayne@69: #define PyFunction_GET_DEFAULTS(func) \ jpayne@69: (((PyFunctionObject *)func) -> func_defaults) jpayne@69: #define PyFunction_GET_KW_DEFAULTS(func) \ jpayne@69: (((PyFunctionObject *)func) -> func_kwdefaults) jpayne@69: #define PyFunction_GET_CLOSURE(func) \ jpayne@69: (((PyFunctionObject *)func) -> func_closure) jpayne@69: #define PyFunction_GET_ANNOTATIONS(func) \ jpayne@69: (((PyFunctionObject *)func) -> func_annotations) jpayne@69: jpayne@69: /* The classmethod and staticmethod types lives here, too */ jpayne@69: PyAPI_DATA(PyTypeObject) PyClassMethod_Type; jpayne@69: PyAPI_DATA(PyTypeObject) PyStaticMethod_Type; jpayne@69: jpayne@69: PyAPI_FUNC(PyObject *) PyClassMethod_New(PyObject *); jpayne@69: PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *); jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } jpayne@69: #endif jpayne@69: #endif /* !Py_FUNCOBJECT_H */ jpayne@69: #endif /* Py_LIMITED_API */