10
10
11
11
#include "clinic/classobject.c.h"
12
12
13
+ #define _PyMethodObject_CAST (op ) _Py_CAST(PyMethodObject*, (op))
13
14
#define TP_DESCR_GET (t ) ((t)->tp_descr_get)
14
15
15
16
/*[clinic input]
@@ -166,13 +167,14 @@ static PyMemberDef method_memberlist[] = {
166
167
should only be used for the class, not for instances */
167
168
168
169
static PyObject *
169
- method_get_doc (PyMethodObject * im , void * context )
170
+ method_get_doc (PyObject * self , void * context )
170
171
{
172
+ PyMethodObject * im = _PyMethodObject_CAST (self );
171
173
return PyObject_GetAttr (im -> im_func , & _Py_ID (__doc__ ));
172
174
}
173
175
174
176
static PyGetSetDef method_getset [] = {
175
- {"__doc__" , ( getter ) method_get_doc , NULL , NULL },
177
+ {"__doc__" , method_get_doc , NULL , NULL },
176
178
{0 }
177
179
};
178
180
@@ -235,8 +237,9 @@ method_new_impl(PyTypeObject *type, PyObject *function, PyObject *instance)
235
237
}
236
238
237
239
static void
238
- method_dealloc (PyMethodObject * im )
240
+ method_dealloc (PyObject * self )
239
241
{
242
+ PyMethodObject * im = _PyMethodObject_CAST (self );
240
243
_PyObject_GC_UNTRACK (im );
241
244
if (im -> im_weakreflist != NULL )
242
245
PyObject_ClearWeakRefs ((PyObject * )im );
@@ -274,8 +277,9 @@ method_richcompare(PyObject *self, PyObject *other, int op)
274
277
}
275
278
276
279
static PyObject *
277
- method_repr (PyMethodObject * a )
280
+ method_repr (PyObject * op )
278
281
{
282
+ PyMethodObject * a = _PyMethodObject_CAST (op );
279
283
PyObject * self = a -> im_self ;
280
284
PyObject * func = a -> im_func ;
281
285
PyObject * funcname , * result ;
@@ -301,22 +305,26 @@ method_repr(PyMethodObject *a)
301
305
}
302
306
303
307
static Py_hash_t
304
- method_hash (PyMethodObject * a )
308
+ method_hash (PyObject * self )
305
309
{
306
- Py_hash_t x , y ;
307
- x = PyObject_GenericHash (a -> im_self );
308
- y = PyObject_Hash (a -> im_func );
309
- if (y == -1 )
310
+ PyMethodObject * a = _PyMethodObject_CAST ( self ) ;
311
+ Py_hash_t x = PyObject_GenericHash (a -> im_self );
312
+ Py_hash_t y = PyObject_Hash (a -> im_func );
313
+ if (y == -1 ) {
310
314
return -1 ;
315
+ }
316
+
311
317
x = x ^ y ;
312
- if (x == -1 )
318
+ if (x == -1 ) {
313
319
x = -2 ;
320
+ }
314
321
return x ;
315
322
}
316
323
317
324
static int
318
- method_traverse (PyMethodObject * im , visitproc visit , void * arg )
325
+ method_traverse (PyObject * self , visitproc visit , void * arg )
319
326
{
327
+ PyMethodObject * im = _PyMethodObject_CAST (self );
320
328
Py_VISIT (im -> im_func );
321
329
Py_VISIT (im -> im_self );
322
330
return 0 ;
@@ -333,17 +341,17 @@ PyTypeObject PyMethod_Type = {
333
341
PyVarObject_HEAD_INIT (& PyType_Type , 0 )
334
342
.tp_name = "method" ,
335
343
.tp_basicsize = sizeof (PyMethodObject ),
336
- .tp_dealloc = ( destructor ) method_dealloc ,
344
+ .tp_dealloc = method_dealloc ,
337
345
.tp_vectorcall_offset = offsetof(PyMethodObject , vectorcall ),
338
- .tp_repr = ( reprfunc ) method_repr ,
339
- .tp_hash = ( hashfunc ) method_hash ,
346
+ .tp_repr = method_repr ,
347
+ .tp_hash = method_hash ,
340
348
.tp_call = PyVectorcall_Call ,
341
349
.tp_getattro = method_getattro ,
342
350
.tp_setattro = PyObject_GenericSetAttr ,
343
351
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
344
352
Py_TPFLAGS_HAVE_VECTORCALL ,
345
353
.tp_doc = method_new__doc__ ,
346
- .tp_traverse = ( traverseproc ) method_traverse ,
354
+ .tp_traverse = method_traverse ,
347
355
.tp_richcompare = method_richcompare ,
348
356
.tp_weaklistoffset = offsetof(PyMethodObject , im_weakreflist ),
349
357
.tp_methods = method_methods ,
@@ -399,7 +407,7 @@ instancemethod_get_doc(PyObject *self, void *context)
399
407
}
400
408
401
409
static PyGetSetDef instancemethod_getset [] = {
402
- {"__doc__" , ( getter ) instancemethod_get_doc , NULL , NULL },
410
+ {"__doc__" , instancemethod_get_doc , NULL , NULL },
403
411
{0 }
404
412
};
405
413
@@ -537,7 +545,7 @@ PyTypeObject PyInstanceMethod_Type = {
537
545
.tp_name = "instancemethod" ,
538
546
.tp_basicsize = sizeof (PyInstanceMethodObject ),
539
547
.tp_dealloc = instancemethod_dealloc ,
540
- .tp_repr = ( reprfunc ) instancemethod_repr ,
548
+ .tp_repr = instancemethod_repr ,
541
549
.tp_call = instancemethod_call ,
542
550
.tp_getattro = instancemethod_getattro ,
543
551
.tp_setattro = PyObject_GenericSetAttr ,
0 commit comments