methodobject.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
  35. PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
  36. PyObject *);
  37. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
  38. #define PyCFunction_NewEx(ML, SELF, MOD) PyCMethod_New((ML), (SELF), (MOD), NULL)
  39. PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *,
  40. PyObject *, PyTypeObject *);
  41. #endif
  42. /* Flag passed to newmethodobject */
  43. /* #define METH_OLDARGS 0x0000 -- unsupported now */
  44. #define METH_VARARGS 0x0001
  45. #define METH_KEYWORDS 0x0002
  46. /* METH_NOARGS and METH_O must not be combined with the flags above. */
  47. #define METH_NOARGS 0x0004
  48. #define METH_O 0x0008
  49. /* METH_CLASS and METH_STATIC are a little different; these control
  50. the construction of methods for a class. These cannot be used for
  51. functions in modules. */
  52. #define METH_CLASS 0x0010
  53. #define METH_STATIC 0x0020
  54. /* METH_COEXIST allows a method to be entered even though a slot has
  55. already filled the entry. When defined, the flag allows a separate
  56. method, "__contains__" for example, to coexist with a defined
  57. slot like sq_contains. */
  58. #define METH_COEXIST 0x0040
  59. #ifndef Py_LIMITED_API
  60. #define METH_FASTCALL 0x0080
  61. #endif
  62. /* This bit is preserved for Stackless Python */
  63. #ifdef STACKLESS
  64. #define METH_STACKLESS 0x0100
  65. #else
  66. #define METH_STACKLESS 0x0000
  67. #endif
  68. /* METH_METHOD means the function stores an
  69. * additional reference to the class that defines it;
  70. * both self and class are passed to it.
  71. * It uses PyCMethodObject instead of PyCFunctionObject.
  72. * May not be combined with METH_NOARGS, METH_O, METH_CLASS or METH_STATIC.
  73. */
  74. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
  75. #define METH_METHOD 0x0200
  76. #endif
  77. #ifndef Py_LIMITED_API
  78. #define Py_CPYTHON_METHODOBJECT_H
  79. #include "cpython/methodobject.h"
  80. #undef Py_CPYTHON_METHODOBJECT_H
  81. #endif
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif /* !Py_METHODOBJECT_H */