PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/pypy/pypy/
C++ Header | 67 lines | 42 code | 12 blank | 13 comment | 0 complexity | 4bfcd2e21a12b0e260a94af7ab16a7bd MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, Apache-2.0
  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. PyObject *m_module; /* The __module__ attribute, can be anything */
  25. } PyCFunctionObject;
  26. /* Flag passed to newmethodobject */
  27. #define METH_OLDARGS 0x0000
  28. #define METH_VARARGS 0x0001
  29. #define METH_KEYWORDS 0x0002
  30. /* METH_NOARGS and METH_O must not be combined with the flags above. */
  31. #define METH_NOARGS 0x0004
  32. #define METH_O 0x0008
  33. /* METH_CLASS and METH_STATIC are a little different; these control
  34. the construction of methods for a class. These cannot be used for
  35. functions in modules. */
  36. #define METH_CLASS 0x0010
  37. #define METH_STATIC 0x0020
  38. /* METH_COEXIST allows a method to be entered eventhough a slot has
  39. already filled the entry. When defined, the flag allows a separate
  40. method, "__contains__" for example, to coexist with a defined
  41. slot like sq_contains. */
  42. #define METH_COEXIST 0x0040
  43. #define PyCFunction_New(ml, self) PyCFunction_NewEx((ml), (self), NULL)
  44. /* Macros for direct access to these values. Type checks are *not*
  45. done, so use with care. */
  46. #define PyCFunction_GET_FUNCTION(func) \
  47. (((PyCFunctionObject *)func) -> m_ml -> ml_meth)
  48. #define PyCFunction_GET_SELF(func) \
  49. (((PyCFunctionObject *)func) -> m_self)
  50. #define PyCFunction_GET_FLAGS(func) \
  51. (((PyCFunctionObject *)func) -> m_ml -> ml_flags)
  52. #ifdef __cplusplus
  53. }
  54. #endif
  55. #endif /* !Py_METHODOBJECT_H */