methodobject.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_CheckExact(op) Py_IS_TYPE(op, &PyCFunction_Type)
  12. #define PyCFunction_Check(op) PyObject_TypeCheck(op, &PyCFunction_Type)
  13. typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
  14. typedef PyObject *(*_PyCFunctionFast) (PyObject *, PyObject *const *, Py_ssize_t);
  15. typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
  16. PyObject *);
  17. typedef PyObject *(*_PyCFunctionFastWithKeywords) (PyObject *,
  18. PyObject *const *, Py_ssize_t,
  19. PyObject *);
  20. typedef PyObject *(*PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *,
  21. size_t, PyObject *);
  22. PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
  23. PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
  24. PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
  25. Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
  26. struct PyMethodDef {
  27. const char *ml_name; /* The name of the built-in function/method */
  28. PyCFunction ml_meth; /* The C function that implements it */
  29. int ml_flags; /* Combination of METH_xxx flags, which mostly
  30. describe the args expected by the C func */
  31. const char *ml_doc; /* The __doc__ attribute, or NULL */
  32. };
  33. typedef struct PyMethodDef PyMethodDef;
  34. /* PyCFunction_New is declared as a function for stable ABI (declaration is
  35. * needed for e.g. GCC with -fvisibility=hidden), but redefined as a macro
  36. * that calls PyCFunction_NewEx. */
  37. PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);
  38. #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
  39. /* PyCFunction_NewEx is similar: on 3.9+, this calls PyCMethod_New. */
  40. PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
  41. PyObject *);
  42. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
  43. #define PyCFunction_NewEx(ML, SELF, MOD) PyCMethod_New((ML), (SELF), (MOD), NULL)
  44. PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *,
  45. PyObject *, PyTypeObject *);
  46. #endif
  47. /* Flag passed to newmethodobject */
  48. /* #define METH_OLDARGS 0x0000 -- unsupported now */
  49. #define METH_VARARGS 0x0001
  50. #define METH_KEYWORDS 0x0002
  51. /* METH_NOARGS and METH_O must not be combined with the flags above. */
  52. #define METH_NOARGS 0x0004
  53. #define METH_O 0x0008
  54. /* METH_CLASS and METH_STATIC are a little different; these control
  55. the construction of methods for a class. These cannot be used for
  56. functions in modules. */
  57. #define METH_CLASS 0x0010
  58. #define METH_STATIC 0x0020
  59. /* METH_COEXIST allows a method to be entered even though a slot has
  60. already filled the entry. When defined, the flag allows a separate
  61. method, "__contains__" for example, to coexist with a defined
  62. slot like sq_contains. */
  63. #define METH_COEXIST 0x0040
  64. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030a0000
  65. # define METH_FASTCALL 0x0080
  66. #endif
  67. /* This bit is preserved for Stackless Python */
  68. #ifdef STACKLESS
  69. # define METH_STACKLESS 0x0100
  70. #else
  71. # define METH_STACKLESS 0x0000
  72. #endif
  73. /* METH_METHOD means the function stores an
  74. * additional reference to the class that defines it;
  75. * both self and class are passed to it.
  76. * It uses PyCMethodObject instead of PyCFunctionObject.
  77. * May not be combined with METH_NOARGS, METH_O, METH_CLASS or METH_STATIC.
  78. */
  79. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
  80. #define METH_METHOD 0x0200
  81. #endif
  82. #ifndef Py_LIMITED_API
  83. #define Py_CPYTHON_METHODOBJECT_H
  84. #include "cpython/methodobject.h"
  85. #undef Py_CPYTHON_METHODOBJECT_H
  86. #endif
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. #endif /* !Py_METHODOBJECT_H */