PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/infrastructure/deimos/python/methodobject.d

https://bitbucket.org/ariovistus/pyd
D | 144 lines | 68 code | 19 blank | 57 comment | 1 complexity | 192cc17f78ab75a9df3fa20e62820d72 MD5 | raw file
  1. /**
  2. Mirror _methodobject.h
  3. Method object interface
  4. */
  5. module deimos.python.methodobject;
  6. import core.stdc.stdio;
  7. import deimos.python.pyport;
  8. import deimos.python.object;
  9. extern(C):
  10. // Python-header-file: Include/methodobject.h:
  11. /** This is about the type 'builtin_function_or_method',
  12. not Python methods in user-defined classes. See classobject.h
  13. for the latter. */
  14. mixin(PyAPI_DATA!"PyTypeObject PyCFunction_Type");
  15. // D translation of C macro:
  16. /// _
  17. int PyCFunction_Check()(PyObject *op) {
  18. return Py_TYPE(op) == &PyCFunction_Type;
  19. }
  20. /// _
  21. alias PyObject* function(PyObject*, PyObject*) PyCFunction;
  22. /// _
  23. alias PyObject* function(PyObject*, PyObject*,PyObject*) PyCFunctionWithKeywords;
  24. /// _
  25. alias PyObject* function(PyObject*) PyNoArgsFunction;
  26. /// _
  27. PyCFunction PyCFunction_GetFunction(PyObject*);
  28. // TODO: returns borrowed ref?
  29. /// _
  30. PyObject* PyCFunction_GetSelf(PyObject*);
  31. /// _
  32. int PyCFunction_GetFlags(PyObject*);
  33. /** Macros for direct access to these values. Type checks are *not*
  34. done, so use with care. */
  35. auto PyCFunction_GET_FUNCTION()(PyObject* func) {
  36. return (cast(PyCFunctionObject*)func).m_ml.ml_meth;
  37. }
  38. /// ditto
  39. auto PyCFunction_GET_SELF()(PyObject* func) {
  40. return (cast(PyCFunctionObject*)func).m_self;
  41. }
  42. /// ditto
  43. auto PyCFunction_GET_FLAGS(PyObject* func) {
  44. return (cast(PyCFunctionObject*)func).m_ml.ml_flags;
  45. }
  46. /// _
  47. PyObject* PyCFunction_Call(PyObject*, PyObject*, PyObject*);
  48. /// _
  49. struct PyMethodDef {
  50. /** The name of the built-in function/method */
  51. const(char)* ml_name;
  52. /** The C function that implements it */
  53. PyCFunction ml_meth;
  54. /** Combination of METH_xxx flags, which mostly
  55. describe the args expected by the C func */
  56. int ml_flags;
  57. /** The __doc__ attribute, or NULL */
  58. const(char)* ml_doc;
  59. }
  60. version(Python_3_0_Or_Later) {
  61. }else{
  62. // TODO: returns borrowed ref?
  63. /// Availability: 2.*
  64. PyObject* Py_FindMethod(PyMethodDef*, PyObject*, const(char)*);
  65. }
  66. /// _
  67. PyObject* PyCFunction_NewEx(PyMethodDef*, PyObject*,PyObject*);
  68. /// _
  69. PyObject* PyCFunction_New()(PyMethodDef* ml, PyObject* self) {
  70. return PyCFunction_NewEx(ml, self, null);
  71. }
  72. /** Flag passed to newmethodobject */
  73. enum int METH_OLDARGS = 0x0000;
  74. /// ditto
  75. enum int METH_VARARGS = 0x0001;
  76. /// ditto
  77. enum int METH_KEYWORDS= 0x0002;
  78. /** METH_NOARGS and METH_O must not be combined with the flags above. */
  79. enum int METH_NOARGS = 0x0004;
  80. /// ditto
  81. enum int METH_O = 0x0008;
  82. /** METH_CLASS and METH_STATIC are a little different; these control
  83. the construction of methods for a class. These cannot be used for
  84. functions in modules. */
  85. enum int METH_CLASS = 0x0010;
  86. /// ditto
  87. enum int METH_STATIC = 0x0020;
  88. /** METH_COEXIST allows a method to be entered eventhough a slot has
  89. already filled the entry. When defined, the flag allows a separate
  90. method, "__contains__" for example, to coexist with a defined
  91. slot like sq_contains. */
  92. enum int METH_COEXIST = 0x0040;
  93. version(Python_3_0_Or_Later) {
  94. }else{
  95. /// Availability: 2.*
  96. struct PyMethodChain {
  97. /** Methods of this type */
  98. PyMethodDef *methods;
  99. /** NULL or base type */
  100. PyMethodChain *link;
  101. }
  102. /// Availability: 2.*
  103. PyObject* Py_FindMethodInChain(PyMethodChain*, PyObject*, const(char)*);
  104. }
  105. /// subclass of PyObject
  106. struct PyCFunctionObject {
  107. mixin PyObject_HEAD;
  108. /** Description of the C function to call */
  109. PyMethodDef* m_ml;
  110. /** Passed as 'self' arg to the C func, can be NULL */
  111. PyObject* m_self;
  112. /** The __module__ attribute, can be anything */
  113. PyObject* m_module;
  114. }
  115. version(Python_2_6_Or_Later) {
  116. /// Availability: >= 2.6
  117. int PyCFunction_ClearFreeList();
  118. }
  119. version(Python_2_7_Or_Later) {
  120. /// Availability: >= 2.7
  121. void _PyCFunction_DebugMallocStats(FILE* out_);
  122. /// Availability: >= 2.7
  123. void _PyMethod_DebugMallocStats(FILE* out_);
  124. }