@@ -308,6 +308,32 @@ test_dict_inner(int count)
308
308
}
309
309
}
310
310
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
+
311
337
static PyObject *
312
338
test_dict_iteration (PyObject * self , PyObject * Py_UNUSED (ignored ))
313
339
{
@@ -5886,6 +5912,7 @@ static PyMethodDef TestMethods[] = {
5886
5912
{"test_long_numbits" , test_long_numbits , METH_NOARGS },
5887
5913
{"test_k_code" , test_k_code , METH_NOARGS },
5888
5914
{"test_empty_argparse" , test_empty_argparse , METH_NOARGS },
5915
+ {"pytype_fromspec_meta" , pytype_fromspec_meta , METH_O },
5889
5916
{"parse_tuple_and_keywords" , parse_tuple_and_keywords , METH_VARARGS },
5890
5917
{"pyobject_repr_from_null" , pyobject_repr_from_null , METH_NOARGS },
5891
5918
{"pyobject_str_from_null" , pyobject_str_from_null , METH_NOARGS },
@@ -7078,6 +7105,38 @@ static PyType_Spec HeapCTypeSubclassWithFinalizer_spec = {
7078
7105
HeapCTypeSubclassWithFinalizer_slots
7079
7106
};
7080
7107
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
+
7081
7140
typedef struct {
7082
7141
PyObject_HEAD
7083
7142
PyObject * dict ;
@@ -7591,6 +7650,20 @@ PyInit__testcapi(void)
7591
7650
Py_DECREF (subclass_with_finalizer_bases );
7592
7651
PyModule_AddObject (m , "HeapCTypeSubclassWithFinalizer" , HeapCTypeSubclassWithFinalizer );
7593
7652
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
+
7594
7667
if (PyType_Ready (& ContainerNoGC_type ) < 0 ) {
7595
7668
return NULL ;
7596
7669
}
0 commit comments