methodobject.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
  13. typedef PyObject *(*_PyCFunctionFast) (PyObject *, PyObject *const *, Py_ssize_t);
  14. typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
  15. PyObject *);
  16. typedef PyObject *(*_PyCFunctionFastWithKeywords) (PyObject *,
  17. PyObject *const *, Py_ssize_t,
  18. PyObject *);
  19. typedef PyObject *(*PyNoArgsFunction)(PyObject *);
  20. PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
  21. PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
  22. PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
  23. /* Macros for direct access to these values. Type checks are *not*
  24. done, so use with care. */
  25. #ifndef Py_LIMITED_API
  26. #define PyCFunction_GET_FUNCTION(func) \
  27. (((PyCFunctionObject *)func) -> m_ml -> ml_meth)
  28. #define PyCFunction_GET_SELF(func) \
  29. (((PyCFunctionObject *)func) -> m_ml -> ml_flags & METH_STATIC ? \
  30. NULL : ((PyCFunctionObject *)func) -> m_self)
  31. #define PyCFunction_GET_FLAGS(func) \
  32. (((PyCFunctionObject *)func) -> m_ml -> ml_flags)
  33. #endif
  34. PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
  35. #ifndef Py_LIMITED_API
  36. PyAPI_FUNC(PyObject *) _PyCFunction_FastCallDict(PyObject *func,
  37. PyObject *const *args,
  38. Py_ssize_t nargs,
  39. PyObject *kwargs);
  40. #endif
  41. struct PyMethodDef {
  42. const char *ml_name; /* The name of the built-in function/method */
  43. PyCFunction ml_meth; /* The C function that implements it */
  44. int ml_flags; /* Combination of METH_xxx flags, which mostly
  45. describe the args expected by the C func */
  46. const char *ml_doc; /* The __doc__ attribute, or NULL */
  47. };
  48. typedef struct PyMethodDef PyMethodDef;
  49. #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
  50. PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
  51. PyObject *);
  52. /* Flag passed to newmethodobject */
  53. /* #define METH_OLDARGS 0x0000 -- unsupported now */
  54. #define METH_VARARGS 0x0001
  55. #define METH_KEYWORDS 0x0002
  56. /* METH_NOARGS and METH_O must not be combined with the flags above. */
  57. #define METH_NOARGS 0x0004
  58. #define METH_O 0x0008
  59. /* METH_CLASS and METH_STATIC are a little different; these control
  60. the construction of methods for a class. These cannot be used for
  61. functions in modules. */
  62. #define METH_CLASS 0x0010
  63. #define METH_STATIC 0x0020
  64. /* METH_COEXIST allows a method to be entered even though a slot has
  65. already filled the entry. When defined, the flag allows a separate
  66. method, "__contains__" for example, to coexist with a defined
  67. slot like sq_contains. */
  68. #define METH_COEXIST 0x0040
  69. #ifndef Py_LIMITED_API
  70. #define METH_FASTCALL 0x0080
  71. #endif
  72. /* This bit is preserved for Stackless Python */
  73. #ifdef STACKLESS
  74. #define METH_STACKLESS 0x0100
  75. #else
  76. #define METH_STACKLESS 0x0000
  77. #endif
  78. #ifndef Py_LIMITED_API
  79. typedef struct {
  80. PyObject_HEAD
  81. PyMethodDef *m_ml; /* Description of the C function to call */
  82. PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */
  83. PyObject *m_module; /* The __module__ attribute, can be anything */
  84. PyObject *m_weakreflist; /* List of weak references */
  85. vectorcallfunc vectorcall;
  86. } PyCFunctionObject;
  87. PyAPI_FUNC(PyObject *) _PyMethodDef_RawFastCallDict(
  88. PyMethodDef *method,
  89. PyObject *self,
  90. PyObject *const *args,
  91. Py_ssize_t nargs,
  92. PyObject *kwargs);
  93. PyAPI_FUNC(PyObject *) _PyMethodDef_RawFastCallKeywords(
  94. PyMethodDef *method,
  95. PyObject *self,
  96. PyObject *const *args,
  97. Py_ssize_t nargs,
  98. PyObject *kwnames);
  99. #endif
  100. PyAPI_FUNC(int) PyCFunction_ClearFreeList(void);
  101. #ifndef Py_LIMITED_API
  102. PyAPI_FUNC(void) _PyCFunction_DebugMallocStats(FILE *out);
  103. PyAPI_FUNC(void) _PyMethod_DebugMallocStats(FILE *out);
  104. #endif
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108. #endif /* !Py_METHODOBJECT_H */