PageRenderTime 73ms CodeModel.GetById 38ms RepoModel.GetById 1ms app.codeStats 0ms

/HTML/S/2801.html

https://github.com/cocoatomo/Python3.2_C_API_Tutorial
HTML | 356 lines | 356 code | 0 blank | 0 comment | 0 complexity | 674dc5115ae4625842501c17646ecb56 MD5 | raw file
  1. <html>
  2. <head>
  3. <title>Objects/methodobject.c</title>
  4. <meta name='robots' content='noindex,nofollow'>
  5. <meta name='generator' content='GLOBAL-5.8.1'>
  6. </head>
  7. <body text='#191970' bgcolor='#f5f5dc' vlink='gray'>
  8. <a name='TOP'><h2><a href='../mains.html'>root</a>/<a href='../files/3391.html'>Objects</a>/methodobject.c</h2>
  9. <i><font color='green'>/* [&lt;][&gt;]<a href='#L17'>[^]</a><a href='#L312'>[v]</a>[top]<a href='#BOTTOM'>[bottom]</a><a href='../mains.html'>[index]</a><a href='../help.html'>[help]</a> */</font></i>
  10. <hr>
  11. <h2>DEFINITIONS</h2>
  12. This source file includes following definitions.
  13. <ol>
  14. <li><a href='#L17' title='Defined at 17.'>PyCFunction_NewEx</a>
  15. <li><a href='#L41' title='Defined at 41.'>PyCFunction_GetFunction</a>
  16. <li><a href='#L51' title='Defined at 51.'>PyCFunction_GetSelf</a>
  17. <li><a href='#L61' title='Defined at 61.'>PyCFunction_GetFlags</a>
  18. <li><a href='#L71' title='Defined at 71.'>PyCFunction_Call</a>
  19. <li><a href='#L122' title='Defined at 122.'>meth_dealloc</a>
  20. <li><a href='#L138' title='Defined at 138.'>meth_get__doc__</a>
  21. <li><a href='#L149' title='Defined at 149.'>meth_get__name__</a>
  22. <li><a href='#L155' title='Defined at 155.'>meth_traverse</a>
  23. <li><a href='#L163' title='Defined at 163.'>meth_get__self__</a>
  24. <li><a href='#L189' title='Defined at 189.'>meth_repr</a>
  25. <li><a href='#L201' title='Defined at 201.'>meth_richcompare</a>
  26. <li><a href='#L228' title='Defined at 228.'>meth_hash</a>
  27. <li><a href='#L286' title='Defined at 286.'>PyCFunction_ClearFreeList</a>
  28. <li><a href='#L301' title='Defined at 301.'>PyCFunction_Fini</a>
  29. <li><a href='#L312' title='Defined at 312.'>PyAPI_FUNC</a>
  30. </ol>
  31. <hr>
  32. <pre>
  33. <a name='L1'>
  34. <a name='L2'><i><font color='green'>/* Method object implementation */</font></i>
  35. <a name='L3'>
  36. <a name='L4'><font color='darkred'>#include</font> "<a href='570.html'>Python.h</a>"
  37. <a name='L5'><font color='darkred'>#include</font> "<a href='577.html'>structmember.h</a>"
  38. <a name='L6'>
  39. <a name='L7'><i><font color='green'>/* Free list for method objects to safe malloc/free overhead</font></i>
  40. <a name='L8'><i><font color='green'> * The m_self element is used to chain the objects.</font></i>
  41. <a name='L9'><i><font color='green'> */</font></i>
  42. <a name='L10'><b>static</b> PyCFunctionObject *free_list = <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>;
  43. <a name='L11'><b>static</b> <b>int</b> numfree = 0;
  44. <a name='L12'><font color='darkred'>#ifndef</font> <a href='../S/2801.html#L13' title='Defined at 13 in Objects/methodobject.c.'>PyCFunction_MAXFREELIST</a>
  45. <a name='L13'><font color='darkred'>#define</font> <a href='../R/2604.html' title='Multiple refered from 2 places.'>PyCFunction_MAXFREELIST</a> 256
  46. <a name='L14'><font color='darkred'>#endif</font>
  47. <a name='L15'>
  48. <a name='L16'><a href='../D/3593.html' title='Multiple defined in 2 places.'>PyObject</a> *
  49. <a name='L17'><a href='../R/2606.html' title='Multiple refered from 3 places.'>PyCFunction_NewEx</a>(PyMethodDef *ml, PyObject *self, PyObject *module)
  50. <a name='L18'><font color='red'>{</font>
  51. <a name='L19'> PyCFunctionObject *op;
  52. <a name='L20'> op = free_list;
  53. <a name='L21'> <b>if</b> (op != <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>) <font color='red'>{</font>
  54. <a name='L22'> free_list = (PyCFunctionObject *)(op-&gt;m_self);
  55. <a name='L23'> PyObject_INIT(op, &amp;PyCFunction_Type);
  56. <a name='L24'> numfree--;
  57. <a name='L25'> <font color='red'>}</font>
  58. <a name='L26'> <b>else</b> <font color='red'>{</font>
  59. <a name='L27'> op = PyObject_GC_New(PyCFunctionObject, &amp;PyCFunction_Type);
  60. <a name='L28'> <b>if</b> (op == <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>)
  61. <a name='L29'> <b>return</b> <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>;
  62. <a name='L30'> <font color='red'>}</font>
  63. <a name='L31'> op-&gt;m_ml = ml;
  64. <a name='L32'> <a href='../S/544.html#L766' title='Defined at 766 in Include/object.h.'>Py_XINCREF</a>(self);
  65. <a name='L33'> op-&gt;m_self = self;
  66. <a name='L34'> <a href='../S/544.html#L766' title='Defined at 766 in Include/object.h.'>Py_XINCREF</a>(module);
  67. <a name='L35'> op-&gt;m_module = module;
  68. <a name='L36'> <a href='../S/545.html#L266' title='Defined at 266 in Include/objimpl.h.'>_PyObject_GC_TRACK</a>(op);
  69. <a name='L37'> <b>return</b> (<a href='../D/3593.html' title='Multiple defined in 2 places.'>PyObject</a> *)op;
  70. <a name='L38'><font color='red'>}</font>
  71. <a name='L39'>
  72. <a name='L40'>PyCFunction
  73. <a name='L41'><a href='../S/2576.html#L1182' title='Refered from 1182 in Modules/_json.c.'>PyCFunction_GetFunction</a>(PyObject *op)
  74. <a name='L42'><font color='red'>{</font>
  75. <a name='L43'> <b>if</b> (!PyCFunction_Check(op)) <font color='red'>{</font>
  76. <a name='L44'> <a href='../D/3142.html' title='Multiple defined in 3 places.'>PyErr_BadInternalCall</a>();
  77. <a name='L45'> <b>return</b> <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>;
  78. <a name='L46'> <font color='red'>}</font>
  79. <a name='L47'> <b>return</b> ((PyCFunctionObject *)op) -&gt; m_ml -&gt; ml_meth;
  80. <a name='L48'><font color='red'>}</font>
  81. <a name='L49'>
  82. <a name='L50'><a href='../D/3593.html' title='Multiple defined in 2 places.'>PyObject</a> *
  83. <a name='L51'>PyCFunction_GetSelf(PyObject *op)
  84. <a name='L52'><font color='red'>{</font>
  85. <a name='L53'> <b>if</b> (!PyCFunction_Check(op)) <font color='red'>{</font>
  86. <a name='L54'> <a href='../D/3142.html' title='Multiple defined in 3 places.'>PyErr_BadInternalCall</a>();
  87. <a name='L55'> <b>return</b> <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>;
  88. <a name='L56'> <font color='red'>}</font>
  89. <a name='L57'> <b>return</b> ((PyCFunctionObject *)op) -&gt; m_self;
  90. <a name='L58'><font color='red'>}</font>
  91. <a name='L59'>
  92. <a name='L60'><b>int</b>
  93. <a name='L61'>PyCFunction_GetFlags(PyObject *op)
  94. <a name='L62'><font color='red'>{</font>
  95. <a name='L63'> <b>if</b> (!PyCFunction_Check(op)) <font color='red'>{</font>
  96. <a name='L64'> <a href='../D/3142.html' title='Multiple defined in 3 places.'>PyErr_BadInternalCall</a>();
  97. <a name='L65'> <b>return</b> -1;
  98. <a name='L66'> <font color='red'>}</font>
  99. <a name='L67'> <b>return</b> ((PyCFunctionObject *)op) -&gt; m_ml -&gt; ml_flags;
  100. <a name='L68'><font color='red'>}</font>
  101. <a name='L69'>
  102. <a name='L70'><a href='../D/3593.html' title='Multiple defined in 2 places.'>PyObject</a> *
  103. <a name='L71'><a href='../R/2600.html' title='Multiple refered from 4 places.'>PyCFunction_Call</a>(PyObject *func, PyObject *arg, PyObject *kw)
  104. <a name='L72'><font color='red'>{</font>
  105. <a name='L73'> PyCFunctionObject* f = (PyCFunctionObject*)func;
  106. <a name='L74'> PyCFunction meth = PyCFunction_GET_FUNCTION(func);
  107. <a name='L75'> <a href='../D/3593.html' title='Multiple defined in 2 places.'>PyObject</a> *self = PyCFunction_GET_SELF(func);
  108. <a name='L76'> <a href='../D/4364.html' title='Multiple defined in 6 places.'>Py_ssize_t</a> size;
  109. <a name='L77'>
  110. <a name='L78'> <b>switch</b> (PyCFunction_GET_FLAGS(func) &amp; ~(METH_CLASS | METH_STATIC | METH_COEXIST)) <font color='red'>{</font>
  111. <a name='L79'> <b>case</b> <a href='../S/2858.html#L633' title='Defined at 633 in PC/bdist_wininst/install.c.'>METH_VARARGS</a>:
  112. <a name='L80'> <b>if</b> (kw == <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a> || <a href='../S/2787.html#L1620' title='Defined at 1620 in Objects/dictobject.c.'>PyDict_Size</a>(kw) == 0)
  113. <a name='L81'> <b>return</b> (*meth)(self, <a href='../D/6730.html' title='Multiple defined in 2 places.'>arg</a>);
  114. <a name='L82'> <b>break</b>;
  115. <a name='L83'> <b>case</b> <a href='../S/2858.html#L633' title='Defined at 633 in PC/bdist_wininst/install.c.'>METH_VARARGS</a> | METH_KEYWORDS:
  116. <a name='L84'> <b>return</b> (*(PyCFunctionWithKeywords)meth)(self, <a href='../D/6730.html' title='Multiple defined in 2 places.'>arg</a>, kw);
  117. <a name='L85'> <b>case</b> <a href='../S/2858.html#L634' title='Defined at 634 in PC/bdist_wininst/install.c.'>METH_NOARGS</a>:
  118. <a name='L86'> <b>if</b> (kw == <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a> || <a href='../S/2787.html#L1620' title='Defined at 1620 in Objects/dictobject.c.'>PyDict_Size</a>(kw) == 0) <font color='red'>{</font>
  119. <a name='L87'> size = PyTuple_GET_SIZE(<a href='../D/6730.html' title='Multiple defined in 2 places.'>arg</a>);
  120. <a name='L88'> <b>if</b> (size == 0)
  121. <a name='L89'> <b>return</b> (*meth)(self, <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>);
  122. <a name='L90'> <a href='../S/3106.html#L600' title='Defined at 600 in Python/errors.c.'>PyErr_Format</a>(PyExc_TypeError,
  123. <a name='L91'> "%.200s() takes no arguments (%zd given)",
  124. <a name='L92'> f-&gt;m_ml-&gt;ml_name, size);
  125. <a name='L93'> <b>return</b> <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>;
  126. <a name='L94'> <font color='red'>}</font>
  127. <a name='L95'> <b>break</b>;
  128. <a name='L96'> <b>case</b> METH_O:
  129. <a name='L97'> <b>if</b> (kw == <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a> || <a href='../S/2787.html#L1620' title='Defined at 1620 in Objects/dictobject.c.'>PyDict_Size</a>(kw) == 0) <font color='red'>{</font>
  130. <a name='L98'> size = PyTuple_GET_SIZE(<a href='../D/6730.html' title='Multiple defined in 2 places.'>arg</a>);
  131. <a name='L99'> <b>if</b> (size == 1)
  132. <a name='L100'> <b>return</b> (*meth)(self, PyTuple_GET_ITEM(<a href='../D/6730.html' title='Multiple defined in 2 places.'>arg</a>, 0));
  133. <a name='L101'> <a href='../S/3106.html#L600' title='Defined at 600 in Python/errors.c.'>PyErr_Format</a>(PyExc_TypeError,
  134. <a name='L102'> "%.200s() takes exactly one argument (%zd given)",
  135. <a name='L103'> f-&gt;m_ml-&gt;ml_name, size);
  136. <a name='L104'> <b>return</b> <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>;
  137. <a name='L105'> <font color='red'>}</font>
  138. <a name='L106'> <b>break</b>;
  139. <a name='L107'> <b>default</b>:
  140. <a name='L108'> <a href='../S/3106.html#L122' title='Defined at 122 in Python/errors.c.'>PyErr_SetString</a>(PyExc_SystemError, "Bad call flags in "
  141. <a name='L109'> "PyCFunction_Call. METH_OLDARGS is no "
  142. <a name='L110'> "longer supported!");
  143. <a name='L111'>
  144. <a name='L112'> <b>return</b> <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>;
  145. <a name='L113'> <font color='red'>}</font>
  146. <a name='L114'> <a href='../S/3106.html#L600' title='Defined at 600 in Python/errors.c.'>PyErr_Format</a>(PyExc_TypeError, "%.200s() takes no keyword arguments",
  147. <a name='L115'> f-&gt;m_ml-&gt;ml_name);
  148. <a name='L116'> <b>return</b> <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>;
  149. <a name='L117'><font color='red'>}</font>
  150. <a name='L118'>
  151. <a name='L119'><i><font color='green'>/* Methods (the standard built-in methods, that is) */</font></i>
  152. <a name='L120'>
  153. <a name='L121'><b>static</b> <b>void</b>
  154. <a name='L122'><a href='../S/2801.html#L253' title='Refered from 253 in Objects/methodobject.c.'>meth_dealloc</a>(PyCFunctionObject *m)
  155. <a name='L123'><font color='red'>{</font>
  156. <a name='L124'> <a href='../S/545.html#L281' title='Defined at 281 in Include/objimpl.h.'>_PyObject_GC_UNTRACK</a>(m);
  157. <a name='L125'> <a href='../S/544.html#L767' title='Defined at 767 in Include/object.h.'>Py_XDECREF</a>(m-&gt;m_self);
  158. <a name='L126'> <a href='../S/544.html#L767' title='Defined at 767 in Include/object.h.'>Py_XDECREF</a>(m-&gt;m_module);
  159. <a name='L127'> <b>if</b> (numfree &lt; <a href='../S/2801.html#L13' title='Defined at 13 in Objects/methodobject.c.'>PyCFunction_MAXFREELIST</a>) <font color='red'>{</font>
  160. <a name='L128'> m-&gt;m_self = (<a href='../D/3593.html' title='Multiple defined in 2 places.'>PyObject</a> *)free_list;
  161. <a name='L129'> free_list = m;
  162. <a name='L130'> numfree++;
  163. <a name='L131'> <font color='red'>}</font>
  164. <a name='L132'> <b>else</b> <font color='red'>{</font>
  165. <a name='L133'> <a href='../D/3617.html' title='Multiple defined in 2 places.'>PyObject_GC_Del</a>(m);
  166. <a name='L134'> <font color='red'>}</font>
  167. <a name='L135'><font color='red'>}</font>
  168. <a name='L136'>
  169. <a name='L137'><b>static</b> <a href='../D/3593.html' title='Multiple defined in 2 places.'>PyObject</a> *
  170. <a name='L138'><a href='../S/2801.html#L175' title='Refered from 175 in Objects/methodobject.c.'>meth_get__doc__</a>(PyCFunctionObject *m, <b>void</b> *closure)
  171. <a name='L139'><font color='red'>{</font>
  172. <a name='L140'> <b>const</b> <b>char</b> *doc = m-&gt;m_ml-&gt;ml_doc;
  173. <a name='L141'>
  174. <a name='L142'> <b>if</b> (doc != <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>)
  175. <a name='L143'> <b>return</b> <a href='../D/4012.html' title='Multiple defined in 3 places.'>PyUnicode_FromString</a>(doc);
  176. <a name='L144'> Py_INCREF(Py_None);
  177. <a name='L145'> <b>return</b> Py_None;
  178. <a name='L146'><font color='red'>}</font>
  179. <a name='L147'>
  180. <a name='L148'><b>static</b> <a href='../D/3593.html' title='Multiple defined in 2 places.'>PyObject</a> *
  181. <a name='L149'><a href='../S/2801.html#L176' title='Refered from 176 in Objects/methodobject.c.'>meth_get__name__</a>(PyCFunctionObject *m, <b>void</b> *closure)
  182. <a name='L150'><font color='red'>{</font>
  183. <a name='L151'> <b>return</b> <a href='../D/4012.html' title='Multiple defined in 3 places.'>PyUnicode_FromString</a>(m-&gt;m_ml-&gt;ml_name);
  184. <a name='L152'><font color='red'>}</font>
  185. <a name='L153'>
  186. <a name='L154'><b>static</b> <b>int</b>
  187. <a name='L155'><a href='../S/2801.html#L270' title='Refered from 270 in Objects/methodobject.c.'>meth_traverse</a>(PyCFunctionObject *m, visitproc visit, <b>void</b> *arg)
  188. <a name='L156'><font color='red'>{</font>
  189. <a name='L157'> Py_VISIT(m-&gt;m_self);
  190. <a name='L158'> Py_VISIT(m-&gt;m_module);
  191. <a name='L159'> <b>return</b> 0;
  192. <a name='L160'><font color='red'>}</font>
  193. <a name='L161'>
  194. <a name='L162'><b>static</b> <a href='../D/3593.html' title='Multiple defined in 2 places.'>PyObject</a> *
  195. <a name='L163'><a href='../S/2801.html#L177' title='Refered from 177 in Objects/methodobject.c.'>meth_get__self__</a>(PyCFunctionObject *m, <b>void</b> *closure)
  196. <a name='L164'><font color='red'>{</font>
  197. <a name='L165'> <a href='../D/3593.html' title='Multiple defined in 2 places.'>PyObject</a> *self;
  198. <a name='L166'>
  199. <a name='L167'> self = m-&gt;m_self;
  200. <a name='L168'> <b>if</b> (self == <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>)
  201. <a name='L169'> self = Py_None;
  202. <a name='L170'> Py_INCREF(self);
  203. <a name='L171'> <b>return</b> self;
  204. <a name='L172'><font color='red'>}</font>
  205. <a name='L173'>
  206. <a name='L174'><b>static</b> <a href='../D/3272.html' title='Multiple defined in 2 places.'>PyGetSetDef</a> meth_getsets [] = <font color='red'>{</font>
  207. <a name='L175'> <font color='red'>{</font>"__doc__", (getter)<a href='../S/2801.html#L138' title='Defined at 138 in Objects/methodobject.c.'>meth_get__doc__</a>, <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>, <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a><font color='red'>}</font>,
  208. <a name='L176'> <font color='red'>{</font>"__name__", (getter)<a href='../S/2801.html#L149' title='Defined at 149 in Objects/methodobject.c.'>meth_get__name__</a>, <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>, <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a><font color='red'>}</font>,
  209. <a name='L177'> <font color='red'>{</font>"__self__", (getter)<a href='../S/2801.html#L163' title='Defined at 163 in Objects/methodobject.c.'>meth_get__self__</a>, <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>, <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a><font color='red'>}</font>,
  210. <a name='L178'> <font color='red'>{</font>0<font color='red'>}</font>
  211. <a name='L179'><font color='red'>}</font>;
  212. <a name='L180'>
  213. <a name='L181'><font color='darkred'>#define</font> <a href='../R/2175.html' title='Multiple refered from 57 places.'>OFF</a>(x) <a href='../D/10194.html' title='Multiple defined in 2 places.'>offsetof</a>(PyCFunctionObject, x)
  214. <a name='L182'>
  215. <a name='L183'><b>static</b> <a href='../D/3506.html' title='Multiple defined in 2 places.'>PyMemberDef</a> meth_members[] = <font color='red'>{</font>
  216. <a name='L184'> <font color='red'>{</font>"__module__", <a href='../S/577.html#L44' title='Defined at 44 in Include/structmember.h.'>T_OBJECT</a>, <a href='../D/2402.html' title='Multiple defined in 16 places.'>OFF</a>(m_module), <a href='../S/577.html#L75' title='Defined at 75 in Include/structmember.h.'>PY_WRITE_RESTRICTED</a><font color='red'>}</font>,
  217. <a name='L185'> <font color='red'>{</font><a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a><font color='red'>}</font>
  218. <a name='L186'><font color='red'>}</font>;
  219. <a name='L187'>
  220. <a name='L188'><b>static</b> <a href='../D/3593.html' title='Multiple defined in 2 places.'>PyObject</a> *
  221. <a name='L189'><a href='../S/2801.html#L258' title='Refered from 258 in Objects/methodobject.c.'>meth_repr</a>(PyCFunctionObject *m)
  222. <a name='L190'><font color='red'>{</font>
  223. <a name='L191'> <b>if</b> (m-&gt;m_self == <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a> || PyModule_Check(m-&gt;m_self))
  224. <a name='L192'> <b>return</b> <a href='../D/4008.html' title='Multiple defined in 3 places.'>PyUnicode_FromFormat</a>("&lt;built-in function %s&gt;",
  225. <a name='L193'> m-&gt;m_ml-&gt;ml_name);
  226. <a name='L194'> <b>return</b> <a href='../D/4008.html' title='Multiple defined in 3 places.'>PyUnicode_FromFormat</a>("&lt;built-in method %s of %s object at %p&gt;",
  227. <a name='L195'> m-&gt;m_ml-&gt;ml_name,
  228. <a name='L196'> m-&gt;m_self-&gt;ob_type-&gt;tp_name,
  229. <a name='L197'> m-&gt;m_self);
  230. <a name='L198'><font color='red'>}</font>
  231. <a name='L199'>
  232. <a name='L200'><b>static</b> <a href='../D/3593.html' title='Multiple defined in 2 places.'>PyObject</a> *
  233. <a name='L201'><a href='../S/2801.html#L272' title='Refered from 272 in Objects/methodobject.c.'>meth_richcompare</a>(PyObject *self, PyObject *other, <b>int</b> op)
  234. <a name='L202'><font color='red'>{</font>
  235. <a name='L203'> PyCFunctionObject *a, *<a href='../D/6949.html' title='Multiple defined in 12 places.'>b</a>;
  236. <a name='L204'> <a href='../D/3593.html' title='Multiple defined in 2 places.'>PyObject</a> *res;
  237. <a name='L205'> <b>int</b> eq;
  238. <a name='L206'>
  239. <a name='L207'> <b>if</b> ((op != <a href='../S/546.html#L151' title='Defined at 151 in Include/opcode.h.'>Py_EQ</a> &amp;&amp; op != <a href='../S/546.html#L151' title='Defined at 151 in Include/opcode.h.'>Py_NE</a>) ||
  240. <a name='L208'> !PyCFunction_Check(self) ||
  241. <a name='L209'> !PyCFunction_Check(<a href='../S/2669.html#L1431' title='Defined at 1431 in Modules/expat/xmltok_impl.c.'>other</a>))
  242. <a name='L210'> <font color='red'>{</font>
  243. <a name='L211'> Py_INCREF(Py_NotImplemented);
  244. <a name='L212'> <b>return</b> Py_NotImplemented;
  245. <a name='L213'> <font color='red'>}</font>
  246. <a name='L214'> a = (PyCFunctionObject *)self;
  247. <a name='L215'> <a href='../D/6949.html' title='Multiple defined in 12 places.'>b</a> = (PyCFunctionObject *)<a href='../S/2669.html#L1431' title='Defined at 1431 in Modules/expat/xmltok_impl.c.'>other</a>;
  248. <a name='L216'> eq = a-&gt;m_self == <a href='../D/6949.html' title='Multiple defined in 12 places.'>b</a>-&gt;m_self;
  249. <a name='L217'> <b>if</b> (eq)
  250. <a name='L218'> eq = a-&gt;m_ml-&gt;ml_meth == <a href='../D/6949.html' title='Multiple defined in 12 places.'>b</a>-&gt;m_ml-&gt;ml_meth;
  251. <a name='L219'> <b>if</b> (op == <a href='../S/546.html#L151' title='Defined at 151 in Include/opcode.h.'>Py_EQ</a>)
  252. <a name='L220'> res = eq ? Py_True : Py_False;
  253. <a name='L221'> <b>else</b>
  254. <a name='L222'> res = eq ? Py_False : Py_True;
  255. <a name='L223'> Py_INCREF(res);
  256. <a name='L224'> <b>return</b> res;
  257. <a name='L225'><font color='red'>}</font>
  258. <a name='L226'>
  259. <a name='L227'><b>static</b> <a href='../S/565.html#L186' title='Defined at 186 in Include/pyport.h.'>Py_hash_t</a>
  260. <a name='L228'><a href='../S/2801.html#L262' title='Refered from 262 in Objects/methodobject.c.'>meth_hash</a>(PyCFunctionObject *a)
  261. <a name='L229'><font color='red'>{</font>
  262. <a name='L230'> <a href='../S/565.html#L186' title='Defined at 186 in Include/pyport.h.'>Py_hash_t</a> x, y;
  263. <a name='L231'> <b>if</b> (a-&gt;m_self == <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>)
  264. <a name='L232'> x = 0;
  265. <a name='L233'> <b>else</b> <font color='red'>{</font>
  266. <a name='L234'> x = <a href='../S/2803.html#L758' title='Defined at 758 in Objects/object.c.'>PyObject_Hash</a>(a-&gt;m_self);
  267. <a name='L235'> <b>if</b> (x == -1)
  268. <a name='L236'> <b>return</b> -1;
  269. <a name='L237'> <font color='red'>}</font>
  270. <a name='L238'> y = <a href='../S/2803.html#L736' title='Defined at 736 in Objects/object.c.'>_Py_HashPointer</a>((<b>void</b>*)(a-&gt;m_ml-&gt;ml_meth));
  271. <a name='L239'> <b>if</b> (y == -1)
  272. <a name='L240'> <b>return</b> -1;
  273. <a name='L241'> x ^= y;
  274. <a name='L242'> <b>if</b> (x == -1)
  275. <a name='L243'> x = -2;
  276. <a name='L244'> <b>return</b> x;
  277. <a name='L245'><font color='red'>}</font>
  278. <a name='L246'>
  279. <a name='L247'>
  280. <a name='L248'><a href='../D/3899.html' title='Multiple defined in 3 places.'>PyTypeObject</a> PyCFunction_Type = <font color='red'>{</font>
  281. <a name='L249'> <a href='../D/4042.html' title='Multiple defined in 3 places.'>PyVarObject_HEAD_INIT</a>(&amp;PyType_Type, 0)
  282. <a name='L250'> "builtin_function_or_method",
  283. <a name='L251'> <b>sizeof</b>(PyCFunctionObject),
  284. <a name='L252'> 0,
  285. <a name='L253'> (<a href='../D/8095.html' title='Multiple defined in 2 places.'>destructor</a>)<a href='../S/2801.html#L122' title='Defined at 122 in Objects/methodobject.c.'>meth_dealloc</a>, <i><font color='green'>/* tp_dealloc */</font></i>
  286. <a name='L254'> 0, <i><font color='green'>/* tp_print */</font></i>
  287. <a name='L255'> 0, <i><font color='green'>/* tp_getattr */</font></i>
  288. <a name='L256'> 0, <i><font color='green'>/* tp_setattr */</font></i>
  289. <a name='L257'> 0, <i><font color='green'>/* tp_reserved */</font></i>
  290. <a name='L258'> (reprfunc)<a href='../S/2801.html#L189' title='Defined at 189 in Objects/methodobject.c.'>meth_repr</a>, <i><font color='green'>/* tp_repr */</font></i>
  291. <a name='L259'> 0, <i><font color='green'>/* tp_as_number */</font></i>
  292. <a name='L260'> 0, <i><font color='green'>/* tp_as_sequence */</font></i>
  293. <a name='L261'> 0, <i><font color='green'>/* tp_as_mapping */</font></i>
  294. <a name='L262'> (hashfunc)<a href='../S/2801.html#L228' title='Defined at 228 in Objects/methodobject.c.'>meth_hash</a>, <i><font color='green'>/* tp_hash */</font></i>
  295. <a name='L263'> <a href='../S/2801.html#L71' title='Defined at 71 in Objects/methodobject.c.'>PyCFunction_Call</a>, <i><font color='green'>/* tp_call */</font></i>
  296. <a name='L264'> 0, <i><font color='green'>/* tp_str */</font></i>
  297. <a name='L265'> <a href='../S/2803.html#L1046' title='Defined at 1046 in Objects/object.c.'>PyObject_GenericGetAttr</a>, <i><font color='green'>/* tp_getattro */</font></i>
  298. <a name='L266'> 0, <i><font color='green'>/* tp_setattro */</font></i>
  299. <a name='L267'> 0, <i><font color='green'>/* tp_as_buffer */</font></i>
  300. <a name='L268'> Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,<i><font color='green'>/* tp_flags */</font></i>
  301. <a name='L269'> 0, <i><font color='green'>/* tp_doc */</font></i>
  302. <a name='L270'> (traverseproc)<a href='../S/2801.html#L155' title='Defined at 155 in Objects/methodobject.c.'>meth_traverse</a>, <i><font color='green'>/* tp_traverse */</font></i>
  303. <a name='L271'> 0, <i><font color='green'>/* tp_clear */</font></i>
  304. <a name='L272'> <a href='../S/2801.html#L201' title='Defined at 201 in Objects/methodobject.c.'>meth_richcompare</a>, <i><font color='green'>/* tp_richcompare */</font></i>
  305. <a name='L273'> 0, <i><font color='green'>/* tp_weaklistoffset */</font></i>
  306. <a name='L274'> 0, <i><font color='green'>/* tp_iter */</font></i>
  307. <a name='L275'> 0, <i><font color='green'>/* tp_iternext */</font></i>
  308. <a name='L276'> 0, <i><font color='green'>/* tp_methods */</font></i>
  309. <a name='L277'> meth_members, <i><font color='green'>/* tp_members */</font></i>
  310. <a name='L278'> meth_getsets, <i><font color='green'>/* tp_getset */</font></i>
  311. <a name='L279'> 0, <i><font color='green'>/* tp_base */</font></i>
  312. <a name='L280'> 0, <i><font color='green'>/* tp_dict */</font></i>
  313. <a name='L281'><font color='red'>}</font>;
  314. <a name='L282'>
  315. <a name='L283'><i><font color='green'>/* Clear out the free list */</font></i>
  316. <a name='L284'>
  317. <a name='L285'><b>int</b>
  318. <a name='L286'><a href='../R/2601.html' title='Multiple refered from 2 places.'>PyCFunction_ClearFreeList</a>(<b>void</b>)
  319. <a name='L287'><font color='red'>{</font>
  320. <a name='L288'> <b>int</b> freelist_size = numfree;
  321. <a name='L289'>
  322. <a name='L290'> <b>while</b> (free_list) <font color='red'>{</font>
  323. <a name='L291'> PyCFunctionObject *v = free_list;
  324. <a name='L292'> free_list = (PyCFunctionObject *)(v-&gt;m_self);
  325. <a name='L293'> <a href='../D/3617.html' title='Multiple defined in 2 places.'>PyObject_GC_Del</a>(v);
  326. <a name='L294'> numfree--;
  327. <a name='L295'> <font color='red'>}</font>
  328. <a name='L296'> <a href='../D/6814.html' title='Multiple defined in 2 places.'>assert</a>(numfree == 0);
  329. <a name='L297'> <b>return</b> freelist_size;
  330. <a name='L298'><font color='red'>}</font>
  331. <a name='L299'>
  332. <a name='L300'><b>void</b>
  333. <a name='L301'><a href='../S/3138.html#L497' title='Refered from 497 in Python/pythonrun.c.'>PyCFunction_Fini</a>(<b>void</b>)
  334. <a name='L302'><font color='red'>{</font>
  335. <a name='L303'> (<b>void</b>)<a href='../S/2801.html#L286' title='Defined at 286 in Objects/methodobject.c.'>PyCFunction_ClearFreeList</a>();
  336. <a name='L304'><font color='red'>}</font>
  337. <a name='L305'>
  338. <a name='L306'><i><font color='green'>/* PyCFunction_New() is now just a macro that calls PyCFunction_NewEx(),</font></i>
  339. <a name='L307'><i><font color='green'> but it's part of the API so we need to keep a function around that</font></i>
  340. <a name='L308'><i><font color='green'> existing C extensions can call.</font></i>
  341. <a name='L309'><i><font color='green'>*/</font></i>
  342. <a name='L310'>
  343. <a name='L311'><font color='darkred'>#undef</font> <a href='../R/2605.html' title='Multiple refered from 13 places.'>PyCFunction_New</a>
  344. <a name='L312'><a href='../R/2475.html' title='Multiple refered from 87 places.'>PyAPI_FUNC</a>(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);
  345. <a name='L313'>
  346. <a name='L314'>PyObject *
  347. <a name='L315'>PyCFunction_New(PyMethodDef *ml, PyObject *self)
  348. <a name='L316'><font color='red'>{</font>
  349. <a name='L317'> <b>return</b> <a href='../S/2801.html#L17' title='Defined at 17 in Objects/methodobject.c.'>PyCFunction_NewEx</a>(ml, self, <a href='../S/2891.html#L5' title='Defined at 5 in PC/os2emx/dllentry.c.'>NULL</a>);
  350. <a name='L318'><font color='red'>}</font>
  351. </pre>
  352. <hr>
  353. <a name='BOTTOM'>
  354. <i><font color='green'>/* [&lt;][&gt;]<a href='#L17'>[^]</a><a href='#L312'>[v]</a><a href='#TOP'>[top]</a>[bottom]<a href='../mains.html'>[index]</a><a href='../help.html'>[help]</a> */</font></i>
  355. </body>
  356. </html>