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