PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/Include/methodobject.h

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