@@ -156,8 +156,9 @@ PyCMethod_GetClass(PyObject *op)
156
156
/* Methods (the standard built-in methods, that is) */
157
157
158
158
static void
159
- meth_dealloc (PyCFunctionObject * m )
159
+ meth_dealloc (PyObject * self )
160
160
{
161
+ PyCFunctionObject * m = _PyCFunctionObject_CAST (self );
161
162
// The Py_TRASHCAN mechanism requires that we be able to
162
163
// call PyObject_GC_UnTrack twice on an object.
163
164
PyObject_GC_UnTrack (m );
@@ -175,8 +176,9 @@ meth_dealloc(PyCFunctionObject *m)
175
176
}
176
177
177
178
static PyObject *
178
- meth_reduce (PyCFunctionObject * m , PyObject * Py_UNUSED (ignored ))
179
+ meth_reduce (PyObject * self , PyObject * Py_UNUSED (ignored ))
179
180
{
181
+ PyCFunctionObject * m = _PyCFunctionObject_CAST (self );
180
182
if (m -> m_self == NULL || PyModule_Check (m -> m_self ))
181
183
return PyUnicode_FromString (m -> m_ml -> ml_name );
182
184
@@ -185,32 +187,35 @@ meth_reduce(PyCFunctionObject *m, PyObject *Py_UNUSED(ignored))
185
187
}
186
188
187
189
static PyMethodDef meth_methods [] = {
188
- {"__reduce__" , ( PyCFunction ) meth_reduce , METH_NOARGS , NULL },
190
+ {"__reduce__" , meth_reduce , METH_NOARGS , NULL },
189
191
{NULL , NULL }
190
192
};
191
193
192
194
static PyObject *
193
- meth_get__text_signature__ (PyCFunctionObject * m , void * closure )
195
+ meth_get__text_signature__ (PyObject * self , void * closure )
194
196
{
197
+ PyCFunctionObject * m = _PyCFunctionObject_CAST (self );
195
198
return _PyType_GetTextSignatureFromInternalDoc (m -> m_ml -> ml_name ,
196
199
m -> m_ml -> ml_doc ,
197
200
m -> m_ml -> ml_flags );
198
201
}
199
202
200
203
static PyObject *
201
- meth_get__doc__ (PyCFunctionObject * m , void * closure )
204
+ meth_get__doc__ (PyObject * self , void * closure )
202
205
{
206
+ PyCFunctionObject * m = _PyCFunctionObject_CAST (self );
203
207
return _PyType_GetDocFromInternalDoc (m -> m_ml -> ml_name , m -> m_ml -> ml_doc );
204
208
}
205
209
206
210
static PyObject *
207
- meth_get__name__ (PyCFunctionObject * m , void * closure )
211
+ meth_get__name__ (PyObject * self , void * closure )
208
212
{
213
+ PyCFunctionObject * m = _PyCFunctionObject_CAST (self );
209
214
return PyUnicode_FromString (m -> m_ml -> ml_name );
210
215
}
211
216
212
217
static PyObject *
213
- meth_get__qualname__ (PyCFunctionObject * m , void * closure )
218
+ meth_get__qualname__ (PyObject * self , void * closure )
214
219
{
215
220
/* If __self__ is a module or NULL, return m.__name__
216
221
(e.g. len.__qualname__ == 'len')
@@ -220,14 +225,15 @@ meth_get__qualname__(PyCFunctionObject *m, void *closure)
220
225
221
226
Otherwise return type(m.__self__).__qualname__ + '.' + m.__name__
222
227
(e.g. [].append.__qualname__ == 'list.append') */
223
- PyObject * type , * type_qualname , * res ;
224
228
225
- if (m -> m_self == NULL || PyModule_Check (m -> m_self ))
229
+ PyCFunctionObject * m = _PyCFunctionObject_CAST (self );
230
+ if (m -> m_self == NULL || PyModule_Check (m -> m_self )) {
226
231
return PyUnicode_FromString (m -> m_ml -> ml_name );
232
+ }
227
233
228
- type = PyType_Check (m -> m_self ) ? m -> m_self : (PyObject * )Py_TYPE (m -> m_self );
234
+ PyObject * type = PyType_Check (m -> m_self ) ? m -> m_self : (PyObject * )Py_TYPE (m -> m_self );
229
235
230
- type_qualname = PyObject_GetAttr (type , & _Py_ID (__qualname__ ));
236
+ PyObject * type_qualname = PyObject_GetAttr (type , & _Py_ID (__qualname__ ));
231
237
if (type_qualname == NULL )
232
238
return NULL ;
233
239
@@ -238,37 +244,38 @@ meth_get__qualname__(PyCFunctionObject *m, void *closure)
238
244
return NULL ;
239
245
}
240
246
241
- res = PyUnicode_FromFormat ("%S.%s" , type_qualname , m -> m_ml -> ml_name );
247
+ PyObject * res = PyUnicode_FromFormat ("%S.%s" , type_qualname , m -> m_ml -> ml_name );
242
248
Py_DECREF (type_qualname );
243
249
return res ;
244
250
}
245
251
246
252
static int
247
- meth_traverse (PyCFunctionObject * m , visitproc visit , void * arg )
253
+ meth_traverse (PyObject * self , visitproc visit , void * arg )
248
254
{
255
+ PyCFunctionObject * m = _PyCFunctionObject_CAST (self );
249
256
Py_VISIT (PyCFunction_GET_CLASS (m ));
250
257
Py_VISIT (m -> m_self );
251
258
Py_VISIT (m -> m_module );
252
259
return 0 ;
253
260
}
254
261
255
262
static PyObject *
256
- meth_get__self__ (PyCFunctionObject * m , void * closure )
263
+ meth_get__self__ (PyObject * meth , void * closure )
257
264
{
258
- PyObject * self ;
259
-
260
- self = PyCFunction_GET_SELF (m );
261
- if (self == NULL )
265
+ PyCFunctionObject * m = _PyCFunctionObject_CAST (meth );
266
+ PyObject * self = PyCFunction_GET_SELF (m );
267
+ if (self == NULL ) {
262
268
self = Py_None ;
269
+ }
263
270
return Py_NewRef (self );
264
271
}
265
272
266
- static PyGetSetDef meth_getsets [] = {
267
- {"__doc__" , ( getter ) meth_get__doc__ , NULL , NULL },
268
- {"__name__" , ( getter ) meth_get__name__ , NULL , NULL },
269
- {"__qualname__" , ( getter ) meth_get__qualname__ , NULL , NULL },
270
- {"__self__" , ( getter ) meth_get__self__ , NULL , NULL },
271
- {"__text_signature__" , ( getter ) meth_get__text_signature__ , NULL , NULL },
273
+ static PyGetSetDef meth_getsets [] = {
274
+ {"__doc__" , meth_get__doc__ , NULL , NULL },
275
+ {"__name__" , meth_get__name__ , NULL , NULL },
276
+ {"__qualname__" , meth_get__qualname__ , NULL , NULL },
277
+ {"__self__" , meth_get__self__ , NULL , NULL },
278
+ {"__text_signature__" , meth_get__text_signature__ , NULL , NULL },
272
279
{0 }
273
280
};
274
281
@@ -280,15 +287,18 @@ static PyMemberDef meth_members[] = {
280
287
};
281
288
282
289
static PyObject *
283
- meth_repr (PyCFunctionObject * m )
290
+ meth_repr (PyObject * self )
284
291
{
285
- if (m -> m_self == NULL || PyModule_Check (m -> m_self ))
292
+ PyCFunctionObject * m = _PyCFunctionObject_CAST (self );
293
+ if (m -> m_self == NULL || PyModule_Check (m -> m_self )) {
286
294
return PyUnicode_FromFormat ("<built-in function %s>" ,
287
- m -> m_ml -> ml_name );
295
+ m -> m_ml -> ml_name );
296
+ }
297
+
288
298
return PyUnicode_FromFormat ("<built-in method %s of %s object at %p>" ,
289
- m -> m_ml -> ml_name ,
290
- Py_TYPE (m -> m_self )-> tp_name ,
291
- m -> m_self );
299
+ m -> m_ml -> ml_name ,
300
+ Py_TYPE (m -> m_self )-> tp_name ,
301
+ m -> m_self );
292
302
}
293
303
294
304
static PyObject *
@@ -317,14 +327,15 @@ meth_richcompare(PyObject *self, PyObject *other, int op)
317
327
}
318
328
319
329
static Py_hash_t
320
- meth_hash (PyCFunctionObject * a )
330
+ meth_hash (PyObject * self )
321
331
{
322
- Py_hash_t x , y ;
323
- x = PyObject_GenericHash (a -> m_self );
324
- y = _Py_HashPointer ((void * )(a -> m_ml -> ml_meth ));
332
+ PyCFunctionObject * a = _PyCFunctionObject_CAST ( self ) ;
333
+ Py_hash_t x = PyObject_GenericHash (a -> m_self );
334
+ Py_hash_t y = _Py_HashPointer ((void * )(a -> m_ml -> ml_meth ));
325
335
x ^= y ;
326
- if (x == -1 )
336
+ if (x == -1 ) {
327
337
x = -2 ;
338
+ }
328
339
return x ;
329
340
}
330
341
@@ -334,16 +345,16 @@ PyTypeObject PyCFunction_Type = {
334
345
"builtin_function_or_method" ,
335
346
sizeof (PyCFunctionObject ),
336
347
0 ,
337
- ( destructor ) meth_dealloc , /* tp_dealloc */
348
+ meth_dealloc , /* tp_dealloc */
338
349
offsetof(PyCFunctionObject , vectorcall ), /* tp_vectorcall_offset */
339
350
0 , /* tp_getattr */
340
351
0 , /* tp_setattr */
341
352
0 , /* tp_as_async */
342
- ( reprfunc ) meth_repr , /* tp_repr */
353
+ meth_repr , /* tp_repr */
343
354
0 , /* tp_as_number */
344
355
0 , /* tp_as_sequence */
345
356
0 , /* tp_as_mapping */
346
- ( hashfunc ) meth_hash , /* tp_hash */
357
+ meth_hash , /* tp_hash */
347
358
cfunction_call , /* tp_call */
348
359
0 , /* tp_str */
349
360
PyObject_GenericGetAttr , /* tp_getattro */
@@ -352,7 +363,7 @@ PyTypeObject PyCFunction_Type = {
352
363
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
353
364
Py_TPFLAGS_HAVE_VECTORCALL , /* tp_flags */
354
365
0 , /* tp_doc */
355
- ( traverseproc ) meth_traverse , /* tp_traverse */
366
+ meth_traverse , /* tp_traverse */
356
367
0 , /* tp_clear */
357
368
meth_richcompare , /* tp_richcompare */
358
369
offsetof(PyCFunctionObject , m_weakreflist ), /* tp_weaklistoffset */
0 commit comments