/pypy/module/cpyext/include/methodobject.h

https://github.com/thepian/pypy · C Header · 66 lines · 41 code · 12 blank · 13 comment · 0 complexity · 4e60df20caf0eab42b1f6b10e4254171 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. typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
  8. typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
  9. PyObject *);
  10. typedef PyObject *(*PyNoArgsFunction)(PyObject *);
  11. struct PyMethodDef {
  12. const char *ml_name; /* The name of the built-in function/method */
  13. PyCFunction ml_meth; /* The C function that implements it */
  14. int ml_flags; /* Combination of METH_xxx flags, which mostly
  15. describe the args expected by the C func */
  16. const char *ml_doc; /* The __doc__ attribute, or NULL */
  17. };
  18. typedef struct PyMethodDef PyMethodDef;
  19. typedef struct
  20. {
  21. PyObject_HEAD
  22. PyMethodDef *m_ml; /* Description of the C function to call */
  23. PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */
  24. } PyCFunctionObject;
  25. /* Flag passed to newmethodobject */
  26. #define METH_OLDARGS 0x0000
  27. #define METH_VARARGS 0x0001
  28. #define METH_KEYWORDS 0x0002
  29. /* METH_NOARGS and METH_O must not be combined with the flags above. */
  30. #define METH_NOARGS 0x0004
  31. #define METH_O 0x0008
  32. /* METH_CLASS and METH_STATIC are a little different; these control
  33. the construction of methods for a class. These cannot be used for
  34. functions in modules. */
  35. #define METH_CLASS 0x0010
  36. #define METH_STATIC 0x0020
  37. /* METH_COEXIST allows a method to be entered eventhough a slot has
  38. already filled the entry. When defined, the flag allows a separate
  39. method, "__contains__" for example, to coexist with a defined
  40. slot like sq_contains. */
  41. #define METH_COEXIST 0x0040
  42. #define PyCFunction_New(ml, self) PyCFunction_NewEx((ml), (self), NULL)
  43. /* Macros for direct access to these values. Type checks are *not*
  44. done, so use with care. */
  45. #define PyCFunction_GET_FUNCTION(func) \
  46. (((PyCFunctionObject *)func) -> m_ml -> ml_meth)
  47. #define PyCFunction_GET_SELF(func) \
  48. (((PyCFunctionObject *)func) -> m_self)
  49. #define PyCFunction_GET_FLAGS(func) \
  50. (((PyCFunctionObject *)func) -> m_ml -> ml_flags)
  51. #ifdef __cplusplus
  52. }
  53. #endif
  54. #endif /* !Py_METHODOBJECT_H */