@@ -84,7 +84,10 @@ PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *c
8484 "flag but no class" );
8585 return NULL ;
8686 }
87- PyCMethodObject * om = PyObject_GC_New (PyCMethodObject , & PyCMethod_Type );
87+ PyCMethodObject * om = PyObject_GC_NewVar (
88+ PyCMethodObject ,
89+ & PyCFunction_Type ,
90+ sizeof (PyCMethodObject ) - sizeof (PyCFunctionObject ));
8891 if (om == NULL ) {
8992 return NULL ;
9093 }
@@ -99,7 +102,7 @@ PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *c
99102 return NULL ;
100103 }
101104 else {
102- op = PyObject_GC_New (PyCFunctionObject , & PyCFunction_Type );
105+ op = PyObject_GC_NewVar (PyCFunctionObject , & PyCFunction_Type , 0 );
103106 if (op == NULL )
104107 return NULL ;
105108 }
@@ -334,7 +337,7 @@ PyTypeObject PyCFunction_Type = {
334337 PyVarObject_HEAD_INIT (& PyType_Type , 0 )
335338 "builtin_function_or_method" ,
336339 sizeof (PyCFunctionObject ),
337- 0 ,
340+ 1 ,
338341 (destructor )meth_dealloc , /* tp_dealloc */
339342 offsetof(PyCFunctionObject , vectorcall ), /* tp_vectorcall_offset */
340343 0 , /* tp_getattr */
@@ -366,26 +369,6 @@ PyTypeObject PyCFunction_Type = {
366369 0 , /* tp_dict */
367370};
368371
369- PyTypeObject PyCMethod_Type = {
370- PyVarObject_HEAD_INIT (& PyType_Type , 0 )
371- .tp_name = "builtin_c_method" ,
372- .tp_basicsize = sizeof (PyCMethodObject ),
373- .tp_dealloc = (destructor )meth_dealloc ,
374- .tp_repr = (reprfunc )meth_repr ,
375- .tp_hash = (hashfunc )meth_hash ,
376- .tp_call = cfunction_call ,
377- .tp_getattro = PyObject_GenericGetAttr ,
378- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC ,
379- .tp_traverse = (traverseproc )meth_traverse ,
380- .tp_richcompare = meth_richcompare ,
381- .tp_weaklistoffset = offsetof(PyCFunctionObject , m_weakreflist ),
382- .tp_methods = meth_methods ,
383- .tp_members = meth_members ,
384- .tp_getset = meth_getsets ,
385- .tp_base = & PyCFunction_Type ,
386- .tp_vectorcall_offset = offsetof(PyCFunctionObject , vectorcall ),
387- };
388-
389372/* Vectorcall functions for each of the PyCFunction calling conventions,
390373 * except for METH_VARARGS (possibly combined with METH_KEYWORDS) which
391374 * doesn't use vectorcall.
0 commit comments