PageRenderTime 82ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Include/methodobject.h

http://unladen-swallow.googlecode.com/
C Header | 125 lines | 74 code | 23 blank | 28 comment | 1 complexity | d76d76df4e6545610aae81ff8174190c MD5 | raw file
Possible License(s): 0BSD, BSD-3-Clause
  1. /* Method object interface */
  2. #ifndef Py_METHODOBJECT_H
  3. #define Py_METHODOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /* This is about the type 'builtin_function_or_method',
  8. not Python methods in user-defined classes. See classobject.h
  9. for the latter. */
  10. PyAPI_DATA(PyTypeObject) PyCFunction_Type;
  11. #define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type)
  12. /* PyCFunction works for METH_ARG_RANGE when arity==0 or arity==1. */
  13. typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
  14. typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
  15. PyObject *);
  16. typedef PyObject *(*PyNoArgsFunction)(PyObject *);
  17. /* Support for METH_ARG_RANGE with arity of two or three. If the callsite passes
  18. fewer arguments than the maximum possible arity, NULLs will be used for those
  19. PyObject * slots. */
  20. typedef PyObject *(*PyCFunctionTwoArgs)(PyObject *, PyObject *, PyObject *);
  21. typedef PyObject *(*PyCFunctionThreeArgs)(PyObject *, PyObject *,
  22. PyObject *, PyObject *);
  23. PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
  24. PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
  25. PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
  26. /* Macros for direct access to these values. Type checks are *not*
  27. done, so use with care. */
  28. #define PyCFunction_GET_FUNCTION(func) \
  29. (((PyCFunctionObject *)func) -> m_ml -> ml_meth)
  30. #define PyCFunction_GET_SELF(func) \
  31. (((PyCFunctionObject *)func) -> m_self)
  32. #define PyCFunction_GET_FLAGS(func) \
  33. (((PyCFunctionObject *)func) -> m_ml -> ml_flags)
  34. /* GET_{MIN,MAX}_ARITY only make sense for METH_ARG_RANGE functions. */
  35. #define PyCFunction_GET_MIN_ARITY(func) \
  36. (assert(PyCFunction_GET_FLAGS(func) & METH_ARG_RANGE), \
  37. (((PyCFunctionObject *)func) -> m_ml -> ml_min_arity))
  38. #define PyCFunction_GET_MAX_ARITY(func) \
  39. (assert(PyCFunction_GET_FLAGS(func) & METH_ARG_RANGE), \
  40. (((PyCFunctionObject *)func) -> m_ml -> ml_max_arity))
  41. #define PyCFunction_GET_METHODDEF(func) \
  42. (((PyCFunctionObject *)func) -> m_ml)
  43. PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
  44. typedef struct PyMethodDef {
  45. const char *ml_name; /* The name of the built-in function/method */
  46. PyCFunction ml_meth; /* The C function that implements it */
  47. int ml_flags; /* Combination of METH_xxx flags, which mostly
  48. describe the args expected by the C func */
  49. const char *ml_doc; /* The __doc__ attribute, or NULL */
  50. short ml_min_arity; /* Min arg count for METH_ARG_RANGE funcs. */
  51. short ml_max_arity; /* Max arg count for METH_ARG_RANGE funcs. */
  52. } PyMethodDef;
  53. /* Maximum value for ml_{min,max}_arity. */
  54. #define PY_MAX_ARITY 3
  55. PyAPI_FUNC(PyObject *) Py_FindMethod(PyMethodDef[], PyObject *, const char *);
  56. /* Make sure a method definition is ready by performing checks and updating old
  57. method protocols to new ones. This must be called before the method
  58. definition can be used to make a call. */
  59. PyAPI_FUNC(int) PyMethodDef_Ready(PyMethodDef *ml);
  60. PyAPI_FUNC(PyObject *) PyMethodDef_Call(PyMethodDef *, PyObject *, PyObject *,
  61. PyObject *);
  62. #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
  63. PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
  64. PyObject *);
  65. /* Flag passed to newmethodobject. These values are spaced out to leave room
  66. for future expansion without necessarily breaking ABI compatibility. */
  67. #define METH_OLDARGS 0x0000
  68. #define METH_VARARGS 0x0001
  69. #define METH_KEYWORDS 0x0002
  70. /* METH_NOARGS, METH_O and METH_ARG_RANGE must not be combined with the flags above.
  71. METH_ARG_RANGE supersedes METHO_O and METH_NOARGS. */
  72. #define METH_O 0x0010 /* Function arity = 1 */
  73. #define METH_ARG_RANGE 0x0020 /* Arity in a known interval */
  74. #define METH_NOARGS 0x0040 /* Arity = 0; backwards compatibility. */
  75. /* METH_CLASS and METH_STATIC are a little different; these control
  76. the construction of methods for a class. These cannot be used for
  77. functions in modules. */
  78. #define METH_CLASS 0x0100
  79. #define METH_STATIC 0x0200
  80. /* METH_COEXIST allows a method to be entered eventhough a slot has
  81. already filled the entry. When defined, the flag allows a separate
  82. method, "__contains__" for example, to coexist with a defined
  83. slot like sq_contains. */
  84. #define METH_COEXIST 0x1000
  85. typedef struct PyMethodChain {
  86. PyMethodDef *methods; /* Methods of this type */
  87. struct PyMethodChain *link; /* NULL or base type */
  88. } PyMethodChain;
  89. PyAPI_FUNC(PyObject *) Py_FindMethodInChain(PyMethodChain *, PyObject *,
  90. const char *);
  91. /* Keep this in sync with Util/PyTypeBuilder.h. */
  92. typedef struct PyCFunctionObject {
  93. PyObject_HEAD
  94. PyMethodDef *m_ml; /* Description of the C function to call */
  95. PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */
  96. PyObject *m_module; /* The __module__ attribute, can be anything */
  97. } PyCFunctionObject;
  98. PyAPI_FUNC(int) PyCFunction_ClearFreeList(void);
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. #endif /* !Py_METHODOBJECT_H */