@@ -308,6 +308,32 @@ test_dict_inner(int count)
308308 }
309309}
310310
311+ static PyObject * pytype_fromspec_meta (PyObject * self , PyObject * meta )
312+ {
313+ if (!PyType_Check (meta )) {
314+ PyErr_SetString (
315+ TestError ,
316+ "pytype_fromspec_meta: must be invoked with a type argument!" );
317+ return NULL ;
318+ }
319+
320+ PyType_Slot HeapCTypeViaMetaclass_slots [] = {
321+ {0 },
322+ };
323+
324+ PyType_Spec HeapCTypeViaMetaclass_spec = {
325+ "_testcapi.HeapCTypeViaMetaclass" ,
326+ sizeof (PyObject ),
327+ 0 ,
328+ Py_TPFLAGS_DEFAULT ,
329+ HeapCTypeViaMetaclass_slots
330+ };
331+
332+ return PyType_FromMetaclass (
333+ (PyTypeObject * ) meta , NULL , & HeapCTypeViaMetaclass_spec , NULL );
334+ }
335+
336+
311337static PyObject *
312338test_dict_iteration (PyObject * self , PyObject * Py_UNUSED (ignored ))
313339{
@@ -5886,6 +5912,7 @@ static PyMethodDef TestMethods[] = {
58865912 {"test_long_numbits" , test_long_numbits , METH_NOARGS },
58875913 {"test_k_code" , test_k_code , METH_NOARGS },
58885914 {"test_empty_argparse" , test_empty_argparse , METH_NOARGS },
5915+ {"pytype_fromspec_meta" , pytype_fromspec_meta , METH_O },
58895916 {"parse_tuple_and_keywords" , parse_tuple_and_keywords , METH_VARARGS },
58905917 {"pyobject_repr_from_null" , pyobject_repr_from_null , METH_NOARGS },
58915918 {"pyobject_str_from_null" , pyobject_str_from_null , METH_NOARGS },
@@ -7078,6 +7105,38 @@ static PyType_Spec HeapCTypeSubclassWithFinalizer_spec = {
70787105 HeapCTypeSubclassWithFinalizer_slots
70797106};
70807107
7108+ static PyType_Slot HeapCTypeMetaclass_slots [] = {
7109+ {0 },
7110+ };
7111+
7112+ static PyType_Spec HeapCTypeMetaclass_spec = {
7113+ "_testcapi.HeapCTypeMetaclass" ,
7114+ sizeof (PyHeapTypeObject ),
7115+ sizeof (PyMemberDef ),
7116+ Py_TPFLAGS_DEFAULT ,
7117+ HeapCTypeMetaclass_slots
7118+ };
7119+
7120+ static PyObject *
7121+ heap_ctype_metaclass_custom_tp_new (PyTypeObject * tp , PyObject * args , PyObject * kwargs )
7122+ {
7123+ return PyType_Type .tp_new (tp , args , kwargs );
7124+ }
7125+
7126+ static PyType_Slot HeapCTypeMetaclassCustomNew_slots [] = {
7127+ { Py_tp_new , heap_ctype_metaclass_custom_tp_new },
7128+ {0 },
7129+ };
7130+
7131+ static PyType_Spec HeapCTypeMetaclassCustomNew_spec = {
7132+ "_testcapi.HeapCTypeMetaclassCustomNew" ,
7133+ sizeof (PyHeapTypeObject ),
7134+ sizeof (PyMemberDef ),
7135+ Py_TPFLAGS_DEFAULT ,
7136+ HeapCTypeMetaclassCustomNew_slots
7137+ };
7138+
7139+
70817140typedef struct {
70827141 PyObject_HEAD
70837142 PyObject * dict ;
@@ -7591,6 +7650,20 @@ PyInit__testcapi(void)
75917650 Py_DECREF (subclass_with_finalizer_bases );
75927651 PyModule_AddObject (m , "HeapCTypeSubclassWithFinalizer" , HeapCTypeSubclassWithFinalizer );
75937652
7653+ PyObject * HeapCTypeMetaclass = PyType_FromMetaclass (
7654+ & PyType_Type , m , & HeapCTypeMetaclass_spec , (PyObject * ) & PyType_Type );
7655+ if (HeapCTypeMetaclass == NULL ) {
7656+ return NULL ;
7657+ }
7658+ PyModule_AddObject (m , "HeapCTypeMetaclass" , HeapCTypeMetaclass );
7659+
7660+ PyObject * HeapCTypeMetaclassCustomNew = PyType_FromMetaclass (
7661+ & PyType_Type , m , & HeapCTypeMetaclassCustomNew_spec , (PyObject * ) & PyType_Type );
7662+ if (HeapCTypeMetaclassCustomNew == NULL ) {
7663+ return NULL ;
7664+ }
7665+ PyModule_AddObject (m , "HeapCTypeMetaclassCustomNew" , HeapCTypeMetaclassCustomNew );
7666+
75947667 if (PyType_Ready (& ContainerNoGC_type ) < 0 ) {
75957668 return NULL ;
75967669 }
0 commit comments