/Include/funcobject.h

http://unladen-swallow.googlecode.com/ · C Header · 77 lines · 45 code · 12 blank · 20 comment · 1 complexity · ac72b468891cb5d9dd95396d5f634b6d MD5 · raw file

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